Import and convert SettingsLib.Utils.getColorAccent
https: //cs.android.com/android/platform/superproject/+/android-12.0.0_r1:frameworks/base/packages/SettingsLib/src/com/android/settingslib/Utils.java?q=SettingsLib.Utils Change-Id: Ieab581569ebaa6f45529c09ad75c1037e93fa772
This commit is contained in:
parent
a717ebaf9c
commit
21f1667a1f
1 changed files with 18 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.stevesoltys.seedvault.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.text.format.DateUtils.MINUTE_IN_MILLIS
|
||||
import android.text.format.DateUtils.getRelativeTimeSpanString
|
||||
import com.stevesoltys.seedvault.R
|
||||
|
|
@ -13,3 +14,20 @@ fun Long.toRelativeTime(context: Context): CharSequence {
|
|||
getRelativeTimeSpanString(this, now, MINUTE_IN_MILLIS, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// Ported from
|
||||
// https://cs.android.com/android/platform/superproject/+/android-12.0.0_r1:frameworks/base/packages/SettingsLib/src/com/android/settingslib/Utils.java
|
||||
fun getColorAccent(context: Context): ColorStateList? {
|
||||
return getColorAttr(context, android.R.attr.colorAccent)
|
||||
}
|
||||
|
||||
fun getColorAttr(context: Context, attr: Int): ColorStateList? {
|
||||
val typedArray = context.obtainStyledAttributes(IntArray(1){ attr })
|
||||
var stateList: ColorStateList? = null
|
||||
try {
|
||||
stateList = typedArray.getColorStateList(0)
|
||||
} finally {
|
||||
typedArray.recycle()
|
||||
}
|
||||
return stateList
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue