/[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 1621 by torben, Fri Oct 21 04:59:27 2011 UTC revision 2185 by torben, Fri May 30 12:41:17 2014 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.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.Toast;  
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    
   
                 @Override  
                 public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg) {  
                         msg("create window");  
                         return super.onCreateWindow(view, dialog, userGesture, resultMsg);  
                 }  
   
   
                 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, JsPromptResult result) {  
                         if (message.trim().toLowerCase().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 {  
                                 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;
40          ConnectivityManager connMgr;          ConnectivityManager connMgr;
41          TelephonyManager telMgr;          TelephonyManager telMgr;
42          WebView web;          WebView web;
         String device = "";  
43                    
44            PowerManager.WakeLock wakeLock;
45            
46            SimHandler simHandler = new SimHandler();
47                    
48          public void msg(String m) {          @Override
49                  Toast.makeText(EKLLauncherActivity.this, m, Toast.LENGTH_SHORT).show();          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);
# Line 119  public class EKLLauncherActivity extends Line 73  public class EKLLauncherActivity extends
73          } catch (Settings.SettingNotFoundException e) {          } catch (Settings.SettingNotFoundException e) {
74                  Log.d("EKL", "Exception " + e.getMessage() );                  Log.d("EKL", "Exception " + e.getMessage() );
75          }          }
76            
77                    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                            
         device = telMgr.getLine1Number();  
         if (device == null || device.equals("")) {  
                 device = telMgr.getDeviceId();  
                   
                 if(device == null)  
                         device = "";  
         }  
81                    
82          
83                    
84                    
85          setContentView(R.layout.main);          setContentView(R.layout.main);
86          web = (WebView) findViewById(R.id.web);          web = (WebView) findViewById(R.id.web);
# Line 157  public class EKLLauncherActivity extends Line 104  public class EKLLauncherActivity extends
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          simHandler.sendEmptyMessage(0);          
117            if (!locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER )) {
118                    //Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "network,gps");
119                    
120                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
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)")
122                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
123                    public void onClick(DialogInterface dialog, int id) {
124                            Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS );                      
125                        startActivity(myIntent);      
126                    }
127                })
128                .create()
129                .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
163            protected void onStop() {
164                    
165            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                    
# Line 202  public class EKLLauncherActivity extends Line 225  public class EKLLauncherActivity extends
225                    
226                    
227    
228          SimHandler simHandler = new SimHandler();  
229                    
230          class SimHandler extends Handler {          class SimHandler extends Handler {
231                                    

Legend:
Removed from v.1621  
changed lines
  Added in v.2185

  ViewVC Help
Powered by ViewVC 1.1.20