improved button highlight

This commit is contained in:
Mariotaku Lee 2017-02-14 00:44:56 +08:00
parent ec38659a41
commit 645e57cd2c
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
15 changed files with 96 additions and 103 deletions

View File

@ -1,36 +0,0 @@
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

@ -1,35 +0,0 @@
package org.mariotaku.twidere.view;
import android.content.Context;
import android.content.res.ColorStateList;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import org.jetbrains.annotations.NotNull;
import org.mariotaku.chameleon.Chameleon;
import org.mariotaku.chameleon.ChameleonUtils;
/**
* Created by mariotaku on 2016/12/23.
*/
public class PreferencesItemTextView extends FixedTextView {
private static final int[] ACTIVATED_STATE_SET = {android.R.attr.state_activated};
private static final int[] EMPTY_STATE_SET = {0};
public PreferencesItemTextView(@NotNull final Context context, @Nullable final AttributeSet attrs) {
super(context, attrs);
}
@Nullable
@Override
public Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) {
Appearance appearance = new Appearance();
final int activatedColor = ChameleonUtils.getColorDependent(theme.getColorControlActivated());
final int defaultColor = theme.getTextColorPrimary();
appearance.setTextColor(new ColorStateList(new int[][]{ACTIVATED_STATE_SET, EMPTY_STATE_SET}, new int[]{activatedColor, defaultColor}));
return appearance;
}
}

View File

@ -1,6 +1,7 @@
package org.mariotaku.twidere.extension
import android.content.DialogInterface.*
import android.content.res.ColorStateList
import android.support.v7.app.AlertDialog
import org.mariotaku.chameleon.Chameleon
import org.mariotaku.chameleon.ChameleonUtils
@ -11,8 +12,10 @@ import org.mariotaku.chameleon.ChameleonUtils
fun AlertDialog.applyTheme(): AlertDialog {
val theme = Chameleon.getOverrideTheme(context, ChameleonUtils.getActivity(context))
getButton(BUTTON_POSITIVE)?.setTextColor(theme.colorAccent)
getButton(BUTTON_NEGATIVE)?.setTextColor(theme.colorAccent)
getButton(BUTTON_NEUTRAL)?.setTextColor(theme.colorAccent)
val buttonColor = ColorStateList(arrayOf(intArrayOf(-android.R.attr.state_enabled), intArrayOf(0)),
intArrayOf(theme.textColorSecondary, theme.colorAccent))
getButton(BUTTON_POSITIVE)?.setTextColor(buttonColor)
getButton(BUTTON_NEGATIVE)?.setTextColor(buttonColor)
getButton(BUTTON_NEUTRAL)?.setTextColor(buttonColor)
return this
}

View File

@ -26,7 +26,6 @@ import android.content.Intent
import android.graphics.Rect
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.LoaderManager.LoaderCallbacks
import android.support.v4.content.Loader
import android.support.v7.widget.LinearLayoutManager
@ -236,7 +235,7 @@ abstract class AbsStatusesFragment : AbsContentListRecyclerViewFragment<Parcelab
}
override fun handleKeyboardShortcutRepeat(handler: KeyboardShortcutsHandler, keyCode: Int, repeatCount: Int,
event: KeyEvent, metaState: Int): Boolean {
event: KeyEvent, metaState: Int): Boolean {
return navigationHelper.handleKeyboardShortcutRepeat(handler, keyCode, repeatCount, event, metaState)
}
@ -376,7 +375,7 @@ abstract class AbsStatusesFragment : AbsContentListRecyclerViewFragment<Parcelab
override fun onItemActionClick(holder: RecyclerView.ViewHolder, id: Int, position: Int) {
val status = adapter.getStatus(position) ?: return
handleActionClick(context, fragmentManager, twitterWrapper, holder as StatusViewHolder, status, id)
handleActionClick(holder as StatusViewHolder, status, id)
}
override fun onItemActionLongClick(holder: RecyclerView.ViewHolder, id: Int, position: Int): Boolean {
@ -483,7 +482,7 @@ abstract class AbsStatusesFragment : AbsContentListRecyclerViewFragment<Parcelab
protected abstract fun hasMoreData(data: List<ParcelableStatus>?): Boolean
protected abstract fun onCreateStatusesLoader(context: Context, args: Bundle,
fromUser: Boolean): Loader<List<ParcelableStatus>?>
fromUser: Boolean): Loader<List<ParcelableStatus>?>
protected abstract fun onStatusesLoaded(loader: Loader<List<ParcelableStatus>?>, data: List<ParcelableStatus>?)
@ -548,24 +547,24 @@ abstract class AbsStatusesFragment : AbsContentListRecyclerViewFragment<Parcelab
const val REQUEST_FAVORITE_SELECT_ACCOUNT = 101
const val REQUEST_RETWEET_SELECT_ACCOUNT = 102
fun handleActionClick(context: Context, fm: FragmentManager, twitter: AsyncTwitterWrapper?,
holder: StatusViewHolder, status: ParcelableStatus, id: Int) {
fun BaseFragment.handleActionClick(holder: StatusViewHolder, status: ParcelableStatus, id: Int) {
when (id) {
R.id.reply -> {
val intent = Intent(INTENT_ACTION_REPLY)
intent.`package` = context.packageName
intent.putExtra(EXTRA_STATUS, status)
context.startActivity(intent)
startActivity(intent)
}
R.id.retweet -> {
RetweetQuoteDialogFragment.show(fm, status)
executeAfterFragmentResumed { fragment ->
RetweetQuoteDialogFragment.show(fragment.childFragmentManager, status)
}
}
R.id.favorite -> {
if (twitter == null) return
if (status.is_favorite) {
twitter.destroyFavoriteAsync(status.account_key, status.id)
twitterWrapper.destroyFavoriteAsync(status.account_key, status.id)
} else {
holder.playLikeAnimation(DefaultOnLikedListener(twitter, status))
holder.playLikeAnimation(DefaultOnLikedListener(twitterWrapper, status))
}
}
}

View File

@ -25,6 +25,7 @@ import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ITEMS
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NEW_DOCUMENT_API
import org.mariotaku.twidere.constant.displaySensitiveContentsKey
import org.mariotaku.twidere.constant.newDocumentApiKey
import org.mariotaku.twidere.fragment.AbsStatusesFragment.Companion.handleActionClick
import org.mariotaku.twidere.model.ParcelableMedia
import org.mariotaku.twidere.util.IntentUtils
import org.mariotaku.twidere.util.MenuUtils
@ -62,8 +63,7 @@ class ItemsListFragment : AbsContentListRecyclerViewFragment<VariousItemsAdapter
override fun onItemActionClick(holder: RecyclerView.ViewHolder, id: Int, position: Int) {
val status = dummyItemAdapter.getStatus(position) ?: return
AbsStatusesFragment.handleActionClick(context, fragmentManager,
twitterWrapper, holder as StatusViewHolder, status, id)
handleActionClick(holder as StatusViewHolder, status, id)
}
override fun onItemActionLongClick(holder: RecyclerView.ViewHolder, id: Int, position: Int): Boolean {

View File

@ -94,6 +94,7 @@ import org.mariotaku.twidere.extension.applyTheme
import org.mariotaku.twidere.extension.model.applyTo
import org.mariotaku.twidere.extension.model.getAccountType
import org.mariotaku.twidere.extension.model.media_type
import org.mariotaku.twidere.fragment.AbsStatusesFragment.Companion.handleActionClick
import org.mariotaku.twidere.loader.ConversationLoader
import org.mariotaku.twidere.loader.ParcelableStatusLoader
import org.mariotaku.twidere.menu.FavoriteItemProvider
@ -315,8 +316,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
override fun onItemActionClick(holder: ViewHolder, id: Int, position: Int) {
val status = adapter.getStatus(position) ?: return
AbsStatusesFragment.handleActionClick(context, fragmentManager, twitterWrapper,
holder as StatusViewHolder, status, id)
handleActionClick(holder as StatusViewHolder, status, id)
}

View File

@ -23,6 +23,7 @@ import android.text.Editable
import android.text.Spanned
import android.text.TextWatcher
import android.widget.TextView
import org.mariotaku.twidere.text.SafeSpannableStringBuilder
import org.mariotaku.twidere.util.EmojiSupportUtils
import org.mariotaku.twidere.util.ExternalThemeManager
@ -33,7 +34,7 @@ import javax.inject.Inject
/**
* Created by mariotaku on 15/12/20.
*/
class EmojiEditableFactory(textView: TextView) : SafeEditableFactory() {
class EmojiEditableFactory(textView: TextView) : Editable.Factory() {
@Inject
lateinit internal var externalThemeManager: ExternalThemeManager
@ -43,7 +44,7 @@ class EmojiEditableFactory(textView: TextView) : SafeEditableFactory() {
}
override fun newEditable(source: CharSequence): Editable {
val editable = super.newEditable(source)
val editable = SafeSpannableStringBuilder(source)
EmojiSupportUtils.applyEmoji(externalThemeManager, editable)
editable.setSpan(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
@ -52,8 +53,7 @@ class EmojiEditableFactory(textView: TextView) : SafeEditableFactory() {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (count <= 0) return
EmojiSupportUtils.applyEmoji(externalThemeManager, editable,
start, count)
EmojiSupportUtils.applyEmoji(externalThemeManager, editable, start, count)
}
override fun afterTextChanged(s: Editable) {

View File

@ -21,6 +21,7 @@ package org.mariotaku.twidere.text.util
import android.text.Spannable
import android.widget.TextView
import org.mariotaku.twidere.text.SafeSpannableString
import org.mariotaku.twidere.util.EmojiSupportUtils
import org.mariotaku.twidere.util.ExternalThemeManager
@ -31,7 +32,7 @@ import javax.inject.Inject
/**
* Created by mariotaku on 15/12/20.
*/
class EmojiSpannableFactory(textView: TextView) : SafeSpannableFactory() {
class EmojiSpannableFactory(textView: TextView) : Spannable.Factory() {
@Inject
lateinit internal var externalThemeManager: ExternalThemeManager
@ -41,7 +42,7 @@ class EmojiSpannableFactory(textView: TextView) : SafeSpannableFactory() {
}
override fun newSpannable(source: CharSequence): Spannable {
val spannable = super.newSpannable(source)
val spannable = SafeSpannableString(source)
EmojiSupportUtils.applyEmoji(externalThemeManager, spannable)
return spannable
}

View File

@ -26,7 +26,7 @@ import org.mariotaku.twidere.text.SafeSpannableStringBuilder
/**
* Created by mariotaku on 15/12/20.
*/
open class SafeEditableFactory : Editable.Factory() {
object SafeEditableFactory : Editable.Factory() {
override fun newEditable(source: CharSequence): Editable {
return SafeSpannableStringBuilder(source)
}

View File

@ -26,7 +26,7 @@ import org.mariotaku.twidere.text.SafeSpannableString
/**
* Created by mariotaku on 15/12/20.
*/
open class SafeSpannableFactory : Spannable.Factory() {
object SafeSpannableFactory : Spannable.Factory() {
override fun newSpannable(source: CharSequence): Spannable {
return SafeSpannableString(source)
}

View File

@ -3,6 +3,8 @@ package org.mariotaku.twidere.view
import android.content.Context
import android.util.AttributeSet
import org.mariotaku.chameleon.view.ChameleonEditText
import org.mariotaku.twidere.text.util.SafeEditableFactory
import org.mariotaku.twidere.text.util.SafeSpannableFactory
/**
* Created by mariotaku on 2017/2/3.
@ -10,6 +12,11 @@ import org.mariotaku.chameleon.view.ChameleonEditText
class FixedEditText(context: Context, attrs: AttributeSet? = null) : ChameleonEditText(context, attrs) {
init {
setSpannableFactory(SafeSpannableFactory)
setEditableFactory(SafeEditableFactory)
}
override fun onTextContextMenuItem(id: Int): Boolean {
try {
return super.onTextContextMenuItem(id)

View File

@ -3,6 +3,8 @@ package org.mariotaku.twidere.view
import android.content.Context
import android.util.AttributeSet
import org.mariotaku.chameleon.view.ChameleonTextView
import org.mariotaku.twidere.text.util.SafeEditableFactory
import org.mariotaku.twidere.text.util.SafeSpannableFactory
/**
* Created by mariotaku on 2017/2/3.
@ -10,6 +12,11 @@ import org.mariotaku.chameleon.view.ChameleonTextView
open class FixedTextView(context: Context, attrs: AttributeSet? = null) : ChameleonTextView(context, attrs) {
init {
setSpannableFactory(SafeSpannableFactory)
setEditableFactory(SafeEditableFactory)
}
override fun onTextContextMenuItem(id: Int): Boolean {
try {
return super.onTextContextMenuItem(id)

View File

@ -22,7 +22,6 @@ package org.mariotaku.twidere.view
import android.content.Context
import android.content.res.Resources
import android.support.v4.text.BidiFormatter
import android.support.v7.widget.AppCompatTextView
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.TextUtils
@ -32,13 +31,12 @@ import android.text.style.StyleSpan
import android.util.AttributeSet
import android.util.TypedValue
import org.mariotaku.twidere.R
import org.mariotaku.twidere.text.util.SafeEditableFactory
import org.mariotaku.twidere.text.util.SafeSpannableFactory
import org.mariotaku.twidere.util.EmojiSupportUtils
/**
* Created by mariotaku on 15/5/28.
*/
class NameView(context: Context, attrs: AttributeSet? = null) : AppCompatTextView(context, attrs, 0) {
class NameView(context: Context, attrs: AttributeSet? = null) : FixedTextView(context, attrs) {
var nameFirst: Boolean = false
var twoLine: Boolean = false
@ -62,8 +60,7 @@ class NameView(context: Context, attrs: AttributeSet? = null) : AppCompatTextVie
private var secondaryTextSize: AbsoluteSizeSpan? = null
init {
setSpannableFactory(SafeSpannableFactory())
setEditableFactory(SafeEditableFactory())
EmojiSupportUtils.initForTextView(this)
ellipsize = TextUtils.TruncateAt.END
val a = context.obtainStyledAttributes(attrs, R.styleable.NameView, 0, 0)
setPrimaryTextColor(a.getColor(R.styleable.NameView_nv_primaryTextColor, 0))

View File

@ -0,0 +1,21 @@
package org.mariotaku.twidere.view
import android.content.Context
import android.util.AttributeSet
import org.mariotaku.chameleon.Chameleon
import org.mariotaku.chameleon.ChameleonUtils
import org.mariotaku.twidere.view.iface.IIconActionButton
/**
* Created by mariotaku on 2016/12/23.
*/
class PreferencesItemIconView(context: Context, attrs: AttributeSet? = null) : IconActionView(context, attrs) {
override fun createAppearance(context: Context, attributeSet: AttributeSet, theme: Chameleon.Theme): IIconActionButton.Appearance? {
val appearance = IIconActionButton.Appearance()
appearance.activatedColor = ChameleonUtils.getColorDependent(theme.colorControlActivated)
appearance.defaultColor = theme.colorForeground
return appearance
}
}

View File

@ -0,0 +1,29 @@
package org.mariotaku.twidere.view
import android.content.Context
import android.content.res.ColorStateList
import android.util.AttributeSet
import org.mariotaku.chameleon.Chameleon
import org.mariotaku.chameleon.ChameleonUtils
import org.mariotaku.chameleon.view.ChameleonTextView
/**
* Created by mariotaku on 2016/12/23.
*/
class PreferencesItemTextView(context: Context, attrs: AttributeSet? = null) : FixedTextView(context, attrs) {
override fun createAppearance(context: Context, attributeSet: AttributeSet, theme: Chameleon.Theme): ChameleonTextView.Appearance? {
val appearance = ChameleonTextView.Appearance()
val activatedColor = ChameleonUtils.getColorDependent(theme.colorControlActivated)
val defaultColor = theme.textColorPrimary
appearance.textColor = ColorStateList(arrayOf(ACTIVATED_STATE_SET, EMPTY_STATE_SET), intArrayOf(activatedColor, defaultColor))
return appearance
}
companion object {
private val ACTIVATED_STATE_SET = intArrayOf(android.R.attr.state_activated)
private val EMPTY_STATE_SET = intArrayOf(0)
}
}