/[zanavi_public1]/navit/navit/android/src/com/zoffcc/applications/zanavi/ZANaviDownloadMapCancelActivity.java
ZANavi

Contents of /navit/navit/android/src/com/zoffcc/applications/zanavi/ZANaviDownloadMapCancelActivity.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (show annotations) (download)
Sat Sep 12 11:02:16 2015 UTC (8 years, 6 months ago) by zoff99
File size: 9071 byte(s)
v2.0.48
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2014 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 package com.zoffcc.applications.zanavi;
21
22 import android.app.Activity;
23 import android.content.Intent;
24 import android.content.res.Resources;
25 import android.graphics.drawable.Drawable;
26 import android.os.Bundle;
27 import android.os.Handler;
28 import android.os.Message;
29 import android.support.v7.app.ActionBarActivity;
30 import android.util.TypedValue;
31 import android.view.Gravity;
32 import android.view.View;
33 import android.view.View.OnClickListener;
34 import android.widget.Button;
35 import android.widget.ProgressBar;
36 import android.widget.TextView;
37
38 public class ZANaviDownloadMapCancelActivity extends ActionBarActivity
39 {
40
41 public static TextView addr_view2 = null;
42 TextView addr_view = null;
43 TextView info_view = null;
44 private static ZANaviDownloadMapCancelActivity my_object = null;
45 static ProgressBar pg = null;
46 static ProgressBar[] pg_speed = null;
47 static Drawable[] pg_speed_d = null;
48 static TextView[] pg_speed_txt = null;
49
50 @Override
51 protected void onCreate(Bundle savedInstanceState)
52 {
53 Navit.applySharedTheme(this, Navit.p.PREF_current_theme);
54
55 super.onCreate(savedInstanceState);
56
57 my_object = this;
58
59 setContentView(R.layout.activity_download_cancel_activity);
60
61 android.support.v7.widget.Toolbar bar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar2nd);
62 bar.setTitle(Navit.get_text("Download"));
63 bar.setNavigationOnClickListener(new View.OnClickListener()
64 {
65 @Override
66 public void onClick(View v)
67 {
68 finish();
69 }
70 });
71
72 // // header text
73 addr_view = (TextView) findViewById(R.id.addr_view);
74 addr_view.setText(Navit.get_text("Stop map download?")); //TRANS
75 addr_view.setGravity(Gravity.CENTER);
76 addr_view.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f);
77 // addr_view.setPadding(4, 10, 4, 10);
78 //
79 // // info text
80 info_view = (TextView) findViewById(R.id.info_view);
81 info_view.setText(Navit.get_text("press HOME to download in the background")); //TRANS
82 info_view.setGravity(Gravity.CENTER);
83 info_view.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f);
84 // info_view.setPadding(4, 10, 4, 10);
85 //
86 // // message
87 addr_view2 = (TextView) findViewById(R.id.addr_view2);
88 addr_view2.setText("");
89 addr_view2.setGravity(Gravity.CENTER_HORIZONTAL);
90 addr_view2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f);
91 // addr_view2.setPadding(4, 10, 4, 10);
92 //
93 // // "Yes" button
94 final Button btnSearch = (Button) findViewById(R.id.btnSearch);
95 btnSearch.setText(Navit.get_text("Yes")); //TRANS
96 // btnSearch.setPadding(4, 10, 4, 10);
97 btnSearch.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25f);
98 btnSearch.setGravity(Gravity.CENTER);
99 btnSearch.setOnClickListener(new OnClickListener()
100 {
101 public void onClick(View v)
102 {
103 // ----- service stop -----
104 // ----- service stop -----
105 System.out.println("Navit:map download cancel dialog -> stop ZANaviMapDownloaderService ---------");
106 try
107 {
108 ZANaviMapDownloaderService.stop_downloading();
109 }
110 catch (Exception e)
111 {
112 }
113
114 try
115 {
116 Navit.getBaseContext_.stopService(Navit.ZANaviMapDownloaderServiceIntent);
117 }
118 catch (Exception e)
119 {
120 }
121 // ----- service stop -----
122 // ----- service stop -----
123
124 executeDone(1);
125 }
126 });
127
128 // // "No" button
129 final Button btnSearch2 = (Button) findViewById(R.id.btnSearch2);
130
131 btnSearch2.setText(Navit.get_text("No")); //TRANS
132 // btnSearch2.setPadding(4, 10, 4, 10);
133 btnSearch2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25f);
134 btnSearch2.setGravity(Gravity.CENTER);
135 btnSearch2.setOnClickListener(new OnClickListener()
136 {
137 public void onClick(View v)
138 {
139 executeDone(0);
140 }
141 });
142
143 pg = (ProgressBar) findViewById(R.id.mapdownload_prog_bar);
144 pg.setProgress(0);
145
146 pg_speed = new ProgressBar[NavitMapDownloader.MULTI_NUM_THREADS_MAX];
147 pg_speed_d = new Drawable[NavitMapDownloader.MULTI_NUM_THREADS_MAX];
148 pg_speed_txt = new TextView[NavitMapDownloader.MULTI_NUM_THREADS_MAX];
149
150 Resources r = getResources();
151 int pg_i = 0;
152 int pg_speed_id = 0;
153 for (pg_i = 0; pg_i < NavitMapDownloader.MULTI_NUM_THREADS_MAX; pg_i++)
154 {
155 try
156 {
157 pg_speed[pg_i] = null;
158 pg_speed_id = r.getIdentifier("mapdownload_speed_bar_t00" + (pg_i + 1), "id", "com.zoffcc.applications.zanavi");
159 pg_speed[pg_i] = (ProgressBar) findViewById(pg_speed_id);
160 //if (pg_i >= NavitMapDownloader.MULTI_NUM_THREADS)
161 //{
162 pg_speed[pg_i].setVisibility(View.INVISIBLE);
163 //}
164 pg_speed_d[pg_i] = pg_speed[pg_i].getProgressDrawable();
165
166 pg_speed_txt[pg_i] = (TextView) findViewById(r.getIdentifier("mapdownload_speed_text_t00" + (pg_i + 1), "id", "com.zoffcc.applications.zanavi"));
167 pg_speed_txt[pg_i].setVisibility(View.INVISIBLE);
168 }
169 catch (Exception e2)
170 {
171 System.out.println("PGB:EE3=" + e2.getMessage());
172 }
173 }
174 }
175
176 public static Handler canceldialog_handler = new Handler()
177 {
178 public void handleMessage(Message msg)
179 {
180 switch (msg.what)
181 {
182 case 0:
183 try
184 {
185 String text1 = msg.getData().getString("text");
186 ZANaviDownloadMapCancelActivity.addr_view2.setText(text1);
187 ZANaviDownloadMapCancelActivity.addr_view2.postInvalidate();
188 }
189 catch (Exception e)
190 {
191 //e.printStackTrace();
192 }
193 break;
194 case 1:
195 try
196 {
197 // clear this activity (map is ready)
198 ZANaviDownloadMapCancelActivity.addr_view2.setText("");
199 ZANaviDownloadMapCancelActivity.addr_view2.postInvalidate();
200 }
201 catch (Exception e)
202 {
203 //e.printStackTrace();
204 }
205
206 try
207 {
208 my_object.executeDone(1);
209 }
210 catch (Exception e)
211 {
212 //e.printStackTrace();
213 }
214 break;
215 case 2:
216 try
217 {
218 ZANaviDownloadMapCancelActivity.pg.setProgress(msg.getData().getInt("pg"));
219 // System.out.println("PG_percent=" + msg.getData().getInt("pg"));
220 // ZANaviDownloadMapCancelActivity.pg.postInvalidate();
221 }
222 catch (Exception e)
223 {
224 // System.out.println("PG_percent:EE:" + e.getMessage());
225 }
226 break;
227 case 3:
228 try
229 {
230 final int max_kb_per_sec = 3000;
231 int t_num = msg.getData().getInt("threadnum");
232 int speed = msg.getData().getInt("speed_kb_per_sec");
233
234 // System.out.println("PGB:num=" + t_num);
235
236 if (speed == -1)
237 {
238 pg_speed[t_num].setVisibility(View.INVISIBLE);
239 }
240 else if (speed == -2)
241 {
242 pg_speed[t_num].setVisibility(View.VISIBLE);
243 }
244 else
245 {
246 try
247 {
248 int progress = (int) (((float) speed / (float) max_kb_per_sec) * 100.f);
249 if (progress > 100)
250 {
251 progress = 100;
252 }
253 pg_speed_d[t_num].setLevel(progress * 100);
254 pg_speed[t_num].setProgress(progress);
255
256 if (pg_speed[t_num].getVisibility() == View.INVISIBLE)
257 {
258 pg_speed[t_num].setVisibility(View.VISIBLE);
259 }
260 }
261 catch (Exception e)
262 {
263 System.out.println("PGB:EE2=" + e.getMessage());
264 }
265 }
266 }
267 catch (Exception e0)
268 {
269 }
270 break;
271
272 case 4:
273 try
274 {
275 int t_num = msg.getData().getInt("threadnum");
276 String srv = msg.getData().getString("srv");
277
278 // System.out.println("PGB:srvname=" + srv + " #" + t_num);
279
280 if (srv.compareTo("-1") == 0)
281 {
282 pg_speed_txt[t_num].setVisibility(View.INVISIBLE);
283 }
284 else if (srv.compareTo("-2") == 0)
285 {
286 pg_speed_txt[t_num].setVisibility(View.VISIBLE);
287 }
288 else
289 {
290 pg_speed_txt[t_num].setText(srv + ":");
291
292 if (pg_speed_txt[t_num].getVisibility() == View.INVISIBLE)
293 {
294 pg_speed_txt[t_num].setVisibility(View.VISIBLE);
295 }
296 }
297 }
298 catch (Exception e)
299 {
300 System.out.println("PGB:EESRV=" + e.getMessage());
301 }
302 break;
303 }
304 }
305 };
306
307 private void executeDone(int code)
308 {
309 System.out.println("Navit:map download cancel dialog -> executeDone()");
310
311 Intent resultIntent = new Intent();
312 if (code == 0)
313 {
314 setResult(Activity.RESULT_CANCELED, resultIntent);
315 }
316 else
317 {
318 setResult(Activity.RESULT_OK, resultIntent);
319 }
320
321 finish();
322 }
323 }

   
Visit the ZANavi Wiki