summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-07-21 15:31:39 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-07-23 13:00:10 +0000
commit74b441131ed615877d56a62c67ce242e95502bb1 (patch)
treee65c9652ac92c3c75215415d99742a6951314aaf /android
parent494cad0d0f0b0ca2d3fb036d6c39df9d0f7b304f (diff)
downloadmullvadvpn-74b441131ed615877d56a62c67ce242e95502bb1.tar.xz
mullvadvpn-74b441131ed615877d56a62c67ce242e95502bb1.zip
Create `BackButton` helper widget
Diffstat (limited to 'android')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/BackButton.kt71
-rw-r--r--android/src/main/res/layout/settings_back_button.xml12
-rw-r--r--android/src/main/res/values/dimensions.xml1
3 files changed, 84 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/BackButton.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/BackButton.kt
new file mode 100644
index 0000000000..b0ae6024ec
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/BackButton.kt
@@ -0,0 +1,71 @@
+package net.mullvad.mullvadvpn.ui.widget
+
+import android.content.Context
+import android.util.AttributeSet
+import android.util.TypedValue
+import android.view.Gravity
+import android.view.LayoutInflater
+import android.widget.LinearLayout
+import android.widget.TextView
+import net.mullvad.mullvadvpn.R
+
+class BackButton : LinearLayout {
+ private val container =
+ context.getSystemService(Context.LAYOUT_INFLATER_SERVICE).let { service ->
+ val inflater = service as LayoutInflater
+
+ inflater.inflate(R.layout.settings_back_button, this)
+ }
+
+ private val label = container.findViewById<TextView>(R.id.label)
+
+ 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_VERTICAL or Gravity.LEFT
+ orientation = HORIZONTAL
+
+ resources.getDimensionPixelSize(R.dimen.settings_back_button_padding).let { padding ->
+ setPadding(padding, padding, padding, padding)
+ }
+
+ loadBackground()
+ }
+
+ 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()
+ }
+ }
+ }
+
+ private fun loadBackground() {
+ val typedValue = TypedValue()
+
+ context.theme.resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true)
+
+ setBackgroundResource(typedValue.resourceId)
+ }
+}
diff --git a/android/src/main/res/layout/settings_back_button.xml b/android/src/main/res/layout/settings_back_button.xml
new file mode 100644
index 0000000000..da8bad7356
--- /dev/null
+++ b/android/src/main/res/layout/settings_back_button.xml
@@ -0,0 +1,12 @@
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+ <ImageView android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_marginRight="8dp"
+ android:src="@drawable/icon_back" />
+ <TextView android:id="@+id/label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textColor="@color/white60"
+ android:textSize="13sp"
+ android:textStyle="bold" />
+</merge>
diff --git a/android/src/main/res/values/dimensions.xml b/android/src/main/res/values/dimensions.xml
index 197cb92ecb..99a79846f5 100644
--- a/android/src/main/res/values/dimensions.xml
+++ b/android/src/main/res/values/dimensions.xml
@@ -14,4 +14,5 @@
<dimen name="cell_switch_knob_margin">4dp</dimen>
<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>
</resources>