summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-07-21 23:14:21 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-07-28 13:52:59 +0000
commitd12d7efc356a93eadf49287493e1945dc0e82a68 (patch)
treea455d07f1ea1f25be2bf99910c8cdf0244d39ac5 /android
parentee608498b17b789d18070e31328a5d50ed16eb53 (diff)
downloadmullvadvpn-d12d7efc356a93eadf49287493e1945dc0e82a68.tar.xz
mullvadvpn-d12d7efc356a93eadf49287493e1945dc0e82a68.zip
Create new `Cell` base widget
Diffstat (limited to 'android')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Cell.kt69
-rw-r--r--android/src/main/res/values/dimensions.xml3
2 files changed, 72 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Cell.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Cell.kt
new file mode 100644
index 0000000000..c8847cf004
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Cell.kt
@@ -0,0 +1,69 @@
+package net.mullvad.mullvadvpn.ui.widget
+
+import android.content.Context
+import android.graphics.Typeface
+import android.util.AttributeSet
+import android.util.TypedValue
+import android.view.Gravity
+import android.widget.LinearLayout
+import android.widget.TextView
+import net.mullvad.mullvadvpn.R
+
+open class Cell : LinearLayout {
+ private val label = TextView(context).apply {
+ val horizontalPadding =
+ resources.getDimensionPixelSize(R.dimen.cell_label_horizontal_padding)
+ val verticalPadding = resources.getDimensionPixelSize(R.dimen.cell_label_vertical_padding)
+
+ layoutParams = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f)
+ setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding)
+
+ setTextColor(context.getColor(R.color.white))
+ setTextSize(TypedValue.COMPLEX_UNIT_SP, 20.0f)
+ setTypeface(null, Typeface.BOLD)
+ }
+
+ constructor(context: Context) : super(context) {}
+
+ constructor(context: Context, attributes: AttributeSet) : super(context, attributes) {
+ loadAttributes(attributes)
+ }
+
+ constructor(context: Context, attributes: AttributeSet, defaultStyleAttribute: Int) :
+ super(context, attributes, defaultStyleAttribute) {
+ loadAttributes(attributes)
+ }
+
+ constructor(
+ context: Context,
+ attributes: AttributeSet,
+ defaultStyleAttribute: Int,
+ defaultStyleResource: Int
+ ) : super(context, attributes, defaultStyleAttribute, defaultStyleResource) {
+ loadAttributes(attributes)
+ }
+
+ init {
+ isClickable = true
+ gravity = Gravity.CENTER
+ orientation = HORIZONTAL
+
+ setBackgroundResource(R.drawable.cell_button_background)
+
+ resources.getDimensionPixelSize(R.dimen.cell_horizontal_padding).let { padding ->
+ setPadding(padding, 0, padding, 0)
+ }
+
+ addView(label)
+ }
+
+ private fun loadAttributes(attributes: AttributeSet) {
+ context.theme.obtainStyledAttributes(attributes, R.styleable.TextAttribute, 0, 0).apply {
+ try {
+ label.text = getString(R.styleable.TextAttribute_text) ?: ""
+ } finally {
+ recycle()
+ }
+ }
+ }
+}
diff --git a/android/src/main/res/values/dimensions.xml b/android/src/main/res/values/dimensions.xml
index 99a79846f5..af521ffb99 100644
--- a/android/src/main/res/values/dimensions.xml
+++ b/android/src/main/res/values/dimensions.xml
@@ -15,4 +15,7 @@
<dimen name="cell_switch_knob_max_translation">20dp</dimen>
<dimen name="cell_switch_knob_size">24dp</dimen>
<dimen name="settings_back_button_padding">12dp</dimen>
+ <dimen name="cell_horizontal_padding">16dp</dimen>
+ <dimen name="cell_label_horizontal_padding">8dp</dimen>
+ <dimen name="cell_label_vertical_padding">17dp</dimen>
</resources>