From 063b3bb161e150ed1f09d6208b996ddb52253599 Mon Sep 17 00:00:00 2001 From: drizea Date: Fri, 15 Jun 2012 00:11:20 +0300 Subject: [PATCH] Bug fix on ApplicationPreferences crash on back and resume --- Open-ILS/src/Android/AndroidManifest.xml | 4 +- .../src/Android/res/layout/search_result_item.xml | 27 +++++---- Open-ILS/src/Android/res/values/styles.xml | 25 ++++++++ .../evergreen/android/globals/GlobalConfigs.java | 6 +- .../android/views/ApplicationPreferences.java | 67 ++++++++++++++++------ .../android/views/MainScreenDashboard.java | 3 +- 6 files changed, 102 insertions(+), 30 deletions(-) diff --git a/Open-ILS/src/Android/AndroidManifest.xml b/Open-ILS/src/Android/AndroidManifest.xml index 73aed056d2..62dd77e620 100644 --- a/Open-ILS/src/Android/AndroidManifest.xml +++ b/Open-ILS/src/Android/AndroidManifest.xml @@ -29,7 +29,9 @@ > + android:label="@string/app_name" + android:theme="@android:style/Theme.Light.NoTitleBar" + > + + + android:layout_height="wrap_content" + + /> - + android:layout_height="wrap_content" + + /> - diff --git a/Open-ILS/src/Android/res/values/styles.xml b/Open-ILS/src/Android/res/values/styles.xml index 37bdd8f385..376cc04edd 100644 --- a/Open-ILS/src/Android/res/values/styles.xml +++ b/Open-ILS/src/Android/res/values/styles.xml @@ -51,4 +51,29 @@ @null + + + + + + + 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 caf1eacc9b..50141d89aa 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 @@ -62,6 +62,10 @@ public class GlobalConfigs { GlobalConfigs.httpAddress = preferences.getString("library_url", ""); AccountAccess.setAccountInfo(preferences.getString("username", ""), preferences.getString("password", "")); + //authenticate + AccountAccess ac = new AccountAccess(GlobalConfigs.httpAddress); + ac.authenticate(); + return true; } return false; @@ -94,7 +98,7 @@ public class GlobalConfigs { System.out.println("Request org " + httpAddress + collectionsRequest ); }catch(Exception e){}; - + organisations = new ArrayList(); if(orgFile != null){ organisations = new ArrayList(); 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 index c745c5cf03..e7d82e2bc2 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/views/ApplicationPreferences.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/views/ApplicationPreferences.java @@ -27,10 +27,13 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar private ProgressDialog progressDialog; + private ApplicationPreferences reference; private Context context; private String TAG = "ApplicationPreferences"; + + private Thread connectionThread = null; @Override protected void onCreate(Bundle savedInstanceState) { @@ -39,12 +42,35 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar addPreferencesFromResource(R.xml.application_preference_screen); context = this; - + reference = this; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); //register preference listener prefs.registerOnSharedPreferenceChangeListener(this); } + + @Override + protected void onResume() { + super.onResume(); + reference = this; + } + @Override + protected void onPause() { + super.onPause(); + reference = null; + } + + @Override + protected void onStop() { + super.onStop(); + reference = null; + } + + @Override + protected void onDestroy() { + super.onDestroy(); + reference = null; + } @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { @@ -60,10 +86,10 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar } //test connection + if(!isFinishing()) + progressDialog = ProgressDialog.show(this, "Account login", "Please wait while we test the new user account information"); - progressDialog = ProgressDialog.show(this, "Account login", "Please wait while we test the new user account information"); - - Thread thread = new Thread(new Runnable() { + connectionThread = new Thread(new Runnable() { @Override public void run() { @@ -71,7 +97,7 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar boolean routeToAddress = true; AccountAccess account = new AccountAccess(GlobalConfigs.httpAddress); try{ - Utils.checkNetworkStatus((ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE), getApplicationContext()); + Utils.checkNetworkStatus((ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE), context); }catch(NoNetworkAccessException e){ routeToAddress = false; @@ -81,10 +107,12 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar @Override public void run() { - progressDialog.dismiss(); - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setMessage("There seams to be no network connectivity! Do you want to start network settings?").setPositiveButton("Yes", dialogClickListener) - .setNegativeButton("No", dialogClickListener).show(); + if(reference != null){ + progressDialog.dismiss(); + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setMessage("There seams to be no network connectivity! Do you want to start network settings?").setPositiveButton("Yes", dialogClickListener) + .setNegativeButton("No", dialogClickListener).show(); + } } }); @@ -96,7 +124,8 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar @Override public void run() { - Toast.makeText(getApplicationContext(), "There is no route to host :" + GlobalConfigs.httpAddress, Toast.LENGTH_LONG); + if(reference != null) + Toast.makeText(getApplicationContext(), "There is no route to host :" + GlobalConfigs.httpAddress, Toast.LENGTH_LONG).show(); } }); @@ -110,8 +139,10 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar @Override public void run() { - progressDialog.dismiss(); - Toast.makeText(context, "Autenthication successfully established :" + GlobalConfigs.httpAddress, Toast.LENGTH_LONG); + if(reference != null){ + progressDialog.dismiss(); + Toast.makeText(context, "Autenthication successfully established :" + GlobalConfigs.httpAddress, Toast.LENGTH_LONG).show(); + } } }); }else{ @@ -119,8 +150,10 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar @Override public void run() { - progressDialog.dismiss(); - Toast.makeText(context, "Please check username and password ", Toast.LENGTH_LONG); + if(reference != null){ + progressDialog.dismiss(); + Toast.makeText(context, "Please check username and password ", Toast.LENGTH_LONG).show(); + } } }); } @@ -130,13 +163,15 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar @Override public void run() { - progressDialog.dismiss(); + if(reference != null) + progressDialog.dismiss(); } }); } }); - thread.start(); + connectionThread.start(); + } /* * Dialog interface for starting the network settings 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 4d4df21c40..5473e9abf8 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 @@ -3,6 +3,7 @@ package org.evergreen.android.views; import org.evergreen.android.R; import org.evergreen.android.globals.GlobalConfigs; +import org.evergreen.android.searchCatalog.SearchCatalogListView; import android.app.Activity; import android.content.Intent; @@ -115,7 +116,7 @@ public class MainScreenDashboard extends Activity { switch (id) { case R.id.main_btn_search : - //startActivity (new Intent(getApplicationContext(), F1Activity.class)); + startActivity (new Intent(getApplicationContext(), SearchCatalogListView.class)); break; case R.id.main_btn_account: startActivity (new Intent(getApplicationContext(), AccountScreenDashboard.class)); -- 2.11.0