Application basic preferences added still have to add test connection thread
authordrizea <danielrizea27@gmail.com>
Tue, 12 Jun 2012 22:09:20 +0000 (01:09 +0300)
committerdrizea <danielrizea27@gmail.com>
Tue, 12 Jun 2012 22:09:20 +0000 (01:09 +0300)
Open-ILS/src/Android/AndroidManifest.xml
Open-ILS/src/Android/res/xml/application_preference_screen.xml [new file with mode: 0644]
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/ApplicationPreferences.java [new file with mode: 0644]
Open-ILS/src/Android/src/org/evergreen/android/views/MainScreenDashboard.java

index e28eec5..59a5bc7 100644 (file)
             android:name=".searchCatalog.SearchCatalogListView"
             android:label="@string/app_name" >
         </activity>
-        
+        <activity
+            android:name=".views.ApplicationPreferences"
+            >
+            
+        </activity>
         <activity android:name=".searchCatalog.RecordDetails_Info"></activity>
                <activity android:name=".searchCatalog.RecordDetails_Content"></activity>
         <activity android:name=".searchCatalog.RecordDetails_Details"></activity>
diff --git a/Open-ILS/src/Android/res/xml/application_preference_screen.xml b/Open-ILS/src/Android/res/xml/application_preference_screen.xml
new file mode 100644 (file)
index 0000000..907a1ff
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        android:key="first_preferencescreen">
+        <PreferenceCategory
+          android:summary="Username and password information"
+          android:title="Login information" >
+               <EditTextPreference
+            android:key="username"
+            android:summary="Please enter your login username"
+            android:title="Username" />
+               <EditTextPreference
+            android:key="password"
+            android:summary="Enter your password"
+            android:title="Password"
+            android:inputType="textPassword"
+             />
+        </PreferenceCategory>
+   
+        
+                <PreferenceCategory
+          android:summary="Username and password information"
+          android:title="Login information" >
+               <EditTextPreference
+            android:key="library_url"
+            android:summary="Please enter the library url in format http://"
+            android:title="Library url address" />
+
+        </PreferenceCategory>
+   
+</PreferenceScreen> 
\ No newline at end of file
index fd55c14..4d17bce 100644 (file)
@@ -14,6 +14,9 @@ import org.opensrf.net.http.HttpConnection;
 import org.opensrf.net.http.HttpRequest;
 import org.opensrf.util.OSRFObject;
 
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+
 /**
  * The Class AuthenticateUser.
  */
@@ -215,10 +218,10 @@ public class AccountAccess {
        private Integer userID = null;
        //for demo purpose
        /** The user name. */
-       private String userName = "daniel";
+       public static String userName = "daniel";
 
        /** The password. */
-       private String password = "demo123";
+       public static String password = "demo123";
        
        /**
         * Instantiates a new authenticate user.
@@ -274,14 +277,21 @@ public class AccountAccess {
            return "";
        }
        
+       public static void setAccountInfo(String username, String password){
+               
+               AccountAccess.userName = username;
+               AccountAccess.password = password;
+               
+       }
+       
        /**
         * Authenticate.
         */
-       public void authenticate(){
+       public boolean authenticate(){
                
                String seed = authenticateInit();
                
-               authenticateComplete(seed);
+               return authenticateComplete(seed);
        }
 
        /**
@@ -341,9 +351,10 @@ public class AccountAccess {
         * Phase 2 of login process
         * Application send's username and hash to confirm login
         * @param seed the seed
+        * @returns bollean if auth was ok
         */
-       private void authenticateComplete(String seed) {
-               
+       private boolean authenticateComplete(String seed) {
+
                //calculate hash to pass to server for authentication process phase 2
                //seed = "b18a9063e0c6f49dfe7a854cc6ab5775";
                String hash = md5(seed+md5(password));
@@ -384,10 +395,12 @@ public class AccountAccess {
                                }catch(Exception e){
                                        System.err.println("Error in parsing authtime " + e.getMessage());
                                }
-                               System.out.println();
+                               
+                               return true;
                        }
                }
                
+               return false;
                
        }
 
@@ -794,6 +807,4 @@ public class AccountAccess {
                
        }
        
-       
-       
 }
index 6f07bbe..4d1a654 100644 (file)
@@ -1,13 +1,16 @@
 package org.evergreen.android.globals;
 
 import java.io.InputStream;
-import java.security.KeyStore.LoadStoreParameter;
 import java.util.ArrayList;
 import java.util.StringTokenizer;
 
+import org.evergreen.android.accountAccess.AccountAccess;
 import org.evergreen.android.searchCatalog.Organisation;
 import org.open_ils.idl.IDLParser;
 
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
 import android.util.Log;
 
 public class GlobalConfigs {
@@ -29,16 +32,16 @@ public class GlobalConfigs {
        private String collectionsRequest = "/opac/common/js/";
        
        
-       private GlobalConfigs(){
+       private GlobalConfigs(Context context){
                
-               initialize();
+               initialize(context);
        }
        
-       public static GlobalConfigs getGlobalConfigs(){
+       public static GlobalConfigs getGlobalConfigs(Context context){
                
                if(globalConfigSingleton == null)
                {
-                       globalConfigSingleton = new GlobalConfigs();
+                       globalConfigSingleton = new GlobalConfigs(context);
                }
                
                return globalConfigSingleton;
@@ -46,7 +49,7 @@ public class GlobalConfigs {
        
        /* Initialize function that retrieves IDL file and Orgs file
         */
-       private boolean initialize(){
+       private boolean initialize(Context context){
                
                if(init == false){
                        
@@ -54,6 +57,11 @@ public class GlobalConfigs {
                        init = true;
                        loadIDLFile();
                        getOrganisations();
+               
+                       SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+                       GlobalConfigs.httpAddress = preferences.getString("library_url", "");
+                       AccountAccess.setAccountInfo(preferences.getString("username", ""), preferences.getString("password", ""));
+                       
                        return true;
                }
                return false;
index 183128e..b88a429 100644 (file)
@@ -64,7 +64,7 @@ public class SearchCatalogListView extends Activity{
         setContentView(R.layout.search_result_list);
 
         //singleton initialize necessary IDL and Org data
-        globalConfigs = GlobalConfigs.getGlobalConfigs();
+        globalConfigs = GlobalConfigs.getGlobalConfigs(this);
         
         context = this;
         search = new SearchCatalog("http://ulysses.calvin.edu",this);
diff --git a/Open-ILS/src/Android/src/org/evergreen/android/views/ApplicationPreferences.java b/Open-ILS/src/Android/src/org/evergreen/android/views/ApplicationPreferences.java
new file mode 100644 (file)
index 0000000..53070e2
--- /dev/null
@@ -0,0 +1,75 @@
+package org.evergreen.android.views;
+
+import org.evergreen.android.R;
+import org.evergreen.android.accountAccess.AccountAccess;
+import org.evergreen.android.globals.GlobalConfigs;
+
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceManager;
+
+public class ApplicationPreferences extends PreferenceActivity implements OnSharedPreferenceChangeListener{
+
+       
+       private ProgressDialog progressDialog;
+       
+       @Override
+       protected void onCreate(Bundle savedInstanceState) {
+
+               super.onCreate(savedInstanceState);
+               
+               addPreferencesFromResource(R.xml.application_preference_screen);
+               
+               Context context = getApplicationContext();
+               
+               SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+               //register preference listener
+               prefs.registerOnSharedPreferenceChangeListener(this);
+       }
+
+       @Override
+       public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
+                       String key) {
+               
+               if(key.equals("username")){
+                       AccountAccess.userName = sharedPreferences.getString("username", "");
+               }else
+                       if(key.equals("password")){
+                               AccountAccess.password = sharedPreferences.getString("password", "");
+                       }else
+                               if(key.equals("library_url")){
+                                       GlobalConfigs.httpAddress = sharedPreferences.getString("library_url", "");
+                               }
+               
+               //test connection
+               
+               progressDialog = ProgressDialog.show(this, "Account login", "Please wait while we test the new user account information");
+               
+               Thread thread = new Thread(new Runnable() {
+                       
+                       @Override
+                       public void run() {
+                               
+                               AccountAccess account = new AccountAccess(GlobalConfigs.httpAddress);
+                               account.authenticate();
+                               runOnUiThread(new Runnable() {
+                                       
+                                       @Override
+                                       public void run() {
+                                               progressDialog.dismiss();
+                                               
+                                       }
+                               });
+                       }
+               });
+               
+               thread.start();
+       }
+
+       
+       
+}
index d687c76..4d4df21 100644 (file)
@@ -32,7 +32,7 @@ public class MainScreenDashboard extends Activity {
                //init here globals, 
                //TODO in future do a splash screen (loading data)
                
-               GlobalConfigs globalConfigs = GlobalConfigs.getGlobalConfigs();
+               GlobalConfigs globalConfigs = GlobalConfigs.getGlobalConfigs(this);
        }
 
        /**
@@ -121,7 +121,7 @@ public class MainScreenDashboard extends Activity {
                   startActivity (new Intent(getApplicationContext(), AccountScreenDashboard.class));
                   break;
              case R.id.main_btn_app_settings :
-                  //startActivity (new Intent(getApplicationContext(), F3Activity.class));
+                  startActivity(new Intent(getApplicationContext(),ApplicationPreferences.class));
                   break;
 
              default: