Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.2 KiB

6 years ago
  1. package eu.faircode.email;
  2. /*
  3. This file is part of FairEmail.
  4. FairEmail is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. NetGuard is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
  14. Copyright 2018 by Marcel Bokhorst (M66B)
  15. */
  16. import android.content.SharedPreferences;
  17. import android.content.res.Configuration;
  18. import android.os.Bundle;
  19. import android.preference.PreferenceManager;
  20. import android.util.Log;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import androidx.appcompat.app.AppCompatActivity;
  24. abstract class ActivityBase extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. Log.i(Helper.TAG, "Create " + this.getClass().getName());
  28. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  29. String theme = prefs.getString("theme", "light");
  30. setTheme("light".equals(theme) ? R.style.AppThemeLight : R.style.AppThemeDark);
  31. PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
  32. super.onCreate(savedInstanceState);
  33. }
  34. @Override
  35. protected void onResume() {
  36. Log.i(Helper.TAG, "Resume " + this.getClass().getName());
  37. super.onResume();
  38. }
  39. @Override
  40. protected void onPause() {
  41. Log.i(Helper.TAG, "Pause " + this.getClass().getName());
  42. super.onPause();
  43. }
  44. @Override
  45. public void onConfigurationChanged(Configuration newConfig) {
  46. Log.i(Helper.TAG, "Config " + this.getClass().getName());
  47. super.onConfigurationChanged(newConfig);
  48. }
  49. @Override
  50. protected void onDestroy() {
  51. Log.i(Helper.TAG, "Destroy " + this.getClass().getName());
  52. PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
  53. super.onDestroy();
  54. }
  55. @Override
  56. public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
  57. Log.i(Helper.TAG, "Preference " + key + "=" + prefs.getAll().get(key));
  58. if ("theme".equals(key) || "debug".equals(key)) {
  59. finish();
  60. startActivity(getIntent());
  61. }
  62. }
  63. private List<IBackPressedListener> backPressedListeners = new ArrayList<>();
  64. public void addBackPressedListener(IBackPressedListener listener) {
  65. backPressedListeners.add(listener);
  66. }
  67. @Override
  68. public void onBackPressed() {
  69. for (IBackPressedListener listener : backPressedListeners)
  70. if (listener.onBackPressed())
  71. return;
  72. super.onBackPressed();
  73. }
  74. public interface IBackPressedListener {
  75. boolean onBackPressed();
  76. }
  77. }