Dialog corner and Filter song duration

This commit is contained in:
h4h13 2019-02-19 16:08:51 +05:30
parent a5a27e62aa
commit fc868e1c2e
75 changed files with 1409 additions and 1294 deletions

View file

@ -0,0 +1,189 @@
package code.name.monkey.appthemehelper
/**
* Designed and developed by Aidan Follestad (@afollestad)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.graphics.Color.parseColor
val PRIMARY_COLORS = intArrayOf(
parseColor("#F44336"), parseColor("#E91E63"), parseColor("#9C27B0"),
parseColor("#673AB7"), parseColor("#3F51B5"), parseColor("#2196F3"),
parseColor("#03A9F4"), parseColor("#00BCD4"), parseColor("#009688"),
parseColor("#4CAF50"), parseColor("#8BC34A"), parseColor("#CDDC39"),
parseColor("#FFEB3B"), parseColor("#FFC107"), parseColor("#FF9800"),
parseColor("#FF5722"), parseColor("#795548"), parseColor("#9E9E9E"),
parseColor("#607D8B")
)
val PRIMARY_COLORS_SUB = arrayOf(
intArrayOf(
parseColor("#FFEBEE"), parseColor("#FFCDD2"), parseColor("#EF9A9A"),
parseColor("#E57373"), parseColor("#EF5350"), parseColor("#F44336"),
parseColor("#E53935"), parseColor("#D32F2F"), parseColor("#C62828"),
parseColor("#B71C1C")
), intArrayOf(
parseColor("#FCE4EC"), parseColor("#F8BBD0"), parseColor("#F48FB1"),
parseColor("#F06292"), parseColor("#EC407A"), parseColor("#E91E63"),
parseColor("#D81B60"), parseColor("#C2185B"), parseColor("#AD1457"),
parseColor("#880E4F")
), intArrayOf(
parseColor("#F3E5F5"), parseColor("#E1BEE7"), parseColor("#CE93D8"),
parseColor("#BA68C8"), parseColor("#AB47BC"), parseColor("#9C27B0"),
parseColor("#8E24AA"), parseColor("#7B1FA2"), parseColor("#6A1B9A"),
parseColor("#4A148C")
), intArrayOf(
parseColor("#EDE7F6"), parseColor("#D1C4E9"), parseColor("#B39DDB"),
parseColor("#9575CD"), parseColor("#7E57C2"), parseColor("#673AB7"),
parseColor("#5E35B1"), parseColor("#512DA8"), parseColor("#4527A0"),
parseColor("#311B92")
), intArrayOf(
parseColor("#E8EAF6"), parseColor("#C5CAE9"), parseColor("#9FA8DA"),
parseColor("#7986CB"), parseColor("#5C6BC0"), parseColor("#3F51B5"),
parseColor("#3949AB"), parseColor("#303F9F"), parseColor("#283593"),
parseColor("#1A237E")
), intArrayOf(
parseColor("#E3F2FD"), parseColor("#BBDEFB"), parseColor("#90CAF9"),
parseColor("#64B5F6"), parseColor("#42A5F5"), parseColor("#2196F3"),
parseColor("#1E88E5"), parseColor("#1976D2"), parseColor("#1565C0"),
parseColor("#0D47A1")
), intArrayOf(
parseColor("#E1F5FE"), parseColor("#B3E5FC"), parseColor("#81D4FA"),
parseColor("#4FC3F7"), parseColor("#29B6F6"), parseColor("#03A9F4"),
parseColor("#039BE5"), parseColor("#0288D1"), parseColor("#0277BD"),
parseColor("#01579B")
), intArrayOf(
parseColor("#E0F7FA"), parseColor("#B2EBF2"), parseColor("#80DEEA"),
parseColor("#4DD0E1"), parseColor("#26C6DA"), parseColor("#00BCD4"),
parseColor("#00ACC1"), parseColor("#0097A7"), parseColor("#00838F"),
parseColor("#006064")
), intArrayOf(
parseColor("#E0F2F1"), parseColor("#B2DFDB"), parseColor("#80CBC4"),
parseColor("#4DB6AC"), parseColor("#26A69A"), parseColor("#009688"),
parseColor("#00897B"), parseColor("#00796B"), parseColor("#00695C"),
parseColor("#004D40")
), intArrayOf(
parseColor("#E8F5E9"), parseColor("#C8E6C9"), parseColor("#A5D6A7"),
parseColor("#81C784"), parseColor("#66BB6A"), parseColor("#4CAF50"),
parseColor("#43A047"), parseColor("#388E3C"), parseColor("#2E7D32"),
parseColor("#1B5E20")
), intArrayOf(
parseColor("#F1F8E9"), parseColor("#DCEDC8"), parseColor("#C5E1A5"),
parseColor("#AED581"), parseColor("#9CCC65"), parseColor("#8BC34A"),
parseColor("#7CB342"), parseColor("#689F38"), parseColor("#558B2F"),
parseColor("#33691E")
), intArrayOf(
parseColor("#F9FBE7"), parseColor("#F0F4C3"), parseColor("#E6EE9C"),
parseColor("#DCE775"), parseColor("#D4E157"), parseColor("#CDDC39"),
parseColor("#C0CA33"), parseColor("#AFB42B"), parseColor("#9E9D24"),
parseColor("#827717")
), intArrayOf(
parseColor("#FFFDE7"), parseColor("#FFF9C4"), parseColor("#FFF59D"),
parseColor("#FFF176"), parseColor("#FFEE58"), parseColor("#FFEB3B"),
parseColor("#FDD835"), parseColor("#FBC02D"), parseColor("#F9A825"),
parseColor("#F57F17")
), intArrayOf(
parseColor("#FFF8E1"), parseColor("#FFECB3"), parseColor("#FFE082"),
parseColor("#FFD54F"), parseColor("#FFCA28"), parseColor("#FFC107"),
parseColor("#FFB300"), parseColor("#FFA000"), parseColor("#FF8F00"),
parseColor("#FF6F00")
), intArrayOf(
parseColor("#FFF3E0"), parseColor("#FFE0B2"), parseColor("#FFCC80"),
parseColor("#FFB74D"), parseColor("#FFA726"), parseColor("#FF9800"),
parseColor("#FB8C00"), parseColor("#F57C00"), parseColor("#EF6C00"),
parseColor("#E65100")
), intArrayOf(
parseColor("#FBE9E7"), parseColor("#FFCCBC"), parseColor("#FFAB91"),
parseColor("#FF8A65"), parseColor("#FF7043"), parseColor("#FF5722"),
parseColor("#F4511E"), parseColor("#E64A19"), parseColor("#D84315"),
parseColor("#BF360C")
), intArrayOf(
parseColor("#EFEBE9"), parseColor("#D7CCC8"), parseColor("#BCAAA4"),
parseColor("#A1887F"), parseColor("#8D6E63"), parseColor("#795548"),
parseColor("#6D4C41"), parseColor("#5D4037"), parseColor("#4E342E"),
parseColor("#3E2723")
), intArrayOf(
parseColor("#FAFAFA"), parseColor("#F5F5F5"), parseColor("#EEEEEE"),
parseColor("#E0E0E0"), parseColor("#BDBDBD"), parseColor("#9E9E9E"),
parseColor("#757575"), parseColor("#616161"), parseColor("#424242"),
parseColor("#212121")
), intArrayOf(
parseColor("#ECEFF1"), parseColor("#CFD8DC"), parseColor("#B0BEC5"),
parseColor("#90A4AE"), parseColor("#78909C"), parseColor("#607D8B"),
parseColor("#546E7A"), parseColor("#455A64"), parseColor("#37474F"),
parseColor("#263238")
)
)
val ACCENT_COLORS = intArrayOf(
parseColor("#FF1744"), parseColor("#F50057"), parseColor("#D500F9"),
parseColor("#651FFF"), parseColor("#3D5AFE"), parseColor("#2979FF"),
parseColor("#00B0FF"), parseColor("#00E5FF"), parseColor("#1DE9B6"),
parseColor("#00E676"), parseColor("#76FF03"), parseColor("#C6FF00"),
parseColor("#FFEA00"), parseColor("#FFC400"), parseColor("#FF9100"),
parseColor("#FF3D00")
)
val ACCENT_COLORS_SUB = arrayOf(
intArrayOf(
parseColor("#FF8A80"), parseColor("#FF5252"), parseColor("#FF1744"),
parseColor("#D50000")
), intArrayOf(
parseColor("#FF80AB"), parseColor("#FF4081"), parseColor("#F50057"),
parseColor("#C51162")
), intArrayOf(
parseColor("#EA80FC"), parseColor("#E040FB"), parseColor("#D500F9"),
parseColor("#AA00FF")
), intArrayOf(
parseColor("#B388FF"), parseColor("#7C4DFF"), parseColor("#651FFF"),
parseColor("#6200EA")
), intArrayOf(
parseColor("#8C9EFF"), parseColor("#536DFE"), parseColor("#3D5AFE"),
parseColor("#304FFE")
), intArrayOf(
parseColor("#82B1FF"), parseColor("#448AFF"), parseColor("#2979FF"),
parseColor("#2962FF")
), intArrayOf(
parseColor("#80D8FF"), parseColor("#40C4FF"), parseColor("#00B0FF"),
parseColor("#0091EA")
), intArrayOf(
parseColor("#84FFFF"), parseColor("#18FFFF"), parseColor("#00E5FF"),
parseColor("#00B8D4")
), intArrayOf(
parseColor("#A7FFEB"), parseColor("#64FFDA"), parseColor("#1DE9B6"),
parseColor("#00BFA5")
), intArrayOf(
parseColor("#B9F6CA"), parseColor("#69F0AE"), parseColor("#00E676"),
parseColor("#00C853")
), intArrayOf(
parseColor("#CCFF90"), parseColor("#B2FF59"), parseColor("#76FF03"),
parseColor("#64DD17")
), intArrayOf(
parseColor("#F4FF81"), parseColor("#EEFF41"), parseColor("#C6FF00"),
parseColor("#AEEA00")
), intArrayOf(
parseColor("#FFFF8D"), parseColor("#FFFF00"), parseColor("#FFEA00"),
parseColor("#FFD600")
), intArrayOf(
parseColor("#FFE57F"), parseColor("#FFD740"), parseColor("#FFC400"),
parseColor("#FFAB00")
), intArrayOf(
parseColor("#FFD180"), parseColor("#FFAB40"), parseColor("#FF9100"),
parseColor("#FF6D00")
), intArrayOf(
parseColor("#FF9E80"), parseColor("#FF6E40"), parseColor("#FF3D00"),
parseColor("#DD2C00")
)
)

View file

@ -1,35 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs
import android.content.Context
import android.util.AttributeSet
import code.name.monkey.appthemehelper.R
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.prefs.MaterialDialogPreference
/**
* @author Aidan Follestad (afollestad)
*/
class ATEDialogPreference : MaterialDialogPreference {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
init()
}
private fun init() {
layoutResource = R.layout.ate_preference_custom
}
}

View file

@ -2,13 +2,13 @@ package code.name.monkey.appthemehelper.common.prefs
import android.content.Context
import android.util.AttributeSet
import androidx.preference.EditTextPreference
import com.afollestad.materialdialogs.prefs.MaterialEditTextPreference
/**
* @author Aidan Follestad (afollestad)
*/
class ATEEditTextPreference : MaterialEditTextPreference {
class ATEEditTextPreference : EditTextPreference {
constructor(context: Context) : super(context) {
init()

View file

@ -2,14 +2,13 @@ package code.name.monkey.appthemehelper.common.prefs
import android.content.Context
import android.util.AttributeSet
import com.afollestad.materialdialogs.prefs.MaterialListPreference
import android.preference.ListPreference
import code.name.monkey.appthemehelper.R
/**
* @author Aidan Follestad (afollestad)
*/
class ATEListPreference : MaterialListPreference {
class ATEListPreference : ListPreference {
constructor(context: Context) : super(context) {
init()
@ -31,5 +30,7 @@ class ATEListPreference : MaterialListPreference {
layoutResource = R.layout.ate_preference_custom
if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty())
summary = "%s"
}
}

View file

@ -1,14 +1,14 @@
package code.name.monkey.appthemehelper.common.prefs
import android.content.Context
import android.preference.ListPreference
import android.util.AttributeSet
import code.name.monkey.appthemehelper.R
import com.afollestad.materialdialogs.prefs.MaterialListPreference
/**
* @author Aidan Follestad (afollestad)
*/
class ATEMultiSelectPreference : MaterialListPreference {
class ATEMultiSelectPreference : ListPreference {
constructor(context: Context) : super(context) {
init()

View file

@ -5,11 +5,11 @@ import android.content.Context
import android.os.Build
import android.preference.Preference
import android.preference.SwitchPreference
import androidx.appcompat.widget.SwitchCompat
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.widget.Switch
import androidx.appcompat.widget.SwitchCompat
import code.name.monkey.appthemehelper.ATH
import code.name.monkey.appthemehelper.R

View file

@ -1,34 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7
import android.content.Context
import android.util.AttributeSet
import androidx.preference.CheckBoxPreference
import code.name.monkey.appthemehelper.R
/**
* @author Aidan Follestad (afollestad)
*/
class ATECheckBoxPreference : CheckBoxPreference {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
init()
}
private fun init() {
layoutResource = R.layout.ate_preference_custom_support
widgetLayoutResource = R.layout.ate_preference_checkbox
}
}

View file

@ -1,9 +1,8 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7
import android.content.Context
import androidx.preference.ListPreference
import android.util.AttributeSet
import androidx.preference.ListPreference
import code.name.monkey.appthemehelper.R
/**

View file

@ -1,52 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7
import android.annotation.SuppressLint
import androidx.fragment.app.DialogFragment
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEEditTextPreferenceDialogFragmentCompat
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEListPreferenceDialogFragmentCompat
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEPreferenceDialogFragment
/**
* @author Karim Abou Zeid (kabouzeid)
*/
@SuppressLint("RestrictedApi")
abstract class ATEPreferenceFragmentCompat : PreferenceFragmentCompat() {
override fun onDisplayPreferenceDialog(preference: Preference) {
if (this.callbackFragment is PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) {
(this.callbackFragment as PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
return
}
if (this.activity is PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) {
(this.activity as PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
return
}
if (this.fragmentManager!!.findFragmentByTag("android.support.v7.preference.PreferenceFragment.DIALOG") == null) {
val dialogFragment = onCreatePreferenceDialog(preference)
if (dialogFragment != null) {
dialogFragment.setTargetFragment(this, 0)
dialogFragment.show(this.fragmentManager!!, "android.support.v7.preference.PreferenceFragment.DIALOG")
return
}
}
super.onDisplayPreferenceDialog(preference)
}
open fun onCreatePreferenceDialog(preference: Preference): DialogFragment? {
if (preference is ATEEditTextPreference) {
return ATEEditTextPreferenceDialogFragmentCompat.newInstance(preference.getKey())
} else if (preference is ATEListPreference) {
return ATEListPreferenceDialogFragmentCompat.newInstance(preference.getKey())
} else if (preference is ATEDialogPreference) {
return ATEPreferenceDialogFragment.newInstance(preference.getKey())
}
return null
}
}

View file

@ -1,50 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs
import android.os.Bundle
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEEditTextPreference
import com.afollestad.materialdialogs.MaterialDialog
/**
* @author Karim Abou Zeid (kabouzeid)
*/
class ATEEditTextPreferenceDialogFragmentCompat : ATEPreferenceDialogFragment(), MaterialDialog.InputCallback {
private var input: CharSequence? = null
private val editTextPreference: ATEEditTextPreference
get() = preference as ATEEditTextPreference
override fun onPrepareDialogBuilder(builder: MaterialDialog.Builder) {
super.onPrepareDialogBuilder(builder)
builder.input("", editTextPreference.text, this)
}
override fun needInputMethod(): Boolean {
return true
}
override fun onDialogClosed(positiveResult: Boolean) {
if (positiveResult) {
val value = input!!.toString()
if (this.editTextPreference.callChangeListener(value)) {
this.editTextPreference.text = value
}
}
}
override fun onInput(dialog: MaterialDialog, input: CharSequence) {
this.input = input
}
companion object {
fun newInstance(key: String): ATEEditTextPreferenceDialogFragmentCompat {
val fragment = ATEEditTextPreferenceDialogFragmentCompat()
val b = Bundle(1)
b.putString(ATEPreferenceDialogFragment.ARG_KEY, key)
fragment.arguments = b
return fragment
}
}
}

View file

@ -1,73 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs
import android.os.Bundle
import androidx.preference.ListPreference
import android.view.View
import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
/**
* @author Karim Abou Zeid (kabouzeid)
*/
class ATEListPreferenceDialogFragmentCompat : ATEPreferenceDialogFragment(), MaterialDialog.ListCallbackSingleChoice {
private var mClickedDialogEntryIndex: Int = 0
private val listPreference: ATEListPreference
get() = preference as ATEListPreference
override fun onPrepareDialogBuilder(builder: MaterialDialog.Builder) {
super.onPrepareDialogBuilder(builder)
val preference = listPreference
if (preference.entries == null || preference.entryValues == null) {
throw IllegalStateException(
"ListPreference requires an entries array and an entryValues array.")
}
mClickedDialogEntryIndex = preference.findIndexOfValue(preference.value)
builder.items(*preference.entries)
.alwaysCallSingleChoiceCallback()
.itemsCallbackSingleChoice(mClickedDialogEntryIndex, this)
/*
* The typical interaction for list-based dialogs is to have
* click-on-an-item dismiss the dialog instead of the user having to
* press 'Ok'.
*/
builder.positiveText("")
builder.negativeText("")
builder.neutralText("")
}
override fun onDialogClosed(positiveResult: Boolean) {
val preference = listPreference
if (positiveResult && mClickedDialogEntryIndex >= 0 &&
preference.entryValues != null) {
val value = preference.entryValues[mClickedDialogEntryIndex].toString()
if (preference.callChangeListener(value)) {
preference.value = value
}
}
}
override fun onSelection(dialog: MaterialDialog, itemView: View, which: Int, text: CharSequence): Boolean {
mClickedDialogEntryIndex = which
onClick(dialog, DialogAction.POSITIVE)
dismiss()
return true
}
companion object {
fun newInstance(key: String): ATEListPreferenceDialogFragmentCompat {
val fragment = ATEListPreferenceDialogFragmentCompat()
val b = Bundle(1)
b.putString(ATEPreferenceDialogFragment.ARG_KEY, key)
fragment.arguments = b
return fragment
}
}
}

View file

@ -1,85 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs
import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import androidx.preference.DialogPreference
import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog
/**
* @author Karim Abou Zeid (kabouzeid)
*/
open class ATEPreferenceDialogFragment : DialogFragment(), MaterialDialog.SingleButtonCallback {
private var mWhichButtonClicked: DialogAction? = null
var preference: DialogPreference? = null
private set
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val rawFragment = this.targetFragment
if (rawFragment !is DialogPreference.TargetFragment) {
throw IllegalStateException("Target fragment must implement TargetFragment interface")
} else {
val fragment = rawFragment as DialogPreference.TargetFragment?
val key = this.arguments!!.getString(ARG_KEY)
this.preference = fragment!!.findPreference(key) as DialogPreference
}
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val context = this.activity
val builder = MaterialDialog.Builder(context!!)
.title(this.preference!!.dialogTitle)
.icon(this.preference!!.dialogIcon)
.onAny(this)
.positiveText(this.preference!!.positiveButtonText)
.negativeText(this.preference!!.negativeButtonText)
builder.content(this.preference!!.dialogMessage)
this.onPrepareDialogBuilder(builder)
val dialog = builder.build()
if (this.needInputMethod()) {
this.requestInputMethod(dialog)
}
return dialog
}
protected open fun onPrepareDialogBuilder(builder: MaterialDialog.Builder) {}
protected open fun needInputMethod(): Boolean {
return false
}
private fun requestInputMethod(dialog: Dialog) {
val window = dialog.window
window!!.setSoftInputMode(5)
}
override fun onClick(dialog: MaterialDialog, which: DialogAction) {
mWhichButtonClicked = which
}
override fun onDismiss(dialog: DialogInterface?) {
super.onDismiss(dialog)
onDialogClosed(mWhichButtonClicked == DialogAction.POSITIVE)
}
open fun onDialogClosed(positiveResult: Boolean) {
}
companion object {
const val ARG_KEY = "key"
fun newInstance(key: String): ATEPreferenceDialogFragment {
val fragment = ATEPreferenceDialogFragment()
val b = Bundle(1)
b.putString(ARG_KEY, key)
fragment.arguments = b
return fragment
}
}
}

View file

@ -71,4 +71,67 @@ object ColorUtil {
val b = Color.blue(color1) * inverseRatio + Color.blue(color2) * ratio
return Color.argb(a.toInt(), r.toInt(), g.toInt(), b.toInt())
}
private fun getColorDarkness(@ColorInt color: Int): Double {
return if (color == Color.BLACK)
1.0
else if (color == Color.WHITE || color == Color.TRANSPARENT)
0.0
else
1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255
}
@ColorInt
fun getInverseColor(@ColorInt color: Int): Int {
return 0xFFFFFF - color or -0x1
}
fun isColorSaturated(@ColorInt color: Int): Boolean {
val max = Math.max(0.299 * Color.red(color), Math.max(0.587 * Color.green(color), 0.114 * Color.blue(color)))
val min = Math.min(0.299 * Color.red(color), Math.min(0.587 * Color.green(color), 0.114 * Color.blue(color)))
val diff = Math.abs(max - min)
return diff > 20
}
@ColorInt
fun getMixedColor(@ColorInt color1: Int, @ColorInt color2: Int): Int {
return Color.rgb(
(Color.red(color1) + Color.red(color2)) / 2,
(Color.green(color1) + Color.green(color2)) / 2,
(Color.blue(color1) + Color.blue(color2)) / 2
)
}
fun getDifference(@ColorInt color1: Int, @ColorInt color2: Int): Double {
var diff = Math.abs(0.299 * (Color.red(color1) - Color.red(color2)))
diff += Math.abs(0.587 * (Color.green(color1) - Color.green(color2)))
diff += Math.abs(0.114 * (Color.blue(color1) - Color.blue(color2)))
return diff
}
@ColorInt
fun getReadableText(@ColorInt textColor: Int, @ColorInt backgroundColor: Int): Int {
return getReadableText(textColor, backgroundColor, 100)
}
@ColorInt
fun getReadableText(@ColorInt textColor: Int, @ColorInt backgroundColor: Int, difference: Int): Int {
var textColor = textColor
val isLight = isColorLight(backgroundColor)
var i = 0
while (getDifference(textColor, backgroundColor) < difference && i < 100) {
textColor = getMixedColor(textColor, if (isLight) Color.BLACK else Color.WHITE)
i++
}
return textColor
}
@ColorInt
fun getContrastColor(@ColorInt color: Int): Int {
// Counting the perceptive luminance - human eye favors green color...
val a = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255
return if (a < 0.5) Color.BLACK else Color.WHITE
}
}

View file

@ -1,24 +0,0 @@
package code.name.monkey.appthemehelper.util
import android.content.Context
import android.content.res.ColorStateList
import com.afollestad.materialdialogs.internal.ThemeSingleton
import code.name.monkey.appthemehelper.ThemeStore
object MaterialDialogsUtil {
fun updateMaterialDialogsThemeSingleton(context: Context) {
val md = ThemeSingleton.get()
md.titleColor = ThemeStore.textColorPrimary(context)
md.contentColor = ThemeStore.textColorSecondary(context)
md.itemColor = md.titleColor
md.widgetColor = ThemeStore.accentColor(context)
md.linkColor = ColorStateList.valueOf(md.widgetColor)
md.positiveColor = ColorStateList.valueOf(md.widgetColor)
md.neutralColor = ColorStateList.valueOf(md.widgetColor)
md.negativeColor = ColorStateList.valueOf(md.widgetColor)
md.darkTheme = ATHUtil.isWindowBackgroundDark(context)
}
}

View file

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@android:id/title"
xmlns:android="http://schemas.android.com/apk/res/android"
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingStart="16dp"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
android:textColor="?android:textColorSecondary"
tools:ignore="RtlSymmetry" />

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<code.name.monkey.appthemehelper.common.views.ATECheckBox android:id="@android:id/checkbox"
xmlns:android="http://schemas.android.com/apk/res/android"
<code.name.monkey.appthemehelper.common.views.ATECheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:layout_margin="6dp"
android:background="@null"
android:clickable="false"
android:focusable="false" />

View file

@ -16,56 +16,56 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/ate_preference_inset"
android:layout_marginStart="@dimen/ate_preference_inset"
android:layout_marginLeft="@dimen/ate_preference_inset"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_marginBottom="12dip"
android:layout_marginEnd="6dip"
android:layout_marginLeft="@dimen/ate_preference_inset"
android:layout_marginRight="6dip"
android:layout_marginStart="@dimen/ate_preference_inset"
android:layout_marginLeft="@dimen/ate_preference_inset"
android:layout_marginTop="12dip"
android:layout_marginEnd="6dip"
android:layout_marginRight="6dip"
android:layout_marginBottom="12dip"
android:layout_weight="1">
<code.name.monkey.appthemehelper.common.views.ATEPrimaryTextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textSize="@dimen/ate_default_textsize_subheading"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
tools:text="Title" />
<code.name.monkey.appthemehelper.common.views.ATESecondaryTextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@android:id/title"
android:layout_alignStart="@android:id/title"
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title"
android:layout_alignLeft="@android:id/title"
android:layout_marginTop="2dp"
android:maxLines="4"
android:textSize="@dimen/ate_default_textsize_body"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
tools:text="Summary" />
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<code.name.monkey.appthemehelper.common.views.ATESwitch xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/switchWidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:button="@drawable/ate_switch"
android:clickable="false"
android:focusable="false"/>
android:id="@+id/switchWidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:button="@drawable/ate_switch"
android:clickable="false"
android:focusable="false" />
</LinearLayout><!-- From: file:/home/jitpack/build/commons/src/main/res/layout/md_preference_custom.xml -->

View file

@ -3,13 +3,13 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:baselineAligned="false"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:paddingEnd="?android:attr/scrollbarSize"
android:paddingRight="?android:attr/scrollbarSize"
android:background="?android:attr/selectableItemBackground"
tools:ignore="RtlSymmetry,UnusedAttribute">
<ImageView
@ -17,44 +17,44 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/ate_preference_inset"
android:layout_marginStart="@dimen/ate_preference_inset"
android:layout_marginLeft="@dimen/ate_preference_inset"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_marginBottom="12dip"
android:layout_marginEnd="6dip"
android:layout_marginLeft="@dimen/ate_preference_inset"
android:layout_marginRight="6dip"
android:layout_marginStart="@dimen/ate_preference_inset"
android:layout_marginLeft="@dimen/ate_preference_inset"
android:layout_marginTop="12dip"
android:layout_marginEnd="6dip"
android:layout_marginRight="6dip"
android:layout_marginBottom="12dip"
android:layout_weight="1">
<code.name.monkey.appthemehelper.common.views.ATEPrimaryTextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textSize="@dimen/ate_default_textsize_subheading"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
tools:text="Title" />
<code.name.monkey.appthemehelper.common.views.ATESecondaryTextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@android:id/title"
android:layout_alignStart="@android:id/title"
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title"
android:layout_alignLeft="@android:id/title"
android:layout_marginTop="2dp"
android:maxLines="4"
android:textSize="@dimen/ate_default_textsize_body"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
tools:text="Summary" />
</RelativeLayout>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/dialogTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6" />
<View
android:layout_width="match_parent"
android:layout_height="2dp" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

View file

@ -6,4 +6,5 @@
android:background="@null"
android:button="@drawable/ate_switch"
android:clickable="false"
android:focusable="false" />
android:focusable="false"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1" />

View file

@ -5,4 +5,5 @@
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:focusable="false" />
android:focusable="false"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1" />

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_list_view_row_table_row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dip"
android:paddingTop="8dip"
android:paddingRight="10dip"
android:paddingBottom="8dip">
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical"
android:padding="0dip">
<TextView
android:id="@+id/custom_list_view_row_text_view"
android:layout_width="fill_parent"
android:layout_height="22dip"
android:gravity="center_vertical"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:id="@+id/custom_list_view_row_subtext_view"
android:layout_width="fill_parent"
android:layout_height="18dip"
android:gravity="center_vertical"
android:textColor="#000000"
android:textSize="12sp" />
</LinearLayout>
<ImageView
android:id="@+id/custom_list_view_row_selected_indicator"
android:layout_width="wrap_content"
android:layout_height="40dip"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_toggle_switch" />
</TableRow>

View file

@ -7,9 +7,6 @@
<attr name="ateKey_pref" format="string" />
</declare-styleable>
<declare-styleable name="ATECheckBoxPreference">
<attr name="ateKey_pref_checkBox" format="string" />
</declare-styleable>
<declare-styleable name="ATESwitchPreference">
<attr name="ateKey_pref_switch" format="string" />