From c75ca897755d2f4c15fc0a5ba431ac88a6280015 Mon Sep 17 00:00:00 2001 From: DF1E Date: Wed, 1 Apr 2015 20:36:10 +0200 Subject: [PATCH 1/5] clean BrowserActivity --- .../browser/lightning/BrowserActivity.java | 248 +++++------------- 1 file changed, 63 insertions(+), 185 deletions(-) diff --git a/src/acr/browser/lightning/BrowserActivity.java b/src/acr/browser/lightning/BrowserActivity.java index 99975ab..aa1852a 100644 --- a/src/acr/browser/lightning/BrowserActivity.java +++ b/src/acr/browser/lightning/BrowserActivity.java @@ -72,14 +72,12 @@ import java.net.URL; import java.net.URLEncoder; import java.util.*; -public class BrowserActivity extends ActionBarActivity implements BrowserController { +public class BrowserActivity extends ActionBarActivity implements BrowserController, OnClickListener { private DrawerLayout mDrawerLayout; - private ListView mDrawerListLeft; - private LinearLayout mDrawerLeft; - private LinearLayout mDrawerRight; - private ListView mDrawerListRight; - private RelativeLayout mNewTab; + private ListView mDrawerListLeft, mDrawerListRight; + private LinearLayout mDrawerLeft, mDrawerRight, mPageLayout, mUiLayout, mToolbarLayout; + private RelativeLayout mNewTab, mSearchBar; private List mWebViews = new ArrayList(); private LightningView mCurrentView; private int mIdGenerator; @@ -94,42 +92,29 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl private AnimatedProgressBar mProgressBar; private boolean mSystemBrowser = false; private ValueCallback mUploadMessage; - private View mCustomView; - private int mOriginalOrientation; - private int mBackgroundColor; + private View mCustomView, mVideoProgressView; + private int mOriginalOrientation, mBackgroundColor; private ActionBar mActionBar; - private boolean mFullScreen; - private boolean mColorMode; + private boolean mFullScreen, mColorMode, mDarkTheme; private FrameLayout mBrowserFrame; - private LinearLayout mPageLayout; - private LinearLayout mUiLayout; private FullscreenHolder mFullscreenContainer; private CustomViewCallback mCustomViewCallback; private final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - private Bitmap mDefaultVideoPoster; - private View mVideoProgressView; - private LinearLayout mToolbarLayout; + private Bitmap mDefaultVideoPoster, mWebpageBitmap; private HistoryDatabase mHistoryDatabase; private SharedPreferences mPreferences; private Context mContext; - private Bitmap mWebpageBitmap; - private String mSearchText; - private String mUntitledTitle; + private String mSearchText, mUntitledTitle, mHomepage; private Activity mActivity; private final int API = android.os.Build.VERSION.SDK_INT; - private Drawable mDeleteIcon; - private Drawable mRefreshIcon; - private Drawable mCopyIcon; - private Drawable mIcon; - private String mHomepage; + private Drawable mDeleteIcon, mRefreshIcon, mCopyIcon, mIcon; private boolean mIsNewIntent = false; private VideoView mVideoView; private static SearchAdapter mSearchAdapter; private static LayoutParams mMatchParent = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); private BookmarkManager mBookmarkManager; - private boolean mDarkTheme; @Override protected void onCreate(Bundle savedInstanceState) { @@ -211,7 +196,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl mHistoryDatabase = HistoryDatabase.getInstance(this); // set display options of the ActionBar - mActionBar.setDisplayShowTitleEnabled(false); mActionBar.setHomeButtonEnabled(false); mActionBar.setDisplayShowHomeEnabled(false); @@ -233,51 +217,13 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl mArrowImage.setImageDrawable(mArrowDrawable); LinearLayout arrowButton = (LinearLayout) mActionBar.getCustomView().findViewById( R.id.arrow_button); - arrowButton.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - if (mSearch != null && mSearch.hasFocus()) { - mCurrentView.requestFocus(); - } else { - mDrawerLayout.openDrawer(mDrawerLeft); - } - } - - }); + arrowButton.setOnClickListener(this); RelativeLayout back = (RelativeLayout) findViewById(R.id.action_back); + back.setOnClickListener(this); + RelativeLayout forward = (RelativeLayout) findViewById(R.id.action_forward); - if (back != null) { - back.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - if (mCurrentView != null) { - if (mCurrentView.canGoBack()) { - mCurrentView.goBack(); - } else { - deleteTab(mDrawerListLeft.getCheckedItemPosition()); - } - } - } - - }); - } - if (forward != null) { - forward.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - if (mCurrentView != null) { - if (mCurrentView.canGoForward()) { - mCurrentView.goForward(); - } - } - } - - }); - } + forward.setOnClickListener(this); // create the search EditText in the ToolBar mSearch = (AutoCompleteTextView) mActionBar.getCustomView().findViewById(R.id.search); @@ -316,15 +262,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl }); initialize.run(); - mNewTab.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View arg0) { - newTab(null, true); - } - - }); - + mNewTab.setOnClickListener(this); mNewTab.setOnLongClickListener(new OnLongClickListener() { @Override @@ -351,7 +289,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl } checkForTor(); - } private class SearchClass { @@ -540,92 +477,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl } - public boolean handleMenuItemClick(MenuItem item) { - // Handle action buttons - switch (item.getItemId()) { - case android.R.id.home: - if (mDrawerLayout.isDrawerOpen(mDrawerRight)) { - mDrawerLayout.closeDrawer(mDrawerRight); - } - // mDrawerToggle.syncState(); - return true; - case R.id.action_back: - if (mCurrentView != null) { - if (mCurrentView.canGoBack()) { - mCurrentView.goBack(); - } - } - return true; - case R.id.action_forward: - if (mCurrentView != null) { - if (mCurrentView.canGoForward()) { - mCurrentView.goForward(); - } - } - return true; - case R.id.action_new_tab: - newTab(null, true); - return true; - case R.id.action_incognito: - startActivity(new Intent(this, IncognitoActivity.class)); - return true; - case R.id.action_share: - if (!mCurrentView.getUrl().startsWith(Constants.FILE)) { - Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); - shareIntent.setType("text/plain"); - shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, - mCurrentView.getTitle()); - String shareMessage = mCurrentView.getUrl(); - shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareMessage); - startActivity(Intent.createChooser(shareIntent, - getResources().getString(R.string.dialog_title_share))); - } - return true; - case R.id.action_bookmarks: - openBookmarks(); - return true; - case R.id.action_copy: - if (mCurrentView != null) { - if (!mCurrentView.getUrl().startsWith(Constants.FILE)) { - ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("label", mCurrentView.getUrl()); - clipboard.setPrimaryClip(clip); - Utils.showToast(mContext, - mContext.getResources().getString(R.string.message_link_copied)); - } - } - return true; - case R.id.action_settings: - startActivity(new Intent(this, SettingsActivity.class)); - return true; - case R.id.action_history: - openHistory(); - return true; - case R.id.action_add_bookmark: - if (!mCurrentView.getUrl().startsWith(Constants.FILE)) { - HistoryItem bookmark = new HistoryItem(mCurrentView.getUrl(), - mCurrentView.getTitle()); - if (mBookmarkManager.addBookmark(bookmark)) { - mBookmarkList.add(bookmark); - Collections.sort(mBookmarkList, new SortIgnoreCase()); - notifyBookmarkDataSetChanged(); - mSearchAdapter.refreshBookmarks(); - } - } - return true; - case R.id.action_find: - findInPage(); - return true; - case R.id.action_reading_mode: - Intent read = new Intent(this, ReadingActivity.class); - read.putExtra(Constants.LOAD_READING_URL, mCurrentView.getUrl()); - startActivity(read); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - /* * If Orbot/Tor is installed, prompt the user if they want to enable * proxying for this session @@ -997,35 +848,20 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl if (mCurrentView != null) { mCurrentView.find(text); } - final RelativeLayout bar = (RelativeLayout) findViewById(R.id.search_bar); - bar.setVisibility(View.VISIBLE); + mSearchBar = (RelativeLayout) findViewById(R.id.search_bar); + mSearchBar.setVisibility(View.VISIBLE); TextView tw = (TextView) findViewById(R.id.search_query); tw.setText("'" + text + "'"); ImageButton up = (ImageButton) findViewById(R.id.button_next); - up.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mCurrentView.getWebView().findNext(false); - } - }); + up.setOnClickListener(this); + ImageButton down = (ImageButton) findViewById(R.id.button_back); - down.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mCurrentView.getWebView().findNext(true); - } - }); + down.setOnClickListener(this); ImageButton quit = (ImageButton) findViewById(R.id.button_quit); - quit.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mCurrentView.getWebView().clearMatches(); - bar.setVisibility(View.GONE); - } - }); + quit.setOnClickListener(this); } private void showCloseDialog(final int position) { @@ -2693,4 +2529,46 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl public int getMenu() { return R.menu.main; } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.action_back: + if (mCurrentView != null) { + if (mCurrentView.canGoBack()) { + mCurrentView.goBack(); + } else { + deleteTab(mDrawerListLeft.getCheckedItemPosition()); + } + } + break; + case R.id.action_forward: + if (mCurrentView != null) { + if (mCurrentView.canGoForward()) { + mCurrentView.goForward(); + } + } + break; + case R.id.arrow_button: + if (mSearch != null && mSearch.hasFocus()) { + mCurrentView.requestFocus(); + } else { + mDrawerLayout.openDrawer(mDrawerLeft); + } + break; + case R.id.new_tab_button: + newTab(null, true); + break; + case R.id.button_next: + mCurrentView.getWebView().findNext(false); + break; + case R.id.button_back: + mCurrentView.getWebView().findNext(true); + break; + case R.id.button_quit: + mCurrentView.getWebView().clearMatches(); + mSearchBar.setVisibility(View.GONE); + break; + } + } } From 625fbb1aa9c6e9c24b207f1c1cbb092f2828d33a Mon Sep 17 00:00:00 2001 From: DF1E Date: Wed, 1 Apr 2015 21:22:42 +0200 Subject: [PATCH 2/5] improve theming 1 --- .../lightning/AboutSettingsActivity.java | 16 +------ .../lightning/AdvancedSettingsActivity.java | 14 +------ .../browser/lightning/BookmarkActivity.java | 10 ++--- .../lightning/DisplaySettingsActivity.java | 14 ++----- .../lightning/GeneralSettingsActivity.java | 14 +------ .../browser/lightning/LicenseActivity.java | 8 +--- .../lightning/PrivacySettingsActivity.java | 14 +------ .../browser/lightning/SettingsActivity.java | 25 +---------- .../browser/lightning/ThemableActivity.java | 42 +++++++++++++++++++ 9 files changed, 58 insertions(+), 99 deletions(-) create mode 100644 src/acr/browser/lightning/ThemableActivity.java 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(); + } + } +} From aedf76e3aef5abadeb43b7f0ea950edd8371974e Mon Sep 17 00:00:00 2001 From: DF1E Date: Wed, 1 Apr 2015 21:31:28 +0200 Subject: [PATCH 3/5] improve theming 2 --- src/acr/browser/lightning/BrowserActivity.java | 9 +-------- src/acr/browser/lightning/MainActivity.java | 16 +--------------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/acr/browser/lightning/BrowserActivity.java b/src/acr/browser/lightning/BrowserActivity.java index aa1852a..49a9050 100644 --- a/src/acr/browser/lightning/BrowserActivity.java +++ b/src/acr/browser/lightning/BrowserActivity.java @@ -55,7 +55,6 @@ import android.webkit.*; import android.webkit.WebChromeClient.CustomViewCallback; import android.webkit.WebView.HitTestResult; import android.widget.*; -import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v7.graphics.Palette; import android.support.v7.widget.Toolbar; @@ -72,7 +71,7 @@ import java.net.URL; import java.net.URLEncoder; import java.util.*; -public class BrowserActivity extends ActionBarActivity implements BrowserController, OnClickListener { +public class BrowserActivity extends ThemableActivity implements BrowserController, OnClickListener { private DrawerLayout mDrawerLayout; private ListView mDrawerListLeft, mDrawerListRight; @@ -642,12 +641,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl mBrowserFrame.removeView(mToolbarLayout); mUiLayout.addView(mToolbarLayout, 0); } - 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); - } switch (mPreferences.getInt(PreferenceConstants.SEARCH, 1)) { case 0: diff --git a/src/acr/browser/lightning/MainActivity.java b/src/acr/browser/lightning/MainActivity.java index 8a4403e..5f295e3 100644 --- a/src/acr/browser/lightning/MainActivity.java +++ b/src/acr/browser/lightning/MainActivity.java @@ -13,16 +13,11 @@ public class MainActivity extends BrowserActivity { SharedPreferences mPreferences; CookieManager mCookieManager; - private boolean mDark; @Override protected void onCreate(Bundle savedInstanceState) { - mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); - mDark = mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false); - if (mDark) { - this.setTheme(R.style.Theme_DarkTheme); - } super.onCreate(savedInstanceState); + mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); } @Override @@ -62,15 +57,6 @@ public class MainActivity extends BrowserActivity { saveOpenTabs(); } - @Override - protected void onResume() { - super.onResume(); - if (mPreferences != null - && mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false) != mDark) { - this.recreate(); - } - } - @Override public void updateHistory(String title, String url) { super.updateHistory(title, url); From 2551b3dc278dd94df317ddc51a7b0a6cfe1b7023 Mon Sep 17 00:00:00 2001 From: DF1E Date: Wed, 1 Apr 2015 21:35:16 +0200 Subject: [PATCH 4/5] improve restart --- .../browser/lightning/DisplaySettingsActivity.java | 2 +- src/acr/browser/lightning/ThemableActivity.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/acr/browser/lightning/DisplaySettingsActivity.java b/src/acr/browser/lightning/DisplaySettingsActivity.java index 44d7cee..5ebae5a 100644 --- a/src/acr/browser/lightning/DisplaySettingsActivity.java +++ b/src/acr/browser/lightning/DisplaySettingsActivity.java @@ -121,7 +121,7 @@ public class DisplaySettingsActivity extends ThemableActivity { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mPreferences.edit().putBoolean(PreferenceConstants.DARK_THEME, isChecked).apply(); - mActivity.recreate(); + restart(); } }); diff --git a/src/acr/browser/lightning/ThemableActivity.java b/src/acr/browser/lightning/ThemableActivity.java index d743a09..9ac4499 100644 --- a/src/acr/browser/lightning/ThemableActivity.java +++ b/src/acr/browser/lightning/ThemableActivity.java @@ -1,5 +1,6 @@ package acr.browser.lightning; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; @@ -36,7 +37,16 @@ public abstract class ThemableActivity extends ActionBarActivity { if (mPreferences != null && mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false) != mDark) { - this.recreate(); + restart(); } } + + protected void restart() { + final Bundle outState = new Bundle(); + onSaveInstanceState(outState); + final Intent intent = new Intent(this, getClass()); + finish(); + overridePendingTransition(0, 0); + startActivity(intent); + } } From addaa3b2b3b2cd1969aaf42dccdea8328254ba06 Mon Sep 17 00:00:00 2001 From: DF1E Date: Wed, 1 Apr 2015 22:13:46 +0200 Subject: [PATCH 5/5] fix theme on BrowserActivity there should be only one ThemableActivity but there are two dark themes - one for settings and on for BrowserActivity --- .../lightning/AboutSettingsActivity.java | 2 +- .../lightning/AdvancedSettingsActivity.java | 2 +- .../browser/lightning/BookmarkActivity.java | 2 +- .../browser/lightning/BrowserActivity.java | 8 ++++ .../lightning/DisplaySettingsActivity.java | 6 +-- .../lightning/GeneralSettingsActivity.java | 2 +- .../browser/lightning/LicenseActivity.java | 2 +- .../lightning/PrivacySettingsActivity.java | 2 +- .../browser/lightning/SettingsActivity.java | 2 +- .../browser/lightning/ThemableActivity.java | 11 +---- .../lightning/ThemableSettingsActivity.java | 43 +++++++++++++++++++ 11 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 src/acr/browser/lightning/ThemableSettingsActivity.java diff --git a/src/acr/browser/lightning/AboutSettingsActivity.java b/src/acr/browser/lightning/AboutSettingsActivity.java index 5a9b27a..7302f12 100644 --- a/src/acr/browser/lightning/AboutSettingsActivity.java +++ b/src/acr/browser/lightning/AboutSettingsActivity.java @@ -16,7 +16,7 @@ import android.view.View.OnClickListener; import android.widget.RelativeLayout; import android.widget.TextView; -public class AboutSettingsActivity extends ThemableActivity { +public class AboutSettingsActivity extends ThemableSettingsActivity { private int mEasterEggCounter; private Context mContext; diff --git a/src/acr/browser/lightning/AdvancedSettingsActivity.java b/src/acr/browser/lightning/AdvancedSettingsActivity.java index 67b272a..1b3b28f 100644 --- a/src/acr/browser/lightning/AdvancedSettingsActivity.java +++ b/src/acr/browser/lightning/AdvancedSettingsActivity.java @@ -20,7 +20,7 @@ import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; -public class AdvancedSettingsActivity extends ThemableActivity { +public class AdvancedSettingsActivity extends ThemableSettingsActivity { private SharedPreferences mPreferences; private CheckBox cbAllowPopups, cbAllowCookies, cbAllowIncognitoCookies, cbRestoreTabs; diff --git a/src/acr/browser/lightning/BookmarkActivity.java b/src/acr/browser/lightning/BookmarkActivity.java index 2f5acb5..339daa9 100644 --- a/src/acr/browser/lightning/BookmarkActivity.java +++ b/src/acr/browser/lightning/BookmarkActivity.java @@ -18,7 +18,7 @@ import android.view.View.OnClickListener; import android.widget.LinearLayout; import android.widget.TextView; -public class BookmarkActivity extends ThemableActivity implements OnClickListener { +public class BookmarkActivity extends ThemableSettingsActivity implements OnClickListener { private BookmarkManager mBookmarkManager; private boolean mSystemBrowser; diff --git a/src/acr/browser/lightning/BrowserActivity.java b/src/acr/browser/lightning/BrowserActivity.java index 49a9050..216baae 100644 --- a/src/acr/browser/lightning/BrowserActivity.java +++ b/src/acr/browser/lightning/BrowserActivity.java @@ -641,6 +641,12 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll mBrowserFrame.removeView(mToolbarLayout); mUiLayout.addView(mToolbarLayout, 0); } + 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); + } switch (mPreferences.getInt(PreferenceConstants.SEARCH, 1)) { case 0: @@ -1374,6 +1380,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll } } } + + supportInvalidateOptionsMenu(); } /** diff --git a/src/acr/browser/lightning/DisplaySettingsActivity.java b/src/acr/browser/lightning/DisplaySettingsActivity.java index 5ebae5a..7d20abf 100644 --- a/src/acr/browser/lightning/DisplaySettingsActivity.java +++ b/src/acr/browser/lightning/DisplaySettingsActivity.java @@ -3,7 +3,6 @@ */ package acr.browser.lightning; -import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.SharedPreferences; @@ -17,21 +16,18 @@ import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.RelativeLayout; -public class DisplaySettingsActivity extends ThemableActivity { +public class DisplaySettingsActivity extends ThemableSettingsActivity { // mPreferences variables private SharedPreferences mPreferences; private CheckBox cbHideStatusBar, cbFullScreen, cbWideViewPort, cbOverView, cbTextReflow, cbDarkTheme; - private Activity mActivity; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.display_settings); - mActivity = this; - mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); // set up ActionBar diff --git a/src/acr/browser/lightning/GeneralSettingsActivity.java b/src/acr/browser/lightning/GeneralSettingsActivity.java index 9c98877..86d99e9 100644 --- a/src/acr/browser/lightning/GeneralSettingsActivity.java +++ b/src/acr/browser/lightning/GeneralSettingsActivity.java @@ -24,7 +24,7 @@ import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; -public class GeneralSettingsActivity extends ThemableActivity { +public class GeneralSettingsActivity extends ThemableSettingsActivity { // mPreferences variables private static final int API = android.os.Build.VERSION.SDK_INT; diff --git a/src/acr/browser/lightning/LicenseActivity.java b/src/acr/browser/lightning/LicenseActivity.java index 1e9869a..2b19bb4 100644 --- a/src/acr/browser/lightning/LicenseActivity.java +++ b/src/acr/browser/lightning/LicenseActivity.java @@ -15,7 +15,7 @@ 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 ThemableActivity implements View.OnClickListener { +public class LicenseActivity extends ThemableSettingsActivity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/src/acr/browser/lightning/PrivacySettingsActivity.java b/src/acr/browser/lightning/PrivacySettingsActivity.java index 0339ec6..8a6df8b 100644 --- a/src/acr/browser/lightning/PrivacySettingsActivity.java +++ b/src/acr/browser/lightning/PrivacySettingsActivity.java @@ -23,7 +23,7 @@ import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.RelativeLayout; import android.widget.TextView; -public class PrivacySettingsActivity extends ThemableActivity { +public class PrivacySettingsActivity extends ThemableSettingsActivity { // mPreferences variables private static final int API = android.os.Build.VERSION.SDK_INT; diff --git a/src/acr/browser/lightning/SettingsActivity.java b/src/acr/browser/lightning/SettingsActivity.java index 53db4fa..b65d056 100644 --- a/src/acr/browser/lightning/SettingsActivity.java +++ b/src/acr/browser/lightning/SettingsActivity.java @@ -26,7 +26,7 @@ import android.widget.EditText; import android.widget.RelativeLayout; import info.guardianproject.onionkit.ui.OrbotHelper; -public class SettingsActivity extends ThemableActivity { +public class SettingsActivity extends ThemableSettingsActivity { private static int API = android.os.Build.VERSION.SDK_INT; private SharedPreferences.Editor mEditPrefs; diff --git a/src/acr/browser/lightning/ThemableActivity.java b/src/acr/browser/lightning/ThemableActivity.java index 9ac4499..f9f745f 100644 --- a/src/acr/browser/lightning/ThemableActivity.java +++ b/src/acr/browser/lightning/ThemableActivity.java @@ -4,7 +4,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; -import android.view.WindowManager; public abstract class ThemableActivity extends ActionBarActivity { @@ -18,15 +17,7 @@ public abstract class ThemableActivity extends ActionBarActivity { // 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); + setTheme(R.style.Theme_DarkTheme); } super.onCreate(savedInstanceState); } diff --git a/src/acr/browser/lightning/ThemableSettingsActivity.java b/src/acr/browser/lightning/ThemableSettingsActivity.java new file mode 100644 index 0000000..631e618 --- /dev/null +++ b/src/acr/browser/lightning/ThemableSettingsActivity.java @@ -0,0 +1,43 @@ +package acr.browser.lightning; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; + +public abstract class ThemableSettingsActivity 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); + } + super.onCreate(savedInstanceState); + } + + @Override + protected void onResume() { + super.onResume(); + if (mPreferences != null + && mPreferences.getBoolean(PreferenceConstants.DARK_THEME, + false) != mDark) { + restart(); + } + } + + protected void restart() { + final Bundle outState = new Bundle(); + onSaveInstanceState(outState); + final Intent intent = new Intent(this, getClass()); + finish(); + overridePendingTransition(0, 0); + startActivity(intent); + } +}