Color the search bar appropriately for the various theme/color mode, fixed bug when restarting activity
This commit is contained in:
parent
1685a13df3
commit
f90ab177d5
@ -147,6 +147,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
|
||||
|
||||
// Toolbar Views
|
||||
private View mSearchBackground;
|
||||
private Toolbar mToolbar;
|
||||
private AutoCompleteTextView mSearch;
|
||||
private ImageView mArrowImage;
|
||||
@ -262,7 +263,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
mShowTabsInDrawer = mPreferences.getShowTabsInDrawer(!isTablet());
|
||||
|
||||
// initialize background ColorDrawable
|
||||
mBackground.setColor(((ColorDrawable) mToolbarLayout.getBackground()).getColor());
|
||||
int primaryColor = ThemeUtils.getPrimaryColor(this);
|
||||
mBackground.setColor(primaryColor);
|
||||
|
||||
// Drawer stutters otherwise
|
||||
mDrawerLeft.setLayerType(View.LAYER_TYPE_NONE, null);
|
||||
@ -353,11 +355,18 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
|
||||
// create the search EditText in the ToolBar
|
||||
mSearch = (AutoCompleteTextView) customView.findViewById(R.id.search);
|
||||
mSearchBackground = customView.findViewById(R.id.search_container);
|
||||
|
||||
// initialize search background color
|
||||
mSearchBackground.getBackground().setColorFilter(getSearchBarColor(primaryColor, primaryColor), PorterDuff.Mode.SRC_IN);
|
||||
mSearch.setHintTextColor(ThemeUtils.getThemedTextHintColor(mDarkTheme));
|
||||
mSearch.setTextColor(mDarkTheme ? Color.WHITE : Color.BLACK);
|
||||
|
||||
mUntitledTitle = getString(R.string.untitled);
|
||||
mBackgroundColor = ContextCompat.getColor(this, R.color.primary_color);
|
||||
mDeleteIcon = ThemeUtils.getLightThemedDrawable(this, R.drawable.ic_action_delete);
|
||||
mRefreshIcon = ThemeUtils.getLightThemedDrawable(this, R.drawable.ic_action_refresh);
|
||||
mClearIcon = ThemeUtils.getLightThemedDrawable(this, R.drawable.ic_action_delete);
|
||||
mBackgroundColor = ThemeUtils.getPrimaryColor(this);
|
||||
mDeleteIcon = ThemeUtils.getThemedDrawable(this, R.drawable.ic_action_delete, mDarkTheme);
|
||||
mRefreshIcon = ThemeUtils.getThemedDrawable(this, R.drawable.ic_action_refresh, mDarkTheme);
|
||||
mClearIcon = ThemeUtils.getThemedDrawable(this, R.drawable.ic_action_delete, mDarkTheme);
|
||||
|
||||
int iconBounds = Utils.dpToPx(30);
|
||||
mDeleteIcon.setBounds(0, 0, iconBounds, iconBounds);
|
||||
@ -1232,7 +1241,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
// OR with opaque black to remove transparency glitches
|
||||
int color = 0xff000000 | palette.getVibrantColor(defaultColor);
|
||||
|
||||
int finalColor; // Lighten up the dark color if it is
|
||||
final int finalColor; // Lighten up the dark color if it is
|
||||
// too dark
|
||||
if (!mShowTabsInDrawer || Utils.isColorTooDark(color)) {
|
||||
finalColor = Utils.mixTwoColors(defaultColor, color, 0.25f);
|
||||
@ -1240,17 +1249,19 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
finalColor = color;
|
||||
}
|
||||
|
||||
ValueAnimator anim = ValueAnimator.ofInt(mCurrentUiColor, finalColor);
|
||||
anim.setEvaluator(new ArgbEvaluator());
|
||||
|
||||
final Window window = getWindow();
|
||||
if (!mShowTabsInDrawer) {
|
||||
window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
|
||||
}
|
||||
anim.addUpdateListener(new AnimatorUpdateListener() {
|
||||
|
||||
final int startSearchColor = getSearchBarColor(mCurrentUiColor, defaultColor);
|
||||
final int finalSearchColor = getSearchBarColor(finalColor, defaultColor);
|
||||
|
||||
Animation animation = new Animation() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
final int color = (Integer) animation.getAnimatedValue();
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
final int color = DrawableUtils.mixColor(interpolatedTime, mCurrentUiColor, finalColor);
|
||||
if (mShowTabsInDrawer) {
|
||||
mBackground.setColor(color);
|
||||
window.setBackgroundDrawable(mBackground);
|
||||
@ -1259,15 +1270,24 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
}
|
||||
mCurrentUiColor = color;
|
||||
mToolbarLayout.setBackgroundColor(color);
|
||||
mSearchBackground.getBackground().setColorFilter(DrawableUtils.mixColor(interpolatedTime,
|
||||
startSearchColor, finalSearchColor), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
});
|
||||
anim.setDuration(300);
|
||||
anim.start();
|
||||
};
|
||||
animation.setDuration(300);
|
||||
mToolbarLayout.startAnimation(animation);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private int getSearchBarColor(int requestedColor, int defaultColor) {
|
||||
if (requestedColor == defaultColor) {
|
||||
return mDarkTheme ? DrawableUtils.mixColor(0.25f, defaultColor, Color.WHITE): Color.WHITE;
|
||||
} else {
|
||||
return DrawableUtils.mixColor(0.5f, requestedColor, Color.WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getUseDarkTheme() {
|
||||
return mDarkTheme;
|
||||
|
@ -48,8 +48,7 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void restart() {
|
||||
Intent intent = getIntent();
|
||||
finish();
|
||||
startActivity(intent);
|
||||
startActivity(new Intent(this, getClass()));
|
||||
}
|
||||
}
|
||||
|
@ -51,4 +51,24 @@ public class DrawableUtils {
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
public static int mixColor(float fraction, int startValue, int endValue) {
|
||||
int startInt = startValue;
|
||||
int startA = (startInt >> 24) & 0xff;
|
||||
int startR = (startInt >> 16) & 0xff;
|
||||
int startG = (startInt >> 8) & 0xff;
|
||||
int startB = startInt & 0xff;
|
||||
|
||||
int endInt = endValue;
|
||||
int endA = (endInt >> 24) & 0xff;
|
||||
int endR = (endInt >> 16) & 0xff;
|
||||
int endG = (endInt >> 8) & 0xff;
|
||||
int endB = endInt & 0xff;
|
||||
|
||||
return (startA + (int)(fraction * (endA - startA))) << 24 |
|
||||
(startR + (int)(fraction * (endR - startR))) << 16 |
|
||||
(startG + (int)(fraction * (endG - startG))) << 8 |
|
||||
(startB + (int)(fraction * (endB - startB)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
@ -87,14 +88,6 @@ public class ThemeUtils {
|
||||
return drawable;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Drawable getLightThemedDrawable(@NonNull Context context, @DrawableRes int res) {
|
||||
final Drawable drawable = ContextCompat.getDrawable(context, res);
|
||||
drawable.mutate();
|
||||
drawable.setColorFilter(getIconLightThemeColor(context), PorterDuff.Mode.SRC_IN);
|
||||
return drawable;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ColorDrawable getSelectedBackground(@NonNull Context context, boolean dark) {
|
||||
@ColorInt final int color = (dark) ? ContextCompat.getColor(context, R.color.selected_dark) :
|
||||
@ -102,6 +95,10 @@ public class ThemeUtils {
|
||||
return new ColorDrawable(color);
|
||||
}
|
||||
|
||||
public static int getThemedTextHintColor(boolean dark){
|
||||
return 0x80ffffff & (dark ? Color.WHITE : Color.BLACK);
|
||||
}
|
||||
|
||||
public static int getTextColor(@NonNull Context context) {
|
||||
return getColor(context, android.R.attr.editTextColor);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@
|
||||
<style name="Theme.BlackTheme" parent="Theme.AppCompat">
|
||||
|
||||
<!-- customize the color palette -->
|
||||
<item name="searchBackground">@drawable/card_bg_elevate</item>
|
||||
<item name="searchBackground">@drawable/card_bg</item>
|
||||
<item name="colorPrimary">@color/black</item>
|
||||
<item name="colorPrimaryDark">@color/black</item>
|
||||
<item name="colorAccent">@color/accent_color</item>
|
||||
|
Loading…
Reference in New Issue
Block a user