From 624777bafd033c425c3610caa40359cf615972d7 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Thu, 30 Apr 2015 18:37:29 +0800 Subject: [PATCH] improved theme --- .../activity/support/ComposeActivity.java | 3 +- .../activity/support/HomeActivity.java | 1 - .../activity/support/ImagePickerActivity.java | 2 +- .../support/AbsContentListViewFragment.java | 4 +- .../AbsContentRecyclerViewFragment.java | 2 - .../mariotaku/twidere/util/ThemeUtils.java | 40 ++++++++-------- .../util/ThemedLayoutInflaterFactory.java | 28 +++++++---- .../ThemedAccentSwipeRefreshLayout.java | 46 +++++++++++++++++++ .../res/layout/fragment_content_listview.xml | 7 ++- .../layout/fragment_content_recyclerview.xml | 4 +- 10 files changed, 94 insertions(+), 43 deletions(-) create mode 100644 twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedAccentSwipeRefreshLayout.java diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java index f41658477..42a0ca1bc 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java @@ -1169,7 +1169,8 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL private void updateLocationState() { final boolean attachLocation = mPreferences.getBoolean(KEY_ATTACH_LOCATION, false); if (attachLocation) { - mLocationIcon.setColorFilter(getCurrentThemeColor(), Mode.SRC_ATOP); + mLocationIcon.setColorFilter(ThemeUtils.getOptimalAccentColor(this, false, + getCurrentThemeResourceId()), Mode.SRC_ATOP); } else { mLocationIcon.setColorFilter(mLocationIcon.getDefaultColor(), Mode.SRC_ATOP); mLocationText.setText(R.string.no_location); diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java index 439920f5d..a32896c1c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java @@ -364,7 +364,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen mTabColumns = getResources().getInteger(R.integer.default_tab_columns); mColorStatusFrameLayout.setOnFitSystemWindowsListener(this); - ThemeUtils.applyBackground(mTabIndicator); mPagerAdapter = new SupportTabsAdapter(this, getSupportFragmentManager(), mTabIndicator, mTabColumns); mViewPager.setAdapter(mPagerAdapter); // mViewPager.setOffscreenPageLimit(3); diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ImagePickerActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ImagePickerActivity.java index 3cb0ff044..951b9272b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ImagePickerActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ImagePickerActivity.java @@ -47,7 +47,7 @@ public class ImagePickerActivity extends ThemedFragmentActivity { @Override public int getThemeColor() { - return 0; + return ThemeUtils.getUserAccentColor(this); } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListViewFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListViewFragment.java index 9c54ef0b7..24fcab94d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListViewFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListViewFragment.java @@ -40,7 +40,6 @@ import android.widget.TextView; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.iface.IControlBarActivity; import org.mariotaku.twidere.activity.iface.IControlBarActivity.ControlBarOffsetListener; -import org.mariotaku.twidere.activity.support.BaseAppCompatActivity; import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface; import org.mariotaku.twidere.util.ContentListScrollListener.ContentListSupport; import org.mariotaku.twidere.util.ThemeUtils; @@ -149,7 +148,6 @@ public abstract class AbsContentListViewFragment extends final int colorRes = TwidereColorUtils.getContrastYIQ(backgroundColor, R.color.bg_refresh_progress_color_light, R.color.bg_refresh_progress_color_dark); mSwipeRefreshLayout.setOnRefreshListener(this); - mSwipeRefreshLayout.setColorSchemeColors(ThemeUtils.getUserAccentColor(context)); mSwipeRefreshLayout.setProgressBackgroundColorSchemeResource(colorRes); mAdapter = onCreateAdapter(context, compact); mListView.setOnTouchListener(new View.OnTouchListener() { @@ -161,7 +159,7 @@ public abstract class AbsContentListViewFragment extends return false; } }); - mListView.setAdapter((ListAdapter) mAdapter); + mListView.setAdapter(mAdapter); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java index 221382fa8..f64daadc2 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java @@ -42,7 +42,6 @@ import android.widget.TextView; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.iface.IControlBarActivity; import org.mariotaku.twidere.activity.iface.IControlBarActivity.ControlBarOffsetListener; -import org.mariotaku.twidere.activity.support.BaseAppCompatActivity; import org.mariotaku.twidere.adapter.decorator.DividerItemDecoration; import org.mariotaku.twidere.adapter.iface.IContentCardAdapter; import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface; @@ -203,7 +202,6 @@ public abstract class AbsContentRecyclerViewFragment 64) + return userAccentColor; + return getColorFromAttribute(context, R.attr.colorAccent, context.getResources().getColor(R.color.branding_color)); + } + public static int getUserHighlightColor(final Context context) { final int color = getUserLinkTextColor(context); final int red = Color.red(color), green = Color.green(color), blue = Color.blue(color); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ThemedLayoutInflaterFactory.java b/twidere/src/main/java/org/mariotaku/twidere/util/ThemedLayoutInflaterFactory.java index 89f8ec14e..d69d69b0f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ThemedLayoutInflaterFactory.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ThemedLayoutInflaterFactory.java @@ -157,31 +157,43 @@ public class ThemedLayoutInflaterFactory implements LayoutInflaterFactory { backgroundColorApprox = Color.WHITE; isColorTint = false; } + final boolean isAccentOptimal = Math.abs(TwidereColorUtils.getYIQContrast(backgroundColorApprox, accentColor)) > 64; if (view instanceof TextView) { final TextView textView = (TextView) view; - - if (Math.abs(TwidereColorUtils.getYIQContrast(backgroundColorApprox, accentColor)) > 64) { + if (isAccentOptimal) { textView.setLinkTextColor(accentColor); } } if (view instanceof IThemeAccentView) { - if (Math.abs(TwidereColorUtils.getYIQContrast(backgroundColorApprox, accentColor)) > 64) { + if (isAccentOptimal) { ((IThemeAccentView) view).setAccentTintColor(ColorStateList.valueOf(accentColor)); + } else { + final int defaultAccentColor = ThemeUtils.getColorFromAttribute(view.getContext(), + R.attr.colorAccent, resources.getColor(R.color.branding_color)); + ((IThemeAccentView) view).setAccentTintColor(ColorStateList.valueOf(defaultAccentColor)); } } else if (view instanceof IThemeBackgroundTintView) { - ((IThemeBackgroundTintView) view).setBackgroundTintColor(ColorStateList.valueOf(backgroundTintColor)); + if (isAccentOptimal || !isColorTint) { + ((IThemeBackgroundTintView) view).setBackgroundTintColor(ColorStateList.valueOf(backgroundTintColor)); + } } else if (view instanceof TintableBackgroundView) { final TintableBackgroundView tintable = (TintableBackgroundView) view; - applyTintableBackgroundViewTint(tintable, accentColor, noTintColor, backgroundTintColor, isColorTint); + if (isAccentOptimal) { + applyTintableBackgroundViewTint(tintable, accentColor, noTintColor, backgroundTintColor, isColorTint); + } } else if (view instanceof TwidereToolbar) { final int itemColor = ThemeUtils.getContrastActionBarItemColor((Context) activity, themeResourceId, actionBarColor); ((TwidereToolbar) view).setItemColor(itemColor); } else if (view instanceof EditText) { - ViewCompat.setBackgroundTintList(view, ColorStateList.valueOf(accentColor)); + if (isAccentOptimal) { + ViewCompat.setBackgroundTintList(view, ColorStateList.valueOf(accentColor)); + } } else if (view instanceof ProgressBar) { - ViewSupport.setProgressTintList((ProgressBar) view, ColorStateList.valueOf(accentColor)); - ViewSupport.setProgressBackgroundTintList((ProgressBar) view, ColorStateList.valueOf(accentColor)); + if (isAccentOptimal) { + ViewSupport.setProgressTintList((ProgressBar) view, ColorStateList.valueOf(accentColor)); + ViewSupport.setProgressBackgroundTintList((ProgressBar) view, ColorStateList.valueOf(accentColor)); + } } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedAccentSwipeRefreshLayout.java b/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedAccentSwipeRefreshLayout.java new file mode 100644 index 000000000..e464a8616 --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/view/themed/ThemedAccentSwipeRefreshLayout.java @@ -0,0 +1,46 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2015 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.view.themed; + +import android.content.Context; +import android.content.res.ColorStateList; +import android.support.annotation.NonNull; +import android.support.v4.widget.SwipeRefreshLayout; +import android.util.AttributeSet; + +import org.mariotaku.twidere.view.iface.IThemeAccentView; + +/** + * Created by mariotaku on 15/4/25. + */ +public class ThemedAccentSwipeRefreshLayout extends SwipeRefreshLayout implements IThemeAccentView { + public ThemedAccentSwipeRefreshLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public ThemedAccentSwipeRefreshLayout(Context context) { + super(context); + } + + @Override + public void setAccentTintColor(@NonNull ColorStateList color) { + setColorSchemeColors(color.getDefaultColor()); + } +} diff --git a/twidere/src/main/res/layout/fragment_content_listview.xml b/twidere/src/main/res/layout/fragment_content_listview.xml index 721f8c8bb..e3bf9548f 100644 --- a/twidere/src/main/res/layout/fragment_content_listview.xml +++ b/twidere/src/main/res/layout/fragment_content_listview.xml @@ -17,8 +17,7 @@ ~ along with this program. If not, see . --> - - - + \ No newline at end of file diff --git a/twidere/src/main/res/layout/fragment_content_recyclerview.xml b/twidere/src/main/res/layout/fragment_content_recyclerview.xml index 4dcb38fdb..07938cb60 100644 --- a/twidere/src/main/res/layout/fragment_content_recyclerview.xml +++ b/twidere/src/main/res/layout/fragment_content_recyclerview.xml @@ -26,7 +26,7 @@ - - + \ No newline at end of file