From add052958a91d2bc950edb6abfde31f79fe7144a Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Sun, 5 Jan 2020 22:31:16 +0100 Subject: [PATCH 1/4] #855 - gradle 3.5.3 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6e3389eb5..829eada26 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.2' + classpath 'com.android.tools.build:gradle:3.5.3' classpath 'io.fabric.tools:gradle:1.31.2' classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2' } From 95cc386d0e25beac69599d3f4791f86fd1b38ee6 Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Sun, 5 Jan 2020 22:33:21 +0100 Subject: [PATCH 2/4] Fixes #855 - Add double back button press to quit option --- .../android/ui/account/AccountsActivity.java | 110 +++++++++++++++++- .../settings/GeneralPreferenceFragment.java | 16 +++ app/src/main/res/values-fr/strings.xml | 4 + app/src/main/res/values/donottranslate.xml | 1 + app/src/main/res/values/strings.xml | 4 + .../res/xml/fragment_general_preferences.xml | 20 +++- 6 files changed, 147 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java index 5e8a94026..ecc996761 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java @@ -30,6 +30,7 @@ import android.content.res.Resources; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.TabLayout; @@ -42,6 +43,7 @@ import android.support.v7.preference.PreferenceManager; import android.util.Log; import android.util.SparseArray; +import android.view.Gravity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -129,12 +131,39 @@ public class AccountsActivity extends BaseDrawerActivity implements OnAccountCli */ private SparseArray mFragmentPageReferenceMap = new SparseArray<>(); + /** + * DoubleBackPressed attributes + * + * @author warrott + */ + + // true if backPress button has already been pressed recently + private boolean mDoubleBackButtonPressedOnce; + + // Runnable to consider BackPress button not more pressed recently + private final Runnable mResetDoubleBackPressedStatusRunnable = new Runnable() { + @Override + public void run() { + + // BackPress button is not more considered pressed recently + mDoubleBackButtonPressedOnce = false; + } + }; + + // Android handler to delay actions + private Handler mHandler = new Handler(); + + // Toast + private Toast mToast; /** * ViewPager which manages the different tabs */ - @BindView(R.id.pager) ViewPager mViewPager; - @BindView(R.id.fab_create_account) FloatingActionButton mFloatingActionButton; - @BindView(R.id.coordinatorLayout) CoordinatorLayout mCoordinatorLayout; + @BindView(R.id.pager) + ViewPager mViewPager; + @BindView(R.id.fab_create_account) + FloatingActionButton mFloatingActionButton; + @BindView(R.id.coordinatorLayout) + CoordinatorLayout mCoordinatorLayout; /** * Configuration for rating the app @@ -221,6 +250,7 @@ public int getTitleRes() { @Override public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); final Intent intent = getIntent(); @@ -267,6 +297,12 @@ public void onClick(View v) { startActivityForResult(addAccountIntent, AccountsActivity.REQUEST_EDIT_ACCOUNT); } }); + + // Prepare a Toast message + mToast = Toast.makeText(getApplicationContext(), + R.string.double_back_press_exit_msg, + Toast.LENGTH_SHORT); + mToast.setGravity(Gravity.CENTER,0,0); } @Override @@ -344,6 +380,14 @@ private void init() { //default to using double entry and save the preference explicitly prefs.edit().putBoolean(getString(R.string.key_use_double_entry), true).apply(); + + // Default preference to use double back button press to exit + prefs.edit() + .putBoolean(getString(R.string.key_use_double_back_button_press_to_quit), + true) + .apply(); + + // Finish Activity finish(); return; } @@ -357,9 +401,69 @@ private void init() { @Override protected void onDestroy() { + super.onDestroy(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); preferences.edit().putInt(LAST_OPEN_TAB_INDEX, mViewPager.getCurrentItem()).apply(); + + // + // Remove callback to avoid memory leak + // + + if (mHandler != null) { + // There is an Android handler + + mHandler.removeCallbacks(mResetDoubleBackPressedStatusRunnable); + } + + } + + /** + * Gérer un double BackPressed pour quitter l'application + */ + @Override + public void onBackPressed() { + + // Get Preference about double back button press to exit + boolean prefShallUseDoubleBackPressToExit = PreferenceManager.getDefaultSharedPreferences(this) + .getBoolean(getString(R.string.key_use_double_back_button_press_to_quit), + true); + + if (mDoubleBackButtonPressedOnce || !prefShallUseDoubleBackPressToExit) { + // BackPress button has already been pressed recently OR shall not use double back press to exit + + // + // Do not show the Toast anymore + // + + if (mToast != null) { + // There is a Toast + + // Do not show the Toast anymore + mToast.cancel(); + + } else { + // There is no Toast + + // NTD + } + + // Perform BackPress + super.onBackPressed(); + + } else { + // BackPress button has been pressed for the first time AND shall use double back press to exit + + // Notice that button has been pressed once + this.mDoubleBackButtonPressedOnce = true; + + // Show a message to explain that user must press again to exit + mToast.show(); + + // After two seconds, it is not more considered as already pressed + mHandler.postDelayed(mResetDoubleBackPressedStatusRunnable, + 2000); + } } /** diff --git a/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java index db07e2753..b68423d77 100644 --- a/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java @@ -125,6 +125,22 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { .putBoolean(getString(R.string.key_use_account_color), Boolean.valueOf(newValue.toString())) .commit(); } + + // + // Preference : use_double_back_button_press_to_quit + // + + if (preference.getKey() + .equals(getString(R.string.key_use_double_back_button_press_to_quit))) { + + // Store the new value of the Preference + getPreferenceManager().getSharedPreferences() + .edit() + .putBoolean(getString(R.string.key_use_double_back_button_press_to_quit), + Boolean.valueOf(newValue.toString())) + .commit(); + } + return true; } diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9ab498501..420f0cdd0 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -446,4 +446,8 @@ Sélectionnez la destination une fois l\'exportation terminée Exporter dans le dossier \'/Apps/GnuCash Android/\' sur Dropbox Préférences + Cliquez à nouveau sur BACK pour Quitter\n(ou modifiez les Préférences Générales) + Préférences d\'ergonomie + Double confirmation pour Quitter + Appuyer deux fois de suite sur le bouton \"BACK\" pour Quitter l\'application diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index 39cae7266..8988087aa 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -31,6 +31,7 @@ google_drive_app_folder enable_crashlytics use_account_color + use_double_back_button_press_to_quit last_export_destination use_compact_list prefs_header_general diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4ef7ae17e..facfc775e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -500,4 +500,8 @@ Tax Placeholder + Please click BACK again to Quit\n(or Change General Preferences) + User Interface Preferences + Use double back button press to quit + Shall click twice on back button to actually quit GnuCashAndroid diff --git a/app/src/main/res/xml/fragment_general_preferences.xml b/app/src/main/res/xml/fragment_general_preferences.xml index fb170c2b9..b19f3d8ee 100644 --- a/app/src/main/res/xml/fragment_general_preferences.xml +++ b/app/src/main/res/xml/fragment_general_preferences.xml @@ -1,18 +1,28 @@ + + + + + - - + - - \ No newline at end of file From 5bb95605576bd609441884e10ec390957510d6bc Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Mon, 6 Jan 2020 00:41:09 +0100 Subject: [PATCH 3/4] Fixes #855 - Align text inside Toast, not Toast inside Screen --- .../org/gnucash/android/ui/account/AccountsActivity.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java index ecc996761..c31a372ee 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java @@ -49,6 +49,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import android.widget.Toast; import com.crashlytics.android.Crashlytics; @@ -302,7 +303,13 @@ public void onClick(View v) { mToast = Toast.makeText(getApplicationContext(), R.string.double_back_press_exit_msg, Toast.LENGTH_SHORT); - mToast.setGravity(Gravity.CENTER,0,0); + + // Align-Center text inside the Toast + TextView toastTextView = (TextView) mToast.getView() + .findViewById(android.R.id.message); + if (toastTextView != null) { + toastTextView.setGravity(Gravity.CENTER); + } } @Override From 21b6e9f5f750ee27c8ba6876640430efb407a7e6 Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Mon, 6 Jan 2020 01:51:58 +0100 Subject: [PATCH 4/4] Fixes #855 - Back button closes the Main Navigation Menu and stay on current Activity --- .../android/ui/account/AccountsActivity.java | 64 +++++++++++-------- .../android/ui/common/BaseDrawerActivity.java | 51 +++++++++++++-- 2 files changed, 81 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java index c31a372ee..1b473dd38 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java @@ -431,45 +431,55 @@ protected void onDestroy() { @Override public void onBackPressed() { - // Get Preference about double back button press to exit - boolean prefShallUseDoubleBackPressToExit = PreferenceManager.getDefaultSharedPreferences(this) - .getBoolean(getString(R.string.key_use_double_back_button_press_to_quit), - true); + if (isNavigationViewOpen()) { + // The main navigation menu is open - if (mDoubleBackButtonPressedOnce || !prefShallUseDoubleBackPressToExit) { - // BackPress button has already been pressed recently OR shall not use double back press to exit + // Close the main navigation menu + super.onBackPressed(); + + } else { + // The main navigation menu is closed - // - // Do not show the Toast anymore - // + // Get Preference about double back button press to exit + boolean prefShallUseDoubleBackPressToExit = PreferenceManager.getDefaultSharedPreferences(this) + .getBoolean(getString(R.string.key_use_double_back_button_press_to_quit), + true); - if (mToast != null) { - // There is a Toast + if (mDoubleBackButtonPressedOnce || !prefShallUseDoubleBackPressToExit) { + // BackPress button has already been pressed recently OR shall not use double back press to exit + // // Do not show the Toast anymore - mToast.cancel(); + // - } else { - // There is no Toast + if (mToast != null) { + // There is a Toast - // NTD - } + // Do not show the Toast anymore + mToast.cancel(); - // Perform BackPress - super.onBackPressed(); + } else { + // There is no Toast - } else { - // BackPress button has been pressed for the first time AND shall use double back press to exit + // NTD + } + + // Perform BackPress + super.onBackPressed(); - // Notice that button has been pressed once - this.mDoubleBackButtonPressedOnce = true; + } else { + // BackPress button has been pressed for the first time AND shall use double back press to exit + + // Notice that button has been pressed once + this.mDoubleBackButtonPressedOnce = true; - // Show a message to explain that user must press again to exit - mToast.show(); + // Show a message to explain that user must press again to exit + mToast.show(); - // After two seconds, it is not more considered as already pressed - mHandler.postDelayed(mResetDoubleBackPressedStatusRunnable, - 2000); + // After two seconds, it is not more considered as already pressed + mHandler.postDelayed(mResetDoubleBackPressedStatusRunnable, + 2000); + } } } diff --git a/app/src/main/java/org/gnucash/android/ui/common/BaseDrawerActivity.java b/app/src/main/java/org/gnucash/android/ui/common/BaseDrawerActivity.java index 83c409d95..3e4638fc4 100644 --- a/app/src/main/java/org/gnucash/android/ui/common/BaseDrawerActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/common/BaseDrawerActivity.java @@ -210,10 +210,11 @@ public void onConfigurationChanged(Configuration newConfig) { @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home){ - if (!mDrawerLayout.isDrawerOpen(mNavigationView)) + if (!isNavigationViewOpen()) { mDrawerLayout.openDrawer(mNavigationView); - else - mDrawerLayout.closeDrawer(mNavigationView); + } else { + closeNavigationView(); + } return true; } @@ -286,7 +287,7 @@ protected void onDrawerMenuItemClicked(int itemId) { UserVoice.launchUserVoice(this); break; } - mDrawerLayout.closeDrawer(mNavigationView); + closeNavigationView(); } @Override @@ -319,7 +320,7 @@ public boolean onMenuItemClick(MenuItem item) { Intent intent = new Intent(this, PreferenceActivity.class); intent.setAction(PreferenceActivity.ACTION_MANAGE_BOOKS); startActivity(intent); - mDrawerLayout.closeDrawer(mNavigationView); + closeNavigationView(); return true; } BooksDbAdapter booksDbAdapter = BooksDbAdapter.getInstance(); @@ -332,9 +333,17 @@ public boolean onMenuItemClick(MenuItem item) { return true; } - public void onClickAppTitle(View view){ + protected void onClickAppTitle(View view) { + + closeNavigationView(); + + // Do not launch AccountsActivity to stay on current Activity +// AccountsActivity.start(this); + } + + protected void closeNavigationView() { + mDrawerLayout.closeDrawer(mNavigationView); - AccountsActivity.start(this); } public void onClickBook(View view){ @@ -354,4 +363,32 @@ public void onClickBook(View view){ popup.show(); } + + @Override + public void onBackPressed() { + + if (isNavigationViewOpen()) { + // The main navigation menu is open + + // Close the main navigation menu +// mDrawerLayout.closeDrawer(mNavigationView); + onClickAppTitle(getCurrentFocus()); + + } else { + // The main navigation menu is closed + + // Close the Activity + super.onBackPressed(); + } + } + + /** + * Return true if main navigation menu is open + * + * @return true if main navigation menu is open + */ + protected boolean isNavigationViewOpen() { + + return mDrawerLayout.isDrawerOpen(mNavigationView); + } }