增加扫码等功能
This commit is contained in:
parent
0b5ed5a03e
commit
099746292a
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@ -3,9 +3,12 @@
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="../../../../.gradle/caches/transforms-2/files-2.1/1d876133b5a2bd3ea40b131cf9d28edb/jetified-zxing-lite-2.1.1/res/layout/zxl_capture.xml" value="0.14322916666666666" />
|
||||
<entry key="app/src/main/res/layout/custom_capture_activity.xml" value="0.18840579710144928" />
|
||||
<entry key="app/src/main/res/layout/qr_vew.xml" value="0.125" />
|
||||
<entry key="app/src/main/res/layout/qrcode_view.xml" value="0.1421875" />
|
||||
<entry key="res/drawable/ic_launcher_background.xml" value="0.225" />
|
||||
<entry key="res/drawable/qr_background.xml" value="0.153" />
|
||||
<entry key="res/layout/activity_main.xml" value="0.18840579710144928" />
|
||||
</map>
|
||||
</option>
|
||||
|
@ -29,6 +29,9 @@
|
||||
<activity
|
||||
android:name="com.king.zxing.CaptureActivity"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
<activity
|
||||
android:name=".activity.CustomCaptureActivity"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
<!--
|
||||
This activity declaration is merged with the version from the library manifest.
|
||||
It demonstrates how an https redirect can be captured, in addition to or instead of
|
||||
|
@ -138,4 +138,5 @@ dependencies {
|
||||
implementation "com.squareup.okio:okio:2.10.0"
|
||||
implementation 'com.android.volley:volley:1.2.1'
|
||||
implementation 'org.greenrobot:eventbus:3.0.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
}
|
@ -16,6 +16,7 @@ import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.Window;
|
||||
|
||||
import com.fitchgc.jcwallet.activity.CustomCaptureActivity;
|
||||
import com.fitchgc.jcwallet.dialog.QRCodeActivity;
|
||||
import com.google.android.gms.auth.api.signin.GoogleSignIn;
|
||||
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
|
||||
@ -29,7 +30,6 @@ import com.jc.jcfw.JcSDK;
|
||||
import com.jc.jcfw.appauth.AuthStateManager;
|
||||
import com.jc.jcfw.appauth.JConfiguration;
|
||||
import com.king.zxing.CameraScan;
|
||||
import com.king.zxing.CaptureActivity;
|
||||
import com.king.zxing.util.CodeUtils;
|
||||
import com.king.zxing.util.LogUtils;
|
||||
import com.unity3d.player.UnityPlayer;
|
||||
@ -161,8 +161,7 @@ public class MainActivity extends Activity
|
||||
case REQUEST_CODE_SCAN:
|
||||
String result = CameraScan.parseScanResult(data);
|
||||
Log.i(TAG, "scan qrcode with funId: " +funId+ " result: " + result);
|
||||
String jsonStr = String.format("{errcode: 0, data: '%s'}", result);
|
||||
JcSDK.csCallback(funId, jsonStr);
|
||||
JcSDK.scanQrCb(funId, null, result);
|
||||
funId = "";
|
||||
break;
|
||||
case REQUEST_CODE_PHOTO:
|
||||
@ -191,8 +190,21 @@ public class MainActivity extends Activity
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// JcSDK.csCallback(funId, "{errcode: 0, errmsg: 'cancel'}");
|
||||
funId = "";
|
||||
boolean next = false;
|
||||
if (requestCode == REQUEST_CODE_SCAN && data != null) {
|
||||
if (data.getBooleanExtra("localImg", false)) {
|
||||
startPhotoCode(this.funId);
|
||||
next = true;
|
||||
}
|
||||
}
|
||||
if (!next) {
|
||||
// JcSDK.csCallback(funId, "{errcode: 0, errmsg: 'cancel'}");
|
||||
if (requestCode == REQUEST_CODE_SCAN) {
|
||||
JcSDK.scanQrCb(funId, "activity result with code: " + resultCode, null);
|
||||
}
|
||||
funId = "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -345,7 +357,6 @@ public class MainActivity extends Activity
|
||||
@Override
|
||||
public void onPermissionsDenied(int requestCode, List<String> list) {
|
||||
// Some permissions have been denied
|
||||
// ...
|
||||
if (requestCode ==RC_CAMERA && null != funId && !"".equals(funId)) {
|
||||
JcSDK.csCallback(funId, "{errcode: 1, errmsg: 'no camera permission'}");
|
||||
funId = "";
|
||||
@ -356,7 +367,7 @@ public class MainActivity extends Activity
|
||||
|
||||
// begin of qrcode
|
||||
/**
|
||||
* 检测拍摄权限
|
||||
* check if had permission for camera
|
||||
*/
|
||||
@AfterPermissionGranted(RC_CAMERA)
|
||||
private void checkCameraPermissions(){
|
||||
@ -375,11 +386,14 @@ public class MainActivity extends Activity
|
||||
*/
|
||||
private void startScan(String title){
|
||||
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeCustomAnimation(this,R.anim.in,R.anim.out);
|
||||
Intent intent = new Intent(this, CaptureActivity.class);
|
||||
Intent intent = new Intent(this, CustomCaptureActivity.class);
|
||||
// Intent intent = new Intent(this, CaptureActivity.class);
|
||||
intent.putExtra(KEY_TITLE, title);
|
||||
intent.putExtra(KEY_IS_CONTINUOUS, false);
|
||||
this.startActivityForResult(intent, REQUEST_CODE_SCAN, optionsCompat.toBundle());
|
||||
// ActivityCompat.startActivityForResult(this, intent, REQUEST_CODE_SCAN, optionsCompat.toBundle());
|
||||
runOnUiThread(() -> {
|
||||
this.startActivityForResult(intent, REQUEST_CODE_SCAN, optionsCompat.toBundle());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void asyncThread(Runnable runnable){
|
||||
@ -390,16 +404,19 @@ public class MainActivity extends Activity
|
||||
try {
|
||||
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),data.getData());
|
||||
asyncThread(() -> {
|
||||
final String result = CodeUtils.parseCode(bitmap);
|
||||
LogUtils.d("result:" + result);
|
||||
String jsonStr = String.format("{errcode: 0, data: '%s'}", result);
|
||||
JcSDK.csCallback(funId, jsonStr);
|
||||
final String result = CodeUtils.parseQRCode(bitmap);
|
||||
if (null == result || "".equals(result)) {
|
||||
JcSDK.scanQrCb(funId, "no qrdeata", null);
|
||||
} else {
|
||||
LogUtils.d("result:" + result);
|
||||
JcSDK.scanQrCb(funId, null, result);
|
||||
}
|
||||
funId = "";
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JcSDK.csCallback(funId, String.format("{errcode: 1, errmsg: '%s'}", e.toString()));
|
||||
JcSDK.scanQrCb(funId, e.toString(), null);
|
||||
funId = "";
|
||||
}
|
||||
|
||||
@ -411,6 +428,16 @@ public class MainActivity extends Activity
|
||||
checkCameraPermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* start image scan
|
||||
*/
|
||||
public void startPhotoCode(String funId){
|
||||
Intent pickIntent = new Intent(Intent.ACTION_PICK,
|
||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
pickIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
|
||||
startActivityForResult(pickIntent, REQUEST_CODE_PHOTO);
|
||||
}
|
||||
|
||||
// end of qrcode
|
||||
|
||||
public void signWithGoogle(String funId) {
|
||||
|
@ -0,0 +1,46 @@
|
||||
package com.fitchgc.jcwallet.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.fitchgc.jcwallet.R;
|
||||
import com.king.zxing.CaptureActivity;
|
||||
|
||||
import static com.fitchgc.jcwallet.MainActivity.KEY_TITLE;
|
||||
|
||||
public class CustomCaptureActivity extends CaptureActivity {
|
||||
private static final String TAG = CustomCaptureActivity.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.custom_capture_activity;
|
||||
}
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
Intent in = getIntent();
|
||||
String title = in.getStringExtra(KEY_TITLE);
|
||||
Button localBtn = findViewById(R.id.qrLocalBtn);
|
||||
localBtn.setOnClickListener(v -> onClickLocalImg());
|
||||
TextView titleLabel = findViewById(R.id.scanQrTitleLabel);
|
||||
titleLabel.setText(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initCameraScan() {
|
||||
super.initCameraScan();
|
||||
getCameraScan()
|
||||
.setPlayBeep(true)
|
||||
.setVibrate(true);
|
||||
}
|
||||
|
||||
protected void onClickLocalImg(){
|
||||
Intent ins=new Intent();
|
||||
ins.putExtra("localImg", true);
|
||||
setResult(1, ins);
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package com.fitchgc.jcwallet.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
@ -11,7 +11,7 @@ import com.fitchgc.jcwallet.MainActivity;
|
||||
import com.fitchgc.jcwallet.R;
|
||||
import com.king.zxing.util.CodeUtils;
|
||||
|
||||
public class QRCodeActivity extends BaseDialog{
|
||||
public class QRCodeActivity extends Dialog {
|
||||
|
||||
private final Context baseContent;
|
||||
private TextView titleLabel;
|
||||
@ -19,7 +19,7 @@ public class QRCodeActivity extends BaseDialog{
|
||||
|
||||
|
||||
public QRCodeActivity(Context context) {
|
||||
super(context);
|
||||
super(context, R.style.DialogStyle);
|
||||
baseContent = context;
|
||||
}
|
||||
|
||||
@ -33,8 +33,8 @@ public class QRCodeActivity extends BaseDialog{
|
||||
|
||||
public void showQRCode(String content, String title){
|
||||
new Thread(() -> {
|
||||
Bitmap logo = BitmapFactory.decodeResource(baseContent.getResources(),R.drawable.zxl_flashlight_on);
|
||||
Bitmap bitmap = CodeUtils.createQRCode(content,600, logo);
|
||||
// Bitmap logo = BitmapFactory.decodeResource(baseContent.getResources(),R.drawable.zxl_flashlight_on);
|
||||
Bitmap bitmap = CodeUtils.createQRCode(content,600, null);
|
||||
MainActivity.app.runOnUiThread(()->{
|
||||
titleLabel.setText(title);
|
||||
ivCode.setImageBitmap(bitmap);
|
||||
|
@ -83,7 +83,6 @@ public class JcSDK {
|
||||
public static void googleOauthCb(String funId, String error, String idToken) {
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
|
||||
if (error != "" && null != error) {
|
||||
result.put("errocde", 1);
|
||||
result.put("errmessage", error);
|
||||
@ -98,4 +97,22 @@ public class JcSDK {
|
||||
String methodName = "jniCallback";
|
||||
JcSDK.runJS(funId, methodName, result.toString());
|
||||
}
|
||||
|
||||
public static void scanQrCb(String funId, String error, String data) {
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
if (error != "" && null != error) {
|
||||
result.put("errocde", 1);
|
||||
result.put("errmessage", error);
|
||||
} else {
|
||||
result.put("errocde", 0);
|
||||
result.put("data", data);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String methodName = "jniCallback";
|
||||
JcSDK.runJS(funId, methodName, result.toString());
|
||||
}
|
||||
}
|
||||
|
58
app/src/main/res/layout/custom_capture_activity.xml
Normal file
58
app/src/main/res/layout/custom_capture_activity.xml
Normal file
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
<androidx.camera.view.PreviewView
|
||||
android:id="@+id/previewView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
<com.king.zxing.ViewfinderView
|
||||
android:id="@+id/viewfinderView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:labelText="@string/tips_scan_code"
|
||||
app:laserColor="@color/colorAccent"
|
||||
app:frameColor="@color/colorPrimary"
|
||||
app:cornerColor="@color/colorPrimary"
|
||||
app:labelTextLocation="bottom"
|
||||
app:laserStyle="grid" />
|
||||
<ImageView
|
||||
android:id="@+id/ivFlashlight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/flash_selected_selector"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginTop="160dp" />
|
||||
<TextView
|
||||
android:id="@+id/scanQrTitleLabel"
|
||||
android:text="sample label"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_marginTop="210dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/qrLocalBtn"
|
||||
android:text="Select Image Local"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginTop="300dp"
|
||||
android:textColor="@color/white"
|
||||
/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout 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:background="@drawable/qr_background"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
@ -15,7 +14,7 @@
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/qrTitleLabel"
|
||||
android:text="假装是 APP 主页"
|
||||
android:text="sample label"
|
||||
android:gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
BIN
res/drawable/flash_off.png
Normal file
BIN
res/drawable/flash_off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
res/drawable/flash_on.png
Normal file
BIN
res/drawable/flash_on.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
5
res/drawable/flash_selected_selector.xml
Normal file
5
res/drawable/flash_selected_selector.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_selected="true" android:drawable="@drawable/flash_on"/>
|
||||
<item android:state_selected="false" android:drawable="@drawable/flash_off"/>
|
||||
</selector>
|
10
res/drawable/qr_background.xml
Normal file
10
res/drawable/qr_background.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<solid android:color="#FFFFFF" />
|
||||
|
||||
<stroke
|
||||
android:width="0.01dp"
|
||||
android:color="#BFBFBF" />
|
||||
|
||||
</shape>
|
@ -4,4 +4,5 @@
|
||||
<string name="permission_camera">Scan QRCode need camera permission</string>
|
||||
<string name="qr_code_title">QRCode</string>
|
||||
<string name="default_web_client_id">165555585193-j22geb66hjku5ns5lq5voaj4v7811cl7.apps.googleusercontent.com</string>
|
||||
<string name="tips_scan_code"></string>
|
||||
</resources>
|
@ -11,10 +11,10 @@
|
||||
</style>
|
||||
<style name="DialogStyle" parent="@android:style/Theme.Dialog">
|
||||
<item name="android:windowFrame">@null</item>
|
||||
<item name="android:windowBackground">@color/transparent</item>
|
||||
<item name="android:windowBackground">@color/white</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="android:windowIsFloating">false</item>
|
||||
<item name="android:windowContentOverlay">@color/white</item>
|
||||
</style>
|
||||
<style name="Dialog_bottom_enter_ani">
|
||||
<item name="android:windowEnterAnimation">@anim/dlg_enter</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user