UI tweaks for pre API 21

This commit is contained in:
topjohnwu 2020-08-27 05:46:41 -07:00
parent fd808bd51e
commit 7e133b0cf4
6 changed files with 26 additions and 38 deletions

View File

@ -3,12 +3,14 @@ package com.topjohnwu.magisk.databinding
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.graphics.Paint import android.graphics.Paint
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.util.TypedValue
import android.view.ContextThemeWrapper import android.view.ContextThemeWrapper
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.* import android.widget.*
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.cardview.widget.CardView
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
@ -302,3 +304,10 @@ fun setListeners(
attrChange.onChange() attrChange.onChange()
} }
} }
@BindingAdapter("cardBackgroundColorAttr")
fun CardView.setCardBackgroundColorAttr(attr: Int) {
val tv = TypedValue()
context.theme.resolveAttribute(attr, tv, true)
setCardBackgroundColor(tv.data)
}

View File

@ -9,7 +9,7 @@ import com.topjohnwu.magisk.utils.set
import org.json.JSONObject import org.json.JSONObject
enum class SafetyNetState { enum class SafetyNetState {
LOADING, PASS, FAILED, IDLE LOADING, PASS, FAILED
} }
data class SafetyNetResult( data class SafetyNetResult(
@ -42,7 +42,7 @@ class SafetynetViewModel : BaseViewModel() {
@get:Bindable @get:Bindable
val isSuccess get() = currentState == PASS val isSuccess get() = currentState == PASS
private var currentState = IDLE private var currentState = LOADING
set(value) = set(value, field, { field = it }, BR.checking, BR.failed, BR.success) set(value) = set(value, field, { field = it }, BR.checking, BR.failed, BR.success)
init { init {

View File

@ -96,33 +96,27 @@
<CheckBox <CheckBox
gone="@{Info.isSAR}" gone="@{Info.isSAR}"
style="@style/WidgetFoundation.Checkbox" style="@style/WidgetFoundation.Checkbox"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:checked="@={Config.keepVerity}" android:checked="@={Config.keepVerity}"
android:gravity="center"
android:text="@string/keep_dm_verity" android:text="@string/keep_dm_verity"
tools:checked="true" /> tools:checked="true" />
<CheckBox <CheckBox
gone="@{Info.isFBE}" gone="@{Info.isFBE}"
style="@style/WidgetFoundation.Checkbox" style="@style/WidgetFoundation.Checkbox"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:checked="@={Config.keepEnc}" android:checked="@={Config.keepEnc}"
android:gravity="center"
android:text="@string/keep_force_encryption" android:text="@string/keep_force_encryption"
app:tint="?colorPrimary" /> app:tint="?colorPrimary" />
<CheckBox <CheckBox
gone="@{Info.ramdisk}" gone="@{Info.ramdisk}"
style="@style/WidgetFoundation.Checkbox" style="@style/WidgetFoundation.Checkbox"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:checked="@={Config.recovery}" android:checked="@={Config.recovery}"
android:gravity="center"
android:text="@string/recovery_mode" android:text="@string/recovery_mode"
app:tint="?colorPrimary" /> app:tint="?colorPrimary" />

View File

@ -7,8 +7,8 @@
<import type="android.os.Build" /> <import type="android.os.Build" />
<import type="com.topjohnwu.magisk.core.Info" /> <import type="com.topjohnwu.magisk.core.Info" />
<import type="com.topjohnwu.magisk.BuildConfig" /> <import type="com.topjohnwu.magisk.BuildConfig" />
<import type="com.topjohnwu.magisk.R" />
<variable <variable
name="viewModel" name="viewModel"
@ -40,7 +40,7 @@
android:textAppearance="@style/AppearanceFoundation.Title" /> android:textAppearance="@style/AppearanceFoundation.Title" />
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
invisibleUnless="@{viewModel.success || viewModel.failed}" invisible="@{viewModel.checking}"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingTop="@dimen/l1" android:paddingTop="@dimen/l1"
@ -49,6 +49,7 @@
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/safetynet_attestation" android:id="@+id/safetynet_attestation"
style="@style/WidgetFoundation.Card.Elevated" style="@style/WidgetFoundation.Card.Elevated"
cardBackgroundColorAttr="@{viewModel.success ? R.attr.colorPrimary : R.attr.colorError}"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1" android:layout_marginStart="@dimen/l1"
@ -62,30 +63,13 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias=".35" app:layout_constraintVertical_bias=".35"
app:layout_constraintWidth_max="300dp"> app:layout_constraintWidth_max="300dp"
tools:cardBackgroundColor="?colorPrimary">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<View
goneUnless="@{viewModel.failed}"
android:layout_width="match_parent"
android:layout_height="0dp"
android:alpha=".5"
android:background="?colorError"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
goneUnless="@{viewModel.success}"
android:layout_width="match_parent"
android:layout_height="0dp"
android:alpha=".5"
android:background="?colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/safetynet_title" android:id="@+id/safetynet_title"
android:layout_width="0dp" android:layout_width="0dp"

View File

@ -77,8 +77,11 @@
<com.topjohnwu.widget.IndeterminateCheckBox <com.topjohnwu.widget.IndeterminateCheckBox
android:id="@+id/hide_expand_icon" android:id="@+id/hide_expand_icon"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minWidth="0dp"
android:minHeight="0dp"
android:layout_marginEnd="@dimen/l1"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"

View File

@ -21,7 +21,7 @@
<item name="cardBackgroundColor">?colorSurfaceVariant</item> <item name="cardBackgroundColor">?colorSurfaceVariant</item>
<item name="cardCornerRadius">@dimen/l_50</item> <item name="cardCornerRadius">@dimen/l_50</item>
<item name="cardElevation">0dp</item> <item name="cardElevation">0dp</item>
<item name="cardPreventCornerOverlap">true</item> <item name="cardPreventCornerOverlap">false</item>
</style> </style>
<style name="WidgetFoundation.Card.Primary"> <style name="WidgetFoundation.Card.Primary">
@ -41,20 +41,18 @@
<item name="strokeColor">?colorPrimary</item> <item name="strokeColor">?colorPrimary</item>
</style> </style>
<style name="WidgetFoundation.Card.Elevated" parent="Widget.MaterialComponents.CardView"> <style name="WidgetFoundation.Card.Elevated">
<item name="cardBackgroundColor">?colorSurfaceSurfaceVariant</item> <item name="cardBackgroundColor">?colorSurfaceSurfaceVariant</item>
<item name="cardCornerRadius">@dimen/l_50</item> <item name="cardCornerRadius">@dimen/l_50</item>
<item name="cardElevation">@dimen/l_125</item> <item name="cardElevation">@dimen/l_125</item>
<item name="cardPreventCornerOverlap">true</item>
</style> </style>
<style name="WidgetFoundation.Card.OnPrimary" parent="Widget.MaterialComponents.CardView"> <style name="WidgetFoundation.Card.OnPrimary">
<item name="cardCornerRadius">@dimen/l_50</item> <item name="cardCornerRadius">@dimen/l_50</item>
<item name="cardElevation">0dp</item> <item name="cardElevation">0dp</item>
<item name="strokeColor">?colorOnPrimaryVariant</item> <item name="strokeColor">?colorOnPrimaryVariant</item>
<item name="strokeWidth">1dp</item> <item name="strokeWidth">1dp</item>
<item name="cardBackgroundColor">?colorPrimary</item> <item name="cardBackgroundColor">?colorPrimary</item>
<item name="cardPreventCornerOverlap">true</item>
</style> </style>