Skip to content

Commit

Permalink
add qr code module
Browse files Browse the repository at this point in the history
  • Loading branch information
huzongyao committed Feb 21, 2019
1 parent 1da70b4 commit d999875
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ A Weex android framework just based like weex playground based on weex sdk
* implement IWXHttpAdapter with OkHttpClient, so we can use cache to speed up.
* implement IWXImgLoaderAdapter with Glide, so it will support gif and also function well.
* implement IWebSocketAdapter with OkHttp WebSocket.
* Add imagePicker module to pick some images
* Add qrCode module to scan and generate QR code

### About Me
* GitHub: [http://huzongyao.github.io/](http://huzongyao.github.io/)
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies {
implementation 'com.taobao.android:weex_sdk:0.20.0.2'
implementation 'cn.bingoogolapple:bga-qrcode-zxing:1.3.6'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'com.blankj:utilcode:1.23.1'
implementation 'com.blankj:utilcode:1.23.4'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.8.0'
implementation('com.alibaba:arouter-api:1.4.1') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hzy.weex.frame.activity;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
Expand All @@ -12,6 +11,7 @@
import android.widget.ImageView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.constant.PermissionConstants;
import com.blankj.utilcode.util.PermissionUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.hzy.weex.frame.R;
Expand Down Expand Up @@ -80,7 +80,7 @@ protected void onStart() {
}

private void startCameraAndSpot() {
PermissionUtils.permission(Manifest.permission.CAMERA)
PermissionUtils.permission(PermissionConstants.CAMERA)
.callback(new PermissionUtils.SimpleCallback() {
@Override
public void onGranted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
Expand Down Expand Up @@ -48,7 +47,6 @@ public void onAnimationRepeat(Animation animation) {

@Override
public void onAnimationEnd(Animation animation) {
mBackImage.setVisibility(View.GONE);
startWxPageAndFinish();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public class RequestCode {
public static final int REQUEST_CODE_SCAN_BY_WX = 101;
public static final int REQUEST_CODE_PICK_IMAGE = 102;
public static final int REQUEST_CODE_TAKE_PHOTO = 103;
public static final int REQUEST_CODE_MODULE_QR_SCAN = 104;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.hzy.weex.frame.weex.module.component.RichText;
import com.hzy.weex.frame.weex.module.imgpicker.ImagePickerModule;
import com.hzy.weex.frame.weex.module.location.GeolocationModule;
import com.hzy.weex.frame.weex.module.qrcode.QRCodeModule;
import com.taobao.weex.WXSDKEngine;

public class WXModuleManager {
Expand All @@ -14,6 +15,7 @@ public static void initialize() {
WXSDKEngine.registerModule("imagePicker", ImagePickerModule.class);
// 覆盖原来的WXNavigatorModule, 防止intent category和别人的一样
WXSDKEngine.registerModule("navigator", ExNavigatorModule.class);
WXSDKEngine.registerModule("qrCode", QRCodeModule.class);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hzy.weex.frame.weex.module.imgpicker;

import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
Expand All @@ -9,6 +8,7 @@
import android.os.Build;
import android.provider.MediaStore;

import com.blankj.utilcode.constant.PermissionConstants;
import com.blankj.utilcode.util.PermissionUtils;
import com.blankj.utilcode.util.UriUtils;
import com.hzy.weex.frame.R;
Expand Down Expand Up @@ -51,7 +51,7 @@ public ImagePickerModule() {
@SuppressWarnings("unused")
public boolean pickImage(Map<String, Object> options, final JSCallback callback) {
Context context = mWXSDKInstance.getContext();
if (context == null || !(context instanceof Activity)) {
if (!(context instanceof Activity)) {
return false;
}
try {
Expand Down Expand Up @@ -83,7 +83,7 @@ public boolean pickImage(Map<String, Object> options, final JSCallback callback)
@SuppressWarnings("unused")
public boolean takePhoto(Map<String, Object> options, final JSCallback callback) {
Context context = mWXSDKInstance.getContext();
if (context == null || !(context instanceof Activity)) {
if (!(context instanceof Activity)) {
return false;
}
try {
Expand Down Expand Up @@ -143,7 +143,7 @@ private void onImageResult() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void compressImageAsync() {
String outPath = ImagePickerHelper.INSTANCE.newPrivateImagePath();
PermissionUtils.permission(Manifest.permission.READ_EXTERNAL_STORAGE)
PermissionUtils.permission(PermissionConstants.STORAGE)
.callback(new PermissionUtils.SimpleCallback() {
@Override
public void onGranted() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.hzy.weex.frame.weex.module.qrcode;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.hzy.weex.frame.activity.QRScanActivity;
import com.hzy.weex.frame.constant.AppConfig;
import com.hzy.weex.frame.constant.RequestCode;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.bridge.JSCallback;
import com.taobao.weex.common.WXModule;

import java.util.Map;

public class QRCodeModule extends WXModule {

private Map<String, Object> mScanOptions;
private JSCallback mCallback;

@JSMethod
@SuppressWarnings("unused")
public boolean startScan(Map<String, Object> options, final JSCallback callback) {
Context context = mWXSDKInstance.getContext();
if (!(context instanceof Activity)) {
return false;
}
try {
mScanOptions = options;
Activity activity = (Activity) context;
Intent intent = new Intent(activity, QRScanActivity.class);
if (intent.resolveActivity(activity.getPackageManager()) != null) {
activity.startActivityForResult(intent, RequestCode.REQUEST_CODE_MODULE_QR_SCAN);
mCallback = callback;
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RequestCode.REQUEST_CODE_MODULE_QR_SCAN) {
if (resultCode == Activity.RESULT_OK && data != null) {
String content = data.getStringExtra(QRScanActivity.EXTRA_CONTENT);
if (!StringUtils.isTrimEmpty(content)) {
if (AppConfig.DEBUG) {
ToastUtils.showShort(content);
}
JSONObject result = new JSONObject();
result.put("content", content);
if (mCallback != null) {
mCallback.invoke(result);
}
return;
}
}
if (mCallback != null) {
mCallback.invoke(null);
}
}
}
}
25 changes: 19 additions & 6 deletions app/src/main/res/anim/splash_back_anim.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000">
android:fillAfter="true">
<translate
android:fromXDelta="0"
android:toXDelta="-25%" />
android:duration="3000"
android:fromXDelta="-20%"
android:toXDelta="-5%" />
<scale
android:duration="3000"
android:fromXScale="1"
android:fromYScale="1"
android:toXScale="1.1"
android:toYScale="1.1" />
android:toXScale="1.2"
android:toYScale="1.2" />
<alpha
android:duration="3000"
android:fromAlpha="1"
android:toAlpha="0.6" />
android:toAlpha="0.7" />
<alpha
android:duration="1000"
android:fromAlpha="0.7"
android:startOffset="3000"
android:toAlpha="1" />
<alpha
android:duration="1000"
android:fromAlpha="1"
android:startOffset="4000"
android:toAlpha="1" />
</set>
9 changes: 5 additions & 4 deletions app/src/main/res/anim/splash_text_anim.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000">
android:duration="3000"
android:fillAfter="true">
<scale
android:fromXScale="0.8"
android:fromYScale="0.8"
android:fromXScale="0.4"
android:fromYScale="0.4"
android:toXScale="1"
android:toYScale="1" />
<alpha
android:fromAlpha="0.3"
android:fromAlpha="0.2"
android:toAlpha="1" />
</set>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_splash.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
android:layout_marginTop="80dp"
android:text="@string/app_name"
android:textColor="#EE9572"
android:textSize="28sp" />
android:textSize="48sp" />

</FrameLayout>

0 comments on commit d999875

Please sign in to comment.