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; |
9 |
import android.net.ConnectivityManager; |
import android.net.ConnectivityManager; |
10 |
|
import android.net.NetworkInfo; |
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; |
23 |
import android.webkit.JsPromptResult; |
import android.webkit.JsPromptResult; |
24 |
import android.webkit.WebChromeClient; |
import android.webkit.WebChromeClient; |
25 |
import android.webkit.WebSettings; |
import android.webkit.WebSettings; |
26 |
|
import android.webkit.WebStorage; |
27 |
import android.webkit.WebStorage.QuotaUpdater; |
import android.webkit.WebStorage.QuotaUpdater; |
28 |
import android.webkit.WebView; |
import android.webkit.WebView; |
29 |
import android.webkit.WebViewClient; |
import android.webkit.WebViewClient; |
30 |
|
import android.widget.EditText; |
31 |
import android.widget.Toast; |
import android.widget.Toast; |
32 |
|
|
33 |
public class EKLLauncherActivity extends Activity { |
public class EKLLauncherActivity extends Activity { |
35 |
class CustomChromeClient extends WebChromeClient { |
class CustomChromeClient extends WebChromeClient { |
36 |
|
|
37 |
@Override |
@Override |
38 |
public boolean onCreateWindow(WebView view, boolean dialog, |
public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota, QuotaUpdater quotaUpdater) { |
39 |
boolean userGesture, Message resultMsg) { |
quotaUpdater.updateQuota(totalUsedQuota + 4096); |
|
msg("create window"); |
|
|
return super.onCreateWindow(view, dialog, userGesture, resultMsg); |
|
40 |
} |
} |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
public void onProgressChanged(WebView view, int progress) { |
public void onProgressChanged(WebView view, int progress) { |
45 |
// Activities and WebViews measure progress with different scales. |
// Activities and WebViews measure progress with different scales. |
46 |
// The progress meter will automatically disappear when we reach 100% |
// The progress meter will automatically disappear when we reach 100% |
72 |
}*/ |
}*/ |
73 |
|
|
74 |
@Override |
@Override |
75 |
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) { |
76 |
if (message.trim().toLowerCase().equals("pda identifikation mangler")) { |
String msg = message.trim().toLowerCase(); |
77 |
result.confirm(device); |
|
78 |
|
if (msg.equals("ekl identifikation mangler")) { |
79 |
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) { |
80 |
return true; |
result.confirm(device); |
81 |
|
|
82 |
|
timeoutHandler.sendEmptyMessageDelayed(1, 500); //efter pdaID er sendt til app'en skal vi genindlæse siden for at tvinge den til at hente data |
83 |
|
return true; |
84 |
|
} else { |
85 |
|
//Hvis vi ikke kunne aflæse device, spørg user via en custom Input Dialog |
86 |
|
//Dialogen kan kun tage imod tal & |
87 |
|
//når at vi får en confirm på den tvinger vi ud i en reload af siden |
88 |
|
|
89 |
|
AlertDialog.Builder alert = new AlertDialog.Builder(EKLLauncherActivity.this); |
90 |
|
|
91 |
|
//alert.setTitle("Title"); |
92 |
|
alert.setMessage(message); |
93 |
|
|
94 |
|
// Set an EditText view to get user input |
95 |
|
final EditText input = new EditText(EKLLauncherActivity.this); |
96 |
|
input.setInputType(InputType.TYPE_CLASS_NUMBER); |
97 |
|
alert.setView(input); |
98 |
|
|
99 |
|
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { |
100 |
|
public void onClick(DialogInterface dialog, int whichButton) { |
101 |
|
result.confirm(input.getText().toString()); |
102 |
|
timeoutHandler.sendEmptyMessageDelayed(1, 500); |
103 |
|
} |
104 |
|
}); |
105 |
|
alert.show(); |
106 |
|
|
107 |
|
return true; |
108 |
|
|
109 |
|
} |
110 |
} else { |
} else { |
111 |
return super.onJsPrompt(view, url, message, defaultValue, result); |
return super.onJsPrompt(view, url, message, defaultValue, result); |
112 |
} |
} |
113 |
} |
} |
|
|
|
114 |
} |
} |
115 |
|
|
116 |
class DummyWebViewClient extends WebViewClient { |
class DummyWebViewClient extends WebViewClient { |
117 |
} |
} |
118 |
|
|
119 |
static final String URL = "http://omdeling.info/mobil/ekl/login.php"; |
static final String LOGTAG = "EklLauncher"; |
120 |
|
static final String URL = "http://omdeling.info/mobil_gpstrack/ekl/"; |
121 |
|
|
122 |
|
LocationManager locMgr; |
123 |
ConnectivityManager connMgr; |
ConnectivityManager connMgr; |
124 |
TelephonyManager telMgr; |
TelephonyManager telMgr; |
125 |
WebView web; |
WebView web; |
126 |
String device = ""; |
String device = ""; |
127 |
|
|
128 |
|
PowerManager.WakeLock wakeLock; |
129 |
|
|
130 |
public void msg(String m) { |
SimHandler simHandler = new SimHandler(); |
|
Toast.makeText(EKLLauncherActivity.this, m, Toast.LENGTH_SHORT).show(); |
|
|
} |
|
131 |
|
|
132 |
/** Called when the activity is first created. */ |
/** Called when the activity is first created. */ |
133 |
@Override |
@Override |
134 |
public void onCreate(Bundle savedInstanceState) { |
public void onCreate(Bundle savedInstanceState) { |
135 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
136 |
|
|
137 |
|
Log.e(LOGTAG, "Starting"); |
138 |
|
|
139 |
getWindow().requestFeature(Window.FEATURE_PROGRESS); |
getWindow().requestFeature(Window.FEATURE_PROGRESS); |
140 |
|
|
141 |
|
|
142 |
try { |
try { |
143 |
int airplane = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON); |
int airplane = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON); |
144 |
|
|
145 |
if (airplane > 0) { |
if (airplane > 0) { |
146 |
Settings.System.putInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0); |
Settings.System.putInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0); |
147 |
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
151 |
} catch (Settings.SettingNotFoundException e) { |
} catch (Settings.SettingNotFoundException e) { |
152 |
Log.d("EKL", "Exception " + e.getMessage() ); |
Log.d("EKL", "Exception " + e.getMessage() ); |
153 |
} |
} |
154 |
|
|
155 |
|
locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); |
156 |
|
telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); |
157 |
|
connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); |
158 |
|
|
159 |
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
160 |
|
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "EklLauncher"); |
161 |
|
wakeLock.acquire(); |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); |
// |
|
connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); |
|
166 |
|
|
167 |
device = telMgr.getLine1Number(); |
device = telMgr.getLine1Number(); |
168 |
if (device == null || device.equals("")) { |
/* if (device == null || device.equals("")) { |
169 |
device = telMgr.getDeviceId(); |
device = telMgr.getSimSerialNumber(); |
170 |
|
|
171 |
if(device == null) |
if(device == null) |
172 |
device = ""; |
device = ""; |
173 |
} |
}*/ |
174 |
|
if(device == null) |
175 |
|
device = ""; |
176 |
|
Log.i(LOGTAG, "Device Line1: " + telMgr.getLine1Number()); |
177 |
|
Log.i(LOGTAG, "Device simserial: " + telMgr.getSimSerialNumber()); |
178 |
|
Log.i(LOGTAG, "Device subscriber: " + telMgr.getSubscriberId()); |
179 |
|
Log.i(LOGTAG, "Device deviceid: " + telMgr.getDeviceId());//IMEI |
180 |
|
|
181 |
|
|
182 |
|
Toast.makeText(EKLLauncherActivity.this, "Device: "+device, Toast.LENGTH_SHORT).show(); |
183 |
|
|
184 |
|
|
185 |
setContentView(R.layout.main); |
setContentView(R.layout.main); |
187 |
|
|
188 |
WebSettings settings = web.getSettings(); |
WebSettings settings = web.getSettings(); |
189 |
|
|
190 |
|
|
191 |
settings.setJavaScriptEnabled(true); |
settings.setJavaScriptEnabled(true); |
192 |
|
|
193 |
settings.setAppCacheEnabled(true); |
settings.setAppCacheEnabled(true); |
194 |
|
settings.setAppCachePath( this.getCacheDir().toString() ); |
195 |
|
|
196 |
settings.setJavaScriptCanOpenWindowsAutomatically(false); |
settings.setJavaScriptCanOpenWindowsAutomatically(false); |
197 |
settings.setGeolocationEnabled(true); |
settings.setGeolocationEnabled(true); |
198 |
|
|
199 |
settings.setDomStorageEnabled(true); |
settings.setDomStorageEnabled(true); |
|
settings.setDatabaseEnabled(true); |
|
200 |
|
|
201 |
|
settings.setDatabaseEnabled(true); |
202 |
settings.setDatabasePath( this.getCacheDir().toString() ); |
settings.setDatabasePath( this.getCacheDir().toString() ); |
203 |
|
|
204 |
|
|
206 |
|
|
207 |
web.setWebChromeClient(new CustomChromeClient() ); |
web.setWebChromeClient(new CustomChromeClient() ); |
208 |
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 |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
//Hvis at tlf rebooter mit i et område uden dækning er det ikke smart at vi skal vente på data |
213 |
|
//simHandler.sendEmptyMessage(0); |
214 |
|
web.loadUrl( URL ); |
215 |
|
|
216 |
if ( (telMgr.getSimState() == TelephonyManager.SIM_STATE_READY && telMgr.getDataState() == TelephonyManager.DATA_CONNECTED) || connMgr.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI) { |
|
217 |
web.loadUrl( URL ); |
if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) { |
218 |
} else { |
//Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "network,gps"); |
219 |
web.loadData("<html><body><h2>afventer netværksforbindelse</h2></body></html>", "text/html", "iso-8859-1"); |
|
220 |
simHandler.sendEmptyMessageDelayed(0, 1500); |
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
221 |
|
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)") |
222 |
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
223 |
|
public void onClick(DialogInterface dialog, int id) { |
224 |
|
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS ); |
225 |
|
startActivity(myIntent); |
226 |
|
} |
227 |
|
}) |
228 |
|
.create() |
229 |
|
.show(); |
230 |
} |
} |
231 |
|
|
232 |
} |
} |
233 |
|
|
234 |
|
void showMessage(String msg) { |
235 |
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
236 |
|
builder.setMessage(msg) |
237 |
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
238 |
|
public void onClick(DialogInterface dialog, int id) { |
239 |
|
dialog.dismiss(); |
240 |
|
} |
241 |
|
}) |
242 |
|
.create() |
243 |
|
.show(); |
244 |
|
|
245 |
|
} |
246 |
|
|
247 |
|
@Override |
248 |
|
protected void onDestroy() { |
249 |
|
super.onDestroy(); |
250 |
|
wakeLock.release(); |
251 |
|
} |
252 |
|
|
253 |
@Override |
@Override |
254 |
public boolean onCreateOptionsMenu(Menu menu) { |
public boolean onCreateOptionsMenu(Menu menu) { |
269 |
break; |
break; |
270 |
case 2: |
case 2: |
271 |
web.clearCache(true); |
web.clearCache(true); |
272 |
|
|
273 |
|
WebStorage.getInstance().deleteAllData(); |
274 |
|
WebStorage.getInstance().deleteOrigin(URL); |
275 |
|
|
276 |
web.reload(); |
web.reload(); |
277 |
break; |
break; |
278 |
} |
} |
289 |
}; |
}; |
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
Handler simHandler = new Handler() { |
class SimHandler extends Handler { |
296 |
@Override |
|
297 |
public void handleMessage(Message msg) { |
public void testNetwork() { |
298 |
super.handleMessage(msg); |
NetworkInfo network = connMgr.getActiveNetworkInfo(); |
299 |
if (telMgr.getSimState() == TelephonyManager.SIM_STATE_READY && telMgr.getDataState() == TelephonyManager.DATA_CONNECTED) { |
|
300 |
|
if ( (telMgr.getSimState() == TelephonyManager.SIM_STATE_READY && telMgr.getDataState() == TelephonyManager.DATA_CONNECTED) || ( network != null && network.getType() == ConnectivityManager.TYPE_WIFI) ) { |
301 |
web.loadUrl( URL ); |
web.loadUrl( URL ); |
302 |
} else { |
} else { |
303 |
|
web.loadData("<html><body><h2>afventer netværksforbindelse</h2></body></html>", "text/html", "iso-8859-1"); |
304 |
this.sendEmptyMessageDelayed(0, 1000); |
this.sendEmptyMessageDelayed(0, 1000); |
305 |
} |
} |
306 |
} |
} |
307 |
|
|
308 |
|
@Override |
309 |
|
public void handleMessage(Message msg) { |
310 |
|
super.handleMessage(msg); |
311 |
|
|
312 |
|
testNetwork(); |
313 |
|
} |
314 |
}; |
}; |
315 |
|
|
316 |
|
|