improved text color

This commit is contained in:
Mariotaku Lee 2016-12-23 09:26:52 +08:00
parent 77299e457c
commit 5493ab43f1
19 changed files with 145 additions and 64 deletions

View File

@ -169,6 +169,7 @@ public class Chameleon {
private int colorControlNormal;
private int colorControlActivated;
private int colorControlHighlight;
private int statusBarColor;
private int navigationBarColor;
@ -348,6 +349,14 @@ public class Chameleon {
this.colorControlActivated = color;
}
public int getColorControlHighlight() {
return colorControlHighlight;
}
public void setColorControlHighlight(int colorControlHighlight) {
this.colorControlHighlight = colorControlHighlight;
}
public void setLightStatusBarMode(@LightStatusBarMode int mode) {
this.lightStatusBarMode = mode;
}
@ -379,6 +388,7 @@ public class Chameleon {
theme.setColorControlNormal(a.getColor(R.styleable.ChameleonTheme_colorControlNormal, 0));
theme.setColorControlActivated(a.getColor(R.styleable.ChameleonTheme_colorControlActivated, 0));
theme.setColorControlHighlight(a.getColor(R.styleable.ChameleonTheme_colorControlHighlight, 0));
theme.setStatusBarColor(a.getColor(R.styleable.ChameleonTheme_android_statusBarColor, 0));
theme.setNavigationBarColor(a.getColor(R.styleable.ChameleonTheme_android_navigationBarColor, Color.BLACK));

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.util.ArrayMap;
import android.support.v4.view.LayoutInflaterFactory;
import android.support.v7.app.AppCompatDelegate;
@ -170,6 +171,10 @@ public class ChameleonInflationFactory implements LayoutInflaterFactory {
R.styleable.ChameleonView, mTheme);
Drawable background = a.getDrawable(R.styleable.ChameleonView_android_background);
if (background != null) {
int tint = a.getColor(R.styleable.ChameleonView_backgroundTint, 0);
if (tint != 0) {
DrawableCompat.setTint(background, tint);
}
SupportMethods.setBackground(view, background);
}
a.recycle();

View File

@ -49,10 +49,6 @@ public class ChameleonTypedArray {
return new ChameleonTypedArray(array, hasAttribute, attributeReferences, theme);
}
public int getColor(int index) {
return wrapped.getColor(index, 0);
}
public int getColor(int index, int defValue) {
final int ref = attributeReferences[index];
int color = getCommonColorReference(ref);
@ -76,6 +72,12 @@ public class ChameleonTypedArray {
return theme.getColorPrimaryDark();
} else if (ref == android.support.design.R.attr.colorAccent) {
return theme.getColorAccent();
} else if (ref == android.support.design.R.attr.colorControlNormal) {
return theme.getColorControlNormal();
} else if (ref == android.support.design.R.attr.colorControlActivated) {
return theme.getColorControlActivated();
} else if (ref == android.support.design.R.attr.colorControlHighlight) {
return theme.getColorControlHighlight();
} else if (ref == R.attr.colorToolbar) {
return theme.getColorToolbar();
}

View File

@ -34,7 +34,7 @@ public class ChameleonAutoCompleteTextView extends AppCompatAutoCompleteTextView
@Nullable
@Override
public ChameleonEditText.Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) {
return ChameleonTextView.Appearance.create(context, attributeSet, theme);
return ChameleonTextView.Appearance.create(this, context, attributeSet, theme);
}

View File

@ -34,7 +34,7 @@ public class ChameleonEditText extends AppCompatEditText implements ChameleonVie
@Nullable
@Override
public Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) {
return ChameleonTextView.Appearance.create(context, attributeSet, theme);
return ChameleonTextView.Appearance.create(this, context, attributeSet, theme);
}

View File

@ -34,7 +34,7 @@ public class ChameleonMultiAutoCompleteTextView extends AppCompatMultiAutoComple
@Nullable
@Override
public ChameleonEditText.Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) {
return ChameleonTextView.Appearance.create(context, attributeSet, theme);
return ChameleonTextView.Appearance.create(this, context, attributeSet, theme);
}

View File

@ -45,37 +45,59 @@ public class ChameleonTextView extends AppCompatTextView implements ChameleonVie
@Nullable
@Override
public Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) {
Appearance appearance = new Appearance();
ChameleonTypedArray a = ChameleonTypedArray.obtain(context, attributeSet,
R.styleable.ChameleonTextView, theme);
appearance.setLinkTextColor(a.getColor(R.styleable.ChameleonTextView_android_textColorLink, theme.getTextColorLink()));
a.recycle();
return appearance;
return Appearance.create(this, context, attributeSet, theme);
}
@Override
public void applyAppearance(@NonNull ChameleonView.Appearance appearance) {
final Appearance a = (Appearance) appearance;
setLinkTextColor(a.getLinkTextColor());
Appearance.apply(this, (Appearance) appearance);
}
public static class Appearance implements ChameleonView.Appearance {
private int textColor;
private int linkTextColor;
private int backgroundColor;
public static void apply(TextView view, ChameleonTextView.Appearance appearance) {
public int getLinkTextColor() {
return linkTextColor;
}
public void setLinkTextColor(int linkTextColor) {
this.linkTextColor = linkTextColor;
}
public int getBackgroundColor() {
return backgroundColor;
}
public void setBackgroundColor(int backgroundColor) {
this.backgroundColor = backgroundColor;
}
public int getTextColor() {
return textColor;
}
public void setTextColor(int textColor) {
this.textColor = textColor;
}
public static void apply(TextView view, Appearance appearance) {
view.setLinkTextColor(appearance.getLinkTextColor());
view.setTextColor(appearance.getTextColor());
ViewCompat.setBackgroundTintList(view, ColorStateList.valueOf(appearance.getBackgroundColor()));
setCursorTint(view, appearance.getBackgroundColor());
setHandlerTint(view, appearance.getBackgroundColor());
view.setHighlightColor(ChameleonUtils.adjustAlpha(appearance.getBackgroundColor(), 0.4f));
}
public static ChameleonEditText.Appearance create(Context context, AttributeSet attributeSet, Chameleon.Theme theme) {
ChameleonTextView.Appearance appearance = new ChameleonTextView.Appearance();
public static Appearance create(TextView view, Context context, AttributeSet attributeSet, Chameleon.Theme theme) {
Appearance appearance = new Appearance();
ChameleonTypedArray a = ChameleonTypedArray.obtain(context, attributeSet,
R.styleable.ChameleonEditText, theme);
appearance.setTextColor(a.getColor(R.styleable.ChameleonEditText_android_textColor, view.getCurrentTextColor()));
appearance.setLinkTextColor(a.getColor(R.styleable.ChameleonEditText_android_textColorLink, theme.getTextColorLink()));
appearance.setBackgroundColor(a.getColor(R.styleable.ChameleonEditText_backgroundTint, theme.getColorAccent()));
a.recycle();
@ -132,21 +154,5 @@ public class ChameleonTextView extends AppCompatTextView implements ChameleonVie
field.setAccessible(true);
field.set(object, value);
}
public int getLinkTextColor() {
return linkTextColor;
}
public void setLinkTextColor(int linkTextColor) {
this.linkTextColor = linkTextColor;
}
public int getBackgroundColor() {
return backgroundColor;
}
public void setBackgroundColor(int backgroundColor) {
this.backgroundColor = backgroundColor;
}
}
}

View File

@ -35,11 +35,14 @@
</declare-styleable>
<declare-styleable name="ChameleonView">
<attr name="android:background"/>
<attr name="backgroundTint"/>
<attr name="backgroundTintMode"/>
</declare-styleable>
<declare-styleable name="ChameleonTextView">
<attr name="android:textColorLink"/>
</declare-styleable>
<declare-styleable name="ChameleonEditText">
<attr name="android:textColor"/>
<attr name="android:textColorLink"/>
<attr name="backgroundTint"/>
</declare-styleable>

View File

@ -0,0 +1,36 @@
package org.mariotaku.twidere.view;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import org.mariotaku.chameleon.Chameleon;
import org.mariotaku.chameleon.ChameleonUtils;
/**
* Created by mariotaku on 2016/12/23.
*/
public class PreferencesItemIconView extends IconActionView {
public PreferencesItemIconView(Context context) {
super(context);
}
public PreferencesItemIconView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public PreferencesItemIconView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Nullable
@Override
public Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) {
Appearance appearance = new Appearance();
appearance.setActivatedColor(ChameleonUtils.getColorDependent(theme.getColorControlActivated()));
appearance.setDefaultColor(theme.getColorForeground());
return appearance;
}
}

View File

@ -314,9 +314,9 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
signInIntent.setClass(this, SignInActivity::class.java)
startActivity(signInIntent)
finish()
if (defaultAutoRefreshKeyAsked !in kPreferences) {
if (defaultAutoRefreshAskedKey !in kPreferences) {
// Assume first install
kPreferences[defaultAutoRefreshKeyAsked] = false
kPreferences[defaultAutoRefreshAskedKey] = false
}
return
} else {
@ -347,16 +347,16 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
}
mainTabs.setTabDisplayOption(tabDisplayOptionInt)
mainTabs.setTabExpandEnabled(tabDisplayOptionInt and TabPagerIndicator.DisplayOption.LABEL == 0)
mainTabs.setDisplayBadge(preferences.getBoolean(SharedPreferenceConstants.KEY_UNREAD_COUNT, true))
mainTabs.setDisplayBadge(preferences[unreadCountKey])
mainTabs.updateAppearance()
if (preferences.getBoolean(SharedPreferenceConstants.KEY_DRAWER_TOGGLE)) {
if (preferences[drawerToggleKey]) {
drawerToggleButton.visibility = View.VISIBLE
} else {
drawerToggleButton.visibility = View.GONE
}
if (preferences.getBoolean(SharedPreferenceConstants.KEY_FAB_VISIBLE)) {
if (preferences[fabVisibleKey]) {
actionsButton.visibility = View.VISIBLE
} else {
actionsButton.visibility = View.GONE
@ -400,7 +400,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
startService(Intent(this, StreamingService::class.java))
}
if (!showDrawerTutorial() && !kPreferences[defaultAutoRefreshKeyAsked]) {
if (!showDrawerTutorial() && !kPreferences[defaultAutoRefreshAskedKey]) {
showAutoRefreshConfirm()
}
}
@ -947,7 +947,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
}
override fun onDismiss(dialog: DialogInterface?) {
kPreferences[defaultAutoRefreshKeyAsked] = true
kPreferences[defaultAutoRefreshAskedKey] = true
super.onDismiss(dialog)
}
}

View File

@ -43,7 +43,10 @@ val bugReportsKey = KBooleanKey(KEY_BUG_REPORTS, BuildConfig.DEBUG)
val readFromBottomKey = KBooleanKey(KEY_READ_FROM_BOTTOM, false)
val randomizeAccountNameKey = KBooleanKey(KEY_RANDOMIZE_ACCOUNT_NAME, false)
val defaultAutoRefreshKey = KBooleanKey(KEY_DEFAULT_AUTO_REFRESH, false)
val defaultAutoRefreshKeyAsked = KBooleanKey("default_auto_refresh_asked", true)
val defaultAutoRefreshAskedKey = KBooleanKey("default_auto_refresh_asked", true)
val unreadCountKey = KBooleanKey(KEY_UNREAD_COUNT, true)
val drawerToggleKey = KBooleanKey(KEY_DRAWER_TOGGLE, false)
val fabVisibleKey = KBooleanKey(KEY_FAB_VISIBLE, true)
object refreshIntervalKey : KSimpleKey<Long>(KEY_REFRESH_INTERVAL, 15) {
override fun read(preferences: SharedPreferences): Long {

View File

@ -68,6 +68,7 @@ import org.mariotaku.twidere.util.CustomTabUtils
import org.mariotaku.twidere.util.DataStoreUtils
import org.mariotaku.twidere.util.ThemeUtils
import org.mariotaku.twidere.view.holder.TwoLineWithIconViewHolder
import java.lang.ref.WeakReference
class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, MultiChoiceModeListener {
@ -149,7 +150,12 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
val icon = conf.icon.createDrawable(context)
icon.mutate().setColorFilter(theme.textColorPrimary, Mode.SRC_ATOP)
subItem.icon = icon
val weakFragment = WeakReference(this)
subItem.setOnMenuItemClickListener { item ->
val fragment = weakFragment.get() ?: return@setOnMenuItemClickListener false
val adapter = fragment.adapter
val fm = fragment.childFragmentManager
val df = TabEditorDialogFragment()
df.arguments = Bundle {
this[EXTRA_TAB_TYPE] = type
@ -157,7 +163,7 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
this[EXTRA_TAB_POSITION] = adapter.getTab(adapter.count - 1).position + 1
}
}
df.show(fragmentManager, TabEditorDialogFragment.TAG_ADD_TAB)
df.show(fm, TabEditorDialogFragment.TAG_ADD_TAB)
return@setOnMenuItemClickListener true
}
}

View File

@ -29,7 +29,11 @@ import org.mariotaku.twidere.model.UserKey
/**
* Created by mariotaku on 15/1/23.
*/
open class StatusLinkClickHandler(context: Context, manager: MultiSelectManager, preferences: SharedPreferencesWrapper) : OnLinkClickHandler(context, manager, preferences), Constants {
open class StatusLinkClickHandler(
context: Context,
manager: MultiSelectManager,
preferences: SharedPreferencesWrapper
) : OnLinkClickHandler(context, manager, preferences), Constants {
var status: ParcelableStatus? = null

View File

@ -19,6 +19,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
@ -27,7 +28,8 @@
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:tag="tint_background|accent_color">
android:tag="tint_background|accent_color"
app:backgroundTint="?colorControlActivated">
<View
android:id="@+id/drag_handle"

View File

@ -29,6 +29,7 @@
android:orientation="vertical"
android:padding="@dimen/element_spacing_normal"
android:tag="tint_background|accent_color"
app:backgroundTint="?colorControlActivated"
app:ignorePadding="true"
tools:context=".adapter.DraftsAdapter">

View File

@ -26,6 +26,5 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="text_color|accent_color"
android:textColor="?colorAccent"
android:maxLines="1"/>
android:maxLines="1"
android:textColor="?colorAccent"/>

View File

@ -26,9 +26,9 @@
android:gravity="center_vertical"
android:minHeight="?listPreferredItemHeightSmall"
android:orientation="horizontal"
android:tag="tint_background|accent_color">
app:backgroundTint="?colorControlActivated">
<org.mariotaku.twidere.view.IconActionView
<org.mariotaku.twidere.view.PreferencesItemIconView
android:id="@android:id/icon"
android:layout_width="@dimen/header_icon_width"
android:layout_height="@dimen/header_icon_width"

View File

@ -17,14 +17,16 @@
<TextView
android:id="@android:id/text1"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator"
android:background="?android:activatedBackgroundIndicator"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:minHeight="?android:listPreferredItemHeightSmall"
android:paddingEnd="?android:listPreferredItemPaddingEnd"
android:paddingLeft="?android:listPreferredItemPaddingLeft"
android:paddingRight="?android:listPreferredItemPaddingRight"
android:paddingStart="?android:listPreferredItemPaddingStart"
android:tag="tint_background|accent_color"
android:textAppearance="?android:attr/textAppearanceListItemSmall"/>
android:textAppearance="?android:textAppearanceListItemSmall"
app:backgroundTint="?colorControlActivated"/>

View File

@ -16,23 +16,25 @@
<TwoLineListItem
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeight"
android:background="?android:activatedBackgroundIndicator"
android:minHeight="?android:listPreferredItemHeight"
android:mode="twoLine"
android:paddingBottom="2dip"
android:paddingTop="2dip"
android:tag="tint_background|accent_color">
android:tag="tint_background|accent_color"
app:backgroundTint="?colorControlActivated">
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="?android:attr/listPreferredItemPaddingLeft"
android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
android:layout_marginLeft="?android:listPreferredItemPaddingLeft"
android:layout_marginStart="?android:listPreferredItemPaddingStart"
android:layout_marginTop="6dip"
android:textAppearance="?android:attr/textAppearanceListItem"/>
android:textAppearance="?android:textAppearanceListItem"/>
<TextView
android:id="@android:id/text2"
@ -41,7 +43,7 @@
android:layout_alignLeft="@android:id/text1"
android:layout_alignStart="@android:id/text1"
android:layout_below="@android:id/text1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="?android:textColorSecondary"/>
</TwoLineListItem>