Solve problems with colors when tabs are switched
This commit is contained in:
parent
6749ca39b8
commit
1f025debd7
@ -235,7 +235,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
mDrawerRight = (ViewGroup) findViewById(R.id.right_drawer);
|
mDrawerRight = (ViewGroup) findViewById(R.id.right_drawer);
|
||||||
mDrawerRight.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
mDrawerRight.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||||
// TODO Probably should be moved to the TabsFragement
|
// TODO Please review this
|
||||||
// ImageView tabTitleImage = (ImageView) findViewById(R.id.plusIcon);
|
// ImageView tabTitleImage = (ImageView) findViewById(R.id.plusIcon);
|
||||||
// tabTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
// tabTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
||||||
|
|
||||||
@ -253,8 +253,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
final TabsFragment tabsFragment = new TabsFragment();
|
final TabsFragment tabsFragment = new TabsFragment();
|
||||||
final int containerId = mShowTabsInDrawer ? R.id.left_drawer : R.id.tabs_toolbar_container;
|
final int containerId = mShowTabsInDrawer ? R.id.left_drawer : R.id.tabs_toolbar_container;
|
||||||
final Bundle arguments = new Bundle();
|
final Bundle arguments = new Bundle();
|
||||||
|
arguments.putBoolean(TabsFragment.IS_INCOGNITO, isIncognito());
|
||||||
arguments.putBoolean(TabsFragment.VERTICAL_MODE, mShowTabsInDrawer);
|
arguments.putBoolean(TabsFragment.VERTICAL_MODE, mShowTabsInDrawer);
|
||||||
arguments.putBoolean(TabsFragment.USE_DARK_THEME, mDarkTheme);
|
|
||||||
tabsFragment.setArguments(arguments);
|
tabsFragment.setArguments(arguments);
|
||||||
getSupportFragmentManager()
|
getSupportFragmentManager()
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package acr.browser.lightning.fragment;
|
package acr.browser.lightning.fragment;
|
||||||
|
|
||||||
|
import android.animation.ArgbEvaluator;
|
||||||
|
import android.animation.ValueAnimator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@ -10,6 +13,7 @@ import android.graphics.ColorMatrixColorFilter;
|
|||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -18,12 +22,14 @@ import android.support.annotation.NonNull;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
|
import android.support.v7.graphics.Palette;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.RecyclerView.LayoutManager;
|
import android.support.v7.widget.RecyclerView.LayoutManager;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.Window;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@ -42,6 +48,7 @@ import acr.browser.lightning.app.BrowserApp;
|
|||||||
import acr.browser.lightning.bus.BrowserEvents;
|
import acr.browser.lightning.bus.BrowserEvents;
|
||||||
import acr.browser.lightning.bus.NavigationEvents;
|
import acr.browser.lightning.bus.NavigationEvents;
|
||||||
import acr.browser.lightning.bus.TabEvents;
|
import acr.browser.lightning.bus.TabEvents;
|
||||||
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
import acr.browser.lightning.utils.ThemeUtils;
|
import acr.browser.lightning.utils.ThemeUtils;
|
||||||
import acr.browser.lightning.utils.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
import acr.browser.lightning.view.LightningView;
|
import acr.browser.lightning.view.LightningView;
|
||||||
@ -59,13 +66,13 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
* If true, the fragment is in the left drawner in the strip otherwise.
|
* If true, the fragment is in the left drawner in the strip otherwise.
|
||||||
*/
|
*/
|
||||||
public static final String VERTICAL_MODE = TAG + ".VERTICAL_MODE";
|
public static final String VERTICAL_MODE = TAG + ".VERTICAL_MODE";
|
||||||
public static final String USE_DARK_THEME = TAG + ".USE_DARK_THEME";
|
public static final String IS_INCOGNITO = TAG + ".IS_INCOGNITO";
|
||||||
|
|
||||||
private boolean mDarkTheme;
|
private boolean mIsIncognito, mDarkTheme;
|
||||||
private int mIconColor;
|
private int mIconColor;
|
||||||
private boolean mColorMode = true; // TODO Only temporary
|
private boolean mColorMode = true;
|
||||||
private boolean isIncognito = false; // TODO Only temporary
|
private boolean mShowInNavigationDrawer;
|
||||||
private int mCurrentUiColor = 0; // TODO Only temporary
|
private int mCurrentUiColor = Color.BLACK; // TODO Only temporary
|
||||||
|
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
private LightningViewAdapter mTabsAdapter;
|
private LightningViewAdapter mTabsAdapter;
|
||||||
@ -76,6 +83,9 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
@Inject
|
@Inject
|
||||||
Bus bus;
|
Bus bus;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
PreferenceManager mPreferences;
|
||||||
|
|
||||||
public TabsFragment() {
|
public TabsFragment() {
|
||||||
BrowserApp.getAppComponent().inject(this);
|
BrowserApp.getAppComponent().inject(this);
|
||||||
}
|
}
|
||||||
@ -85,7 +95,11 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
final Bundle arguments = getArguments();
|
final Bundle arguments = getArguments();
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
mDarkTheme = arguments.getBoolean(USE_DARK_THEME, false);
|
mIsIncognito = arguments.getBoolean(IS_INCOGNITO, false);
|
||||||
|
mShowInNavigationDrawer = arguments.getBoolean(VERTICAL_MODE, true);
|
||||||
|
mDarkTheme = mPreferences.getUseTheme() != 0 || mIsIncognito;
|
||||||
|
mColorMode = mPreferences.getColorModeEnabled();
|
||||||
|
mColorMode &= !mDarkTheme;
|
||||||
mIconColor = mDarkTheme ?
|
mIconColor = mDarkTheme ?
|
||||||
ThemeUtils.getIconDarkThemeColor(context) :
|
ThemeUtils.getIconDarkThemeColor(context) :
|
||||||
ThemeUtils.getIconLightThemeColor(context);
|
ThemeUtils.getIconLightThemeColor(context);
|
||||||
@ -95,10 +109,9 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
final Bundle arguments = getArguments();
|
final Bundle arguments = getArguments();
|
||||||
final boolean vertical = arguments.getBoolean(VERTICAL_MODE, true);
|
|
||||||
final View view;
|
final View view;
|
||||||
final LayoutManager layoutManager;
|
final LayoutManager layoutManager;
|
||||||
if (vertical) {
|
if (mShowInNavigationDrawer) {
|
||||||
view = inflater.inflate(R.layout.tab_drawer, container, false);
|
view = inflater.inflate(R.layout.tab_drawer, container, false);
|
||||||
layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
|
layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
|
||||||
// TODO Handle also long press
|
// TODO Handle also long press
|
||||||
@ -112,7 +125,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
}
|
}
|
||||||
mRecyclerView = (RecyclerView) view.findViewById(R.id.tabs_list);
|
mRecyclerView = (RecyclerView) view.findViewById(R.id.tabs_list);
|
||||||
mRecyclerView.setLayoutManager(layoutManager);
|
mRecyclerView.setLayoutManager(layoutManager);
|
||||||
mTabsAdapter = new LightningViewAdapter(vertical);
|
mTabsAdapter = new LightningViewAdapter(mShowInNavigationDrawer);
|
||||||
mRecyclerView.setAdapter(mTabsAdapter);
|
mRecyclerView.setAdapter(mTabsAdapter);
|
||||||
mRecyclerView.setHasFixedSize(true);
|
mRecyclerView.setHasFixedSize(true);
|
||||||
return view;
|
return view;
|
||||||
@ -249,7 +262,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
Drawable foregroundDrawable;
|
Drawable foregroundDrawable;
|
||||||
if (!vertical) {
|
if (!vertical) {
|
||||||
foregroundDrawable = new BitmapDrawable(getResources(), mForegroundTabBitmap);
|
foregroundDrawable = new BitmapDrawable(getResources(), mForegroundTabBitmap);
|
||||||
if (!isIncognito && mColorMode) {
|
if (!mIsIncognito && mColorMode) {
|
||||||
foregroundDrawable.setColorFilter(mCurrentUiColor, PorterDuff.Mode.SRC_IN);
|
foregroundDrawable.setColorFilter(mCurrentUiColor, PorterDuff.Mode.SRC_IN);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -260,9 +273,8 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
} else {
|
} else {
|
||||||
holder.layout.setBackgroundDrawable(foregroundDrawable);
|
holder.layout.setBackgroundDrawable(foregroundDrawable);
|
||||||
}
|
}
|
||||||
if (!isIncognito && mColorMode) {
|
if (!mIsIncognito && mColorMode) {
|
||||||
// TODO Restore this
|
changeToolbarBackground(favicon, foregroundDrawable);
|
||||||
// changeToolbarBackground(favicon, foregroundDrawable);
|
|
||||||
}
|
}
|
||||||
holder.favicon.setImageBitmap(favicon);
|
holder.favicon.setImageBitmap(favicon);
|
||||||
} else {
|
} else {
|
||||||
@ -302,6 +314,64 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
return grayscaleBitmap;
|
return grayscaleBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Animates the color of the toolbar from one color to another. Optionally animates
|
||||||
|
* the color of the tab background, for use when the tabs are displayed on the top
|
||||||
|
* of the screen.
|
||||||
|
*
|
||||||
|
* @param favicon the Bitmap to extract the color from
|
||||||
|
* @param tabBackground the optional LinearLayout to color
|
||||||
|
*/
|
||||||
|
private void changeToolbarBackground(@NonNull Bitmap favicon, @Nullable final Drawable tabBackground) {
|
||||||
|
if (mShowInNavigationDrawer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int defaultColor;
|
||||||
|
final Resources resources = getResources();
|
||||||
|
final ColorDrawable mBackground = new ColorDrawable();
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
defaultColor = resources.getColor(R.color.primary_color, null);
|
||||||
|
} else {
|
||||||
|
defaultColor = resources.getColor(R.color.primary_color);
|
||||||
|
}
|
||||||
|
if (mCurrentUiColor == Color.BLACK) {
|
||||||
|
mCurrentUiColor = defaultColor;
|
||||||
|
}
|
||||||
|
Palette.from(favicon).generate(new Palette.PaletteAsyncListener() {
|
||||||
|
@Override
|
||||||
|
public void onGenerated(Palette palette) {
|
||||||
|
|
||||||
|
// OR with opaque black to remove transparency glitches
|
||||||
|
int color = 0xff000000 | palette.getVibrantColor(defaultColor);
|
||||||
|
|
||||||
|
int finalColor = Utils.mixTwoColors(defaultColor, color, 0.25f);
|
||||||
|
|
||||||
|
ValueAnimator anim = ValueAnimator.ofInt(mCurrentUiColor, finalColor);
|
||||||
|
anim.setEvaluator(new ArgbEvaluator());
|
||||||
|
// final Window window = getWindow();
|
||||||
|
// TODO Check this
|
||||||
|
// if (!mShowInNavigationDrawer) {
|
||||||
|
// window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
|
||||||
|
// }
|
||||||
|
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationUpdate(ValueAnimator animation) {
|
||||||
|
final int color = (Integer) animation.getAnimatedValue();
|
||||||
|
if (tabBackground != null) {
|
||||||
|
tabBackground.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||||
|
}
|
||||||
|
mCurrentUiColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
anim.setDuration(300);
|
||||||
|
anim.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public class LightningViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
public class LightningViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
|
|
||||||
public LightningViewHolder(View view) {
|
public LightningViewHolder(View view) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user