improved theme

close #697
This commit is contained in:
Mariotaku Lee 2017-04-02 15:59:09 +08:00
parent 318fedf6db
commit 099d90c450
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
9 changed files with 39 additions and 13 deletions

View File

@ -7,6 +7,7 @@ import android.util.AttributeSet;
/**
* Created by mariotaku on 16/3/18.
*/
@SuppressWarnings("RestrictedApi")
public class TwidereActionMenuItemView extends ActionMenuItemView {
public TwidereActionMenuItemView(Context context) {

View File

@ -60,6 +60,7 @@ import org.mariotaku.twidere.preference.ThemeBackgroundPreference;
import org.mariotaku.twidere.util.menu.TwidereMenuInfo;
import org.mariotaku.twidere.util.support.ViewSupport;
@SuppressWarnings("RestrictedApi")
public class ThemeUtils implements Constants {
public static final int ACCENT_COLOR_THRESHOLD = 192;
@ -74,9 +75,8 @@ public class ThemeUtils implements Constants {
public static void applyColorFilterToMenuIcon(final Menu menu, @ColorInt final int color,
@ColorInt final int popupColor,
@ColorInt final int highlightColor, final Mode mode,
final int... excludedGroups) {
@ColorInt final int popupColor, @ColorInt final int highlightColor, final Mode mode,
final int... excludedGroups) {
for (int i = 0, j = menu.size(); i < j; i++) {
final MenuItem item = menu.getItem(i);
final Drawable icon = item.getIcon();
@ -558,7 +558,7 @@ public class ThemeUtils implements Constants {
@StyleRes
public static int getCurrentTheme(@NonNull final Context context, @StyleRes final int lightTheme,
@StyleRes final int darkTheme) {
@StyleRes final int darkTheme) {
if (TwilightManagerAccessor.INSTANCE.isNight(context)) return darkTheme;
return lightTheme;
}

View File

@ -276,7 +276,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
val imageExtensionsIntent = Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE)
val mediaMenuItem = menu.findItem(R.id.status_attachment)
if (mediaMenuItem != null && mediaMenuItem.hasSubMenu()) {
MenuUtils.addIntentToMenu(this, mediaMenuItem.subMenu, imageExtensionsIntent, MENU_GROUP_IMAGE_EXTENSION)
MenuUtils.addIntentToMenu(this, mediaMenuItem.subMenu, imageExtensionsIntent,
MENU_GROUP_IMAGE_EXTENSION)
}
updateViewStyle()
setMenu()
@ -1277,8 +1278,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
menu.setItemAvailability(R.id.add_gif, extraFeaturesService.isSupported(
ExtraFeaturesService.FEATURE_SHARE_GIF))
menu.setGroupEnabled(MENU_GROUP_IMAGE_EXTENSION, hasMedia)
menu.setGroupVisible(MENU_GROUP_IMAGE_EXTENSION, hasMedia)
menu.setGroupAvailability(MENU_GROUP_IMAGE_EXTENSION, hasMedia)
menu.setItemChecked(R.id.toggle_sensitive, hasMedia && possiblySensitive)
val attachLocation = kPreferences[attachLocationKey]
@ -1295,6 +1295,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
menu.setMenuItemIcon(R.id.location_submenu, R.drawable.ic_action_location)
}
ThemeUtils.wrapMenuIcon(menuBar, MENU_GROUP_IMAGE_EXTENSION)
ThemeUtils.resetCheatSheet(menuBar)
}

View File

@ -39,6 +39,7 @@ import android.view.ViewGroup
import android.widget.*
import android.widget.AdapterView.OnItemClickListener
import kotlinx.android.synthetic.main.activity_settings.*
import org.mariotaku.chameleon.Chameleon
import org.mariotaku.ktextension.Bundle
import org.mariotaku.ktextension.set
import org.mariotaku.twidere.R
@ -369,7 +370,11 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF
internal class HeaderEntry(private val title: String) : Entry() {
override fun bind(view: View) {
(view.findViewById(android.R.id.title) as TextView).text = title
val theme = Chameleon.getOverrideTheme(view.context, view.context)
val textView = view.findViewById(android.R.id.title) as TextView
textView.setTextColor(ThemeUtils.getOptimalAccentColor(theme.colorAccent,
theme.colorForeground))
textView.text = title
}
}

View File

@ -5,6 +5,7 @@ import android.content.res.ColorStateList
import android.support.v7.app.AlertDialog
import org.mariotaku.chameleon.Chameleon
import org.mariotaku.chameleon.ChameleonUtils
import org.mariotaku.twidere.util.ThemeUtils
/**
* Created by mariotaku on 2017/2/5.
@ -12,8 +13,9 @@ import org.mariotaku.chameleon.ChameleonUtils
fun AlertDialog.applyTheme(): AlertDialog {
val theme = Chameleon.getOverrideTheme(context, ChameleonUtils.getActivity(context))
val optimalAccent = ThemeUtils.getOptimalAccentColor(theme.colorAccent, theme.colorForeground)
val buttonColor = ColorStateList(arrayOf(intArrayOf(-android.R.attr.state_enabled), intArrayOf(0)),
intArrayOf(theme.textColorSecondary, theme.colorAccent))
intArrayOf(theme.textColorSecondary, optimalAccent))
getButton(BUTTON_POSITIVE)?.setTextColor(buttonColor)
getButton(BUTTON_NEGATIVE)?.setTextColor(buttonColor)
getButton(BUTTON_NEUTRAL)?.setTextColor(buttonColor)

View File

@ -7,16 +7,20 @@ import android.util.AttributeSet
import android.widget.TextView
import org.mariotaku.chameleon.Chameleon
import org.mariotaku.chameleon.ChameleonUtils
import org.mariotaku.twidere.util.ThemeUtils
/**
* Created by mariotaku on 2017/2/5.
*/
open class TintedPreferenceCategory(context: Context, attrs: AttributeSet? = null) : PreferenceCategory(context, attrs) {
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
val theme = Chameleon.getOverrideTheme(context, ChameleonUtils.getActivity(context))
val textView = holder.findViewById(android.R.id.title) as? TextView
textView?.setTextColor(theme.colorAccent)
textView?.setTextColor(ThemeUtils.getOptimalAccentColor(theme.colorAccent,
theme.colorForeground))
}
}

View File

@ -6,9 +6,8 @@
<item
android:id="@+id/status_attachment"
android:icon="@drawable/ic_action_add"
android:title="@string/action_add"
android:visible="true"
android:icon="@drawable/ic_action_attachment"
android:title="@string/action_status_attachment"
app:showAsAction="always"
tools:ignore="AlwaysShowAction">
<menu>

View File

@ -122,6 +122,7 @@
<!-- [verb] Used for skip some settings -->
<string name="action_skip">Skip</string>
<string name="action_start">Start</string>
<string name="action_status_attachment">Tweet attachment</string>
<string name="action_status_block_users">Block users…</string>
<string name="action_status_mute_users">Mute users…</string>
<string name="action_status_schedule">Tweet schedule</string>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 42 (36781) - http://www.bohemiancoding.com/sketch -->
<title>ic_action_attachment-mdpi</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Action-Icons" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="ic_action_attachment-mdpi">
<path d="M20.5,10 L20.5,21.5 C20.5,23.71 18.71,25.5 16.5,25.5 C14.29,25.5 12.5,23.71 12.5,21.5 L12.5,9 C12.5,7.62 13.62,6.5 15,6.5 C16.38,6.5 17.5,7.62 17.5,9 L17.5,19.5 C17.5,20.05 17.05,20.5 16.5,20.5 C15.95,20.5 15.5,20.05 15.5,19.5 L15.5,10 L14,10 L14,19.5 C14,20.88 15.12,22 16.5,22 C17.88,22 19,20.88 19,19.5 L19,9 C19,6.79 17.21,5 15,5 C12.79,5 11,6.79 11,9 L11,21.5 C11,24.54 13.46,27 16.5,27 C19.54,27 22,24.54 22,21.5 L22,10 L20.5,10 Z" id="Shape" fill="#FFFFFF" fill-rule="nonzero"></path>
<polygon id="Shape" points="4 4 28 4 28 28 4 28"></polygon>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB