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

   
Visit the ZANavi Wiki