1 |
package dk.thoerup.ekllauncher; |
package dk.thoerup.ekllauncher; |
2 |
|
|
3 |
import android.app.Activity; |
import android.app.Activity; |
4 |
|
import android.app.AlertDialog; |
5 |
import android.content.Context; |
import android.content.Context; |
6 |
|
import android.content.DialogInterface; |
7 |
import android.content.Intent; |
import android.content.Intent; |
8 |
import android.location.LocationManager; |
import android.location.LocationManager; |
9 |
import android.net.ConnectivityManager; |
import android.net.ConnectivityManager; |
11 |
import android.os.Bundle; |
import android.os.Bundle; |
12 |
import android.os.Handler; |
import android.os.Handler; |
13 |
import android.os.Message; |
import android.os.Message; |
14 |
|
import android.os.PowerManager; |
15 |
import android.provider.Settings; |
import android.provider.Settings; |
16 |
import android.telephony.TelephonyManager; |
import android.telephony.TelephonyManager; |
17 |
|
import android.text.InputType; |
18 |
import android.util.Log; |
import android.util.Log; |
19 |
import android.view.Menu; |
import android.view.Menu; |
20 |
import android.view.MenuItem; |
import android.view.MenuItem; |
21 |
import android.view.Window; |
import android.view.Window; |
22 |
|
import android.view.WindowManager; |
23 |
import android.webkit.GeolocationPermissions.Callback; |
import android.webkit.GeolocationPermissions.Callback; |
24 |
import android.webkit.JsPromptResult; |
import android.webkit.JsPromptResult; |
25 |
import android.webkit.WebChromeClient; |
import android.webkit.WebChromeClient; |
28 |
import android.webkit.WebStorage.QuotaUpdater; |
import android.webkit.WebStorage.QuotaUpdater; |
29 |
import android.webkit.WebView; |
import android.webkit.WebView; |
30 |
import android.webkit.WebViewClient; |
import android.webkit.WebViewClient; |
31 |
|
import android.widget.EditText; |
32 |
import android.widget.Toast; |
import android.widget.Toast; |
33 |
|
|
34 |
public class EKLLauncherActivity extends Activity { |
public class EKLLauncherActivity extends Activity { |
73 |
}*/ |
}*/ |
74 |
|
|
75 |
@Override |
@Override |
76 |
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { |
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, final JsPromptResult result) { |
77 |
if (message.trim().toLowerCase().equals("pda identifikation mangler")) { |
String msg = message.trim().toLowerCase(); |
78 |
result.confirm(device); |
|
79 |
|
if (msg.equals("ekl identifikation mangler")) { |
80 |
timeoutHandler.sendEmptyMessageDelayed(1, 500); //efter pdaID er sendt til app'en skal vi genindlæse siden for at tvinge den til at hente data |
if (device != null && device.equals("")==false) { |
81 |
return true; |
result.confirm(device); |
82 |
|
|
83 |
|
timeoutHandler.sendEmptyMessageDelayed(1, 500); //efter pdaID er sendt til app'en skal vi genindlæse siden for at tvinge den til at hente data |
84 |
|
return true; |
85 |
|
} else { |
86 |
|
//Hvis vi ikke kunne aflæse device, spørg user via en custom Input Dialog |
87 |
|
//Dialogen kan kun tage imod tal & |
88 |
|
//når at vi får en confirm på den tvinger vi ud i en reload af siden |
89 |
|
|
90 |
|
AlertDialog.Builder alert = new AlertDialog.Builder(EKLLauncherActivity.this); |
91 |
|
|
92 |
|
//alert.setTitle("Title"); |
93 |
|
alert.setMessage(message); |
94 |
|
|
95 |
|
// Set an EditText view to get user input |
96 |
|
final EditText input = new EditText(EKLLauncherActivity.this); |
97 |
|
input.setInputType(InputType.TYPE_CLASS_NUMBER); |
98 |
|
alert.setView(input); |
99 |
|
|
100 |
|
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { |
101 |
|
public void onClick(DialogInterface dialog, int whichButton) { |
102 |
|
result.confirm(input.getText().toString()); |
103 |
|
timeoutHandler.sendEmptyMessageDelayed(1, 500); |
104 |
|
} |
105 |
|
}); |
106 |
|
alert.show(); |
107 |
|
|
108 |
|
return true; |
109 |
|
|
110 |
|
} |
111 |
} else { |
} else { |
112 |
return super.onJsPrompt(view, url, message, defaultValue, result); |
return super.onJsPrompt(view, url, message, defaultValue, result); |
113 |
} |
} |
114 |
} |
} |
|
|
|
115 |
} |
} |
116 |
|
|
117 |
class DummyWebViewClient extends WebViewClient { |
class DummyWebViewClient extends WebViewClient { |
118 |
} |
} |
119 |
|
|
120 |
static final String URL = "http://omdeling.info/mobil/ekl/login.php"; |
static final String LOGTAG = "EklLauncher"; |
121 |
|
static final String URL = "http://omdeling.info/mobil/ekl/"; |
122 |
|
|
123 |
LocationManager locMgr; |
LocationManager locMgr; |
124 |
ConnectivityManager connMgr; |
ConnectivityManager connMgr; |
126 |
WebView web; |
WebView web; |
127 |
String device = ""; |
String device = ""; |
128 |
|
|
129 |
|
PowerManager.WakeLock wakeLock; |
130 |
|
|
131 |
|
SimHandler simHandler = new SimHandler(); |
132 |
|
|
133 |
|
@Override |
134 |
|
public void onAttachedToWindow() { |
135 |
|
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); |
136 |
|
super.onAttachedToWindow(); |
137 |
|
} |
138 |
|
|
139 |
/** Called when the activity is first created. */ |
/** Called when the activity is first created. */ |
140 |
@Override |
@Override |
141 |
public void onCreate(Bundle savedInstanceState) { |
public void onCreate(Bundle savedInstanceState) { |
142 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
143 |
|
|
144 |
|
Log.e(LOGTAG, "Creating"); |
145 |
|
|
146 |
getWindow().requestFeature(Window.FEATURE_PROGRESS); |
getWindow().requestFeature(Window.FEATURE_PROGRESS); |
147 |
|
|
148 |
|
|
149 |
try { |
try { |
150 |
int airplane = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON); |
int airplane = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON); |
151 |
|
|
152 |
if (airplane > 0) { |
if (airplane > 0) { |
153 |
Settings.System.putInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0); |
Settings.System.putInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0); |
154 |
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
158 |
} catch (Settings.SettingNotFoundException e) { |
} catch (Settings.SettingNotFoundException e) { |
159 |
Log.d("EKL", "Exception " + e.getMessage() ); |
Log.d("EKL", "Exception " + e.getMessage() ); |
160 |
} |
} |
161 |
|
|
|
|
|
|
|
|
162 |
locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); |
locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); |
163 |
telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); |
telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); |
164 |
connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); |
connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
device = telMgr.getLine1Number(); |
device = telMgr.getLine1Number(); |
170 |
if (device == null || device.equals("")) { |
if(device == null) { |
171 |
device = telMgr.getDeviceId(); |
device = ""; |
172 |
|
} |
173 |
if(device == null) |
if (device != null && device.equals("") == false){//Hvis vi kunne aflæse TLF nummer fra sim, så hvis den som en toast |
174 |
device = ""; |
Toast.makeText(EKLLauncherActivity.this, "Device: "+device, Toast.LENGTH_SHORT).show(); |
175 |
} |
} |
176 |
|
|
177 |
|
Log.i(LOGTAG, "Device Line1: " + telMgr.getLine1Number()); |
178 |
|
Log.i(LOGTAG, "Device simserial: " + telMgr.getSimSerialNumber()); |
179 |
|
Log.i(LOGTAG, "Device subscriber: " + telMgr.getSubscriberId()); |
180 |
|
Log.i(LOGTAG, "Device deviceid: " + telMgr.getDeviceId());//IMEI |
181 |
|
|
182 |
if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) { |
|
|
//Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "network,gps"); |
|
|
Toast.makeText(this, "GPS er slået fra på telefonen!", Toast.LENGTH_LONG); |
|
|
} |
|
183 |
|
|
184 |
setContentView(R.layout.main); |
setContentView(R.layout.main); |
185 |
web = (WebView) findViewById(R.id.web); |
web = (WebView) findViewById(R.id.web); |
205 |
|
|
206 |
web.setWebChromeClient(new CustomChromeClient() ); |
web.setWebChromeClient(new CustomChromeClient() ); |
207 |
web.setWebViewClient( new DummyWebViewClient() ); // skal have en webviewclient for at kunne styre ved forlad tur |
web.setWebViewClient( new DummyWebViewClient() ); // skal have en webviewclient for at kunne styre ved forlad tur |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
//Hvis at tlf rebooter mit i et område uden dækning er det ikke smart at vi skal vente på data |
212 |
|
//simHandler.sendEmptyMessage(0); |
213 |
|
web.loadUrl( URL ); |
214 |
|
|
|
simHandler.sendEmptyMessage(0); |
|
215 |
|
|
216 |
|
if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) { |
217 |
|
//Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "network,gps"); |
218 |
|
|
219 |
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
220 |
|
builder.setMessage("GPS er slået fra på telefonen!\nSæt et flueben ved GPS i næste vindue og tryk derefter på tilbage knappen (nederst på telefonen)") |
221 |
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
222 |
|
public void onClick(DialogInterface dialog, int id) { |
223 |
|
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS ); |
224 |
|
startActivity(myIntent); |
225 |
|
} |
226 |
|
}) |
227 |
|
.create() |
228 |
|
.show(); |
229 |
|
} |
230 |
|
|
231 |
|
} |
232 |
|
|
233 |
|
@Override |
234 |
|
protected void onStart() { |
235 |
|
super.onStart(); |
236 |
|
|
237 |
|
Log.e(LOGTAG, "Starting"); |
238 |
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
239 |
|
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "EklLauncher"); |
240 |
|
wakeLock.acquire(); |
241 |
|
} |
242 |
|
|
243 |
|
void showMessage(String msg) { |
244 |
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
245 |
|
builder.setMessage(msg) |
246 |
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
247 |
|
public void onClick(DialogInterface dialog, int id) { |
248 |
|
dialog.dismiss(); |
249 |
|
} |
250 |
|
}) |
251 |
|
.create() |
252 |
|
.show(); |
253 |
|
|
254 |
} |
} |
255 |
|
|
256 |
@Override |
@Override |
257 |
|
protected void onStop() { |
258 |
|
|
259 |
|
Log.e(LOGTAG, "Stopping"); |
260 |
|
|
261 |
|
if (wakeLock != null && wakeLock.isHeld()) |
262 |
|
wakeLock.release(); |
263 |
|
|
264 |
|
if (!web.getUrl().equals("about:blank")) |
265 |
|
web.loadUrl("about:blank"); |
266 |
|
|
267 |
|
super.onStop(); |
268 |
|
} |
269 |
|
|
270 |
|
static final int RELOAD = 1; |
271 |
|
static final int FLUSH = 2; |
272 |
|
static final int EXIT = 3; |
273 |
|
|
274 |
|
@Override |
275 |
public boolean onCreateOptionsMenu(Menu menu) { |
public boolean onCreateOptionsMenu(Menu menu) { |
276 |
MenuItem item; |
MenuItem item; |
277 |
item = menu.add(0, 1, 0, "Genindlæs side"); |
item = menu.add(0, RELOAD, 0, "Genindlæs side"); |
278 |
item.setIcon( R.drawable.ic_menu_refresh ); |
item.setIcon( R.drawable.ic_menu_refresh ); |
279 |
|
|
280 |
item = menu.add(0, 2, 0, "Slet cache"); |
item = menu.add(0, FLUSH, 0, "Slet cache"); |
281 |
item.setIcon( R.drawable.ic_menu_delete ); |
item.setIcon( R.drawable.ic_menu_delete ); |
282 |
|
|
283 |
|
item = menu.add(0, EXIT, 0, "Forlad"); |
284 |
|
item.setIcon( android.R.drawable.ic_menu_close_clear_cancel); |
285 |
|
|
286 |
return super.onCreateOptionsMenu(menu); |
return super.onCreateOptionsMenu(menu); |
287 |
} |
} |
288 |
|
|
289 |
@Override |
@Override |
290 |
public boolean onMenuItemSelected(int featureId, MenuItem item) { |
public boolean onMenuItemSelected(int featureId, MenuItem item) { |
291 |
switch (item.getItemId()) { |
switch (item.getItemId()) { |
292 |
case 1: |
case RELOAD: |
293 |
web.reload(); |
web.reload(); |
294 |
break; |
break; |
295 |
case 2: |
case FLUSH: |
|
WebStorage.getInstance().deleteAllData(); |
|
296 |
web.clearCache(true); |
web.clearCache(true); |
297 |
|
|
298 |
|
WebStorage.getInstance().deleteAllData(); |
299 |
|
WebStorage.getInstance().deleteOrigin(URL); |
300 |
|
|
301 |
web.reload(); |
web.reload(); |
302 |
break; |
break; |
303 |
|
case EXIT: |
304 |
|
this.finish(); |
305 |
|
break; |
306 |
} |
} |
307 |
|
|
308 |
return super.onMenuItemSelected(featureId, item); |
return super.onMenuItemSelected(featureId, item); |
309 |
} |
} |
310 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
SimHandler simHandler = new SimHandler(); |
|
323 |
|
|
324 |
class SimHandler extends Handler { |
class SimHandler extends Handler { |
325 |
|
|