Changeset 17620
- Timestamp:
- 04/01/14 13:37:08 (11 years ago)
- Location:
- issm/mobile/android/ISSM_APP
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/mobile/android/ISSM_APP/AndroidManifest.xml
r17423 r17620 66 66 <activity 67 67 android:name="gov.nasa.jpl.issm.ISSMWebActivity" 68 android:label="@string/title_activity_issmweb_online" android: configChanges="orientation|screenSize">68 android:label="@string/title_activity_issmweb_online" android:screenOrientation="landscape"> 69 69 </activity> 70 70 </application> -
issm/mobile/android/ISSM_APP/bin/AndroidManifest.xml
r17423 r17620 66 66 <activity 67 67 android:name="gov.nasa.jpl.issm.ISSMWebActivity" 68 android:label="@string/title_activity_issmweb_online" android: configChanges="orientation|screenSize">68 android:label="@string/title_activity_issmweb_online" android:screenOrientation="landscape"> 69 69 </activity> 70 70 </application> -
issm/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ISSMAPP.java
r17423 r17620 14 14 import android.os.AsyncTask; 15 15 import android.os.Bundle; 16 import android.os.CountDownTimer; 16 17 import android.os.Environment; 18 import android.os.Handler; 17 19 import android.util.Log; 18 20 import android.view.Window; … … 43 45 setContentView(R.layout.splashscreen); 44 46 settings = this.getSharedPreferences("MenuPage", 0); 45 final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 46 if (conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED 47 || conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED) { 48 49 // temporary: display modes without messing with the network to 50 // be able to access offline mode 51 // AlertDialog.Builder builder = new AlertDialog.Builder(this); 52 // builder.setMessage("Pick a mode"); 53 // CharSequence[] options = { "Native", "Offline", "Online" }; 54 // builder.setItems(options, new DialogInterface.OnClickListener() { 55 // public void onClick(DialogInterface dialog, int which) { 56 // switch (which) { 57 // case 0: 58 // boolean firstrun = settings.getBoolean( 59 // PREFERENCE_FIRST_RUN, true); 60 // extStorageDirectory = Environment 61 // .getExternalStorageDirectory().toString(); 62 // issmFolder = extStorageDirectory + "/ISSM/input_files/"; 63 // imageList = new ImageList(ISSMAPP.this); 64 // new CopyDataTask().execute(firstrun); 65 // break; 66 // case 1: 67 // Intent j = new Intent(ISSMAPP.this, 68 // ISSMWebActivity.class); 69 // j.putExtra("mode", 1); 70 // startActivity(j); 71 // finish(); 72 // break; 73 // case 2: 74 // Intent i = new Intent(ISSMAPP.this, 75 // ISSMWebActivity.class); 76 // i.putExtra("mode", 0); 77 // startActivity(i); 78 // finish(); 79 // break; 80 // } 81 // } 82 // }); 83 // builder.create().show(); 84 new AlertDialog.Builder(this) 85 .setMessage("Pick a mode") 86 .setCancelable(false) 87 .setPositiveButton("Online", 88 new DialogInterface.OnClickListener() { 89 public void onClick(DialogInterface dialog, 90 int id) { 91 Intent i = new Intent(ISSMAPP.this, 92 ISSMWebActivity.class); 93 i.putExtra("mode", 0); 94 startActivity(i); 95 finish(); 96 } 97 }) 98 .setNeutralButton("Offline", 99 new DialogInterface.OnClickListener() { 100 public void onClick(DialogInterface dialog, 101 int id) { 102 Intent i = new Intent(ISSMAPP.this, 103 ISSMWebActivity.class); 104 i.putExtra("mode", 1); 105 startActivity(i); 106 finish(); 107 } 108 }) 109 .setNegativeButton("Native", 110 new DialogInterface.OnClickListener() { 111 public void onClick(DialogInterface dialog, 112 int id) { 113 boolean firstrun = settings.getBoolean( 114 PREFERENCE_FIRST_RUN, true); 115 extStorageDirectory = Environment 116 .getExternalStorageDirectory() 117 .toString(); 118 issmFolder = extStorageDirectory 119 + "/ISSM/input_files/"; 120 imageList = new ImageList(ISSMAPP.this); 121 new CopyDataTask().execute(firstrun); 122 } 123 }).show(); 124 125 } else { 126 boolean firstrun = settings.getBoolean(PREFERENCE_FIRST_RUN, true); 127 extStorageDirectory = Environment.getExternalStorageDirectory() 128 .toString(); 129 issmFolder = extStorageDirectory + "/ISSM/input_files/"; 130 imageList = new ImageList(this); 131 new CopyDataTask().execute(firstrun); 132 } 47 new Handler().postDelayed(new Runnable() { 48 @Override 49 public void run() { 50 // This method will be executed once the timer is over 51 final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 52 if (conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED 53 || conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED) { 54 Intent i = new Intent(ISSMAPP.this, ISSMWebActivity.class); 55 i.putExtra("mode", 0); 56 startActivity(i); 57 finish(); 58 } else { 59 60 boolean firstrun = settings.getBoolean( 61 PREFERENCE_FIRST_RUN, true); 62 extStorageDirectory = Environment 63 .getExternalStorageDirectory().toString(); 64 issmFolder = extStorageDirectory + "/ISSM/input_files/"; 65 new CopyMapTask().execute(firstrun); 66 } 67 } 68 }, 2000); 133 69 } 134 70 … … 174 110 i.putExtra("pathToFile", issmFolder); 175 111 startActivity(i); 112 } 113 } 114 115 // ----------------------------------------------------------------------- 116 private class CopyMapTask extends AsyncTask<Boolean, Void, Boolean> { 117 @Override 118 protected Boolean doInBackground(Boolean... target) { 119 // imageList.decodeAndResizeImageFromURL(); 120 // imageList.decodeAndResizeImage(); 121 // imageList.decodeLargeImage(); 122 // not sure why, but target[0] can be true on install! more to be 123 // done. 124 // if(target[0] = false) 125 // { 126 SharedPreferences.Editor e = settings.edit(); 127 e.putBoolean(PREFERENCE_FIRST_RUN, false); 128 129 e.commit(); 130 // If not, run these methods: 131 SetDirectory(issmFolder); 132 // } 133 return true; 134 } 135 136 @Override 137 protected void onPreExecute() { 138 progressDialog = new ProgressDialog(ISSMAPP.this); 139 progressDialog.setMessage("No connection detected. Loading offline mode"); 140 progressDialog.setIndeterminate(true); 141 progressDialog.setCancelable(false); 142 progressDialog.show(); 143 } 144 145 protected void onPostExecute(Boolean result) { 146 progressDialog.dismiss(); 147 // Log.i("imageList size: ", 148 // String.valueOf(ImageList.getImageList().size())); 149 // Log.i("largeImageList size: ", 150 // String.valueOf(ImageList.getLargeImages().size())); 151 Intent i = new Intent(ISSMAPP.this, ISSMWebActivity.class); 152 i.putExtra("pathToFile", issmFolder); 153 i.putExtra("mode", 1); 154 startActivity(i); 155 finish(); 176 156 } 177 157 } -
issm/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ISSMWebActivity.java
r17423 r17620 1 1 package gov.nasa.jpl.issm; 2 2 3 import android.net.NetworkInfo; 3 import java.net.URI; 4 4 5 import android.os.Bundle; 6 import android.os.Handler; 5 7 import android.app.ActionBar; 6 8 import android.app.Activity; 7 9 import android.app.AlertDialog; 8 import android.app.ProgressDialog;9 10 import android.content.DialogInterface; 10 import android.content.Intent;11 11 import android.util.Log; 12 12 import android.view.Menu; … … 14 14 import android.view.View; 15 15 import android.view.View.OnClickListener; 16 import android.webkit.WebResourceResponse; 16 17 import android.webkit.WebView; 17 18 import android.widget.Button; … … 20 21 21 22 // URL of the index page of the ISSM web application 22 private String srcPath = " http://issm.jpl.nasa.gov/externalicelab/index.html";23 private String srcPath = "++"; 23 24 private String offPath = "file:///android_asset/externalicelab/index.html"; 24 25 private final String KEY = "mode"; 26 private String issmFolder = ""; 25 27 private int MODE; 26 28 // private String srcPath = … … 69 71 myWebView = (WebView) findViewById(R.id.issmWeb); 70 72 myWebView.setWebViewClient(new MyWebViewClient() { 71 // @Override 72 // public boolean shouldOverrideUrlLoading(WebView view, String url) 73 // { 74 // loading.show(); 75 // return false; 76 // } 77 // 78 // @Override 79 // public void onPageFinished(WebView view, String url) { 80 // // hide loading 81 // loading.dismiss(); 82 // } 73 74 @Override 75 public boolean shouldOverrideUrlLoading(WebView view, String url) { 76 if (MODE != 0) { 77 if (url.startsWith("http") 78 && !url.contains("http://thwaites.jpl.nasa.gov/fastcgi/visl-solve.py?callbacks")) { 79 myWebView.setVisibility(View.INVISIBLE); 80 new AlertDialog.Builder(ISSMWebActivity.this) 81 .setTitle("Error!") 82 .setMessage( 83 "Option requires online mode. Please exit and enable connection to access the option.") 84 .setCancelable(false) 85 .setPositiveButton("Okay", 86 new DialogInterface.OnClickListener() { 87 public void onClick( 88 DialogInterface dialog, 89 int id) { 90 myWebView.loadUrl(offPath); 91 new Handler().postDelayed( 92 new Runnable() { 93 @Override 94 public void run() { 95 // This method 96 // will be 97 // executed once 98 // the timer is 99 // over 100 myWebView 101 .setVisibility(View.VISIBLE); 102 } 103 }, 700); 104 } 105 }).show(); 106 } 107 } 108 return false; 109 } 110 111 @Override 112 public WebResourceResponse shouldInterceptRequest(WebView view, 113 String url) { 114 Log.i("QUERY URL: ", url); 115 if (url.contains("http://thwaites.jpl.nasa.gov/fastcgi/visl-solve.py?callback")) { 116 new AlertDialog.Builder(ISSMWebActivity.this) 117 .setTitle("Yes!") 118 .setMessage("Caught server request sucessfully.") 119 .setCancelable(false) 120 .setPositiveButton("Okay", 121 new DialogInterface.OnClickListener() { 122 public void onClick( 123 DialogInterface dialog, int id) { 124 125 } 126 }).show(); 127 128 } 129 // temporary created to avoid compile error. This will cause app 130 // to crash at one point during runtime 131 return null; 132 133 // URI uri = URI.create(url); 134 // String scheme = uri.getScheme(); 135 // // If scheme not http(s), let the default webview manage it 136 // if (!"http".equals(scheme) && !"https".equals(scheme)) { 137 // return null; 138 // } 139 140 // URL url = uri.toURL(); 141 // 142 // if(doCancelRequest(url)) { 143 // // Empty response 144 // Log.d(TAG, "URL filtered: " + url); 145 // return new WebResourceResponse("text/plain", "UTF-8", new 146 // EmptyInputStream()); 147 // 148 // } else { 149 // Log.d(TAG, "URL: " + url); 150 // 151 // HttpURLConnection conn = (HttpURLConnection) 152 // url.openConnection(); 153 // conn.setRequestProperty("User-Agent", 154 // mSettings.getUserAgentString()); 155 // 156 // // Configure connections 157 // configureConnection(conn); 158 // 159 // String mimeType = conn.getContentType(); 160 // String encoding = conn.getContentEncoding(); 161 // 162 // if(mimeType != null && mimeType.contains(CONTENT_TYPE_SPLIT)) 163 // { 164 // String[] split = mimeType.split(CONTENT_TYPE_SPLIT); 165 // mimeType = split[0]; 166 // 167 // Matcher matcher = CONTENT_TYPE_PATTERN.matcher(split[1]); 168 // if(matcher.find()) { 169 // encoding = matcher.group(1); 170 // } 171 // } 172 // 173 // InputStream is = conn.getInputStream(); 174 // return new WebResourceResponse(mimeType, encoding, is); 175 // return null; 176 // } 177 } 83 178 }); 84 179 myWebView.getSettings().setJavaScriptEnabled(true); … … 89 184 myWebView.loadUrl(srcPath); 90 185 } else { 186 issmFolder = getIntent().getExtras().getString("pathToFile"); 91 187 myWebView.loadUrl(offPath); 92 188 } … … 142 238 }).setNegativeButton("No", null).show(); 143 239 } 144 145 240 } -
issm/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/MyWebViewClient.java
r17423 r17620 2 2 3 3 import android.view.View; 4 import android.webkit.WebResourceResponse; 4 5 import android.webkit.WebView; 5 6 import android.webkit.WebViewClient; … … 20 21 } 21 22 23 public WebResourceResponse shouldInterceptRequest(WebView view, String url) { 24 return null; 25 } 26 22 27 }
Note:
See TracChangeset
for help on using the changeset viewer.