Skip to content

Commit

Permalink
Fixed: crash when clicking home button in SettingsActivity.java in AP…
Browse files Browse the repository at this point in the history
…I level 10 and below

Show preference setting in summary
Set ActionBar title of preference screens
  • Loading branch information
codinguser committed Aug 20, 2012
1 parent 4133c28 commit fd5e4c4
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 22 deletions.
2 changes: 1 addition & 1 deletion GnucashMobile/res/menu/account_actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:showAsAction="always"/>

<item android:id="@+id/menu_export"
android:icon="@drawable/content_import_export_holo_dark"
android:icon="@drawable/content_import_export_holo_light"
android:title="@string/export_ofx"
android:showAsAction="never"
android:orderInCategory="3"/>
Expand Down
10 changes: 6 additions & 4 deletions GnucashMobile/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<string name="btn_export">Export</string>
<string name="confirm_post_export_delete">Delete after export</string>
<string name="hint_delete_after_export">All exported transactions will be deleted when exporting is completed</string>

<string name="title_settings">Settings</string>
<string-array name="export_destinations">
<item>Share file&#8230;</item>
<item>SD Card</item>
Expand All @@ -68,7 +68,7 @@
<string name="label_move_destination">Destination Account</string>
<string name="permission_access_sdcard">Access SD Card</string>
<string name="title_share_ofx_with">Share OFX export with&#8230;</string>
<string name="pref_default_currency">default_currency</string>
<string name="key_default_currency">default_currency</string>
<string name="toast_incompatible_currency">Cannot move transactions.\nThe destination account uses a different currency from origin account</string>
<string name="header_general_settings">General</string>
<string name="header_about_gnucash">About</string>
Expand Down Expand Up @@ -452,13 +452,15 @@
<string name="title_build_version">Build version</string>
<string name="app_version">1.0.beta1</string>
<string name="title_license">License</string>
<string name="summary_licence_details">Details to the application license</string>
<string name="summary_licence_details">Apache License v2.0. Click for details</string>
<string name="title_general_prefs">General</string>
<string name="key_license">app_license</string>
<string name="label_widget_configuration">Select Account</string>
<string name="toast_no_transactions_to_export">There are no transactions available to export</string>
<string name="key_about">About GnucashMobile</string>
<string name="title_about_gnucash">About GnucashMobile</string>
<string name="title_about_gnucash">About Gnucash</string>
<string name="summary_about_gnucash">GnucashMobile is a mobile finance expense tracker application for Android.\nIt enables flexible tracking of expenses on-the-go which can be exported to the Open Financial eXchange (OFX) format and imported into Gnucash for the desktop.</string>
<string name="title_about">About</string>


</resources>
2 changes: 1 addition & 1 deletion GnucashMobile/res/xml/fragment_about_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<Preference android:key="@string/key_about" android:summary="@string/summary_about_gnucash"/><Preference android:summary="@string/app_version" android:key="@string/key_build_version" android:title="@string/title_build_version"/>
<Preference android:key="@string/key_about" android:summary="@string/summary_about_gnucash" android:title="@string/title_about"/><Preference android:summary="@string/app_version" android:key="@string/key_build_version" android:title="@string/title_build_version"/>
<Preference android:summary="@string/summary_licence_details"
android:title="@string/title_license"
android:key="@string/key_license">
Expand Down
2 changes: 1 addition & 1 deletion GnucashMobile/res/xml/fragment_general_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<ListPreference android:summary="@string/summary_default_currency" android:key="@string/pref_default_currency" android:dialogTitle="@string/choose_currency" android:title="@string/title_default_currency" android:entries="@array/currency_names" android:entryValues="@array/currency_codes"/>
<ListPreference android:summary="@string/summary_default_currency" android:key="@string/key_default_currency" android:dialogTitle="@string/choose_currency" android:title="@string/title_default_currency" android:entries="@array/currency_names" android:entryValues="@array/currency_codes"/>


</PreferenceScreen>
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_accounts);

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String currencyCode = prefs.getString(getString(R.string.pref_default_currency),
String currencyCode = prefs.getString(getString(R.string.key_default_currency),
Currency.getInstance(Locale.getDefault()).getCurrencyCode());
Money.DEFAULT_CURRENCY_CODE = currencyCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
import java.util.List;

import org.gnucash.android.R;
import org.gnucash.android.data.Money;

import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
Expand All @@ -33,7 +38,7 @@
* @author Ngewi Fet <ngewif@gmail.com>
*
*/
public class SettingsActivity extends SherlockPreferenceActivity{
public class SettingsActivity extends SherlockPreferenceActivity implements OnPreferenceChangeListener{

/**
* Constructs the headers to display in the header list when the Settings activity is first opened
Expand All @@ -49,52 +54,101 @@ public void onBuildHeaders(List<Header> target) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(R.string.title_settings);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
addPreferencesFromResource(R.xml.fragment_general_preferences);
addPreferencesFromResource(R.xml.fragment_about_preferences);
}
setDefaultCurrencyListener();
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
android.app.FragmentManager fm = getFragmentManager();
if (fm.getBackStackEntryCount() > 0) {
fm.popBackStack();
} else {
finish();
}
case android.R.id.home:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
android.app.FragmentManager fm = getFragmentManager();
if (fm.getBackStackEntryCount() > 0) {
fm.popBackStack();
} else {
finish();
}
} else {
finish();
}
return true;

default:
return false;
}
}


@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(newValue.toString());
if (preference.getKey().equals(getString(R.string.key_default_currency))){
Money.DEFAULT_CURRENCY_CODE = newValue.toString();
}
return true;
}

private void setDefaultCurrencyListener() {
SharedPreferences manager = PreferenceManager.getDefaultSharedPreferences(this);
String defaultCurrency = manager.getString(getString(R.string.key_default_currency), Money.DEFAULT_CURRENCY_CODE);
@SuppressWarnings("deprecation")
Preference pref = findPreference(getString(R.string.key_default_currency));
pref.setSummary(defaultCurrency);
pref.setOnPreferenceChangeListener(this);
}

/**
* Fragment for displaying general preferences
* @author Ngewi Fet <ngewif@gmail.com>
*
*/
public static class GeneralPreferenceFragment extends PreferenceFragment{
public static class GeneralPreferenceFragment extends PreferenceFragment implements OnPreferenceChangeListener{

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

addPreferencesFromResource(R.xml.fragment_general_preferences);
ActionBar actionBar = ((SherlockPreferenceActivity) getActivity()).getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
actionBar.setTitle(R.string.title_general_prefs);

}

@Override
public void onResume() {
super.onResume();
SharedPreferences manager = PreferenceManager.getDefaultSharedPreferences(getActivity());
String defaultCurrency = manager.getString(getString(R.string.key_default_currency), Money.DEFAULT_CURRENCY_CODE);
Preference pref = findPreference(getString(R.string.key_default_currency));
pref.setSummary(defaultCurrency);
pref.setOnPreferenceChangeListener(this);
}

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(newValue.toString());
if (preference.getKey().equals(getString(R.string.key_default_currency))){
Money.DEFAULT_CURRENCY_CODE = newValue.toString();
}
return true;
}

}

/**
* Fragment for displaying information about the application
* @author Ngewi
* @author Ngewi Fet <ngewif@gmail.com>
*
*/
public static class AboutPreferenceFragment extends PreferenceFragment{
Expand All @@ -106,6 +160,7 @@ public void onCreate(Bundle savedInstanceState) {
ActionBar actionBar = ((SherlockPreferenceActivity) getActivity()).getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.title_about_gnucash);

}
}
Expand Down

0 comments on commit fd5e4c4

Please sign in to comment.