Changeset 17620


Ignore:
Timestamp:
04/01/14 13:37:08 (11 years ago)
Author:
toanqngu
Message:

Updates to include online and offline web app mode

Location:
issm/mobile/android/ISSM_APP
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • issm/mobile/android/ISSM_APP/AndroidManifest.xml

    r17423 r17620  
    6666        <activity
    6767            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">
    6969        </activity>
    7070    </application>
  • issm/mobile/android/ISSM_APP/bin/AndroidManifest.xml

    r17423 r17620  
    6666        <activity
    6767            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">
    6969        </activity>
    7070    </application>
  • issm/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ISSMAPP.java

    r17423 r17620  
    1414import android.os.AsyncTask;
    1515import android.os.Bundle;
     16import android.os.CountDownTimer;
    1617import android.os.Environment;
     18import android.os.Handler;
    1719import android.util.Log;
    1820import android.view.Window;
     
    4345                setContentView(R.layout.splashscreen);
    4446                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);
    13369        }
    13470
     
    174110                        i.putExtra("pathToFile", issmFolder);
    175111                        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();
    176156                }
    177157        }
  • issm/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ISSMWebActivity.java

    r17423 r17620  
    11package gov.nasa.jpl.issm;
    22
    3 import android.net.NetworkInfo;
     3import java.net.URI;
     4
    45import android.os.Bundle;
     6import android.os.Handler;
    57import android.app.ActionBar;
    68import android.app.Activity;
    79import android.app.AlertDialog;
    8 import android.app.ProgressDialog;
    910import android.content.DialogInterface;
    10 import android.content.Intent;
    1111import android.util.Log;
    1212import android.view.Menu;
     
    1414import android.view.View;
    1515import android.view.View.OnClickListener;
     16import android.webkit.WebResourceResponse;
    1617import android.webkit.WebView;
    1718import android.widget.Button;
     
    2021
    2122        // 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 = "++";
    2324        private String offPath = "file:///android_asset/externalicelab/index.html";
    2425        private final String KEY = "mode";
     26        private String issmFolder = "";
    2527        private int MODE;
    2628        // private String srcPath =
     
    6971                myWebView = (WebView) findViewById(R.id.issmWeb);
    7072                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                        }
    83178                });
    84179                myWebView.getSettings().setJavaScriptEnabled(true);
     
    89184                        myWebView.loadUrl(srcPath);
    90185                } else {
     186                        issmFolder = getIntent().getExtras().getString("pathToFile");
    91187                        myWebView.loadUrl(offPath);
    92188                }
     
    142238                                                }).setNegativeButton("No", null).show();
    143239        }
    144 
    145240}
  • issm/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/MyWebViewClient.java

    r17423 r17620  
    22
    33import android.view.View;
     4import android.webkit.WebResourceResponse;
    45import android.webkit.WebView;
    56import android.webkit.WebViewClient;
     
    2021        }
    2122
     23        public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
     24                return null;
     25        }
     26
    2227}
Note: See TracChangeset for help on using the changeset viewer.