diff --git a/src/acr/browser/lightning/AboutSettingsActivity.java b/src/acr/browser/lightning/AboutSettingsActivity.java index 0f77f15..5a9b27a 100644 --- a/src/acr/browser/lightning/AboutSettingsActivity.java +++ b/src/acr/browser/lightning/AboutSettingsActivity.java @@ -5,33 +5,24 @@ package acr.browser.lightning; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.net.Uri; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.view.WindowManager; import android.widget.RelativeLayout; import android.widget.TextView; -public class AboutSettingsActivity extends ActionBarActivity { +public class AboutSettingsActivity extends ThemableActivity { - // mPreferences variables - private SharedPreferences mPreferences; private int mEasterEggCounter; private Context mContext; @Override protected void onCreate(Bundle savedInstanceState) { - mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); - if (mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false)) { - this.setTheme(R.style.Theme_SettingsTheme_Dark); - } super.onCreate(savedInstanceState); setContentView(R.layout.about_settings); @@ -41,11 +32,6 @@ public class AboutSettingsActivity extends ActionBarActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); - if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) { - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); - } - mContext = this; initialize(); } diff --git a/src/acr/browser/lightning/AdvancedSettingsActivity.java b/src/acr/browser/lightning/AdvancedSettingsActivity.java index 7eb24d4..67b272a 100644 --- a/src/acr/browser/lightning/AdvancedSettingsActivity.java +++ b/src/acr/browser/lightning/AdvancedSettingsActivity.java @@ -9,12 +9,10 @@ import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.view.WindowManager; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; @@ -22,7 +20,7 @@ import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; -public class AdvancedSettingsActivity extends ActionBarActivity { +public class AdvancedSettingsActivity extends ThemableActivity { private SharedPreferences mPreferences; private CheckBox cbAllowPopups, cbAllowCookies, cbAllowIncognitoCookies, cbRestoreTabs; @@ -34,10 +32,6 @@ public class AdvancedSettingsActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { - mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); - if (mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false)) { - this.setTheme(R.style.Theme_SettingsTheme_Dark); - } super.onCreate(savedInstanceState); setContentView(R.layout.advanced_settings); @@ -47,11 +41,6 @@ public class AdvancedSettingsActivity extends ActionBarActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); - if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) { - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); - } - mContext = this; mActivity = this; initialize(); @@ -64,6 +53,7 @@ public class AdvancedSettingsActivity extends ActionBarActivity { } private void initialize() { + mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); RelativeLayout rAllowPopups, rAllowCookies, rAllowIncognitoCookies, rRestoreTabs; LinearLayout lRenderPicker, lUrlContent; diff --git a/src/acr/browser/lightning/BookmarkActivity.java b/src/acr/browser/lightning/BookmarkActivity.java index 94e6f9e..2f5acb5 100644 --- a/src/acr/browser/lightning/BookmarkActivity.java +++ b/src/acr/browser/lightning/BookmarkActivity.java @@ -11,7 +11,6 @@ import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Environment; -import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; @@ -19,7 +18,7 @@ import android.view.View.OnClickListener; import android.widget.LinearLayout; import android.widget.TextView; -public class BookmarkActivity extends ActionBarActivity implements OnClickListener { +public class BookmarkActivity extends ThemableActivity implements OnClickListener { private BookmarkManager mBookmarkManager; private boolean mSystemBrowser; @@ -31,10 +30,6 @@ public class BookmarkActivity extends ActionBarActivity implements OnClickListen @Override public void onCreate(Bundle savedInstanceState) { - mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); - if (mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false)) { - this.setTheme(R.style.Theme_SettingsTheme_Dark); - } super.onCreate(savedInstanceState); setContentView(R.layout.bookmark_settings); @@ -52,6 +47,8 @@ public class BookmarkActivity extends ActionBarActivity implements OnClickListen mBookmarkManager = new BookmarkManager(this); + mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); + mSystemBrowser = mPreferences.getBoolean(PreferenceConstants.SYSTEM_BROWSER_PRESENT, false); exportBackup.setOnClickListener(this); @@ -63,7 +60,6 @@ public class BookmarkActivity extends ActionBarActivity implements OnClickListen } else { importBookmarks.setText(getResources().getString(R.string.stock_browser_unavailable)); } - } @Override diff --git a/src/acr/browser/lightning/DisplaySettingsActivity.java b/src/acr/browser/lightning/DisplaySettingsActivity.java index b21b035..44d7cee 100644 --- a/src/acr/browser/lightning/DisplaySettingsActivity.java +++ b/src/acr/browser/lightning/DisplaySettingsActivity.java @@ -8,18 +8,16 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.view.WindowManager; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.RelativeLayout; -public class DisplaySettingsActivity extends ActionBarActivity { +public class DisplaySettingsActivity extends ThemableActivity { // mPreferences variables private SharedPreferences mPreferences; @@ -29,25 +27,19 @@ public class DisplaySettingsActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { - mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); - if (mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false)) { - this.setTheme(R.style.Theme_SettingsTheme_Dark); - } super.onCreate(savedInstanceState); setContentView(R.layout.display_settings); mActivity = this; + mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); + // set up ActionBar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) { - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); - } initialize(); } diff --git a/src/acr/browser/lightning/GeneralSettingsActivity.java b/src/acr/browser/lightning/GeneralSettingsActivity.java index 935ad05..9c98877 100644 --- a/src/acr/browser/lightning/GeneralSettingsActivity.java +++ b/src/acr/browser/lightning/GeneralSettingsActivity.java @@ -10,14 +10,12 @@ import android.content.SharedPreferences; import android.graphics.Color; import android.os.Bundle; import android.os.Environment; -import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.util.TypedValue; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.view.WindowManager; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; @@ -26,7 +24,7 @@ import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; -public class GeneralSettingsActivity extends ActionBarActivity { +public class GeneralSettingsActivity extends ThemableActivity { // mPreferences variables private static final int API = android.os.Build.VERSION.SDK_INT; @@ -44,10 +42,6 @@ public class GeneralSettingsActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { - mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); - if (mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false)) { - this.setTheme(R.style.Theme_SettingsTheme_Dark); - } super.onCreate(savedInstanceState); setContentView(R.layout.general_settings); @@ -57,13 +51,9 @@ public class GeneralSettingsActivity extends ActionBarActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); - if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) { - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); - } - // TODO WARNING: SharedPreferences.edit() without a corresponding // commit() or apply() call + mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mEditPrefs = mPreferences.edit(); mActivity = this; diff --git a/src/acr/browser/lightning/LicenseActivity.java b/src/acr/browser/lightning/LicenseActivity.java index 2cf3f17..1e9869a 100644 --- a/src/acr/browser/lightning/LicenseActivity.java +++ b/src/acr/browser/lightning/LicenseActivity.java @@ -4,10 +4,8 @@ package acr.browser.lightning; import android.content.Intent; -import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; @@ -17,14 +15,10 @@ import android.view.View; *under which this code is licensed. Unless you plan on providing other attribution in the app to *the original source in another visible way, it is advised against the removal of this Activity. */ -public class LicenseActivity extends ActionBarActivity implements View.OnClickListener { +public class LicenseActivity extends ThemableActivity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { - SharedPreferences preferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); - if (preferences.getBoolean(PreferenceConstants.DARK_THEME, false)) { - this.setTheme(R.style.Theme_SettingsTheme_Dark); - } super.onCreate(savedInstanceState); setContentView(R.layout.license_activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); diff --git a/src/acr/browser/lightning/PrivacySettingsActivity.java b/src/acr/browser/lightning/PrivacySettingsActivity.java index d8e55f3..0339ec6 100644 --- a/src/acr/browser/lightning/PrivacySettingsActivity.java +++ b/src/acr/browser/lightning/PrivacySettingsActivity.java @@ -12,12 +12,10 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.provider.Browser; -import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.view.WindowManager; import android.webkit.*; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -25,7 +23,7 @@ import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.RelativeLayout; import android.widget.TextView; -public class PrivacySettingsActivity extends ActionBarActivity { +public class PrivacySettingsActivity extends ThemableActivity { // mPreferences variables private static final int API = android.os.Build.VERSION.SDK_INT; @@ -39,10 +37,6 @@ public class PrivacySettingsActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { - mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); - if (mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false)) { - this.setTheme(R.style.Theme_SettingsTheme_Dark); - } super.onCreate(savedInstanceState); setContentView(R.layout.privacy_settings); @@ -52,13 +46,9 @@ public class PrivacySettingsActivity extends ActionBarActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); - if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) { - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); - } - // TODO WARNING: SharedPreferences.edit() without a corresponding // commit() or apply() call + mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mEditPrefs = mPreferences.edit(); mSystemBrowser = mPreferences.getBoolean(PreferenceConstants.SYSTEM_BROWSER_PRESENT, false); diff --git a/src/acr/browser/lightning/SettingsActivity.java b/src/acr/browser/lightning/SettingsActivity.java index 524b5e3..53db4fa 100644 --- a/src/acr/browser/lightning/SettingsActivity.java +++ b/src/acr/browser/lightning/SettingsActivity.java @@ -15,12 +15,10 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.view.WindowManager; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; @@ -28,24 +26,18 @@ import android.widget.EditText; import android.widget.RelativeLayout; import info.guardianproject.onionkit.ui.OrbotHelper; -public class SettingsActivity extends ActionBarActivity { +public class SettingsActivity extends ThemableActivity { private static int API = android.os.Build.VERSION.SDK_INT; private SharedPreferences.Editor mEditPrefs; private SharedPreferences mPreferences; private Context mContext; private Activity mActivity; - private boolean mDark; @Override protected void onCreate(Bundle savedInstanceState) { - mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); - if (mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false)) { - this.setTheme(R.style.Theme_SettingsTheme_Dark); - } super.onCreate(savedInstanceState); setContentView(R.layout.settings); - mDark = mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false); mContext = this; mActivity = this; init(); @@ -57,15 +49,6 @@ public class SettingsActivity extends ActionBarActivity { return true; } - @Override - protected void onResume() { - super.onResume(); - if (mPreferences != null - && mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false) != mDark) { - this.recreate(); - } - } - @SuppressLint("NewApi") public void init() { // set up ActionBar @@ -75,11 +58,7 @@ public class SettingsActivity extends ActionBarActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); // mPreferences storage - if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) { - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); - } - + mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mEditPrefs = mPreferences.edit(); // initialize UI diff --git a/src/acr/browser/lightning/ThemableActivity.java b/src/acr/browser/lightning/ThemableActivity.java new file mode 100644 index 0000000..d743a09 --- /dev/null +++ b/src/acr/browser/lightning/ThemableActivity.java @@ -0,0 +1,42 @@ +package acr.browser.lightning; + +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.view.WindowManager; + +public abstract class ThemableActivity extends ActionBarActivity { + + private SharedPreferences mPreferences; + private boolean mDark; + + @Override + protected void onCreate(Bundle savedInstanceState) { + mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); + mDark = mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false); + + // set the theme + if (mDark) { + setTheme(R.style.Theme_SettingsTheme_Dark); + } + + // set window params + if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) { + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } else { + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + } + super.onCreate(savedInstanceState); + } + + @Override + protected void onResume() { + super.onResume(); + if (mPreferences != null + && mPreferences.getBoolean(PreferenceConstants.DARK_THEME, + false) != mDark) { + this.recreate(); + } + } +}