/[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 1625 by torben, Wed Oct 26 12:15:52 2011 UTC revision 2188 by torben, Fri May 30 13:02:24 2014 UTC
# Line 7  import android.content.DialogInterface; Line 7  import android.content.DialogInterface;
7  import android.content.Intent;  import android.content.Intent;
8  import android.location.LocationManager;  import android.location.LocationManager;
9  import android.net.ConnectivityManager;  import android.net.ConnectivityManager;
 import android.net.NetworkInfo;  
10  import android.os.Bundle;  import android.os.Bundle;
11  import android.os.Handler;  import android.os.PowerManager;
 import android.os.Message;  
12  import android.provider.Settings;  import android.provider.Settings;
13  import android.telephony.TelephonyManager;  import android.telephony.TelephonyManager;
 import android.text.InputType;  
14  import android.util.Log;  import android.util.Log;
15  import android.view.Menu;  import android.view.Menu;
16  import android.view.MenuItem;  import android.view.MenuItem;
17  import android.view.Window;  import android.view.Window;
18  import android.webkit.GeolocationPermissions.Callback;  import android.view.WindowManager;
 import android.webkit.JsPromptResult;  
 import android.webkit.WebChromeClient;  
19  import android.webkit.WebSettings;  import android.webkit.WebSettings;
20  import android.webkit.WebStorage;  import android.webkit.WebStorage;
 import android.webkit.WebStorage.QuotaUpdater;  
21  import android.webkit.WebView;  import android.webkit.WebView;
22  import android.webkit.WebViewClient;  import android.webkit.WebViewClient;
 import android.widget.EditText;  
23    
24  public class EKLLauncherActivity extends Activity {  public class EKLLauncherActivity extends Activity {
25                    
         class CustomChromeClient extends WebChromeClient {  
                   
                 @Override  
                 public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota, QuotaUpdater quotaUpdater) {  
                         quotaUpdater.updateQuota(totalUsedQuota + 4096);  
                 }  
   
   
26    
                 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  
                 }  
27                    
28    
                 @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);  
                         }                                                                        
                 }  
   
         }  
   
29          class DummyWebViewClient extends WebViewClient {                          class DummyWebViewClient extends WebViewClient {                
30          }          }
31                    
32          static final String URL = "http://omdeling.info/mobil/ekl/login.php";          public static final String LOGTAG = "EklLauncher";
33            static final String URL = "http://omdeling.info/mobil/ekl/";
34            //static final String URL = "http://t-hoerup.dk/android_js.html";
35                    
36          LocationManager locMgr;          LocationManager locMgr;
37          ConnectivityManager connMgr;          ConnectivityManager connMgr;
38          TelephonyManager telMgr;          TelephonyManager telMgr;
39          WebView web;          WebView web;
40          String device = "";          
41            PowerManager.WakeLock wakeLock;
42                    
43                    
44            @Override
45            public void onAttachedToWindow() {
46                this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
47                super.onAttachedToWindow();
48            }
49                    
50      /** Called when the activity is first created. */      /** Called when the activity is first created. */
51      @Override          @Override
52      public void onCreate(Bundle savedInstanceState) {      public void onCreate(Bundle savedInstanceState) {
53          super.onCreate(savedInstanceState);          super.onCreate(savedInstanceState);
54                    
55            Log.e(LOGTAG, "Creating");
56            
57          getWindow().requestFeature(Window.FEATURE_PROGRESS);          getWindow().requestFeature(Window.FEATURE_PROGRESS);
58                    
59                    
60          try {          try {
61                  int airplane = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON);                  int airplane = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON);
62                    
63                  if (airplane > 0) {                  if (airplane > 0) {
64                          Settings.System.putInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);                          Settings.System.putInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);
65                          Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);                          Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
# Line 137  public class EKLLauncherActivity extends Line 69  public class EKLLauncherActivity extends
69          } catch (Settings.SettingNotFoundException e) {          } catch (Settings.SettingNotFoundException e) {
70                  Log.d("EKL", "Exception " + e.getMessage() );                  Log.d("EKL", "Exception " + e.getMessage() );
71          }          }
72            
           
           
73          locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);          locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
74          telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);          telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
75          connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);          connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);        
76                            
         device = telMgr.getLine1Number();  
         if (device == null || device.equals("")) {  
                 device = telMgr.getDeviceId();  
                   
                 if(device == null)  
                         device = "";  
         }  
77                    
78          
79                    
80                    
81          setContentView(R.layout.main);          setContentView(R.layout.main);
82          web = (WebView) findViewById(R.id.web);          web = (WebView) findViewById(R.id.web);
# Line 176  public class EKLLauncherActivity extends Line 100  public class EKLLauncherActivity extends
100                    
101          settings.setSupportMultipleWindows(false);          settings.setSupportMultipleWindows(false);
102                    
103          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);  
104                    
105            web.addJavascriptInterface( jsPhone , "jsPhone");
106                    
107            web.setWebChromeClient(new EKLChromeClient(this) );
108            web.setWebViewClient( new DummyWebViewClient() ); // skal have en webviewclient for at kunne styre ved forlad tur
109                    
110    
111                    
112                    
113            //Vi kan ikke styre LocationManager - kun læse nuværende tilstand
114          if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) {          if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) {
                 //Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "network,gps");  
115                                    
116                  AlertDialog.Builder builder = new AlertDialog.Builder(this);                  AlertDialog.Builder builder = new AlertDialog.Builder(this);
117                  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)")
118              .setPositiveButton("OK", new DialogInterface.OnClickListener() {              .setPositiveButton("OK", new DialogInterface.OnClickListener() {
119                  public void onClick(DialogInterface dialog, int id) {                  public void onClick(DialogInterface dialog, int id) {
120                          Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS );                          Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS );                      
121                      startActivity(myIntent);                            startActivity(myIntent);      
122                  }                  }
123              })              })
124              .create()              .create()
125              .show();                    .show();      
126          }          }
127            
128      }      }
129            
130            @Override
131            protected void onStart() {
132                    super.onStart();
133                    
134                    Log.e(LOGTAG, "Starting");
135            PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
136            wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "EklLauncher");
137            wakeLock.acquire();
138            
139            web.loadUrl( URL );
140            
141            }
142        
143    
144            @Override
145            protected void onStop() {
146                    
147            Log.e(LOGTAG, "Stopping");
148            
149                    if (wakeLock != null && wakeLock.isHeld())
150                            wakeLock.release();
151                    
152                    if (!web.getUrl().equals("about:blank"))
153                            web.loadUrl("about:blank");
154                    
155                    super.onStop();
156            }
157            
158            static final int RELOAD = 1;
159            static final int FLUSH = 2;
160            static final int EXIT = 3;
161    
162          @Override          @Override
163          public boolean onCreateOptionsMenu(Menu menu) {          public boolean onCreateOptionsMenu(Menu menu) {
164                  MenuItem item;                  MenuItem item;
165                  item = menu.add(0, 1, 0, "Genindlæs side");                  item = menu.add(0, RELOAD, 0, "Genindlæs side");
166                  item.setIcon( R.drawable.ic_menu_refresh );                  item.setIcon( R.drawable.ic_menu_refresh );
167                                    
168                  item = menu.add(0, 2, 0, "Slet cache");                  item = menu.add(0, FLUSH, 0, "Slet cache");
169                  item.setIcon( R.drawable.ic_menu_delete );                  item.setIcon( R.drawable.ic_menu_delete );
170                    
171                    item = menu.add(0, EXIT, 0, "Forlad");
172                    item.setIcon( android.R.drawable.ic_menu_close_clear_cancel);
173                    
174                  return super.onCreateOptionsMenu(menu);                  return super.onCreateOptionsMenu(menu);
175          }          }
176    
177          @Override          @Override
178          public boolean onMenuItemSelected(int featureId, MenuItem item) {          public boolean onMenuItemSelected(int featureId, MenuItem item) {
179                  switch (item.getItemId()) {                  switch (item.getItemId()) {
180                  case 1:                  case RELOAD:
181                          web.reload();                          web.reload();
182                          break;                          break;
183                  case 2:                  case FLUSH:
                         WebStorage.getInstance().deleteAllData();  
184                          web.clearCache(true);                          web.clearCache(true);
185                            
186                            WebStorage.getInstance().deleteAllData();                      
187                            WebStorage.getInstance().deleteOrigin(URL);
188                            
189                          web.reload();                          web.reload();
190                          break;                          break;
191                    case EXIT:                                                      
192                            this.finish();
193                            break;                  
194                  }                  }
195                    
196                  return super.onMenuItemSelected(featureId, item);                  return super.onMenuItemSelected(featureId, item);
197          }          }
198                    
199        /*void showMessage(String msg) {
200            AlertDialog.Builder builder = new AlertDialog.Builder(this);
201            builder.setMessage(msg)
202        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
203            public void onClick(DialogInterface dialog, int id) {
204                dialog.dismiss();
205            }
206        })
207        .create()
208        .show();      
209            
210    }*/    
211            
212            /* Proof-of-concept code
213          Handler timeoutHandler = new Handler() {          Handler timeoutHandler = new Handler() {
214                  @Override                  @Override
215                  public void handleMessage(Message msg) {                  public void handleMessage(Message msg) {
# Line 236  public class EKLLauncherActivity extends Line 219  public class EKLLauncherActivity extends
219                                    
220          };          };
221                    
           
222    
         SimHandler simHandler = new SimHandler();  
223                    
224          class SimHandler extends Handler {          class SimHandler extends Handler {
225                                    
# Line 260  public class EKLLauncherActivity extends Line 241  public class EKLLauncherActivity extends
241                          testNetwork();                          testNetwork();
242                  }                  }
243          };          };
244            */
245            
246  }  }

Legend:
Removed from v.1625  
changed lines
  Added in v.2188

  ViewVC Help
Powered by ViewVC 1.1.20