mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-04-30 06:34:29 +02:00
refactor: switches and view apperance
Co-authored-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
parent
8932129bfd
commit
cfb0ba5d65
@ -4,13 +4,16 @@ import android.annotation.SuppressLint
|
|||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Switch
|
import android.widget.Switch
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import me.rhunk.snapenhance.Constants
|
import me.rhunk.snapenhance.Constants
|
||||||
|
|
||||||
object ViewAppearanceHelper {
|
object ViewAppearanceHelper {
|
||||||
@SuppressLint("UseSwitchCompatOrMaterialCode", "RtlHardcoded", "DiscouragedApi")
|
@SuppressLint("UseSwitchCompatOrMaterialCode", "RtlHardcoded", "DiscouragedApi",
|
||||||
|
"ClickableViewAccessibility"
|
||||||
|
)
|
||||||
fun applyTheme(viewModel: View, view: TextView) {
|
fun applyTheme(viewModel: View, view: TextView) {
|
||||||
val snapchatFontResId = view.context.resources.getIdentifier("avenir_next_medium", "font", "com.snapchat.android")
|
val snapchatFontResId = view.context.resources.getIdentifier("avenir_next_medium", "font", "com.snapchat.android")
|
||||||
//remove the shadow
|
//remove the shadow
|
||||||
@ -24,25 +27,44 @@ object ViewAppearanceHelper {
|
|||||||
//DPI Calculator
|
//DPI Calculator
|
||||||
val scalingFactor = view.context.resources.displayMetrics.densityDpi.toDouble() / 400
|
val scalingFactor = view.context.resources.displayMetrics.densityDpi.toDouble() / 400
|
||||||
view.height = (150 * scalingFactor).toInt()
|
view.height = (150 * scalingFactor).toInt()
|
||||||
view.setPadding((40 * scalingFactor).toInt(), 0, (25 * scalingFactor).toInt(), 0)
|
view.setPadding((40 * scalingFactor).toInt(), 0, (40 * scalingFactor).toInt(), 0)
|
||||||
view.isAllCaps = false
|
view.isAllCaps = false
|
||||||
view.textSize = 16f
|
view.textSize = 16f
|
||||||
view.typeface = view.context.resources.getFont(snapchatFontResId)
|
view.typeface = view.context.resources.getFont(snapchatFontResId)
|
||||||
|
|
||||||
//remove click effect
|
//FIXME: wrong color, shouldn't be that much noticeable though
|
||||||
if (view.javaClass == TextView::class.java) {
|
view.setOnTouchListener { _, event ->
|
||||||
view.setBackgroundColor(0)
|
when (event.action) {
|
||||||
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
view.setBackgroundColor(0x5395026)
|
||||||
}
|
}
|
||||||
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||||
|
view.setBackgroundColor(0x00000000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
if (view is Switch) {
|
if (view is Switch) {
|
||||||
|
with(viewModel.resources) {
|
||||||
|
view.switchMinWidth = getDimension(getIdentifier("v11_switch_min_width", "dimen", Constants.SNAPCHAT_PACKAGE_NAME)).toInt()
|
||||||
|
}
|
||||||
val colorStateList = ColorStateList(
|
val colorStateList = ColorStateList(
|
||||||
arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)
|
arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)
|
||||||
), intArrayOf(
|
), intArrayOf(
|
||||||
Color.parseColor("#3d3d3d"),
|
Color.parseColor("#1d1d1d"),
|
||||||
Color.parseColor("#2196F3")
|
Color.parseColor("#26bd49")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val thumbStateList = ColorStateList(
|
||||||
|
arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)
|
||||||
|
), intArrayOf(
|
||||||
|
Color.parseColor("#F5F5F5"),
|
||||||
|
Color.parseColor("#26bd49")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
view.trackTintList = colorStateList
|
view.trackTintList = colorStateList
|
||||||
view.thumbTintList = colorStateList
|
view.thumbTintList = thumbStateList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,14 @@ import me.rhunk.snapenhance.features.impl.ui.menus.AbstractMenu
|
|||||||
import me.rhunk.snapenhance.features.impl.ui.menus.ViewAppearanceHelper
|
import me.rhunk.snapenhance.features.impl.ui.menus.ViewAppearanceHelper
|
||||||
|
|
||||||
class SettingsMenu : AbstractMenu() {
|
class SettingsMenu : AbstractMenu() {
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private fun createCategoryTitle(viewModel: View, key: String): TextView {
|
private fun createCategoryTitle(viewModel: View, key: String): TextView {
|
||||||
val categoryText = TextView(viewModel.context)
|
val categoryText = TextView(viewModel.context)
|
||||||
categoryText.text = context.translation.get(key)
|
categoryText.text = context.translation.get(key)
|
||||||
ViewAppearanceHelper.applyTheme(viewModel, categoryText)
|
ViewAppearanceHelper.applyTheme(viewModel, categoryText)
|
||||||
categoryText.textSize = 20f
|
categoryText.textSize = 20f
|
||||||
categoryText.typeface = categoryText.typeface?.let { Typeface.create(it, Typeface.BOLD) }
|
categoryText.typeface = categoryText.typeface?.let { Typeface.create(it, Typeface.BOLD) }
|
||||||
|
categoryText.setOnTouchListener { _, _ -> true }
|
||||||
return categoryText
|
return categoryText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user