From: drizea Date: Tue, 12 Jun 2012 22:09:20 +0000 (+0300) Subject: Application basic preferences added still have to add test connection thread X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b8f2059f45e1ca096e861d38126db5ccdd643afd;p=working%2FEvergreen.git Application basic preferences added still have to add test connection thread --- diff --git a/Open-ILS/src/Android/AndroidManifest.xml b/Open-ILS/src/Android/AndroidManifest.xml index e28eec553b..59a5bc7a3a 100644 --- a/Open-ILS/src/Android/AndroidManifest.xml +++ b/Open-ILS/src/Android/AndroidManifest.xml @@ -30,7 +30,11 @@ android:name=".searchCatalog.SearchCatalogListView" android:label="@string/app_name" > - + + + 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 index 0000000000..907a1ff07a --- /dev/null +++ b/Open-ILS/src/Android/res/xml/application_preference_screen.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java index fd55c148a0..4d17bceaf6 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java @@ -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 { } - - } diff --git a/Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java b/Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java index 6f07bbeb2a..4d1a654cb2 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java @@ -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; diff --git a/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java b/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java index 183128e58f..b88a429414 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalogListView.java @@ -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 index 0000000000..53070e2755 --- /dev/null +++ b/Open-ILS/src/Android/src/org/evergreen/android/views/ApplicationPreferences.java @@ -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(); + } + + + +} diff --git a/Open-ILS/src/Android/src/org/evergreen/android/views/MainScreenDashboard.java b/Open-ILS/src/Android/src/org/evergreen/android/views/MainScreenDashboard.java index d687c767f8..4d4df21c40 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/views/MainScreenDashboard.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/views/MainScreenDashboard.java @@ -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: