diff options
author | pacien | 2018-06-10 23:47:57 +0200 |
---|---|---|
committer | pacien | 2018-06-10 23:47:57 +0200 |
commit | a2ffefc02bdcbab6fc8f13f30585eb43aab2d078 (patch) | |
tree | f9134eb51069a2a235baa0716bbcc7fd7926ba51 /app/src/main | |
parent | 7b38ed30cd0fb5a6068c99d97a8c048e891285fa (diff) | |
download | tincapp-a2ffefc02bdcbab6fc8f13f30585eb43aab2d078.tar.gz |
Better qr-code scanner integration
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt | 23 | ||||
-rw-r--r-- | app/src/main/res/values-zh-rCN/strings.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/values-zh-rHK/strings.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/values-zh-rTW/strings.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 1 |
5 files changed, 7 insertions, 20 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt index e311415..5f6a3fe 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt | |||
@@ -1,13 +1,12 @@ | |||
1 | package org.pacien.tincapp.activities | 1 | package org.pacien.tincapp.activities |
2 | 2 | ||
3 | import android.app.Activity | ||
4 | import android.content.ActivityNotFoundException | ||
5 | import android.content.Intent | 3 | import android.content.Intent |
6 | import android.net.Uri | ||
7 | import android.os.Bundle | 4 | import android.os.Bundle |
8 | import android.support.annotation.StringRes | 5 | import android.support.annotation.StringRes |
9 | import android.support.v7.app.AlertDialog | 6 | import android.support.v7.app.AlertDialog |
10 | import android.view.View | 7 | import android.view.View |
8 | import com.google.zxing.integration.android.IntentIntegrator | ||
9 | import com.google.zxing.integration.android.IntentResult | ||
11 | import java8.util.concurrent.CompletableFuture | 10 | import java8.util.concurrent.CompletableFuture |
12 | import kotlinx.android.synthetic.main.base.* | 11 | import kotlinx.android.synthetic.main.base.* |
13 | import kotlinx.android.synthetic.main.dialog_encrypt_decrypt_keys.view.* | 12 | import kotlinx.android.synthetic.main.dialog_encrypt_decrypt_keys.view.* |
@@ -26,8 +25,6 @@ import java.util.regex.Pattern | |||
26 | */ | 25 | */ |
27 | class ConfigureActivity : BaseActivity() { | 26 | class ConfigureActivity : BaseActivity() { |
28 | companion object { | 27 | companion object { |
29 | private const val REQUEST_SCAN = 0 | ||
30 | private const val SCAN_PROVIDER = "com.google.zxing.client.android" | ||
31 | private val NETWORK_NAME_PATTERN = Pattern.compile("^[^\\x00/]*$") | 28 | private val NETWORK_NAME_PATTERN = Pattern.compile("^[^\\x00/]*$") |
32 | } | 29 | } |
33 | 30 | ||
@@ -36,8 +33,10 @@ class ConfigureActivity : BaseActivity() { | |||
36 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | 33 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
37 | super.onActivityResult(requestCode, resultCode, data) | 34 | super.onActivityResult(requestCode, resultCode, data) |
38 | 35 | ||
39 | if (requestCode == REQUEST_SCAN && resultCode == Activity.RESULT_OK) | 36 | IntentIntegrator.parseActivityResult(requestCode, resultCode, data) |
40 | joinDialog?.invitation_url?.setText(data!!.getStringExtra("SCAN_RESULT").trim()) | 37 | ?.let(IntentResult::getContents) |
38 | ?.let(String::trim) | ||
39 | ?.let { joinDialog?.invitation_url?.setText(it) } | ||
41 | } | 40 | } |
42 | 41 | ||
43 | override fun onCreate(savedInstanceState: Bundle?) { | 42 | override fun onCreate(savedInstanceState: Bundle?) { |
@@ -48,15 +47,7 @@ class ConfigureActivity : BaseActivity() { | |||
48 | } | 47 | } |
49 | 48 | ||
50 | fun scanCode(@Suppress("UNUSED_PARAMETER") v: View) { | 49 | fun scanCode(@Suppress("UNUSED_PARAMETER") v: View) { |
51 | try { | 50 | IntentIntegrator(this).initiateScan() |
52 | startActivityForResult(Intent("$SCAN_PROVIDER.SCAN"), REQUEST_SCAN) | ||
53 | } catch (e: ActivityNotFoundException) { | ||
54 | AlertDialog.Builder(this).setTitle(R.string.action_scan_qr_code) | ||
55 | .setMessage(R.string.message_no_qr_code_scanner) | ||
56 | .setPositiveButton(R.string.action_install) { _, _ -> | ||
57 | startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$SCAN_PROVIDER"))) | ||
58 | }.setNegativeButton(R.string.action_cancel, { _, _ -> Unit }).show() | ||
59 | } | ||
60 | } | 51 | } |
61 | 52 | ||
62 | fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) { | 53 | fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) { |
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index ce0a854..5feb75d 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml | |||
@@ -70,7 +70,6 @@ | |||
70 | <string name="message_no_configuration_for_network_format">没有找到网络“%1$s”的配置。</string> | 70 | <string name="message_no_configuration_for_network_format">没有找到网络“%1$s”的配置。</string> |
71 | <string name="message_network_config_not_found_format">在“%1$s”找不到网络配置文件。</string> | 71 | <string name="message_network_config_not_found_format">在“%1$s”找不到网络配置文件。</string> |
72 | <string name="message_network_config_invalid_format">network.conf 中的网络配置无效:\n\n%1$s</string> | 72 | <string name="message_network_config_invalid_format">network.conf 中的网络配置无效:\n\n%1$s</string> |
73 | <string name="message_no_qr_code_scanner">无法启动扫描器。\n\n安装 Barcode Scanner?</string> | ||
74 | <string name="message_encrypting_decrypting_private_keys">加密/解密私钥</string> | 73 | <string name="message_encrypting_decrypting_private_keys">加密/解密私钥</string> |
75 | <string name="message_could_not_decrypt_private_keys_format">无法解密私钥:\n\n%1$s</string> | 74 | <string name="message_could_not_decrypt_private_keys_format">无法解密私钥:\n\n%1$s</string> |
76 | 75 | ||
diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 6879117..dfc27fe 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml | |||
@@ -70,7 +70,6 @@ | |||
70 | <string name="message_no_configuration_for_network_format">沒有找到網絡“%1$s”的配置。</string> | 70 | <string name="message_no_configuration_for_network_format">沒有找到網絡“%1$s”的配置。</string> |
71 | <string name="message_network_config_not_found_format">在“%1$s”找不到網絡配置文件。</string> | 71 | <string name="message_network_config_not_found_format">在“%1$s”找不到網絡配置文件。</string> |
72 | <string name="message_network_config_invalid_format">network.conf 中的網絡配置無效:\n\n%1$s</string> | 72 | <string name="message_network_config_invalid_format">network.conf 中的網絡配置無效:\n\n%1$s</string> |
73 | <string name="message_no_qr_code_scanner">無法啟動掃描器。\n\n安裝 Barcode Scanner?</string> | ||
74 | <string name="message_encrypting_decrypting_private_keys">加密/解密私鑰</string> | 73 | <string name="message_encrypting_decrypting_private_keys">加密/解密私鑰</string> |
75 | <string name="message_could_not_decrypt_private_keys_format">無法解密私鑰:\n\n%1$s</string> | 74 | <string name="message_could_not_decrypt_private_keys_format">無法解密私鑰:\n\n%1$s</string> |
76 | 75 | ||
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 3c9927f..c553138 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml | |||
@@ -70,7 +70,6 @@ | |||
70 | <string name="message_no_configuration_for_network_format">沒有找到網路“%1$s”的配置。</string> | 70 | <string name="message_no_configuration_for_network_format">沒有找到網路“%1$s”的配置。</string> |
71 | <string name="message_network_config_not_found_format">在“%1$s”找不到網路配置檔案。</string> | 71 | <string name="message_network_config_not_found_format">在“%1$s”找不到網路配置檔案。</string> |
72 | <string name="message_network_config_invalid_format">network.conf 中的網路配置無效:\n\n%1$s</string> | 72 | <string name="message_network_config_invalid_format">network.conf 中的網路配置無效:\n\n%1$s</string> |
73 | <string name="message_no_qr_code_scanner">無法啟動掃描器。\n\n安裝 Barcode Scanner?</string> | ||
74 | <string name="message_encrypting_decrypting_private_keys">加密/解密私鑰</string> | 73 | <string name="message_encrypting_decrypting_private_keys">加密/解密私鑰</string> |
75 | <string name="message_could_not_decrypt_private_keys_format">無法解密私鑰:\n\n%1$s</string> | 74 | <string name="message_could_not_decrypt_private_keys_format">無法解密私鑰:\n\n%1$s</string> |
76 | 75 | ||
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6ac776f..ba0233d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml | |||
@@ -79,7 +79,6 @@ | |||
79 | <string name="message_no_configuration_for_network_format">No configuration has been found for network \"%1$s\".</string> | 79 | <string name="message_no_configuration_for_network_format">No configuration has been found for network \"%1$s\".</string> |
80 | <string name="message_network_config_not_found_format">Network configuration file not found at \"%1$s\".</string> | 80 | <string name="message_network_config_not_found_format">Network configuration file not found at \"%1$s\".</string> |
81 | <string name="message_network_config_invalid_format">Invalid network configuration in network.conf:\n\n%1$s</string> | 81 | <string name="message_network_config_invalid_format">Invalid network configuration in network.conf:\n\n%1$s</string> |
82 | <string name="message_no_qr_code_scanner">No scanner could be started.\n\nInstall Barcode Scanner?</string> | ||
83 | <string name="message_encrypting_decrypting_private_keys">Encrypting/decrypting private keys</string> | 82 | <string name="message_encrypting_decrypting_private_keys">Encrypting/decrypting private keys</string> |
84 | <string name="message_could_not_decrypt_private_keys_format">Could not decrypt private keys:\n\n%1$s</string> | 83 | <string name="message_could_not_decrypt_private_keys_format">Could not decrypt private keys:\n\n%1$s</string> |
85 | <string name="message_storage_unavailable">Storage directory is unavailable.</string> | 84 | <string name="message_storage_unavailable">Storage directory is unavailable.</string> |