1 |
/**
|
2 |
* ZANavi, Zoff Android Navigation system.
|
3 |
* Copyright (C) 2011 Zoff <zoff@zoff.cc>
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* version 2 as published by the Free Software Foundation.
|
8 |
*
|
9 |
* This program is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* GNU General Public License for more details.
|
13 |
*
|
14 |
* You should have received a copy of the GNU General Public License
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
* Boston, MA 02110-1301, USA.
|
18 |
*/
|
19 |
|
20 |
/**
|
21 |
* Navit, a modular navigation system.
|
22 |
* Copyright (C) 2005-2008 Navit Team
|
23 |
*
|
24 |
* This program is free software; you can redistribute it and/or
|
25 |
* modify it under the terms of the GNU General Public License
|
26 |
* version 2 as published by the Free Software Foundation.
|
27 |
*
|
28 |
* This program is distributed in the hope that it will be useful,
|
29 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
30 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
31 |
* GNU General Public License for more details.
|
32 |
*
|
33 |
* You should have received a copy of the GNU General Public License
|
34 |
* along with this program; if not, write to the
|
35 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
36 |
* Boston, MA 02110-1301, USA.
|
37 |
*/
|
38 |
|
39 |
package com.zoffcc.applications.zanavi;
|
40 |
|
41 |
import android.app.Activity;
|
42 |
import android.app.ListActivity;
|
43 |
import android.content.Intent;
|
44 |
import android.os.Build;
|
45 |
import android.os.Bundle;
|
46 |
import android.support.v7.widget.Toolbar;
|
47 |
import android.support.v7.widget.Toolbar.LayoutParams;
|
48 |
import android.util.Log;
|
49 |
import android.view.LayoutInflater;
|
50 |
import android.view.View;
|
51 |
import android.view.ViewGroup;
|
52 |
import android.widget.ArrayAdapter;
|
53 |
import android.widget.LinearLayout;
|
54 |
import android.widget.ListView;
|
55 |
|
56 |
public class NavitDownloadSelectMapActivity extends ListActivity
|
57 |
{
|
58 |
private int selected_id = -1;
|
59 |
private int my_id = 0;
|
60 |
|
61 |
protected void onPostCreate(Bundle savedInstanceState)
|
62 |
{
|
63 |
super.onPostCreate(savedInstanceState);
|
64 |
Toolbar bar;
|
65 |
|
66 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
67 |
{
|
68 |
ViewGroup root_view = (ViewGroup) findViewById(my_id).getParent().getParent();
|
69 |
|
70 |
bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root_view, false);
|
71 |
bar.setTitle(Navit.get_text("download maps"));
|
72 |
root_view.addView(bar, 0); // insert at top
|
73 |
}
|
74 |
else
|
75 |
{
|
76 |
ViewGroup root_view = (ViewGroup) findViewById(android.R.id.content);
|
77 |
|
78 |
System.out.println("ZZXX22:r1=" + findViewById(android.R.id.content));
|
79 |
System.out.println("ZZXX22:r2=" + findViewById(android.R.id.content).getParent());
|
80 |
System.out.println("ZZXX22:r3=" + findViewById(android.R.id.content).getParent().getParent());
|
81 |
|
82 |
View content = (View) root_view.getChildAt(0);
|
83 |
System.out.println("ZZXX22:r4=" + root_view.getChildAt(0));
|
84 |
System.out.println("ZZXX22:r5=" + root_view.getChildCount());
|
85 |
System.out.println("ZZXX22:r6=" + root_view.getChildAt(1));
|
86 |
|
87 |
root_view.removeAllViews();
|
88 |
|
89 |
LinearLayout ll = new LinearLayout(this);
|
90 |
ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
91 |
ll.setOrientation(LinearLayout.VERTICAL);
|
92 |
|
93 |
bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root_view, false);
|
94 |
bar.setTitle(Navit.get_text("download maps"));
|
95 |
root_view.addView(ll);
|
96 |
|
97 |
// int height;
|
98 |
// TypedValue tv = new TypedValue();
|
99 |
// if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true))
|
100 |
// {
|
101 |
// height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
|
102 |
// }
|
103 |
// else
|
104 |
// {
|
105 |
// height = bar.getHeight();
|
106 |
// }
|
107 |
//
|
108 |
// content.setPadding(0, height, 0, 0);
|
109 |
|
110 |
ll.addView(bar);
|
111 |
ll.addView(content);
|
112 |
}
|
113 |
|
114 |
bar.setNavigationOnClickListener(new View.OnClickListener()
|
115 |
{
|
116 |
@Override
|
117 |
public void onClick(View v)
|
118 |
{
|
119 |
finish();
|
120 |
}
|
121 |
});
|
122 |
}
|
123 |
|
124 |
@Override
|
125 |
public void onCreate(Bundle savedInstanceState)
|
126 |
{
|
127 |
Navit.applySharedTheme(this, Navit.p.PREF_current_theme);
|
128 |
|
129 |
super.onCreate(savedInstanceState);
|
130 |
//Log.e("Navit", "all ok");
|
131 |
|
132 |
//TextView text_v = new TextView(this);
|
133 |
//text_v.setText(Navit.get_text("Select Map to download")); // TRANS
|
134 |
//text_v.setTextSize(25);
|
135 |
//this.getListView().addHeaderView(text_v);
|
136 |
|
137 |
NavitMapDownloader.init();
|
138 |
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, NavitMapDownloader.OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE);
|
139 |
setListAdapter(adapter);
|
140 |
this.getListView().setFastScrollEnabled(true);
|
141 |
this.getListView().setVerticalFadingEdgeEnabled(true);
|
142 |
this.getListView().setFadingEdgeLength(25);
|
143 |
|
144 |
my_id = this.getListView().getId();
|
145 |
}
|
146 |
|
147 |
@Override
|
148 |
protected void onListItemClick(ListView l, View v, int position, long id)
|
149 |
{
|
150 |
super.onListItemClick(l, v, position, id);
|
151 |
// Get the item that was clicked
|
152 |
// Object o = this.getListAdapter().getItem(position);
|
153 |
// String keyword = o.toString();
|
154 |
this.selected_id = position;
|
155 |
//Toast.makeText(this, "You selected: " + position + " " + keyword, Toast.LENGTH_LONG).show();
|
156 |
Log.e("Navit", "p:" + position);
|
157 |
Log.e("Navit", "i:" + id);
|
158 |
|
159 |
// close this activity
|
160 |
executeDone();
|
161 |
}
|
162 |
|
163 |
// @Override
|
164 |
// public void onBackPressed()
|
165 |
// {
|
166 |
// executeDone();
|
167 |
// super.onBackPressed();
|
168 |
// }
|
169 |
|
170 |
private void executeDone()
|
171 |
{
|
172 |
Intent resultIntent = new Intent();
|
173 |
resultIntent.putExtra("selected_id", String.valueOf(this.selected_id));
|
174 |
setResult(Activity.RESULT_OK, resultIntent);
|
175 |
finish();
|
176 |
}
|
177 |
|
178 |
}
|