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.webkit.GeolocationPermissions.Callback; |
import android.view.WindowManager; |
|
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; |
|
26 |
|
|
27 |
public class EKLLauncherActivity extends Activity { |
public class EKLLauncherActivity extends Activity { |
28 |
|
|
|
class CustomChromeClient extends WebChromeClient { |
|
|
|
|
|
@Override |
|
|
public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota, QuotaUpdater quotaUpdater) { |
|
|
quotaUpdater.updateQuota(totalUsedQuota + 4096); |
|
|
} |
|
|
|
|
|
|
|
29 |
|
|
|
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 |
|
|
} |
|
30 |
|
|
31 |
|
|
|
@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("pda identifikation mangler")) { |
|
|
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 if (msg.startsWith("indtast retur antal")) { |
|
|
|
|
|
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()); |
|
|
} |
|
|
}); |
|
|
alert.show(); |
|
|
|
|
|
return true; |
|
|
} else { |
|
|
return super.onJsPrompt(view, url, message, defaultValue, result); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
32 |
class DummyWebViewClient extends WebViewClient { |
class DummyWebViewClient extends WebViewClient { |
33 |
} |
} |
34 |
|
|
35 |
static final String URL = "http://omdeling.info/mobil/ekl/login.php"; |
public static final String LOGTAG = "EklLauncher"; |
36 |
|
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 |
|
|
46 |
|
SimHandler simHandler = new SimHandler(); |
47 |
|
|
48 |
|
@Override |
49 |
|
public void onAttachedToWindow() { |
50 |
|
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); |
51 |
|
super.onAttachedToWindow(); |
52 |
|
} |
53 |
|
|
54 |
/** Called when the activity is first created. */ |
/** Called when the activity is first created. */ |
55 |
@Override |
@Override |
56 |
public void onCreate(Bundle savedInstanceState) { |
public void onCreate(Bundle savedInstanceState) { |
57 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
58 |
|
|
59 |
|
Log.e(LOGTAG, "Creating"); |
60 |
|
|
61 |
getWindow().requestFeature(Window.FEATURE_PROGRESS); |
getWindow().requestFeature(Window.FEATURE_PROGRESS); |
62 |
|
|
63 |
|
|
64 |
try { |
try { |
65 |
int airplane = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON); |
int airplane = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON); |
66 |
|
|
67 |
if (airplane > 0) { |
if (airplane > 0) { |
68 |
Settings.System.putInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0); |
Settings.System.putInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0); |
69 |
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
73 |
} catch (Settings.SettingNotFoundException e) { |
} catch (Settings.SettingNotFoundException e) { |
74 |
Log.d("EKL", "Exception " + e.getMessage() ); |
Log.d("EKL", "Exception " + e.getMessage() ); |
75 |
} |
} |
76 |
|
|
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
|
|
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "EklLauncher"); |
|
|
wakeLock.acquire(); |
|
|
|
|
|
|
|
77 |
locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); |
locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); |
78 |
telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); |
telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); |
79 |
connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); |
connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); |
80 |
|
|
81 |
|
|
82 |
device = telMgr.getLine1Number(); |
|
83 |
if (device == null || device.equals("")) { |
|
|
device = telMgr.getDeviceId(); |
|
|
|
|
|
if(device == null) |
|
|
device = ""; |
|
|
} |
|
|
|
|
|
|
|
84 |
|
|
85 |
setContentView(R.layout.main); |
setContentView(R.layout.main); |
86 |
web = (WebView) findViewById(R.id.web); |
web = (WebView) findViewById(R.id.web); |
104 |
|
|
105 |
settings.setSupportMultipleWindows(false); |
settings.setSupportMultipleWindows(false); |
106 |
|
|
107 |
web.setWebChromeClient(new CustomChromeClient() ); |
JsPhoneObject jsPhone = new JsPhoneObject(telMgr); |
|
web.setWebViewClient( new DummyWebViewClient() ); // skal have en webviewclient for at kunne styre ved forlad tur |
|
|
|
|
|
|
|
|
simHandler.sendEmptyMessage(0); |
|
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 |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) { |
if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) { |
121 |
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)") |
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)") |
122 |
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
123 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
124 |
Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS ); |
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS ); |
125 |
startActivity(myIntent); |
startActivity(myIntent); |
126 |
} |
} |
127 |
}) |
}) |
128 |
.create() |
.create() |
129 |
.show(); |
.show(); |
130 |
} |
} |
131 |
|
|
132 |
|
} |
133 |
|
|
134 |
|
@Override |
135 |
|
protected void onStart() { |
136 |
|
super.onStart(); |
137 |
|
|
138 |
|
Log.e(LOGTAG, "Starting"); |
139 |
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
140 |
|
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "EklLauncher"); |
141 |
|
wakeLock.acquire(); |
142 |
|
|
143 |
|
//Hvis at tlf rebooter mit i et område uden dækning er det ikke smart at vi skal vente på data |
144 |
|
//simHandler.sendEmptyMessage(0); |
145 |
|
web.loadUrl( URL ); |
146 |
|
|
147 |
|
} |
148 |
|
|
149 |
|
void showMessage(String msg) { |
150 |
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
151 |
|
builder.setMessage(msg) |
152 |
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
153 |
|
public void onClick(DialogInterface dialog, int id) { |
154 |
|
dialog.dismiss(); |
155 |
|
} |
156 |
|
}) |
157 |
|
.create() |
158 |
|
.show(); |
159 |
|
|
160 |
} |
} |
161 |
|
|
162 |
@Override |
@Override |
163 |
protected void onDestroy() { |
protected void onStop() { |
164 |
super.onDestroy(); |
|
165 |
wakeLock.release(); |
Log.e(LOGTAG, "Stopping"); |
166 |
|
|
167 |
|
if (wakeLock != null && wakeLock.isHeld()) |
168 |
|
wakeLock.release(); |
169 |
|
|
170 |
|
if (!web.getUrl().equals("about:blank")) |
171 |
|
web.loadUrl("about:blank"); |
172 |
|
|
173 |
|
super.onStop(); |
174 |
} |
} |
175 |
|
|
176 |
|
static final int RELOAD = 1; |
177 |
|
static final int FLUSH = 2; |
178 |
|
static final int EXIT = 3; |
179 |
|
|
180 |
@Override |
@Override |
181 |
public boolean onCreateOptionsMenu(Menu menu) { |
public boolean onCreateOptionsMenu(Menu menu) { |
182 |
MenuItem item; |
MenuItem item; |
183 |
item = menu.add(0, 1, 0, "Genindlæs side"); |
item = menu.add(0, RELOAD, 0, "Genindlæs side"); |
184 |
item.setIcon( R.drawable.ic_menu_refresh ); |
item.setIcon( R.drawable.ic_menu_refresh ); |
185 |
|
|
186 |
item = menu.add(0, 2, 0, "Slet cache"); |
item = menu.add(0, FLUSH, 0, "Slet cache"); |
187 |
item.setIcon( R.drawable.ic_menu_delete ); |
item.setIcon( R.drawable.ic_menu_delete ); |
188 |
|
|
189 |
|
item = menu.add(0, EXIT, 0, "Forlad"); |
190 |
|
item.setIcon( android.R.drawable.ic_menu_close_clear_cancel); |
191 |
|
|
192 |
return super.onCreateOptionsMenu(menu); |
return super.onCreateOptionsMenu(menu); |
193 |
} |
} |
194 |
|
|
195 |
@Override |
@Override |
196 |
public boolean onMenuItemSelected(int featureId, MenuItem item) { |
public boolean onMenuItemSelected(int featureId, MenuItem item) { |
197 |
switch (item.getItemId()) { |
switch (item.getItemId()) { |
198 |
case 1: |
case RELOAD: |
199 |
web.reload(); |
web.reload(); |
200 |
break; |
break; |
201 |
case 2: |
case FLUSH: |
|
WebStorage.getInstance().deleteAllData(); |
|
202 |
web.clearCache(true); |
web.clearCache(true); |
203 |
|
|
204 |
|
WebStorage.getInstance().deleteAllData(); |
205 |
|
WebStorage.getInstance().deleteOrigin(URL); |
206 |
|
|
207 |
web.reload(); |
web.reload(); |
208 |
break; |
break; |
209 |
|
case EXIT: |
210 |
|
this.finish(); |
211 |
|
break; |
212 |
} |
} |
213 |
|
|
214 |
return super.onMenuItemSelected(featureId, item); |
return super.onMenuItemSelected(featureId, item); |
215 |
} |
} |
216 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
SimHandler simHandler = new SimHandler(); |
|
229 |
|
|
230 |
class SimHandler extends Handler { |
class SimHandler extends Handler { |
231 |
|
|