Browse Source

Added back/forward icon enable/disabling on tablet devices

master
Anthony Restaino 9 years ago
parent
commit
737c02d6e8
  1. 46
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 2
      app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java
  3. 4
      app/src/main/java/acr/browser/lightning/browser/BrowserView.java
  4. 4
      app/src/main/java/acr/browser/lightning/controller/UIController.java
  5. 2
      app/src/main/java/acr/browser/lightning/view/LightningWebClient.java
  6. 2
      app/src/main/res/values/colors.xml

46
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -179,6 +179,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private int mOriginalOrientation; private int mOriginalOrientation;
private int mBackgroundColor; private int mBackgroundColor;
private int mIconColor; private int mIconColor;
private int mDisabledIconColor;
private int mCurrentUiColor = Color.BLACK; private int mCurrentUiColor = Color.BLACK;
private String mSearchText; private String mSearchText;
private String mUntitledTitle; private String mUntitledTitle;
@ -258,6 +259,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
//TODO make sure dark theme flag gets set correctly //TODO make sure dark theme flag gets set correctly
mDarkTheme = mPreferences.getUseTheme() != 0 || isIncognito(); mDarkTheme = mPreferences.getUseTheme() != 0 || isIncognito();
mIconColor = mDarkTheme ? ThemeUtils.getIconDarkThemeColor(this) : ThemeUtils.getIconLightThemeColor(this); mIconColor = mDarkTheme ? ThemeUtils.getIconDarkThemeColor(this) : ThemeUtils.getIconLightThemeColor(this);
mDisabledIconColor = mDarkTheme ? ContextCompat.getColor(this, R.color.icon_dark_theme_disabled) :
ContextCompat.getColor(this, R.color.icon_light_theme_disabled);
mShowTabsInDrawer = mPreferences.getShowTabsInDrawer(!isTablet()); mShowTabsInDrawer = mPreferences.getShowTabsInDrawer(!isTablet());
// initialize background ColorDrawable // initialize background ColorDrawable
@ -1360,14 +1363,45 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mDrawerLayout.closeDrawers(); mDrawerLayout.closeDrawers();
} }
@Override
public void setForwardButtonEnabled(boolean enabled) {
if (mForwardMenuItem != null && mForwardMenuItem.getIcon() != null) {
int colorFilter;
if (enabled) {
colorFilter = mIconColor;
} else {
colorFilter = mDisabledIconColor;
}
mForwardMenuItem.getIcon().setColorFilter(colorFilter, PorterDuff.Mode.SRC_IN);
mForwardMenuItem.setIcon(mForwardMenuItem.getIcon());
}
}
@Override
public void setBackButtonEnabled(boolean enabled) {
if (mBackMenuItem != null && mBackMenuItem.getIcon() != null) {
int colorFilter;
if (enabled) {
colorFilter = mIconColor;
} else {
colorFilter = mDisabledIconColor;
}
mBackMenuItem.getIcon().setColorFilter(colorFilter, PorterDuff.Mode.SRC_IN);
mBackMenuItem.setIcon(mBackMenuItem.getIcon());
}
}
private MenuItem mBackMenuItem;
private MenuItem mForwardMenuItem;
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuItem back = menu.findItem(R.id.action_back); mBackMenuItem = menu.findItem(R.id.action_back);
MenuItem forward = menu.findItem(R.id.action_forward); mForwardMenuItem = menu.findItem(R.id.action_forward);
if (back != null && back.getIcon() != null) if (mBackMenuItem != null && mBackMenuItem.getIcon() != null)
back.getIcon().setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); mBackMenuItem.getIcon().setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
if (forward != null && forward.getIcon() != null) if (mForwardMenuItem != null && mForwardMenuItem.getIcon() != null)
forward.getIcon().setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); mForwardMenuItem.getIcon().setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
return super.onCreateOptionsMenu(menu); return super.onCreateOptionsMenu(menu);
} }

2
app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java

@ -91,6 +91,8 @@ public class BrowserPresenter {
newTab.resumeTimers(); newTab.resumeTimers();
newTab.setForegroundTab(true); newTab.setForegroundTab(true);
mView.updateProgress(newTab.getProgress()); mView.updateProgress(newTab.getProgress());
mView.setBackButtonEnabled(newTab.canGoBack());
mView.setForwardButtonEnabled(newTab.canGoForward());
mView.updateUrl(newTab.getUrl(), true); mView.updateUrl(newTab.getUrl(), true);
mView.setTabView(newTab.getWebView()); mView.setTabView(newTab.getWebView());
} }

4
app/src/main/java/acr/browser/lightning/browser/BrowserView.java

@ -25,4 +25,8 @@ public interface BrowserView {
void showSnackbar(@StringRes int resource); void showSnackbar(@StringRes int resource);
void setForwardButtonEnabled(boolean enabled);
void setBackButtonEnabled(boolean enabled);
} }

4
app/src/main/java/acr/browser/lightning/controller/UIController.java

@ -55,4 +55,8 @@ public interface UIController {
void newTabClicked(); void newTabClicked();
void setForwardButtonEnabled(boolean enabled);
void setBackButtonEnabled(boolean enabled);
} }

2
app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

@ -97,6 +97,8 @@ public class LightningWebClient extends WebViewClient {
public void onPageFinished(@NonNull WebView view, String url) { public void onPageFinished(@NonNull WebView view, String url) {
if (view.isShown()) { if (view.isShown()) {
mUIController.updateUrl(url, true); mUIController.updateUrl(url, true);
mUIController.setBackButtonEnabled(view.canGoBack());
mUIController.setForwardButtonEnabled(view.canGoForward());
view.postInvalidate(); view.postInvalidate();
} }
if (view.getTitle() == null || view.getTitle().isEmpty()) { if (view.getTitle() == null || view.getTitle().isEmpty()) {

2
app/src/main/res/values/colors.xml

@ -32,6 +32,8 @@
<color name="icon_light_theme">#8A000000</color> <color name="icon_light_theme">#8A000000</color>
<color name="icon_dark_theme">#FFFFFFFF</color> <color name="icon_dark_theme">#FFFFFFFF</color>
<color name="icon_light_theme_disabled">#40000000</color>
<color name="icon_dark_theme_disabled">#8AFFFFFF</color>
<color name="error_red">#F44336</color> <color name="error_red">#F44336</color>

Loading…
Cancel
Save