Browse Source

Fixed ColorMode on the desktop tab UI by caching the backing Bitmap rather than immutable BitmapDrawable

BitmapDrawable turns out is sort of immutable even when using mutate()
so what was happening was that when switching from a tab on the right to
a tab on the left, the foreground drawable was set as the background of
two views for a small instant as the RecyclerView binds views from left
to right and the setColorFilter on the left foreground tab was not
working at all. When you switched from a left to right tab, it worked
fine because the left tab background was changed before the right and
the foreground drawable was only used by one view in that case. The
solution was to not reuse the drawable but instead reuse the backing
bitmap and create a new drawable whenever a tab moved to the foreground.
master
Anthony Restaino 9 years ago
parent
commit
57a25eb9dc
  1. 38
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 6
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java

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

@ -167,7 +167,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -167,7 +167,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mIsFullScreen = false,
mIsImmersive = false,
mShowTabsInDrawer;
private int mOriginalOrientation, mBackgroundColor, mIdGenerator, mIconColor;
private int mOriginalOrientation, mBackgroundColor, mIdGenerator, mIconColor,
mCurrentUiColor;
private String mSearchText, mUntitledTitle, mHomepage, mCameraPhotoPath;
// Storage
@ -1307,6 +1308,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1307,6 +1308,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private final CloseTabListener mExitListener;
private final Drawable mBackgroundTabDrawable;
private final Drawable mForegroundTabDrawable;
private final Bitmap mForegroundTabBitmap;
private final DrawerItemClickListener mClickListener;
private final DrawerItemLongClickListener mLongClickListener;
private ColorMatrix mColorMatrix;
@ -1324,6 +1326,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1324,6 +1326,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
if (mShowTabsInDrawer) {
mBackgroundTabDrawable = null;
mForegroundTabBitmap = null;
mForegroundTabDrawable = ThemeUtils.getSelectedBackground(context, mDarkTheme);
} else {
int backgroundColor = Utils.mixTwoColors(ThemeUtils.getPrimaryColor(mActivity), Color.BLACK, 0.75f);
@ -1332,9 +1335,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1332,9 +1335,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mBackgroundTabDrawable = new BitmapDrawable(getResources(), backgroundTabBitmap);
int foregroundColor = ThemeUtils.getPrimaryColor(context);
Bitmap foregroundTabBitmap = Bitmap.createBitmap(Utils.dpToPx(175), Utils.dpToPx(30), Bitmap.Config.ARGB_8888);
Utils.drawTrapezoid(new Canvas(foregroundTabBitmap), foregroundColor, false);
mForegroundTabDrawable = new BitmapDrawable(getResources(), foregroundTabBitmap).mutate();
mForegroundTabBitmap = Bitmap.createBitmap(Utils.dpToPx(175), Utils.dpToPx(30), Bitmap.Config.ARGB_8888);
Utils.drawTrapezoid(new Canvas(mForegroundTabBitmap), foregroundColor, false);
mForegroundTabDrawable = null;
}
}
@ -1364,13 +1367,22 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1364,13 +1367,22 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} else {
holder.txtTitle.setTextAppearance(context, R.style.boldText);
}
Drawable foregroundDrawable;
if (!mShowTabsInDrawer) {
foregroundDrawable = new BitmapDrawable(getResources(), mForegroundTabBitmap);
if (!isIncognito() && mColorMode) {
foregroundDrawable.setColorFilter(mCurrentUiColor, PorterDuff.Mode.SRC_IN);
}
} else {
foregroundDrawable = mForegroundTabDrawable;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.layout.setBackground(mForegroundTabDrawable);
holder.layout.setBackground(foregroundDrawable);
} else {
holder.layout.setBackgroundDrawable(mForegroundTabDrawable);
holder.layout.setBackgroundDrawable(foregroundDrawable);
}
if (!isIncognito() && mColorMode) {
changeToolbarBackground(favicon, null /* mForegroundTabDrawable */);
changeToolbarBackground(favicon, foregroundDrawable);
}
holder.favicon.setImageBitmap(favicon);
} else {
@ -1448,16 +1460,15 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1448,16 +1460,15 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
* @param tabBackground the optional LinearLayout to color
*/
private void changeToolbarBackground(@NonNull Bitmap favicon, @Nullable final Drawable tabBackground) {
if (!mShowTabsInDrawer) {
// TODO something is messed up and keeping this from working when the tablet tabs are used
return;
}
final int defaultColor;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
defaultColor = getResources().getColor(R.color.primary_color);
} else {
defaultColor = getColor(R.color.primary_color);
}
if (mCurrentUiColor == Color.BLACK) {
mCurrentUiColor = defaultColor;
}
Palette.from(favicon).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
@ -1467,13 +1478,13 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1467,13 +1478,13 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
int finalColor; // Lighten up the dark color if it is
// too dark
if (Utils.isColorTooDark(color)) {
if (!mShowTabsInDrawer || Utils.isColorTooDark(color)) {
finalColor = Utils.mixTwoColors(defaultColor, color, 0.25f);
} else {
finalColor = color;
}
ValueAnimator anim = ValueAnimator.ofInt(mBackground.getColor(), finalColor);
ValueAnimator anim = ValueAnimator.ofInt(mCurrentUiColor, finalColor);
anim.setEvaluator(new ArgbEvaluator());
final Window window = getWindow();
if (!mShowTabsInDrawer) {
@ -1490,6 +1501,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1490,6 +1501,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} else if (tabBackground != null) {
tabBackground.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
mCurrentUiColor = color;
mToolbarLayout.setBackgroundColor(color);
}

6
app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java

@ -490,9 +490,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe @@ -490,9 +490,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
v.setPadding(padding, padding, 0, padding);
layout.addView(v);
layout.addView(getDownload);
if (API < Build.VERSION_CODES.JELLY_BEAN) {
layout.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.edit_text));
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Drawable drawable;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawable = getResources().getDrawable(android.R.drawable.edit_text, getActivity().getTheme());
@ -500,6 +498,8 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe @@ -500,6 +498,8 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
drawable = getResources().getDrawable(android.R.drawable.edit_text);
}
layout.setBackground(drawable);
} else {
layout.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.edit_text));
}
downLocationPicker.setView(layout);
downLocationPicker.setPositiveButton(getResources().getString(R.string.action_ok),

Loading…
Cancel
Save