improved theme
This commit is contained in:
parent
46f85ce421
commit
624777bafd
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -47,7 +47,7 @@ public class ImagePickerActivity extends ThemedFragmentActivity {
|
|||
|
||||
@Override
|
||||
public int getThemeColor() {
|
||||
return 0;
|
||||
return ThemeUtils.getUserAccentColor(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<A extends ListAdapter> 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<A extends ListAdapter> extends
|
|||
return false;
|
||||
}
|
||||
});
|
||||
mListView.setAdapter((ListAdapter) mAdapter);
|
||||
mListView.setAdapter(mAdapter);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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<A extends IContentCardAdapt
|
|||
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);
|
||||
mLayoutManager = new FixedLinearLayoutManager(context);
|
||||
|
|
|
@ -26,7 +26,6 @@ import android.content.Context;
|
|||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
|
@ -131,26 +130,6 @@ public class ThemeUtils implements Constants {
|
|||
actionBar.setStackedBackground(getActionBarStackedBackground(context, themeRes, accentColor, outlineEnabled));
|
||||
}
|
||||
|
||||
|
||||
public static void applyBackground(final View view) {
|
||||
if (view == null) return;
|
||||
applyBackground(view, getUserAccentColor(view.getContext()));
|
||||
}
|
||||
|
||||
public static void applyBackground(final View view, final int color) {
|
||||
if (view == null) return;
|
||||
try {
|
||||
final Drawable bg = view.getBackground();
|
||||
if (bg == null) return;
|
||||
final Drawable mutated = bg.mutate();
|
||||
if (mutated == null) return;
|
||||
mutated.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
|
||||
view.invalidate();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void applyColorFilterToMenuIcon(Activity activity, Menu menu) {
|
||||
final ActionBar actionBar = activity.getActionBar();
|
||||
final Context context = actionBar != null ? actionBar.getThemedContext() : activity;
|
||||
|
@ -793,6 +772,25 @@ public class ThemeUtils implements Constants {
|
|||
return pref.getInt(KEY_THEME_COLOR, def);
|
||||
}
|
||||
|
||||
public static int getOptimalAccentColor(final Context context, boolean isActionBarContext, int themeResId) {
|
||||
final int userAccentColor = getUserAccentColor(context);
|
||||
final int backgroundColorApprox;
|
||||
final boolean isDarkTheme = isDarkTheme(themeResId);
|
||||
if (!isActionBarContext) {
|
||||
backgroundColorApprox = isDarkTheme ? Color.BLACK : Color.WHITE;
|
||||
} else if (isDarkTheme) {
|
||||
// View context is derived from ActionBar but is currently dark theme, so we should show
|
||||
// light
|
||||
backgroundColorApprox = Color.BLACK;
|
||||
} else {
|
||||
// View context is derived from ActionBar and it's light theme, so we use contrast color
|
||||
backgroundColorApprox = Color.WHITE;
|
||||
}
|
||||
if (Math.abs(TwidereColorUtils.getYIQContrast(backgroundColorApprox, userAccentColor)) > 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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -17,8 +17,7 @@
|
|||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/fragment_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -26,7 +25,7 @@
|
|||
|
||||
<include layout="@layout/layout_content_fragment_common" />
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
<org.mariotaku.twidere.view.themed.ThemedAccentSwipeRefreshLayout
|
||||
android:id="@+id/swipe_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -42,5 +41,5 @@
|
|||
android:focusableInTouchMode="false"
|
||||
android:listSelector="?selectableItemBackground" />
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
</org.mariotaku.twidere.view.themed.ThemedAccentSwipeRefreshLayout>
|
||||
</FrameLayout>
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
<include layout="@layout/layout_content_fragment_common" />
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
<org.mariotaku.twidere.view.themed.ThemedAccentSwipeRefreshLayout
|
||||
android:id="@+id/swipe_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -41,5 +41,5 @@
|
|||
android:focusableInTouchMode="false"
|
||||
android:scrollbars="vertical" />
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
</org.mariotaku.twidere.view.themed.ThemedAccentSwipeRefreshLayout>
|
||||
</FrameLayout>
|
Loading…
Reference in New Issue