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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations) (download)
Tue Aug 11 18:50:37 2015 UTC (8 years, 8 months ago) by zoff99
File size: 5724 byte(s)
many fixes, and new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011 - 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.Notification;
23 import android.app.NotificationManager;
24 import android.app.PendingIntent;
25 import android.app.Service;
26 import android.content.Context;
27 import android.content.Intent;
28 import android.os.Bundle;
29 import android.os.IBinder;
30 import android.os.Message;
31
32 import com.zoffcc.applications.zanavi.NavitMapDownloader.ProgressThread;
33
34 public class ZANaviMapDownloaderService extends Service
35 {
36 private static NotificationManager nm;
37 private static Notification notification;
38 public static int NOTIFICATION_ID__DUMMY = 1;
39 public static int NOTIFICATION_ID__DUMMY2 = 2;
40 public static String Notification_header = "";
41 public static String Notification_text = "";
42 private static Context con = null;
43 private static PendingIntent p_activity = null;
44 private static Intent notificationIntent = null;
45
46 private static ProgressThread progressThread_pri = null;
47 public static boolean service_running = false;
48 private static ZANaviMapDownloaderService my_object = null;
49
50 @Override
51 public int onStartCommand(Intent intent, int flags, int startId)
52 {
53 System.out.println("ZANaviMapDownloaderService: ************************ start ************************");
54
55 Notification_header = "ZANavi";
56 Notification_text = Navit.get_text("downloading, please wait ...");
57
58 con = this;
59
60 nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
61 notification = new Notification(R.drawable.icon, Navit.get_text("downloading, please wait ..."), System.currentTimeMillis());
62 notification.flags = Notification.FLAG_NO_CLEAR;
63 notificationIntent = new Intent(con, ZANaviDownloadMapCancelActivity.class);
64 notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
65 p_activity = PendingIntent.getActivity(con, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
66
67 notification.setLatestEventInfo(con, Notification_header, Notification_text, p_activity);
68
69 try
70 {
71 nm.notify(NOTIFICATION_ID__DUMMY, notification);
72 }
73 catch (Exception e)
74 {
75 e.printStackTrace();
76
77 try
78 {
79 p_activity = PendingIntent.getActivity(con, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
80 notification.setLatestEventInfo(con, Notification_header, Notification_text, p_activity);
81 nm.notify(NOTIFICATION_ID__DUMMY, notification);
82 }
83 catch (Exception e2)
84 {
85 e2.printStackTrace();
86 }
87 }
88
89 service_running = true;
90
91 start_map_download();
92 System.out.println("ZANaviMapDownloaderService: ************************ start(finished) ************************");
93
94 return Service.START_NOT_STICKY;
95 }
96
97 @Override
98 public IBinder onBind(Intent intent)
99 {
100 return null;
101 }
102
103 public static void start_map_download()
104 {
105 try
106 {
107 System.out.println("ZANaviMapDownloaderService: xxxxxxxx download start xxxxxxxx");
108 Navit.mapdownloader_pri = new NavitMapDownloader(Navit.Global_Navit_Object);
109 progressThread_pri = Navit.mapdownloader_pri.new ProgressThread(Navit.Navit_progress_h, NavitMapDownloader.z_OSM_MAPS[Navit.download_map_id], Navit.MAP_NUM_PRIMARY);
110 progressThread_pri.start();
111 }
112 catch (Exception e)
113 {
114 }
115 }
116
117 public static void set_noti_text(String text)
118 {
119 try
120 {
121 // System.out.println("ZANaviMapDownloaderService: !!!!!!!!! NOTIFY !!!!!!!!!" + " text=" + text + " con=" + con + " p_activity=" + p_activity);
122 Notification_text = text;
123 notification.setLatestEventInfo(con, Notification_header, Notification_text, p_activity);
124 nm.notify(NOTIFICATION_ID__DUMMY, notification);
125 }
126 catch (Exception e)
127 {
128 }
129 }
130
131 public static void set_large_text(String text)
132 {
133 try
134 {
135 Message msg2 = new Message();
136 Bundle b2 = new Bundle();
137 b2.putString("text", text);
138 msg2.what = 0;
139 msg2.setData(b2);
140 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg2);
141 }
142 catch (Exception e)
143 {
144 }
145 }
146
147 public static void stop_downloading()
148 {
149 System.out.println("ZANaviMapDownloaderService: xxxxxxxx download stop 1 xxxxxxxx");
150 try
151 {
152 progressThread_pri.stop_thread();
153 }
154 catch (Exception e)
155 {
156 }
157
158 try
159 {
160 my_object.stopSelf();
161 }
162 catch (Exception e)
163 {
164 }
165
166 try
167 {
168 nm.cancel(NOTIFICATION_ID__DUMMY);
169 }
170 catch (Exception e)
171 {
172 }
173
174 System.out.println("ZANaviMapDownloaderService: xxxxxxxx download stop 2 xxxxxxxx");
175 }
176
177 public void onCreate()
178 {
179 my_object = this;
180 }
181
182 @Override
183 public void onDestroy()
184 {
185 super.onDestroy();
186
187 try
188 {
189 nm.cancel(NOTIFICATION_ID__DUMMY);
190 }
191 catch (Exception e)
192 {
193 }
194
195 try
196 {
197 progressThread_pri.stop_thread();
198 }
199 catch (Exception e)
200 {
201 }
202
203 System.out.println("ZANaviMapDownloaderService: ####################### STOPPED #######################");
204
205 service_running = false;
206 }
207
208 }

   
Visit the ZANavi Wiki