For #2389 - Create Theme Onboarding Card
parent
42d1491976
commit
d347f73e69
@ -0,0 +1,64 @@
|
|||||||
|
package org.mozilla.fenix.onboarding
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.widget.RadioButton
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.utils.Settings
|
||||||
|
|
||||||
|
class OnboardingRadioButton : RadioButton {
|
||||||
|
private val radioGroups = mutableListOf<OnboardingRadioButton>()
|
||||||
|
private var clickListener: (() -> Unit)? = null
|
||||||
|
var key: Int = 0
|
||||||
|
|
||||||
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
||||||
|
attrs.let {
|
||||||
|
context.theme.obtainStyledAttributes(
|
||||||
|
it,
|
||||||
|
R.styleable.OnboardingRadioButton,
|
||||||
|
0, 0
|
||||||
|
).apply {
|
||||||
|
try {
|
||||||
|
key = getResourceId(
|
||||||
|
R.styleable.OnboardingRadioButton_onboardingKey, 0
|
||||||
|
)
|
||||||
|
} finally {
|
||||||
|
recycle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addToRadioGroup(radioButton: OnboardingRadioButton) {
|
||||||
|
radioGroups.add(radioButton)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onClickListener(listener: (() -> Unit)) {
|
||||||
|
clickListener = listener
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
setOnClickListener {
|
||||||
|
updateRadioValue(true)
|
||||||
|
toggleRadioGroups()
|
||||||
|
clickListener?.invoke()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateRadioValue(isChecked: Boolean) {
|
||||||
|
this.isChecked = isChecked
|
||||||
|
Settings.getInstance(context).preferences.edit().putBoolean(context.getString(key), isChecked)
|
||||||
|
.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toggleRadioGroups() {
|
||||||
|
if (this.isChecked) {
|
||||||
|
radioGroups.forEach { it.updateRadioValue(false) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 8.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 8.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:color="?android:attr/colorControlHighlight">
|
||||||
|
<item android:id="@android:id/mask">
|
||||||
|
<shape>
|
||||||
|
<solid android:color="#000000" />
|
||||||
|
<corners
|
||||||
|
android:bottomLeftRadius="@dimen/tab_corner_radius"
|
||||||
|
android:bottomRightRadius="@dimen/tab_corner_radius" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<stroke
|
||||||
|
android:width="1dp"
|
||||||
|
android:color="?shadow" />
|
||||||
|
<solid android:color="?inset" />
|
||||||
|
<corners
|
||||||
|
android:bottomLeftRadius="@dimen/tab_corner_radius"
|
||||||
|
android:bottomRightRadius="@dimen/tab_corner_radius" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</ripple>
|
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:color="?android:attr/colorControlHighlight">
|
||||||
|
<item android:id="@android:id/mask">
|
||||||
|
<shape>
|
||||||
|
<solid android:color="#000000" />
|
||||||
|
<corners android:radius="8dp" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="@android:color/transparent" />
|
||||||
|
<corners android:radius="8dp" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</ripple>
|
Loading…
Reference in New Issue