Fix edit text handle colors
This commit is contained in:
parent
1145405832
commit
b7ed2488f2
9 changed files with 72 additions and 115 deletions
File diff suppressed because one or more lines are too long
|
@ -18,6 +18,7 @@ import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||||
import code.name.monkey.appthemehelper.util.TintHelper
|
import code.name.monkey.appthemehelper.util.TintHelper
|
||||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
|
import code.name.monkey.retromusic.extensions.appHandleColor
|
||||||
import code.name.monkey.retromusic.glide.GlideApp
|
import code.name.monkey.retromusic.glide.GlideApp
|
||||||
import code.name.monkey.retromusic.glide.RetroSimpleTarget
|
import code.name.monkey.retromusic.glide.RetroSimpleTarget
|
||||||
import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper
|
import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper
|
||||||
|
@ -95,10 +96,10 @@ class AlbumTagEditorActivity : AbsTagEditorActivity(), TextWatcher {
|
||||||
MaterialUtil.setTint(albumTitleContainer, false)
|
MaterialUtil.setTint(albumTitleContainer, false)
|
||||||
MaterialUtil.setTint(albumArtistContainer, false)
|
MaterialUtil.setTint(albumArtistContainer, false)
|
||||||
|
|
||||||
albumText.addTextChangedListener(this)
|
albumText.appHandleColor().addTextChangedListener(this)
|
||||||
albumArtistText.addTextChangedListener(this)
|
albumArtistText.appHandleColor().addTextChangedListener(this)
|
||||||
genreTitle.addTextChangedListener(this)
|
genreTitle.appHandleColor().addTextChangedListener(this)
|
||||||
yearTitle.addTextChangedListener(this)
|
yearTitle.appHandleColor().addTextChangedListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fillViewsWithFileTags() {
|
private fun fillViewsWithFileTags() {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||||
import code.name.monkey.appthemehelper.util.TintHelper
|
import code.name.monkey.appthemehelper.util.TintHelper
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
|
import code.name.monkey.retromusic.extensions.appHandleColor
|
||||||
import code.name.monkey.retromusic.loaders.SongLoader
|
import code.name.monkey.retromusic.loaders.SongLoader
|
||||||
import kotlinx.android.synthetic.main.activity_song_tag_editor.*
|
import kotlinx.android.synthetic.main.activity_song_tag_editor.*
|
||||||
import org.jaudiotagger.tag.FieldKey
|
import org.jaudiotagger.tag.FieldKey
|
||||||
|
@ -44,6 +45,7 @@ class SongTagEditorActivity : AbsTagEditorActivity(), TextWatcher {
|
||||||
private fun setUpViews() {
|
private fun setUpViews() {
|
||||||
fillViewsWithFileTags()
|
fillViewsWithFileTags()
|
||||||
MaterialUtil.setTint(songTextContainer, false)
|
MaterialUtil.setTint(songTextContainer, false)
|
||||||
|
|
||||||
MaterialUtil.setTint(composerContainer, false)
|
MaterialUtil.setTint(composerContainer, false)
|
||||||
MaterialUtil.setTint(albumTextContainer, false)
|
MaterialUtil.setTint(albumTextContainer, false)
|
||||||
MaterialUtil.setTint(artistContainer, false)
|
MaterialUtil.setTint(artistContainer, false)
|
||||||
|
@ -53,15 +55,14 @@ class SongTagEditorActivity : AbsTagEditorActivity(), TextWatcher {
|
||||||
MaterialUtil.setTint(trackNumberContainer, false)
|
MaterialUtil.setTint(trackNumberContainer, false)
|
||||||
MaterialUtil.setTint(lyricsContainer, false)
|
MaterialUtil.setTint(lyricsContainer, false)
|
||||||
|
|
||||||
albumText.addTextChangedListener(this)
|
songText.appHandleColor().addTextChangedListener(this)
|
||||||
songText.addTextChangedListener(this)
|
albumText.appHandleColor().addTextChangedListener(this)
|
||||||
albumText.addTextChangedListener(this)
|
artistText.appHandleColor().addTextChangedListener(this)
|
||||||
artistText.addTextChangedListener(this)
|
genreText.appHandleColor().addTextChangedListener(this)
|
||||||
genreText.addTextChangedListener(this)
|
yearText.appHandleColor().addTextChangedListener(this)
|
||||||
yearText.addTextChangedListener(this)
|
trackNumberText.appHandleColor().addTextChangedListener(this)
|
||||||
trackNumberText.addTextChangedListener(this)
|
lyricsText.appHandleColor().addTextChangedListener(this)
|
||||||
lyricsText.addTextChangedListener(this)
|
songComposerText.appHandleColor().addTextChangedListener(this)
|
||||||
songComposerText.addTextChangedListener(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fillViewsWithFileTags() {
|
private fun fillViewsWithFileTags() {
|
||||||
|
@ -132,3 +133,5 @@ class SongTagEditorActivity : AbsTagEditorActivity(), TextWatcher {
|
||||||
val TAG: String = SongTagEditorActivity::class.java.simpleName
|
val TAG: String = SongTagEditorActivity::class.java.simpleName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.R.layout
|
import code.name.monkey.retromusic.R.layout
|
||||||
import code.name.monkey.retromusic.R.string
|
import code.name.monkey.retromusic.R.string
|
||||||
|
import code.name.monkey.retromusic.extensions.appHandleColor
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.util.PlaylistsUtil
|
import code.name.monkey.retromusic.util.PlaylistsUtil
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
|
@ -70,7 +71,7 @@ class CreatePlaylistDialog : DialogFragment() {
|
||||||
MaterialUtil.setTint(actionNewPlaylistContainer, false)
|
MaterialUtil.setTint(actionNewPlaylistContainer, false)
|
||||||
|
|
||||||
val playlistId = arguments!!.getLong(MediaStore.Audio.Playlists.Members.PLAYLIST_ID)
|
val playlistId = arguments!!.getLong(MediaStore.Audio.Playlists.Members.PLAYLIST_ID)
|
||||||
playlistView.setText(PlaylistsUtil.getNameForPlaylist(context!!, playlistId), TextView.BufferType.EDITABLE)
|
playlistView.appHandleColor().setText(PlaylistsUtil.getNameForPlaylist(context!!, playlistId), TextView.BufferType.EDITABLE)
|
||||||
return materialDialog
|
return materialDialog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.R.layout
|
import code.name.monkey.retromusic.R.layout
|
||||||
import code.name.monkey.retromusic.R.string
|
import code.name.monkey.retromusic.R.string
|
||||||
|
import code.name.monkey.retromusic.extensions.appHandleColor
|
||||||
import code.name.monkey.retromusic.util.PlaylistsUtil
|
import code.name.monkey.retromusic.util.PlaylistsUtil
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import com.afollestad.materialdialogs.WhichButton
|
import com.afollestad.materialdialogs.WhichButton
|
||||||
|
@ -36,46 +37,6 @@ import com.google.android.material.textfield.TextInputLayout
|
||||||
|
|
||||||
|
|
||||||
class RenamePlaylistDialog : DialogFragment() {
|
class RenamePlaylistDialog : DialogFragment() {
|
||||||
|
|
||||||
/*override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
|
||||||
return inflater.inflate(R.layout.dialog_playlist, container, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
|
|
||||||
|
|
||||||
MaterialUtil.setTint(actionNewPlaylistContainer, false)
|
|
||||||
val accentColor = ThemeStore.accentColor(context!!)
|
|
||||||
actionNewPlaylist.setHintTextColor(ColorStateList.valueOf(accentColor))
|
|
||||||
actionNewPlaylist.setTextColor(ThemeStore.textColorPrimary(context!!))
|
|
||||||
|
|
||||||
actionNewPlaylist.apply {
|
|
||||||
var playlistId: Long = 0
|
|
||||||
if (arguments != null) {
|
|
||||||
playlistId = arguments!!.getLong("playlist_id")
|
|
||||||
}
|
|
||||||
setText(PlaylistsUtil.getNameForPlaylist(activity!!, playlistId))
|
|
||||||
}
|
|
||||||
|
|
||||||
actionCancel.apply {
|
|
||||||
MaterialUtil.setTint(this, false)
|
|
||||||
setOnClickListener { dismiss() }
|
|
||||||
icon = ContextCompat.getDrawable(context, R.drawable.ic_close_white_24dp)
|
|
||||||
}
|
|
||||||
|
|
||||||
actionCreate.apply {
|
|
||||||
setText(R.string.action_rename)
|
|
||||||
setOnClickListener {
|
|
||||||
if (actionNewPlaylist.toString().trim { it <= ' ' } != "") {
|
|
||||||
val playlistId = arguments!!.getLong("playlist_id")
|
|
||||||
PlaylistsUtil.renamePlaylist(context!!, playlistId, actionNewPlaylist.text!!.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MaterialUtil.setTint(this)
|
|
||||||
icon = ContextCompat.getDrawable(context, R.drawable.ic_edit_white_24dp)
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
private lateinit var playlistView: TextInputEditText
|
private lateinit var playlistView: TextInputEditText
|
||||||
private lateinit var actionNewPlaylistContainer: TextInputLayout
|
private lateinit var actionNewPlaylistContainer: TextInputLayout
|
||||||
|
|
||||||
|
@ -101,7 +62,7 @@ class RenamePlaylistDialog : DialogFragment() {
|
||||||
MaterialUtil.setTint(actionNewPlaylistContainer, false)
|
MaterialUtil.setTint(actionNewPlaylistContainer, false)
|
||||||
|
|
||||||
val playlistId = arguments!!.getLong(PLAYLIST_ID)
|
val playlistId = arguments!!.getLong(PLAYLIST_ID)
|
||||||
playlistView.setText(PlaylistsUtil.getNameForPlaylist(context!!, playlistId), TextView.BufferType.EDITABLE)
|
playlistView.appHandleColor().setText(PlaylistsUtil.getNameForPlaylist(context!!, playlistId), TextView.BufferType.EDITABLE)
|
||||||
return materialDialog
|
return materialDialog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,10 @@ package code.name.monkey.retromusic.extensions
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.EditText
|
||||||
import androidx.annotation.LayoutRes
|
import androidx.annotation.LayoutRes
|
||||||
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
|
import code.name.monkey.appthemehelper.util.TintHelper
|
||||||
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
@ -33,4 +36,9 @@ fun View.hide() {
|
||||||
visibility = View.GONE
|
visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
fun View.showOrHide(show: Boolean) = if (show) show() else hide()
|
fun View.showOrHide(show: Boolean) = if (show) show() else hide()
|
||||||
|
|
||||||
|
fun EditText.appHandleColor(): EditText {
|
||||||
|
TintHelper.colorHandles(this, ThemeStore.accentColor(context))
|
||||||
|
return this
|
||||||
|
}
|
|
@ -1,33 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Hemanth Savarala.
|
|
||||||
*
|
|
||||||
* Licensed under the GNU General Public License v3
|
|
||||||
*
|
|
||||||
* This 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 software 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package code.name.monkey.appthemehelper.common.views
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.AttributeSet
|
|
||||||
import code.name.monkey.appthemehelper.ATH
|
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
|
||||||
|
|
||||||
class ATEEditText @JvmOverloads constructor(
|
|
||||||
context: Context,
|
|
||||||
attrs: AttributeSet? = null,
|
|
||||||
defStyleAttr: Int = 0
|
|
||||||
) : TextInputEditText(context, attrs, defStyleAttr) {
|
|
||||||
|
|
||||||
init {
|
|
||||||
ATH.setTint(this, ThemeStore.accentColor(context))
|
|
||||||
setTextColor(ThemeStore.textColorPrimary(context))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -47,31 +47,6 @@ object MaterialUtil {
|
||||||
textInputLayout.defaultHintTextColor = colorState
|
textInputLayout.defaultHintTextColor = colorState
|
||||||
textInputLayout.isHintAnimationEnabled = true
|
textInputLayout.isHintAnimationEnabled = true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun setCursorPointerColor(view: EditText, @ColorInt color: Int) {
|
|
||||||
try {
|
|
||||||
//get the pointer resource id
|
|
||||||
var field = TextView::class.java.getDeclaredField("mTextSelectHandleRes")
|
|
||||||
field.isAccessible = true
|
|
||||||
val drawableResId = field.getInt(view)
|
|
||||||
|
|
||||||
//get the editor
|
|
||||||
field = TextView::class.java.getDeclaredField("mEditor")
|
|
||||||
field.isAccessible = true
|
|
||||||
val editor = field.get(view)
|
|
||||||
|
|
||||||
//tint drawable
|
|
||||||
val drawable = ContextCompat.getDrawable(view.context, drawableResId)!!
|
|
||||||
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN)
|
|
||||||
|
|
||||||
//set the drawable
|
|
||||||
field = editor.javaClass.getDeclaredField("mSelectHandleCenter")
|
|
||||||
field.isAccessible = true
|
|
||||||
field.set(editor, drawable)
|
|
||||||
|
|
||||||
} catch (ex: Exception) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,4 +407,45 @@ public final class TintHelper {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@SuppressWarnings("JavaReflectionMemberAccess")
|
||||||
|
public static void colorHandles(@NonNull TextView view, int color) {
|
||||||
|
try {
|
||||||
|
Field editorField = TextView.class.getDeclaredField("mEditor");
|
||||||
|
if (!editorField.isAccessible()) {
|
||||||
|
editorField.setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object editor = editorField.get(view);
|
||||||
|
Class<?> editorClass = editor.getClass();
|
||||||
|
|
||||||
|
String[] handleNames = {"mSelectHandleLeft", "mSelectHandleRight", "mSelectHandleCenter"};
|
||||||
|
String[] resNames = {"mTextSelectHandleLeftRes", "mTextSelectHandleRightRes", "mTextSelectHandleRes"};
|
||||||
|
|
||||||
|
for (int i = 0; i < handleNames.length; i++) {
|
||||||
|
Field handleField = editorClass.getDeclaredField(handleNames[i]);
|
||||||
|
if (!handleField.isAccessible()) {
|
||||||
|
handleField.setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Drawable handleDrawable = (Drawable) handleField.get(editor);
|
||||||
|
|
||||||
|
if (handleDrawable == null) {
|
||||||
|
Field resField = TextView.class.getDeclaredField(resNames[i]);
|
||||||
|
if (!resField.isAccessible()) {
|
||||||
|
resField.setAccessible(true);
|
||||||
|
}
|
||||||
|
int resId = resField.getInt(view);
|
||||||
|
handleDrawable = view.getResources().getDrawable(resId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handleDrawable != null) {
|
||||||
|
Drawable drawable = handleDrawable.mutate();
|
||||||
|
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||||
|
handleField.set(editor, drawable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue