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 @@ -179,6 +179,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private int mOriginalOrientation;
private int mBackgroundColor;
private int mIconColor;
private int mDisabledIconColor;
private int mCurrentUiColor = Color.BLACK;
private String mSearchText;
private String mUntitledTitle;
@ -258,6 +259,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -258,6 +259,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
//TODO make sure dark theme flag gets set correctly
mDarkTheme = mPreferences.getUseTheme() != 0 || isIncognito();
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());
// initialize background ColorDrawable
@ -1360,14 +1363,45 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1360,14 +1363,45 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
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
public boolean onCreateOptionsMenu(Menu menu) {
MenuItem back = menu.findItem(R.id.action_back);
MenuItem forward = menu.findItem(R.id.action_forward);
if (back != null && back.getIcon() != null)
back.getIcon().setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
if (forward != null && forward.getIcon() != null)
forward.getIcon().setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
mBackMenuItem = menu.findItem(R.id.action_back);
mForwardMenuItem = menu.findItem(R.id.action_forward);
if (mBackMenuItem != null && mBackMenuItem.getIcon() != null)
mBackMenuItem.getIcon().setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
if (mForwardMenuItem != null && mForwardMenuItem.getIcon() != null)
mForwardMenuItem.getIcon().setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
return super.onCreateOptionsMenu(menu);
}

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

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

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

@ -25,4 +25,8 @@ public interface BrowserView { @@ -25,4 +25,8 @@ public interface BrowserView {
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 { @@ -55,4 +55,8 @@ public interface UIController {
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 { @@ -97,6 +97,8 @@ public class LightningWebClient extends WebViewClient {
public void onPageFinished(@NonNull WebView view, String url) {
if (view.isShown()) {
mUIController.updateUrl(url, true);
mUIController.setBackButtonEnabled(view.canGoBack());
mUIController.setForwardButtonEnabled(view.canGoForward());
view.postInvalidate();
}
if (view.getTitle() == null || view.getTitle().isEmpty()) {

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

@ -32,6 +32,8 @@ @@ -32,6 +32,8 @@
<color name="icon_light_theme">#8A000000</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>

Loading…
Cancel
Save