forked from upstream-mirrors/quik
@@ -19,7 +19,9 @@
|
||||
package com.moez.QKSMS.common.util
|
||||
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.TextViewStyler.Companion.SIZE_PRIMARY
|
||||
@@ -32,6 +34,8 @@ import com.moez.QKSMS.common.widget.QkTextView
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
|
||||
class TextViewStyler @Inject constructor(
|
||||
private val prefs: Preferences,
|
||||
private val colors: Colors,
|
||||
@@ -93,40 +97,45 @@ class TextViewStyler @Inject constructor(
|
||||
}
|
||||
|
||||
fun applyAttributes(textView: TextView, attrs: AttributeSet?) {
|
||||
textView.run {
|
||||
var colorAttr = 0
|
||||
var textSizeAttr = 0
|
||||
var colorAttr = 0
|
||||
var textSizeAttr = 0
|
||||
|
||||
if (!prefs.systemFont.get()) {
|
||||
fontProvider.getLato { lato ->
|
||||
setTypeface(lato, typeface?.style ?: Typeface.NORMAL)
|
||||
}
|
||||
if (!prefs.systemFont.get()) {
|
||||
fontProvider.getLato { lato ->
|
||||
textView.setTypeface(lato, textView.typeface?.style ?: Typeface.NORMAL)
|
||||
}
|
||||
}
|
||||
|
||||
when (textView) {
|
||||
is QkTextView -> textView.context.obtainStyledAttributes(attrs, R.styleable.QkTextView).run {
|
||||
colorAttr = getInt(R.styleable.QkTextView_textColor, -1)
|
||||
textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1)
|
||||
recycle()
|
||||
}
|
||||
|
||||
when (this) {
|
||||
is QkTextView -> context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
|
||||
colorAttr = getInt(R.styleable.QkTextView_textColor, -1)
|
||||
textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1)
|
||||
recycle()
|
||||
}
|
||||
|
||||
is QkEditText -> context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run {
|
||||
colorAttr = getInt(R.styleable.QkEditText_textColor, -1)
|
||||
textSizeAttr = getInt(R.styleable.QkEditText_textSize, -1)
|
||||
recycle()
|
||||
}
|
||||
|
||||
else -> return
|
||||
is QkEditText -> textView.context.obtainStyledAttributes(attrs, R.styleable.QkEditText).run {
|
||||
colorAttr = getInt(R.styleable.QkEditText_textColor, -1)
|
||||
textSizeAttr = getInt(R.styleable.QkEditText_textSize, -1)
|
||||
recycle()
|
||||
}
|
||||
|
||||
when (colorAttr) {
|
||||
COLOR_THEME -> setTextColor(colors.theme().theme)
|
||||
COLOR_PRIMARY_ON_THEME -> setTextColor(colors.theme().textPrimary)
|
||||
COLOR_SECONDARY_ON_THEME -> setTextColor(colors.theme().textSecondary)
|
||||
COLOR_TERTIARY_ON_THEME -> setTextColor(colors.theme().textTertiary)
|
||||
}
|
||||
else -> return
|
||||
}
|
||||
|
||||
setTextSize(textView, textSizeAttr)
|
||||
when (colorAttr) {
|
||||
COLOR_THEME -> textView.setTextColor(colors.theme().theme)
|
||||
COLOR_PRIMARY_ON_THEME -> textView.setTextColor(colors.theme().textPrimary)
|
||||
COLOR_SECONDARY_ON_THEME -> textView.setTextColor(colors.theme().textSecondary)
|
||||
COLOR_TERTIARY_ON_THEME -> textView.setTextColor(colors.theme().textTertiary)
|
||||
}
|
||||
|
||||
setTextSize(textView, textSizeAttr)
|
||||
|
||||
if (textView is EditText) {
|
||||
val drawable = textView.resources.getDrawable(R.drawable.cursor).apply { setTint(colors.theme().theme) }
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
textView.textCursorDrawable = drawable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2019 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
~
|
||||
~ This file is part of QKSMS.
|
||||
~
|
||||
~ QKSMS 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.
|
||||
~
|
||||
~ QKSMS 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.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/white" />
|
||||
<size android:width="2dp" />
|
||||
</shape>
|
||||
Reference in New Issue
Block a user