/[projects]/android/EKLLauncher/src/dk/thoerup/ekllauncher/EKLLauncherActivity.java
ViewVC logotype

Diff of /android/EKLLauncher/src/dk/thoerup/ekllauncher/EKLLauncherActivity.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1620 by torben, Thu Oct 20 20:59:48 2011 UTC revision 1925 by torben, Mon Feb 25 08:39:29 2013 UTC
# Line 1  Line 1 
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;  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;
# Line 18  import android.webkit.GeolocationPermiss Line 23  import android.webkit.GeolocationPermiss
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 {
# Line 33  public class EKLLauncherActivity extends Line 40  public class EKLLauncherActivity extends
40                  }                  }
41    
42    
                 @Override  
                 public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg) {  
                         msg("create window");  
                         return super.onCreateWindow(view, dialog, userGesture, resultMsg);  
                 }  
   
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.
# Line 71  public class EKLLauncherActivity extends Line 72  public class EKLLauncherActivity extends
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    
78                            if (msg.equals("ekl identifikation mangler")) {
79                                  result.confirm(device);                                  result.confirm(device);
80                                    
81                                  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
82                                  return true;                                  return true;
83                            } else if (msg.startsWith("indtast retur antal")) {
84    
85                                    AlertDialog.Builder alert = new AlertDialog.Builder(EKLLauncherActivity.this);
86    
87                                    //alert.setTitle("Title");
88                                    alert.setMessage(message);
89    
90                                    // Set an EditText view to get user input
91                                    final EditText input = new EditText(EKLLauncherActivity.this);
92                                    input.setInputType(InputType.TYPE_CLASS_NUMBER);
93                                    alert.setView(input);
94    
95                                    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
96                                            public void onClick(DialogInterface dialog, int whichButton) {
97                                                    result.confirm(input.getText().toString());
98                                            }
99                                    });
100                                    alert.show();
101    
102                                    return true;                            
103                          } else {                          } else {
104                                  return super.onJsPrompt(view, url, message, defaultValue, result);                                  return super.onJsPrompt(view, url, message, defaultValue, result);
105                          }                                                                                                }                                                                      
106                  }                  }
                   
107          }          }
108    
109          class DummyWebViewClient extends WebViewClient {                          class DummyWebViewClient extends WebViewClient {                
110          }          }
111                    
112          static final String URL = "http://omdeling.info/mobil/ekl/login.php";          static final String URL = "http://omdeling.info/mobil_gpstrack/ekl/login.php";
113                    
114            LocationManager locMgr;
115          ConnectivityManager connMgr;          ConnectivityManager connMgr;
116          TelephonyManager telMgr;          TelephonyManager telMgr;
117          WebView web;          WebView web;
118          String device = "";          String device = "";
119                    
120            PowerManager.WakeLock wakeLock;
121                    
122          public void msg(String m) {          SimHandler simHandler = new SimHandler();
                 Toast.makeText(EKLLauncherActivity.this, m, Toast.LENGTH_SHORT).show();  
         }  
123                    
124      /** Called when the activity is first created. */      /** Called when the activity is first created. */
125      @Override      @Override
# Line 118  public class EKLLauncherActivity extends Line 140  public class EKLLauncherActivity extends
140          } catch (Settings.SettingNotFoundException e) {          } catch (Settings.SettingNotFoundException e) {
141                  Log.d("EKL", "Exception " + e.getMessage() );                  Log.d("EKL", "Exception " + e.getMessage() );
142          }          }
143    
144            locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
145            telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
146            connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);        
147                    
148            PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
149            wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "EklLauncher");
150            wakeLock.acquire();        
151                    
152                    
153                    
         telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);  
         connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);  
           
154          device = telMgr.getLine1Number();          device = telMgr.getLine1Number();
155          if (device == null || device.equals("")) {          if (device == null || device.equals("")) {
156                  device = telMgr.getDeviceId();                  device = telMgr.getSimSerialNumber();
157                                    
158                  if(device == null)                  if(device == null)
159                          device = "";                          device = "";                            
160          }          }
161                    
162            Toast.makeText(EKLLauncherActivity.this, "Device:"+device, Toast.LENGTH_SHORT).show();
163            
164    
165                    
166          setContentView(R.layout.main);          setContentView(R.layout.main);
167          web = (WebView) findViewById(R.id.web);          web = (WebView) findViewById(R.id.web);
# Line 162  public class EKLLauncherActivity extends Line 191  public class EKLLauncherActivity extends
191                    
192          simHandler.sendEmptyMessage(0);          simHandler.sendEmptyMessage(0);
193                    
194            
195            
196            
197            if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) {
198                    //Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "network,gps");
199                    
200                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
201                    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)")
202                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
203                    public void onClick(DialogInterface dialog, int id) {
204                            Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS );
205                        startActivity(myIntent);      
206                    }
207                })
208                .create()
209                .show();      
210            }
211      }      }
212    
213          @Override          @Override
214            protected void onDestroy() {
215                    super.onDestroy();
216                    wakeLock.release();
217            }
218    
219            @Override
220          public boolean onCreateOptionsMenu(Menu menu) {          public boolean onCreateOptionsMenu(Menu menu) {
221                  MenuItem item;                  MenuItem item;
222                  item = menu.add(0, 1, 0, "Genindlæs side");                  item = menu.add(0, 1, 0, "Genindlæs side");
# Line 182  public class EKLLauncherActivity extends Line 234  public class EKLLauncherActivity extends
234                          web.reload();                          web.reload();
235                          break;                          break;
236                  case 2:                  case 2:
237                            WebStorage.getInstance().deleteAllData();
238                          web.clearCache(true);                          web.clearCache(true);
239                          web.reload();                          web.reload();
240                          break;                          break;
# Line 200  public class EKLLauncherActivity extends Line 253  public class EKLLauncherActivity extends
253                    
254                    
255    
256          SimHandler simHandler = new SimHandler();  
257                    
258          class SimHandler extends Handler {          class SimHandler extends Handler {
259                                    

Legend:
Removed from v.1620  
changed lines
  Added in v.1925

  ViewVC Help
Powered by ViewVC 1.1.20