14 |
import android.os.PowerManager; |
import android.os.PowerManager; |
15 |
import android.provider.Settings; |
import android.provider.Settings; |
16 |
import android.telephony.TelephonyManager; |
import android.telephony.TelephonyManager; |
|
import android.text.InputType; |
|
17 |
import android.util.Log; |
import android.util.Log; |
18 |
import android.view.Menu; |
import android.view.Menu; |
19 |
import android.view.MenuItem; |
import android.view.MenuItem; |
20 |
import android.view.Window; |
import android.view.Window; |
21 |
import android.view.WindowManager; |
import android.view.WindowManager; |
|
import android.webkit.GeolocationPermissions.Callback; |
|
|
import android.webkit.JsPromptResult; |
|
|
import android.webkit.WebChromeClient; |
|
22 |
import android.webkit.WebSettings; |
import android.webkit.WebSettings; |
23 |
import android.webkit.WebStorage; |
import android.webkit.WebStorage; |
|
import android.webkit.WebStorage.QuotaUpdater; |
|
24 |
import android.webkit.WebView; |
import android.webkit.WebView; |
25 |
import android.webkit.WebViewClient; |
import android.webkit.WebViewClient; |
|
import android.widget.EditText; |
|
|
import android.widget.Toast; |
|
26 |
|
|
27 |
public class EKLLauncherActivity extends Activity { |
public class EKLLauncherActivity extends Activity { |
28 |
|
|
29 |
class CustomChromeClient extends WebChromeClient { |
|
30 |
|
|
|
@Override |
|
|
public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota, QuotaUpdater quotaUpdater) { |
|
|
quotaUpdater.updateQuota(totalUsedQuota + 4096); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onProgressChanged(WebView view, int progress) { |
|
|
// Activities and WebViews measure progress with different scales. |
|
|
// The progress meter will automatically disappear when we reach 100% |
|
|
EKLLauncherActivity.this.setProgress(progress * 100); |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, QuotaUpdater quotaUpdater) { |
|
|
quotaUpdater.updateQuota(estimatedSize); // altid giv tilladelse til større db quota |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) { |
|
|
callback.invoke(origin, true, true); //altid give tilladelse til geo location |
|
|
} |
|
|
/* |
|
|
@Override |
|
|
public boolean onJsAlert(WebView view, String url, String message, JsResult result) { |
|
|
|
|
|
return super.onJsAlert(view, url, message, result); |
|
|
} |
|
|
|
|
|
@Override |
|
|
public boolean onJsConfirm(WebView view, String url, String message, JsResult result) { |
|
|
Toast.makeText(EKLLauncherActivity.this, "Oh no! " + message, Toast.LENGTH_SHORT).show(); |
|
|
return super.onJsConfirm(view, url, message, result); |
|
|
}*/ |
|
|
|
|
|
@Override |
|
|
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, final JsPromptResult result) { |
|
|
String msg = message.trim().toLowerCase(); |
|
|
|
|
|
if (msg.equals("ekl identifikation mangler")) { |
|
|
if (device != null && device.equals("")==false) { |
|
|
result.confirm(device); |
|
|
|
|
|
timeoutHandler.sendEmptyMessageDelayed(1, 500); //efter pdaID er sendt til app'en skal vi genindlæse siden for at tvinge den til at hente data |
|
|
return true; |
|
|
} else { |
|
|
//Hvis vi ikke kunne aflæse device, spørg user via en custom Input Dialog |
|
|
//Dialogen kan kun tage imod tal & |
|
|
//når at vi får en confirm på den tvinger vi ud i en reload af siden |
|
|
|
|
|
AlertDialog.Builder alert = new AlertDialog.Builder(EKLLauncherActivity.this); |
|
|
|
|
|
//alert.setTitle("Title"); |
|
|
alert.setMessage(message); |
|
|
|
|
|
// Set an EditText view to get user input |
|
|
final EditText input = new EditText(EKLLauncherActivity.this); |
|
|
input.setInputType(InputType.TYPE_CLASS_NUMBER); |
|
|
alert.setView(input); |
|
|
|
|
|
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { |
|
|
public void onClick(DialogInterface dialog, int whichButton) { |
|
|
result.confirm(input.getText().toString()); |
|
|
timeoutHandler.sendEmptyMessageDelayed(1, 500); |
|
|
} |
|
|
}); |
|
|
alert.show(); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
} else { |
|
|
return super.onJsPrompt(view, url, message, defaultValue, result); |
|
|
} |
|
|
} |
|
|
} |
|
31 |
|
|
32 |
class DummyWebViewClient extends WebViewClient { |
class DummyWebViewClient extends WebViewClient { |
33 |
} |
} |
34 |
|
|
35 |
static final String LOGTAG = "EklLauncher"; |
public static final String LOGTAG = "EklLauncher"; |
36 |
static final String URL = "http://omdeling.info/mobil/ekl/"; |
static final String URL = "http://omdeling.info/mobil/ekl/"; |
37 |
|
//static final String URL = "http://t-hoerup.dk/android_js.html"; |
38 |
|
|
39 |
LocationManager locMgr; |
LocationManager locMgr; |
40 |
ConnectivityManager connMgr; |
ConnectivityManager connMgr; |
41 |
TelephonyManager telMgr; |
TelephonyManager telMgr; |
42 |
WebView web; |
WebView web; |
|
String device = ""; |
|
43 |
|
|
44 |
PowerManager.WakeLock wakeLock; |
PowerManager.WakeLock wakeLock; |
45 |
|
|
79 |
connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); |
connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); |
80 |
|
|
81 |
|
|
82 |
|
|
|
|
|
|
device = telMgr.getLine1Number(); |
|
|
if(device == null) { |
|
|
device = ""; |
|
|
} |
|
|
if (device != null && device.equals("") == false){//Hvis vi kunne aflæse TLF nummer fra sim, så hvis den som en toast |
|
|
Toast.makeText(EKLLauncherActivity.this, "Device: "+device, Toast.LENGTH_SHORT).show(); |
|
|
} |
|
|
|
|
|
Log.i(LOGTAG, "Device Line1: " + telMgr.getLine1Number()); |
|
|
Log.i(LOGTAG, "Device simserial: " + telMgr.getSimSerialNumber()); |
|
|
Log.i(LOGTAG, "Device subscriber: " + telMgr.getSubscriberId()); |
|
|
Log.i(LOGTAG, "Device deviceid: " + telMgr.getDeviceId());//IMEI |
|
|
|
|
83 |
|
|
84 |
|
|
85 |
setContentView(R.layout.main); |
setContentView(R.layout.main); |
104 |
|
|
105 |
settings.setSupportMultipleWindows(false); |
settings.setSupportMultipleWindows(false); |
106 |
|
|
107 |
web.setWebChromeClient(new CustomChromeClient() ); |
JsPhoneObject jsPhone = new JsPhoneObject(telMgr); |
108 |
|
|
109 |
|
web.addJavascriptInterface( jsPhone , "jsPhone"); |
110 |
|
|
111 |
|
web.setWebChromeClient(new EKLChromeClient(this) ); |
112 |
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 |
113 |
|
|
|
|
|
|
|
|
114 |
|
|
115 |
|
|
116 |
|
|