added first application run configuration dialog
authordrizea <danielrizea27@gmail.com>
Wed, 25 Jul 2012 14:47:19 +0000 (17:47 +0300)
committerdrizea <danielrizea27@gmail.com>
Wed, 25 Jul 2012 14:47:19 +0000 (17:47 +0300)
if running the application for the first time the user must set an library
http server address and username and password for his account. For now the
logic at launch is that the application will not start if there if no network
access, and if there is route to library server url the application will
start a configuration dialog. When the correct http server address is entered
the splash screen will start and IDL and orgTree files will be downloaded
and parsed

Open-ILS/src/Android/res/layout/dialog_configure_application.xml [new file with mode: 0644]
Open-ILS/src/Android/res/values/strings.xml
Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java
Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java
Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java
Open-ILS/src/Android/src/org/evergreen/android/views/splashscreen/LoadingTask.java
Open-ILS/src/Android/src/org/evergreen/android/views/splashscreen/SplashActivity.java

diff --git a/Open-ILS/src/Android/res/layout/dialog_configure_application.xml b/Open-ILS/src/Android/res/layout/dialog_configure_application.xml
new file mode 100644 (file)
index 0000000..95434a1
--- /dev/null
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical" >
+
+    <TableLayout 
+        android:id="@+id/credentials"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        
+        >
+        
+        <TableRow 
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            >
+               <TextView 
+               android:layout_width = "wrap_content"
+               android:layout_height = "wrap_content"
+               android:text = "@string/server_name_dialog"
+               />   
+               
+               <EditText 
+                   android:id="@+id/server_http_adress"
+                   android:layout_width="200dip"
+                   android:layout_height="wrap_content"
+                   android:hint="@string/server_name_dialog"
+                   />
+            
+        </TableRow>
+        <TableRow 
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            >
+               <TextView 
+               android:layout_width = "wrap_content"
+               android:layout_height = "wrap_content"
+               android:text = "@string/username"
+               />   
+               
+               <EditText 
+                   android:id="@+id/username"
+                   android:layout_width="200dip"
+                   android:layout_height="wrap_content"
+                   android:hint="@string/username"
+                   />
+            
+        </TableRow>
+        <TableRow 
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            >
+               <TextView 
+               android:layout_width = "wrap_content"
+               android:layout_height = "wrap_content"
+               android:text = "@string/password"
+               />   
+               
+               <EditText 
+                   android:id="@+id/password"
+                   android:layout_width="200dip"
+                   android:layout_height="wrap_content"
+                   android:password="true"
+                   />
+            
+        </TableRow>
+    </TableLayout> 
+    
+    <Button
+        android:id="@+id/cancel_button"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/cancel"
+        android:layout_below="@id/credentials"
+        />
+    <Button 
+        android:id="@+id/connect_button"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/connect_button"
+        android:layout_below="@id/credentials"
+        android:layout_toRightOf="@id/cancel_button"
+        />
+    
+</RelativeLayout>
\ No newline at end of file
index 1333c20..a6b3bd0 100644 (file)
     
     
     
+    <string name="server_name_dialog">http:// </string>
+    <string name="username">username : </string>
+    <string name="password">password : </string>
+    
+    <string name="cancel_button">cancel</string>
+    <string name="connect_button">connect</string>
+    
     <string name="search_hint">What are you looking for?</string>
     <string name="advanced_search_hint">Enter text here</string>
     <string name="advanced_search_add_filter_button">Add filter</string>
index 7fbf4f9..c41639d 100644 (file)
@@ -24,6 +24,7 @@ import org.opensrf.net.http.HttpRequest;
 import org.opensrf.util.OSRFObject;
 
 import android.net.ConnectivityManager;
+import android.util.Log;
 
 /**
  * The Class AuthenticateUser.
@@ -225,6 +226,9 @@ public class AccountAccess {
        public static String METHOD_CONTAINER_ITEM_CREATE = "open-ils.actor.container.item.create";
        
        public static String METHOD_CONTAINER_FULL_DELETE = "open-ils.actor.container.full_delete";
+       
+       public ArrayList<BookBag> bookBags = null;
+       
        /** The conn. */
        public HttpConnection conn;
 
@@ -458,7 +462,12 @@ public class AccountAccess {
                                }
                                
                                //get user ID
-                               accountAccess.getAccountSummary();
+                               try{
+                                       accountAccess.getAccountSummary();
+                               }catch(Exception e){
+                                       Log.d(TAG, "Error in retrieving account info, this is normal if it is before IDL load");
+                               }
+                               
                                return true;
                        }
                
@@ -1002,6 +1011,9 @@ public class AccountAccess {
                
                ArrayList<BookBag> bookBagObj = new ArrayList<BookBag>();
                
+               //in order to refresh bookbags
+               this.bookBags = bookBagObj;
+               
                for(int i=0;i<bookbags.size();i++){
                        
                        BookBag bag = new BookBag(bookbags.get(i));     
index b3d0e09..18aab14 100644 (file)
@@ -23,7 +23,7 @@ import android.util.Log;
 
 public class GlobalConfigs {
 
-       public static String httpAddress = "http://ulysses.calvin.edu";
+       public static String httpAddress = "";
 
        private boolean init = false;
 
index a4ec2e5..a518e4d 100644 (file)
@@ -176,6 +176,9 @@ public class SearchCatalogListView extends Activity{
                 dialog.show();
                        }
                });
+        //get bookbags
+        AccountAccess ac = AccountAccess.getAccountAccess();
+        bookBags = ac.bookBags;
         
         libraryHoursButton = (Button) findViewById(R.id.library_hours_button);
         libraryHoursButton.setOnClickListener(new OnClickListener() {
@@ -447,54 +450,6 @@ public class SearchCatalogListView extends Activity{
                        }
         
         });
-    
-        //get bookbags
-        Runnable getBookbagsRunnable = new Runnable() {
-                       
-                       @Override
-                       public void run() {
-                               runOnUiThread(new Runnable() {
-                                       @Override
-                                       public void run() {
-                                               progressDialog = ProgressDialog.show(context, "Plese wait", "retrieving Bookbag data");
-                                       }
-                               });
-                               AccountAccess accountAccess = AccountAccess.getAccountAccess();
-                               try {
-                                       bookBags = accountAccess.getBookbags();
-                               }  catch (NoNetworkAccessException e) {
-                                       Utils.showNetworkNotAvailableDialog(context);
-                               } catch (NoAccessToServer e) {
-                                       Utils.showServerNotAvailableDialog(context);
-                                       
-                               }catch (SessionNotFoundException e) {
-                                       //TODO other way?
-                                       try{
-                                               if(accountAccess.authenticate())
-                                                       accountAccess.getBookbags();
-                                       }catch(Exception eauth){
-                                               System.out.println("Exception in reAuth");
-                                       }
-                               }                       
-       
-                               runOnUiThread(new Runnable() {
-                                       
-                                       @Override
-                                       public void run() {
-                                               progressDialog.dismiss();
-                                               
-                                       
-                                               
-                                       }
-                               });
-                               
-                               
-                       }
-               };
-
-               Thread getBookBags = new Thread(getBookbagsRunnable);
-               getBookBags.start();
-        
         
     }
     @Override
index 77217f8..cb825b2 100644 (file)
@@ -1,8 +1,12 @@
 package org.evergreen.android.views.splashscreen;
 
 import org.evergreen.android.accountAccess.AccountAccess;
+import org.evergreen.android.accountAccess.SessionNotFoundException;
 import org.evergreen.android.globals.GlobalConfigs;
+import org.evergreen.android.globals.NoAccessToServer;
+import org.evergreen.android.globals.NoNetworkAccessException;
 
+import android.app.Activity;
 import android.content.Context;
 import android.net.ConnectivityManager;
 import android.os.AsyncTask;
@@ -25,22 +29,25 @@ public class LoadingTask extends AsyncTask<String, Integer, Integer> {
        
        private TextView progressText;
        
+       private Activity callingActivity;
+       
        private String text;
        /**
         * A Loading task that will load some resources that are necessary for the app to start
         * @param progressBar - the progress bar you want to update while the task is in progress
         * @param finishedListener - the listener that will be told when this task is finished
         */
-       public LoadingTask(ProgressBar progressBar, LoadingTaskFinishedListener finishedListener, Context context, TextView progressText) {
+       public LoadingTask(ProgressBar progressBar, LoadingTaskFinishedListener finishedListener, Context context, TextView progressText, Activity callingActivity) {
                this.progressBar = progressBar;
                this.finishedListener = finishedListener;
                this.context = context;
                this.progressText = progressText;
+               this.callingActivity = callingActivity;
        }
 
        @Override
        protected Integer doInBackground(String... params) {
-               Log.i("Tutorial", "Starting task with url: "+params[0]);
+               Log.i("Start download", "Starting task with url: "+params[0]);
                if(resourcesDontAlreadyExist()){
                        downloadResources();
                }
@@ -69,6 +76,20 @@ public class LoadingTask extends AsyncTask<String, Integer, Integer> {
                try{
                        ac.authenticate();
                }catch(Exception e){}
+               text = "get user bookbags";
+               publishProgress(90);
+               
+               try {
+                       ac.bookBags = ac.getBookbags();
+               } catch (SessionNotFoundException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (NoNetworkAccessException e) {
+                       e.printStackTrace();
+               } catch (NoAccessToServer e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
                text = "loading application";
                publishProgress(100);
                
index cb056b3..5580150 100644 (file)
 package org.evergreen.android.views.splashscreen;
 
-
-
 import org.evergreen.android.R;
+import org.evergreen.android.accountAccess.AccountAccess;
+import org.evergreen.android.globals.GlobalConfigs;
+import org.evergreen.android.globals.NoAccessToServer;
+import org.evergreen.android.globals.NoNetworkAccessException;
+import org.evergreen.android.globals.Utils;
 import org.evergreen.android.views.MainScreenDashboard;
 import org.evergreen.android.views.splashscreen.LoadingTask.LoadingTaskFinishedListener;
 
 import android.app.Activity;
+import android.app.Dialog;
+import android.app.ProgressDialog;
+import android.app.Service;
+import android.content.Context;
 import android.content.Intent;
+import android.content.SharedPreferences;
+import android.net.ConnectivityManager;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
 import android.widget.ProgressBar;
 import android.widget.TextView;
+import android.widget.Toast;
 
-public class SplashActivity extends Activity implements LoadingTaskFinishedListener {
+public class SplashActivity extends Activity implements
+               LoadingTaskFinishedListener {
 
-       
        private TextView progressText;
-       
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        // Show the splash screen
-        setContentView(R.layout.activity_splash);
-        
-        progressText = (TextView) findViewById(R.id.action_in_progress);
-        
-        // Find the progress bar
-        ProgressBar progressBar = (ProgressBar) findViewById(R.id.activity_splash_progress_bar);
-        // Start your loading
-        new LoadingTask(progressBar, this, this, progressText).execute("download"); // Pass in whatever you need a url is just an example we don't use it in this tutorial
-    }
-
-    // This is the callback for when your async task has finished
-    @Override
+
+       private Context context;
+
+       private Dialog dialog = null;
+
+       private ProgressDialog progressDialog = null;
+
+       private EditText server_http;
+
+       private EditText username;
+
+       private EditText password;
+
+       private ProgressBar progressBar;
+
+       private SplashActivity activity;
+
+       private String TAG = "SplashActivity";
+
+       @Override
+       public void onCreate(Bundle savedInstanceState) {
+               super.onCreate(savedInstanceState);
+               this.context = this;
+               // Show the splash screen
+               setContentView(R.layout.activity_splash);
+
+               activity = this;
+               dialog = new Dialog(context);
+               dialog.setContentView(R.layout.dialog_configure_application);
+               dialog.setTitle("Configure application");
+
+               server_http = (EditText) dialog.findViewById(R.id.server_http_adress);
+               username = (EditText) dialog.findViewById(R.id.username);
+               password = (EditText) dialog.findViewById(R.id.password);
+               Button cancel = (Button) dialog.findViewById(R.id.cancel_button);
+               Button connect = (Button) dialog.findViewById(R.id.connect_button);
+
+               cancel.setOnClickListener(new OnClickListener() {
+
+                       @Override
+                       public void onClick(View v) {
+                               Toast.makeText(context, "Exit application", Toast.LENGTH_SHORT)
+                                               .show();
+                               finish();
+                       }
+               });
+
+               connect.setOnClickListener(new OnClickListener() {
+
+                       @Override
+                       public void onClick(View v) {
+
+                               Thread checkConn = new Thread(new Runnable() {
+                                       @Override
+                                       public void run() {
+
+                                               boolean server_address = false;
+                                               boolean auth = false;
+
+                                               try {
+                                                       server_address = Utils
+                                                                       .checkIfNetAddressIsReachable(server_http
+                                                                                       .getText().toString());
+                                               } catch (NoAccessToServer e) {
+                                                       server_address = false;
+                                               }
+
+                                               if (server_address == true) {
+
+                                                       SharedPreferences preferences = PreferenceManager
+                                                                       .getDefaultSharedPreferences(context);
+                                                       SharedPreferences.Editor editor = preferences
+                                                                       .edit();
+                                                       //store into preference
+                                                       editor.putString("library_url", server_http
+                                                                       .getText().toString());
+
+                                                       
+                                                       editor.putString("username", username.getText().toString());
+                                                       editor.putString("password", password.getText().toString());
+                                                       
+                                                       editor.commit();
+                                                       GlobalConfigs.httpAddress = server_http.getText().toString();
+                                                       AccountAccess accountAccess = AccountAccess
+                                                                       .getAccountAccess(GlobalConfigs.httpAddress,(ConnectivityManager) activity.getSystemService(Service.CONNECTIVITY_SERVICE));
+                                                       
+                                                       AccountAccess.setAccountInfo(username.getText().toString(),password.getText().toString());
+
+                                                       try {
+                                                               auth = accountAccess.authenticate();
+                                                               Log.d(TAG, "Auth " + auth);
+                                                       } catch (Exception e) {
+                                                               System.out.println("Exception " + e.getMessage());
+                                                       }
+
+                                                       if (auth == true) {
+
+                                                               runOnUiThread(new Runnable() {
+                                                                       @Override
+                                                                       public void run() {
+                                                                               progressDialog.dismiss();
+                                                                               dialog.dismiss();
+                                                                               // Start your loading
+                                                                               new LoadingTask(progressBar, activity,
+                                                                                               activity, progressText, activity)
+                                                                                               .execute("download");
+                                                                       }
+                                                               });
+
+                                                       } else {
+                                                               runOnUiThread(new Runnable() {
+                                                                       @Override
+                                                                       public void run() {
+                                                                               progressDialog.dismiss();
+                                                                               Toast.makeText(context,
+                                                                                               "Bad user login information",
+                                                                                               Toast.LENGTH_LONG).show();
+                                                                       }
+                                                               });
+                                                       }
+
+                                               } else {
+                                                       runOnUiThread(new Runnable() {
+                                                               @Override
+                                                               public void run() {
+                                                                       progressDialog.dismiss();
+                                                                       Toast.makeText(context,
+                                                                                       "Bad library server url",
+                                                                                       Toast.LENGTH_LONG).show();
+                                                               }
+                                                       });
+
+                                               }
+
+                                       }
+                               });
+
+                               progressDialog = ProgressDialog.show(context, "Please wait",
+                                               "Checking server and credentials");
+                               checkConn.start();
+                       }
+               });
+
+               dialog.setCancelable(true);
+
+               progressText = (TextView) findViewById(R.id.action_in_progress);
+
+               // Find the progress bar
+               progressBar = (ProgressBar) findViewById(R.id.activity_splash_progress_bar);
+
+               boolean abort = false;
+               
+               
+               SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+               GlobalConfigs.httpAddress = prefs.getString("library_url", ""); 
+               String username = prefs.getString("username", "username");
+               String password = prefs.getString("password", "pas");
+               AccountAccess.setAccountInfo(username, password);
+               try {
+                       
+                       Utils.checkNetworkStatus((ConnectivityManager) getSystemService(Service.CONNECTIVITY_SERVICE));
+               } catch (NoNetworkAccessException e) {
+                       abort = true;
+                       e.printStackTrace();
+               } catch (NoAccessToServer e) {
+                       abort = true;
+
+                       dialog.show();
+
+               }
+
+               if (abort != true) {
+                       // Start your loading
+                       new LoadingTask(progressBar, this, this, progressText, this)
+                                       .execute("download"); // Pass in whatever you need a url is
+                                                                                       // just an example we don't use it
+                                                                                       // in this tutorial
+               }
+       }
+
+       // This is the callback for when your async task has finished
+       @Override
        public void onTaskFinished() {
                completeSplash();
        }
 
-    private void completeSplash(){
+       private void completeSplash() {
                startApp();
-               finish(); // Don't forget to finish this Splash Activity so the user can't return to it!
-    }
+               finish(); // Don't forget to finish this Splash Activity so the user
+                                       // can't return to it!
+       }
 
-    private void startApp() {
-               Intent intent = new Intent(SplashActivity.this, MainScreenDashboard.class);
+       private void startApp() {
+               Intent intent = new Intent(SplashActivity.this,
+                               MainScreenDashboard.class);
                startActivity(intent);
        }
 }
\ No newline at end of file