diff --git a/android/app/build.gradle b/android/app/build.gradle index 804f8143..3d7ea62c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -98,8 +98,6 @@ dependencies { // for wallet core implementation files('libs/armeabi-v7a.jar') implementation files('libs/x86.jar') - // for gen qrcode -// implementation 'com.github.qingmei2:QrCodeScannerView-Android:1.1.2' // for flurry implementation 'com.flurry.android:analytics:11.6.0@aar' } diff --git a/android/app/src/main/java/bitshares/OrgUtils.kt b/android/app/src/main/java/bitshares/OrgUtils.kt index fdbcce28..bc93041e 100644 --- a/android/app/src/main/java/bitshares/OrgUtils.kt +++ b/android/app/src/main/java/bitshares/OrgUtils.kt @@ -1,13 +1,10 @@ package bitshares -import android.app.Activity import android.content.Context -import android.os.Build import android.os.Looper import com.btsplusplus.fowallet.BuildConfig import com.btsplusplus.fowallet.NativeInterface import com.btsplusplus.fowallet.R -import com.btsplusplus.fowallet.showToast import com.btsplusplus.fowallet.utils.BigDecimalHandler import com.crashlytics.android.Crashlytics import com.fowallet.walletcore.bts.ChainObjectManager diff --git a/android/app/src/main/java/bitshares/Utils.kt b/android/app/src/main/java/bitshares/Utils.kt index 7bcab6db..213b0aa7 100644 --- a/android/app/src/main/java/bitshares/Utils.kt +++ b/android/app/src/main/java/bitshares/Utils.kt @@ -1,20 +1,22 @@ package bitshares -import android.app.Activity import android.content.ClipData import android.content.ClipboardManager import android.content.Context import android.content.Context.CLIPBOARD_SERVICE -import android.content.pm.PackageManager import android.content.res.Resources +import android.graphics.Bitmap import android.net.ConnectivityManager import android.net.wifi.WifiManager import android.telephony.TelephonyManager import android.util.TypedValue -import android.widget.ImageView import com.btsplusplus.fowallet.BuildConfig import com.btsplusplus.fowallet.R -//import com.qingmei2.library.encode.QRCodeEncoder +import com.google.zxing.BarcodeFormat +import com.google.zxing.EncodeHintType +import com.google.zxing.MultiFormatWriter +import com.google.zxing.common.CharacterSetECI +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel import org.json.JSONArray import org.json.JSONObject import java.io.BufferedReader @@ -22,6 +24,7 @@ import java.io.InputStreamReader import java.math.BigDecimal import java.text.SimpleDateFormat import java.util.* +import kotlin.collections.HashMap import kotlin.math.floor import kotlin.math.max import kotlin.math.min @@ -583,23 +586,41 @@ class Utils { /** * 创建二维码到 ImageView */ - fun createQRCodeImage(ctx: Context, text: String, out_image_view: ImageView) { - // TODO:3.0 -// //构造方法: -// val qrcode = QRCodeEncoder(ctx as Activity) -// -// qrcode.createQrCode2ImageView(text, out_image_view) + private fun createQRBitmap(text: String, width: Int): Bitmap? { + try { + val hints = HashMap() + hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.H + hints[EncodeHintType.CHARACTER_SET] = CharacterSetECI.UTF8 + hints[EncodeHintType.MARGIN] = 1 - //生成带Icon的二维码 - // qrCodeEncoder.createQrCode2ImageView(textContent, ivQRCode, R.mipmap.ic_launcher) + val bitMatrix = MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, width, hints) + + val h = bitMatrix.height + val w = bitMatrix.width + + val black = 0xFF000000.toInt() + val white = 0xFFFFFFFF.toInt() + val pixels = IntArray(w * h) + for (y in 0 until h) { + for (x in 0 until w) { + pixels[y * w + x] = if (bitMatrix.get(x, y)) black else white + } + } + + val bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565) + bitmap.setPixels(pixels, 0, w, 0, 0, w, h) + + return bitmap + } catch (e: Exception) { + return null + } } - fun asyncCreateQRBitmap(ctx: Context, text: String, width: Int): Promise { + fun asyncCreateQRBitmap(text: String, width: Int): Promise { val p = Promise() - // TODO:3.0 -// Thread(Runnable { -// p.resolve(QRCodeEncoder(ctx as Activity).createQrCode(text, width)) -// }).start() + Thread(Runnable { + p.resolve(createQRBitmap(text, width)) + }).start() return p } diff --git a/android/app/src/main/java/bitshares/WalletManager.kt b/android/app/src/main/java/bitshares/WalletManager.kt index 7753e011..909a058c 100644 --- a/android/app/src/main/java/bitshares/WalletManager.kt +++ b/android/app/src/main/java/bitshares/WalletManager.kt @@ -345,7 +345,7 @@ class WalletManager { account_name_list.put(currentAccountName) if (extra_account_name_list != null && extra_account_name_list.length() > 0) { val extraNameHash = JSONObject() - extra_account_name_list.forEach { name-> + extra_account_name_list.forEach { name -> if (name!! != currentAccountName) { extraNameHash.put(name, true) } @@ -365,7 +365,8 @@ class WalletManager { assert(unlockInfos.getBoolean("unlockSuccess") && unlockInfos.optBoolean("haveActivePermission")) // [统计] - btsppLogCustom("loginEvent", jsonObjectfromKVS("mode", login_mode.value, "desc", login_desc ?: "unknown")) + btsppLogCustom("loginEvent", jsonObjectfromKVS("mode", login_mode.value, "desc", login_desc + ?: "unknown")) // 成功 return EImportToWalletStatus.eitws_ok diff --git a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityDepositAndWithdraw.kt b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityDepositAndWithdraw.kt index 6a38a3e9..237eebc8 100644 --- a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityDepositAndWithdraw.kt +++ b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityDepositAndWithdraw.kt @@ -489,7 +489,7 @@ class ActivityDepositAndWithdraw : BtsppActivity() { } val deposit_item = it as JSONObject // create qrcode - Utils.asyncCreateQRBitmap(ctx, deposit_item.optString("inputAddress"), 150.dp).then { btm -> + Utils.asyncCreateQRBitmap(deposit_item.optString("inputAddress"), 150.dp).then { btm -> mask.dismiss() // 转到充币界面 goTo(ActivityGatewayDeposit::class.java, true, args = JSONObject().apply { diff --git a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityIndexServices.kt b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityIndexServices.kt index a7d9ff9f..823a20b8 100644 --- a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityIndexServices.kt +++ b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityIndexServices.kt @@ -3,7 +3,10 @@ package com.btsplusplus.fowallet import android.Manifest import android.os.Bundle import android.view.View -import bitshares.* +import bitshares.Promise +import bitshares.TempManager +import bitshares.jsonObjectfromKVS +import bitshares.xmlstring import com.fowallet.walletcore.bts.ChainObjectManager import com.fowallet.walletcore.bts.WalletManager import kotlinx.android.synthetic.main.activity_index_services.* diff --git a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanAccountName.kt b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanAccountName.kt index 7076ff50..80afe75a 100644 --- a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanAccountName.kt +++ b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanAccountName.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.widget.Button import android.widget.TextView import bitshares.Promise -import bitshares.jsonArrayfrom import bitshares.jsonObjectfromKVS import bitshares.xmlstring import com.fowallet.walletcore.bts.ChainObjectManager diff --git a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultPaySuccess.kt b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultPaySuccess.kt index 51ba7d70..e388994f 100644 --- a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultPaySuccess.kt +++ b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultPaySuccess.kt @@ -1,8 +1,6 @@ package com.btsplusplus.fowallet import android.os.Bundle -import bitshares.OrgUtils -import bitshares.Utils import kotlinx.android.synthetic.main.activity_scan_result_pay_success.* class ActivityScanResultPaySuccess : BtsppActivity() { diff --git a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultPrivateKey.kt b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultPrivateKey.kt index 301ae64c..8c889c94 100644 --- a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultPrivateKey.kt +++ b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultPrivateKey.kt @@ -63,7 +63,7 @@ class ActivityScanResultPrivateKey : BtsppActivity() { findViewById(R.id.txt_account_id).text = account_data.getString("id") findViewById(R.id.txt_account_name).text = account_data.getString("name") findViewById(R.id.txt_private_key_type).let { - it.text = priKeyTypeArray.join(" ") + it.text = priKeyTypeArray.toList().joinToString(" ") } // 初始化钱包密码(可选) diff --git a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultTransfer.kt b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultTransfer.kt index a338d707..497f44ae 100644 --- a/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultTransfer.kt +++ b/android/app/src/main/java/com/btsplusplus/fowallet/ActivityScanResultTransfer.kt @@ -3,7 +3,6 @@ package com.btsplusplus.fowallet import android.os.Bundle import android.view.View import android.widget.EditText -import android.widget.LinearLayout import bitshares.* import com.fowallet.walletcore.bts.BitsharesClientManager import com.fowallet.walletcore.bts.ChainObjectManager @@ -300,7 +299,7 @@ class ActivityScanResultTransfer : BtsppActivity() { return true } - private fun _processTransferCore(transfer_asset: JSONObject, transfer_n_amount:BigDecimal, op_data:JSONObject, full_account_data: JSONObject) { + private fun _processTransferCore(transfer_asset: JSONObject, transfer_n_amount: BigDecimal, op_data: JSONObject, full_account_data: JSONObject) { // 请求网络广播 val mask = ViewMask(R.string.kTipsBeRequesting.xmlstring(this), this) mask.show() diff --git a/android/app/src/main/java/com/google/zxing/client/android/AutoScannerView.java b/android/app/src/main/java/com/google/zxing/client/android/AutoScannerView.java index dade1fcb..f01bd38d 100644 --- a/android/app/src/main/java/com/google/zxing/client/android/AutoScannerView.java +++ b/android/app/src/main/java/com/google/zxing/client/android/AutoScannerView.java @@ -81,7 +81,7 @@ protected void onDraw(Canvas canvas) { canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, maskPaint); canvas.drawRect(0, frame.bottom + 1, width, height, maskPaint); - String text = "将二维码放入框内,即可自动扫描"; + String text = getResources().getString(R.string.kVcScanAutoScanTips); canvas.drawText(text, (width - textPaint.measureText(text)) / 2, frame.bottom + textMarinTop, textPaint); // 四个角落的三角 diff --git a/android/app/src/main/res/layout/activity_index_services.xml b/android/app/src/main/res/layout/activity_index_services.xml index 5558d60f..4369b885 100644 --- a/android/app/src/main/res/layout/activity_index_services.xml +++ b/android/app/src/main/res/layout/activity_index_services.xml @@ -114,14 +114,13 @@ android:layout_marginTop="30dp" android:orientation="horizontal"> - + android:src="@drawable/icon_scan"/> - + android:src="@drawable/paysuccess"/>