summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-05-22 14:43:36 -0300
committerTorsten Grote <t@grobox.de>2020-05-22 14:43:36 -0300
commit882c2c50c878215c380ee1cfd132030a0b0c80f8 (patch)
tree5396c0e666b7548f9ec53f62d529abc2da02f9cd
parentb0869289dc9fa2f983991915e77ba0260e59ed8b (diff)
downloadtaler-android-882c2c50c878215c380ee1cfd132030a0b0c80f8.tar.gz
taler-android-882c2c50c878215c380ee1cfd132030a0b0c80f8.tar.bz2
taler-android-882c2c50c878215c380ee1cfd132030a0b0c80f8.zip
[wallet] add option to enter URI manually by long pressing scan button
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainFragment.kt4
-rw-r--r--wallet/src/main/java/net/taler/wallet/UriInputFragment.kt68
-rw-r--r--wallet/src/main/res/drawable/ic_content_paste.xml9
-rw-r--r--wallet/src/main/res/layout/fragment_uri_input.xml75
-rw-r--r--wallet/src/main/res/navigation/nav_graph.xml9
-rw-r--r--wallet/src/main/res/values/strings.xml5
6 files changed, 170 insertions, 0 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/MainFragment.kt b/wallet/src/main/java/net/taler/wallet/MainFragment.kt
index 26c5a905..a735987d 100644
--- a/wallet/src/main/java/net/taler/wallet/MainFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainFragment.kt
@@ -62,6 +62,10 @@ class MainFragment : Fragment() {
mainFab.setOnClickListener {
scanQrCode(requireActivity())
}
+ mainFab.setOnLongClickListener {
+ findNavController().navigate(R.id.action_nav_main_to_nav_uri_input)
+ true
+ }
}
override fun onStart() {
diff --git a/wallet/src/main/java/net/taler/wallet/UriInputFragment.kt b/wallet/src/main/java/net/taler/wallet/UriInputFragment.kt
new file mode 100644
index 00000000..eaa6d169
--- /dev/null
+++ b/wallet/src/main/java/net/taler/wallet/UriInputFragment.kt
@@ -0,0 +1,68 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2020 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+package net.taler.wallet
+
+import android.content.ClipboardManager
+import android.content.Intent
+import android.content.Intent.ACTION_VIEW
+import android.net.Uri
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.Toast
+import android.widget.Toast.LENGTH_LONG
+import androidx.fragment.app.Fragment
+import kotlinx.android.synthetic.main.fragment_uri_input.*
+
+class UriInputFragment : Fragment() {
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ return inflater.inflate(R.layout.fragment_uri_input, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ val clipboard = requireContext().getSystemService(ClipboardManager::class.java)!!
+
+ pasteButton.setOnClickListener {
+ val item = clipboard.primaryClip?.getItemAt(0)
+ if (item?.text != null) {
+ uriView.setText(item.text)
+ } else {
+ if (item?.uri != null) {
+ uriView.setText(item.uri.toString())
+ } else {
+ Toast.makeText(requireContext(), R.string.paste_invalid, LENGTH_LONG).show()
+ }
+ }
+ }
+ okButton.setOnClickListener {
+ if (uriView.text?.startsWith("taler://") == true) {
+ uriLayout.error = null
+ val i = Intent(ACTION_VIEW, Uri.parse(uriView.text.toString()))
+ startActivity(i)
+ } else {
+ uriLayout.error = getString(R.string.uri_invalid)
+ }
+ }
+ }
+
+}
diff --git a/wallet/src/main/res/drawable/ic_content_paste.xml b/wallet/src/main/res/drawable/ic_content_paste.xml
new file mode 100644
index 00000000..40235c22
--- /dev/null
+++ b/wallet/src/main/res/drawable/ic_content_paste.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M19,2h-4.18C14.4,0.84 13.3,0 12,0c-1.3,0 -2.4,0.84 -2.82,2L5,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM12,2c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM19,20L5,20L5,4h2v3h10L17,4h2v16z" />
+</vector>
diff --git a/wallet/src/main/res/layout/fragment_uri_input.xml b/wallet/src/main/res/layout/fragment_uri_input.xml
new file mode 100644
index 00000000..60155e3a
--- /dev/null
+++ b/wallet/src/main/res/layout/fragment_uri_input.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ This file is part of GNU Taler
+ ~ (C) 2020 Taler Systems S.A.
+ ~
+ ~ GNU Taler is free software; you can redistribute it and/or modify it under the
+ ~ terms of the GNU General Public License as published by the Free Software
+ ~ Foundation; either version 3, or (at your option) any later version.
+ ~
+ ~ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ ~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ ~ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License along with
+ ~ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ -->
+
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <com.google.android.material.textfield.TextInputLayout
+ android:id="@+id/uriLayout"
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_margin="16dp"
+ android:hint="@string/enter_uri"
+ app:boxBackgroundMode="outline"
+ app:endIconMode="clear_text"
+ app:endIconTint="?attr/colorControlNormal"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent">
+
+ <com.google.android.material.textfield.TextInputEditText
+ android:id="@+id/uriView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="textUri" />
+
+ </com.google.android.material.textfield.TextInputLayout>
+
+ <Button
+ android:id="@+id/pasteButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_marginTop="16dp"
+ android:layout_marginEnd="16dp"
+ android:layout_weight="1"
+ android:drawableLeft="@drawable/ic_content_paste"
+ android:drawableTint="?attr/colorOnPrimarySurface"
+ android:text="@string/paste"
+ app:layout_constraintEnd_toStartOf="@+id/okButton"
+ app:layout_constraintHorizontal_chainStyle="spread_inside"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/uriLayout"
+ tools:ignore="RtlHardcoded" />
+
+ <Button
+ android:id="@+id/okButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_marginTop="16dp"
+ android:layout_marginEnd="16dp"
+ android:backgroundTint="@color/green"
+ android:text="@string/ok"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toEndOf="@+id/pasteButton"
+ app:layout_constraintTop_toBottomOf="@+id/uriLayout" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/wallet/src/main/res/navigation/nav_graph.xml b/wallet/src/main/res/navigation/nav_graph.xml
index a06abad0..d5ce6579 100644
--- a/wallet/src/main/res/navigation/nav_graph.xml
+++ b/wallet/src/main/res/navigation/nav_graph.xml
@@ -34,6 +34,9 @@
<action
android:id="@+id/action_nav_main_to_nav_transactions"
app:destination="@id/nav_transactions" />
+ <action
+ android:id="@+id/action_nav_main_to_nav_uri_input"
+ app:destination="@id/nav_uri_input" />
</fragment>
<fragment
@@ -124,6 +127,12 @@
tools:layout="@layout/fragment_transactions" />
<fragment
+ android:id="@+id/nav_uri_input"
+ android:name="net.taler.wallet.UriInputFragment"
+ android:label="@string/enter_uri"
+ tools:layout="@layout/fragment_uri_input" />
+
+ <fragment
android:id="@+id/errorFragment"
android:name="net.taler.wallet.withdraw.ErrorFragment"
android:label="@string/nav_error"
diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml
index 167ab538..3da30f98 100644
--- a/wallet/src/main/res/values/strings.xml
+++ b/wallet/src/main/res/values/strings.xml
@@ -45,6 +45,11 @@ GNU Taler is immune against many types of fraud, such as phishing of credit card
<string name="button_back">Go Back</string>
<string name="button_scan_qr_code">Scan Taler QR Code</string>
+ <string name="enter_uri">Enter Taler URI</string>
+ <string name="paste">Paste</string>
+ <string name="paste_invalid">Clipboard contains an invalid data type</string>
+ <string name="uri_invalid">Not a valid Taler URI</string>
+ <string name="ok">OK</string>
<string name="search">Search</string>
<string name="menu_settings">Settings</string>