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; |
import android.app.AlertDialog; |
6 |
import android.content.Context; |
import android.content.Context; |
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; |
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 |
|
|
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; |
LocationManager locMgr; |
117 |
ConnectivityManager connMgr; |
ConnectivityManager connMgr; |
119 |
WebView web; |
WebView web; |
120 |
String device = ""; |
String device = ""; |
121 |
|
|
122 |
|
PowerManager.WakeLock wakeLock; |
123 |
|
|
124 |
|
SimHandler simHandler = new SimHandler(); |
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 |
|
|
|
locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); |
|
|
telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); |
|
|
connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); |
|
159 |
|
|
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); |
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); |
//simHandler.sendEmptyMessage(0); |
199 |
|
web.loadUrl( URL ); |
|
|
|
200 |
|
|
201 |
|
|
202 |
if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) { |
if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) { |
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)") |
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() { |
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
208 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
209 |
Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS ); |
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS ); |
210 |
startActivity(myIntent); |
startActivity(myIntent); |
211 |
} |
} |
212 |
}) |
}) |
213 |
.create() |
.create() |
214 |
.show(); |
.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) { |
272 |
|
|
273 |
|
|
274 |
|
|
275 |
SimHandler simHandler = new SimHandler(); |
|
276 |
|
|
277 |
class SimHandler extends Handler { |
class SimHandler extends Handler { |
278 |
|
|