Skip to content

Commit

Permalink
android: gen qrcode iamge.
Browse files Browse the repository at this point in the history
  • Loading branch information
syalon committed Sep 20, 2019
1 parent d2f6e9e commit 94f9002
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 38 deletions.
2 changes: 0 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
3 changes: 0 additions & 3 deletions android/app/src/main/java/bitshares/OrgUtils.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
55 changes: 38 additions & 17 deletions android/app/src/main/java/bitshares/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
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
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
Expand Down Expand Up @@ -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<EncodeHintType, Any>()
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
}

Expand Down
5 changes: 3 additions & 2 deletions android/app/src/main/java/bitshares/WalletManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> { name->
extra_account_name_list.forEach<String> { name ->
if (name!! != currentAccountName) {
extraNameHash.put(name, true)
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ActivityScanResultPrivateKey : BtsppActivity() {
findViewById<TextView>(R.id.txt_account_id).text = account_data.getString("id")
findViewById<TextView>(R.id.txt_account_name).text = account_data.getString("name")
findViewById<TextView>(R.id.txt_private_key_type).let {
it.text = priKeyTypeArray.join(" ")
it.text = priKeyTypeArray.toList<String>().joinToString(" ")
}

// 初始化钱包密码(可选)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

// 四个角落的三角
Expand Down
3 changes: 1 addition & 2 deletions android/app/src/main/res/layout/activity_index_services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,13 @@
android:layout_marginTop="30dp"
android:orientation="horizontal">

<!-- TODO:3.0 图标 -->
<ImageView
android:id="@+id/img_icon_qrscan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:src="@drawable/icon_transfer"/>
android:src="@drawable/icon_scan"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/layout/activity_qr_scan.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

<Button
android:id="@+id/btn_album"
android:layout_width="48dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#00000000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@
android:layout_marginTop="15dp"
android:gravity="center"
android:orientation="horizontal">
<!-- TOOD:3.0图标 -->
<ImageView
android:id="@+id/img_pay_success"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:src="@drawable/avatar"/>
android:src="@drawable/paysuccess"/>
</LinearLayout>

<!-- 支付成功Text -->
Expand Down

0 comments on commit 94f9002

Please sign in to comment.