/[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 41 - (show annotations) (download)
Tue Aug 11 18:50:37 2015 UTC (8 years, 7 months ago) by zoff99
File size: 5953 byte(s)
many fixes, and new features
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.os.Bundle;
25 import android.os.Handler;
26 import android.os.Message;
27 import android.util.TypedValue;
28 import android.view.Gravity;
29 import android.view.View;
30 import android.view.View.OnClickListener;
31 import android.widget.Button;
32 import android.widget.LinearLayout;
33 import android.widget.RelativeLayout.LayoutParams;
34 import android.widget.TextView;
35
36 public class ZANaviDownloadMapCancelActivity extends Activity
37 {
38
39 public static TextView addr_view2 = null;
40 TextView addr_view = null;
41 TextView info_view = null;
42 private static ZANaviDownloadMapCancelActivity my_object = null;
43
44 @Override
45 protected void onCreate(Bundle savedInstanceState)
46 {
47 Navit.applySharedTheme(this, Navit.p.PREF_current_theme);
48
49 super.onCreate(savedInstanceState);
50
51 my_object = this;
52
53 // panel linearlayout
54 LinearLayout panel = new LinearLayout(this);
55 panel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
56 panel.setOrientation(LinearLayout.VERTICAL);
57
58 // header text
59 addr_view = new TextView(this);
60 addr_view.setText(Navit.get_text("Stop map download?")); //TRANS
61 addr_view.setGravity(Gravity.CENTER);
62 addr_view.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f);
63 addr_view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
64 addr_view.setPadding(4, 10, 4, 10);
65
66 // info text
67 info_view = new TextView(this);
68 info_view.setText(Navit.get_text("press HOME to download in the background")); //TRANS
69 info_view.setGravity(Gravity.CENTER);
70 info_view.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f);
71 info_view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
72 info_view.setPadding(4, 10, 4, 10);
73
74 // message
75 addr_view2 = new TextView(this);
76 addr_view2.setText("");
77 addr_view2.setGravity(Gravity.CENTER_HORIZONTAL);
78 addr_view2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f);
79 addr_view2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
80 addr_view2.setPadding(4, 10, 4, 10);
81
82 // "Yes" button
83 final Button btnSearch = new Button(this);
84 btnSearch.setText(Navit.get_text("Yes")); //TRANS
85 btnSearch.setPadding(4, 10, 4, 10);
86 btnSearch.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25f);
87 btnSearch.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
88 btnSearch.setGravity(Gravity.CENTER);
89 btnSearch.setOnClickListener(new OnClickListener()
90 {
91 public void onClick(View v)
92 {
93 // ----- service stop -----
94 // ----- service stop -----
95 System.out.println("Navit:map download cancel dialog -> stop ZANaviMapDownloaderService ---------");
96 try
97 {
98 ZANaviMapDownloaderService.stop_downloading();
99 }
100 catch (Exception e)
101 {
102 }
103
104 try
105 {
106 Navit.getBaseContext_.stopService(Navit.ZANaviMapDownloaderServiceIntent);
107 }
108 catch (Exception e)
109 {
110 }
111 // ----- service stop -----
112 // ----- service stop -----
113
114 executeDone(1);
115 }
116 });
117
118 // "No" button
119 final Button btnSearch2 = new Button(this);
120 btnSearch2.setText(Navit.get_text("No")); //TRANS
121 btnSearch2.setPadding(4, 10, 4, 10);
122 btnSearch2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25f);
123 btnSearch2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
124 btnSearch2.setGravity(Gravity.CENTER);
125 btnSearch2.setOnClickListener(new OnClickListener()
126 {
127 public void onClick(View v)
128 {
129 executeDone(0);
130 }
131 });
132
133 // actually adding the views (that have layout set on them) to the panel
134 panel.addView(addr_view);
135 panel.addView(btnSearch);
136 panel.addView(btnSearch2);
137 panel.addView(info_view);
138 panel.addView(addr_view2);
139
140 // set the main view
141 setContentView(panel);
142 }
143
144 public static Handler canceldialog_handler = new Handler()
145 {
146 public void handleMessage(Message msg)
147 {
148 switch (msg.what)
149 {
150 case 0:
151 try
152 {
153 String text1 = msg.getData().getString("text");
154 ZANaviDownloadMapCancelActivity.addr_view2.setText(text1);
155 ZANaviDownloadMapCancelActivity.addr_view2.postInvalidate();
156 }
157 catch (Exception e)
158 {
159 //e.printStackTrace();
160 }
161 break;
162 case 1:
163 try
164 {
165 // clear this activity (map is ready)
166 ZANaviDownloadMapCancelActivity.addr_view2.setText("");
167 ZANaviDownloadMapCancelActivity.addr_view2.postInvalidate();
168 }
169 catch (Exception e)
170 {
171 //e.printStackTrace();
172 }
173
174 try
175 {
176 my_object.executeDone(1);
177 }
178 catch (Exception e)
179 {
180 //e.printStackTrace();
181 }
182 break;
183 }
184 }
185 };
186
187 private void executeDone(int code)
188 {
189 System.out.println("Navit:map download cancel dialog -> executeDone()");
190
191 Intent resultIntent = new Intent();
192 if (code == 0)
193 {
194 setResult(Activity.RESULT_CANCELED, resultIntent);
195 }
196 else
197 {
198 setResult(Activity.RESULT_OK, resultIntent);
199 }
200
201 finish();
202 }
203 }

   
Visit the ZANavi Wiki