1 |
package dk.thoerup.ekllauncher; |
package dk.thoerup.ekllauncher; |
2 |
|
|
3 |
|
import android.annotation.SuppressLint; |
4 |
import android.app.Activity; |
import android.app.Activity; |
5 |
|
import android.app.AlertDialog; |
6 |
import android.content.Context; |
import android.content.Context; |
7 |
|
import android.content.DialogInterface; |
8 |
import android.content.Intent; |
import android.content.Intent; |
9 |
|
import android.location.LocationManager; |
10 |
import android.net.ConnectivityManager; |
import android.net.ConnectivityManager; |
11 |
|
import android.net.NetworkInfo; |
12 |
import android.os.Bundle; |
import android.os.Bundle; |
13 |
import android.os.Handler; |
import android.os.Handler; |
14 |
import android.os.Message; |
import android.os.Message; |
15 |
|
import android.os.PowerManager; |
16 |
import android.provider.Settings; |
import android.provider.Settings; |
17 |
import android.telephony.TelephonyManager; |
import android.telephony.TelephonyManager; |
18 |
|
import android.text.InputType; |
19 |
import android.util.Log; |
import android.util.Log; |
20 |
import android.view.Menu; |
import android.view.Menu; |
21 |
import android.view.MenuItem; |
import android.view.MenuItem; |
24 |
import android.webkit.JsPromptResult; |
import android.webkit.JsPromptResult; |
25 |
import android.webkit.WebChromeClient; |
import android.webkit.WebChromeClient; |
26 |
import android.webkit.WebSettings; |
import android.webkit.WebSettings; |
27 |
|
import android.webkit.WebStorage; |
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 { |
36 |
class CustomChromeClient extends WebChromeClient { |
class CustomChromeClient extends WebChromeClient { |
37 |
|
|
38 |
@Override |
@Override |
39 |
public boolean onCreateWindow(WebView view, boolean dialog, |
public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota, QuotaUpdater quotaUpdater) { |
40 |
boolean userGesture, Message resultMsg) { |
quotaUpdater.updateQuota(totalUsedQuota + 4096); |
|
msg("create window"); |
|
|
return super.onCreateWindow(view, dialog, userGesture, resultMsg); |
|
41 |
} |
} |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
public void onProgressChanged(WebView view, int progress) { |
public void onProgressChanged(WebView view, int progress) { |
46 |
// Activities and WebViews measure progress with different scales. |
// Activities and WebViews measure progress with different scales. |
47 |
// The progress meter will automatically disappear when we reach 100% |
// The progress meter will automatically disappear when we reach 100% |
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 |
|
|
79 |
|
if (msg.equals("ekl identifikation mangler")) { |
80 |
result.confirm(device); |
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 |
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; |
return true; |
84 |
|
} else if (msg.startsWith("indtast retur antal")) { |
85 |
|
|
86 |
|
AlertDialog.Builder alert = new AlertDialog.Builder(EKLLauncherActivity.this); |
87 |
|
|
88 |
|
//alert.setTitle("Title"); |
89 |
|
alert.setMessage(message); |
90 |
|
|
91 |
|
// Set an EditText view to get user input |
92 |
|
final EditText input = new EditText(EKLLauncherActivity.this); |
93 |
|
input.setInputType(InputType.TYPE_CLASS_NUMBER); |
94 |
|
alert.setView(input); |
95 |
|
|
96 |
|
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { |
97 |
|
public void onClick(DialogInterface dialog, int whichButton) { |
98 |
|
result.confirm(input.getText().toString()); |
99 |
|
} |
100 |
|
}); |
101 |
|
alert.show(); |
102 |
|
|
103 |
|
return true; |
104 |
} else { |
} else { |
105 |
return super.onJsPrompt(view, url, message, defaultValue, result); |
return super.onJsPrompt(view, url, message, defaultValue, result); |
106 |
} |
} |
107 |
} |
} |
|
|
|
108 |
} |
} |
109 |
|
|
110 |
class DummyWebViewClient extends WebViewClient { |
class DummyWebViewClient extends WebViewClient { |
111 |
} |
} |
112 |
|
|
113 |
static final String URL = "http://omdeling.info/mobil/ekl/login.php"; |
static final String LOGTAG = "EklLauncher"; |
114 |
|
static final String URL = "http://omdeling.info/mobil_gpstrack/ekl/login.php"; |
115 |
|
|
116 |
|
LocationManager locMgr; |
117 |
ConnectivityManager connMgr; |
ConnectivityManager connMgr; |
118 |
TelephonyManager telMgr; |
TelephonyManager telMgr; |
119 |
WebView web; |
WebView web; |
120 |
String device = ""; |
String device = ""; |
121 |
|
|
122 |
|
PowerManager.WakeLock wakeLock; |
123 |
|
|
124 |
public void msg(String m) { |
SimHandler simHandler = new SimHandler(); |
|
Toast.makeText(EKLLauncherActivity.this, m, Toast.LENGTH_SHORT).show(); |
|
|
} |
|
125 |
|
|
126 |
/** Called when the activity is first created. */ |
/** Called when the activity is first created. */ |
127 |
@Override |
@SuppressLint("SetJavaScriptEnabled") |
128 |
|
@Override |
129 |
public void onCreate(Bundle savedInstanceState) { |
public void onCreate(Bundle savedInstanceState) { |
130 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
131 |
|
|
132 |
|
Log.e(LOGTAG, "Starting"); |
133 |
|
|
134 |
getWindow().requestFeature(Window.FEATURE_PROGRESS); |
getWindow().requestFeature(Window.FEATURE_PROGRESS); |
135 |
|
|
136 |
|
|
137 |
try { |
try { |
138 |
int airplane = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON); |
int airplane = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON); |
139 |
|
|
140 |
if (airplane > 0) { |
if (airplane > 0) { |
141 |
Settings.System.putInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0); |
Settings.System.putInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0); |
142 |
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
146 |
} catch (Settings.SettingNotFoundException e) { |
} catch (Settings.SettingNotFoundException e) { |
147 |
Log.d("EKL", "Exception " + e.getMessage() ); |
Log.d("EKL", "Exception " + e.getMessage() ); |
148 |
} |
} |
149 |
|
|
150 |
|
locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); |
151 |
|
telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); |
152 |
|
connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); |
153 |
|
|
154 |
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
155 |
|
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "EklLauncher"); |
156 |
|
wakeLock.acquire(); |
157 |
|
|
158 |
|
|
159 |
|
|
|
telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); |
|
|
connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); |
|
|
|
|
160 |
device = telMgr.getLine1Number(); |
device = telMgr.getLine1Number(); |
161 |
if (device == null || device.equals("")) { |
if (device == null || device.equals("")) { |
162 |
device = telMgr.getDeviceId(); |
device = telMgr.getSimSerialNumber(); |
163 |
|
|
164 |
if(device == null) |
if(device == null) |
165 |
device = ""; |
device = ""; |
166 |
} |
} |
167 |
|
|
168 |
|
Toast.makeText(EKLLauncherActivity.this, "Device: "+device, Toast.LENGTH_SHORT).show(); |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
setContentView(R.layout.main); |
setContentView(R.layout.main); |
173 |
web = (WebView) findViewById(R.id.web); |
web = (WebView) findViewById(R.id.web); |
174 |
|
|
175 |
WebSettings settings = web.getSettings(); |
WebSettings settings = web.getSettings(); |
176 |
|
|
177 |
|
|
178 |
settings.setJavaScriptEnabled(true); |
settings.setJavaScriptEnabled(true); |
179 |
|
|
180 |
settings.setAppCacheEnabled(true); |
settings.setAppCacheEnabled(true); |
181 |
|
settings.setAppCachePath( this.getCacheDir().toString() ); |
182 |
|
|
183 |
settings.setJavaScriptCanOpenWindowsAutomatically(false); |
settings.setJavaScriptCanOpenWindowsAutomatically(false); |
184 |
settings.setGeolocationEnabled(true); |
settings.setGeolocationEnabled(true); |
185 |
|
|
186 |
settings.setDomStorageEnabled(true); |
settings.setDomStorageEnabled(true); |
|
settings.setDatabaseEnabled(true); |
|
187 |
|
|
188 |
|
settings.setDatabaseEnabled(true); |
189 |
settings.setDatabasePath( this.getCacheDir().toString() ); |
settings.setDatabasePath( this.getCacheDir().toString() ); |
190 |
|
|
191 |
|
|
193 |
|
|
194 |
web.setWebChromeClient(new CustomChromeClient() ); |
web.setWebChromeClient(new CustomChromeClient() ); |
195 |
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 |
196 |
|
|
197 |
|
//Hvis at tlf rebooter mit i et område uden dækning er det ikke smart at vi skal vente på data |
198 |
|
//simHandler.sendEmptyMessage(0); |
199 |
|
web.loadUrl( URL ); |
200 |
|
|
201 |
if ( (telMgr.getSimState() == TelephonyManager.SIM_STATE_READY && telMgr.getDataState() == TelephonyManager.DATA_CONNECTED) || connMgr.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI) { |
|
202 |
web.loadUrl( URL ); |
if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) { |
203 |
} else { |
//Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "network,gps"); |
204 |
web.loadData("<html><body><h2>afventer netværksforbindelse</h2></body></html>", "text/html", "iso-8859-1"); |
|
205 |
simHandler.sendEmptyMessageDelayed(0, 1500); |
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
206 |
|
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)") |
207 |
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
208 |
|
public void onClick(DialogInterface dialog, int id) { |
209 |
|
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS ); |
210 |
|
startActivity(myIntent); |
211 |
|
} |
212 |
|
}) |
213 |
|
.create() |
214 |
|
.show(); |
215 |
} |
} |
216 |
|
|
217 |
} |
} |
218 |
|
|
219 |
|
void showMessage(String msg) { |
220 |
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
221 |
|
builder.setMessage(msg) |
222 |
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
223 |
|
public void onClick(DialogInterface dialog, int id) { |
224 |
|
dialog.dismiss(); |
225 |
|
} |
226 |
|
}) |
227 |
|
.create() |
228 |
|
.show(); |
229 |
|
|
230 |
|
} |
231 |
|
|
232 |
|
@Override |
233 |
|
protected void onDestroy() { |
234 |
|
super.onDestroy(); |
235 |
|
wakeLock.release(); |
236 |
|
} |
237 |
|
|
238 |
@Override |
@Override |
239 |
public boolean onCreateOptionsMenu(Menu menu) { |
public boolean onCreateOptionsMenu(Menu menu) { |
253 |
web.reload(); |
web.reload(); |
254 |
break; |
break; |
255 |
case 2: |
case 2: |
256 |
|
WebStorage.getInstance().deleteAllData(); |
257 |
web.clearCache(true); |
web.clearCache(true); |
258 |
web.reload(); |
web.reload(); |
259 |
break; |
break; |
271 |
}; |
}; |
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
Handler simHandler = new Handler() { |
class SimHandler extends Handler { |
278 |
@Override |
|
279 |
public void handleMessage(Message msg) { |
public void testNetwork() { |
280 |
super.handleMessage(msg); |
NetworkInfo network = connMgr.getActiveNetworkInfo(); |
281 |
if (telMgr.getSimState() == TelephonyManager.SIM_STATE_READY && telMgr.getDataState() == TelephonyManager.DATA_CONNECTED) { |
|
282 |
|
if ( (telMgr.getSimState() == TelephonyManager.SIM_STATE_READY && telMgr.getDataState() == TelephonyManager.DATA_CONNECTED) || ( network != null && network.getType() == ConnectivityManager.TYPE_WIFI) ) { |
283 |
web.loadUrl( URL ); |
web.loadUrl( URL ); |
284 |
} else { |
} else { |
285 |
|
web.loadData("<html><body><h2>afventer netværksforbindelse</h2></body></html>", "text/html", "iso-8859-1"); |
286 |
this.sendEmptyMessageDelayed(0, 1000); |
this.sendEmptyMessageDelayed(0, 1000); |
287 |
} |
} |
288 |
} |
} |
289 |
|
|
290 |
|
@Override |
291 |
|
public void handleMessage(Message msg) { |
292 |
|
super.handleMessage(msg); |
293 |
|
|
294 |
|
testNetwork(); |
295 |
|
} |
296 |
}; |
}; |
297 |
|
|
298 |
|
|