|
@@ -1,15 +1,15 @@
|
|
|
package com.zzliaoyuan.power_sensor.activity;
|
|
|
|
|
|
import android.Manifest;
|
|
|
-import android.app.ActionBar;
|
|
|
-import android.app.ProgressDialog;
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
import android.media.AudioManager;
|
|
|
import android.media.SoundPool;
|
|
|
-import android.os.AsyncTask;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Environment;
|
|
|
import android.util.Log;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.widget.Toast;
|
|
@@ -17,20 +17,18 @@ import android.widget.Toast;
|
|
|
import com.facebook.react.ReactActivity;
|
|
|
import com.facebook.react.ReactActivityDelegate;
|
|
|
import com.facebook.react.ReactRootView;
|
|
|
-import com.github.dfqin.grantor.PermissionListener;
|
|
|
-import com.github.dfqin.grantor.PermissionsUtil;
|
|
|
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import androidx.annotation.NonNull;
|
|
|
|
|
|
import com.zzliaoyuan.power_sensor.MainApplication;
|
|
|
import com.zzliaoyuan.power_sensor.R;
|
|
|
import com.rscja.deviceapi.RFIDWithUHFUART;
|
|
|
import com.zzliaoyuan.power_sensor.fragment.UHFReadTagFragment;
|
|
|
+import com.zzliaoyuan.rifdmastercore.LibCore;
|
|
|
|
|
|
public class MainActivity extends ReactActivity {
|
|
|
/**
|
|
@@ -50,10 +48,7 @@ public class MainActivity extends ReactActivity {
|
|
|
|
|
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // 禁用横屏
|
|
|
|
|
|
-// requirePerms();
|
|
|
- initSound();
|
|
|
- initUHF();
|
|
|
- UHFReadTagFragment.getInstance().setContext(this);
|
|
|
+ checkLicense();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -66,9 +61,10 @@ public class MainActivity extends ReactActivity {
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
- if (keyCode == 139 ||keyCode == 280) {
|
|
|
+ if (keyCode == 139 || keyCode == 280) {
|
|
|
|
|
|
if (event.getRepeatCount() == 0) {
|
|
|
UHFReadTagFragment.getInstance().myOnKeyDwon();
|
|
@@ -78,17 +74,94 @@ public class MainActivity extends ReactActivity {
|
|
|
}
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
}
|
|
|
+
|
|
|
+ public void checkLicense() {
|
|
|
+ // 生成机器码
|
|
|
+ String macCode = null;
|
|
|
+ String serialNumber = "ZZLY_" + Build.SERIAL;
|
|
|
+ MessageDigest md = null;
|
|
|
+ byte[] bt = serialNumber.getBytes();
|
|
|
+ try {
|
|
|
+ md = MessageDigest.getInstance("SHA-256");
|
|
|
+ md.update(bt);
|
|
|
+ macCode = bytes2Hex(md.digest());
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 读取授权文件
|
|
|
+ StringBuilder sb = new StringBuilder("");
|
|
|
+ try {
|
|
|
+ String filename = Environment.getExternalStorageDirectory().getCanonicalPath() + "/rfidmaster.lic";
|
|
|
+ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
|
|
+ FileInputStream input = new FileInputStream(filename);
|
|
|
+ byte[] temp = new byte[1024];
|
|
|
+
|
|
|
+ int len = 0;
|
|
|
+ while ((len = input.read(temp)) > 0) {
|
|
|
+ sb.append(new String(temp, 0, len));
|
|
|
+ }
|
|
|
+ input.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ String licenseCode = sb.toString().trim();
|
|
|
+ boolean ret = LibCore.verifyLicense(macCode, licenseCode);
|
|
|
+ if (ret) {
|
|
|
+ initSound();
|
|
|
+ initUHF();
|
|
|
+ UHFReadTagFragment.getInstance().setContext(this);
|
|
|
+ } else {
|
|
|
+ final AlertDialog.Builder normalDialog = new AlertDialog.Builder(this);
|
|
|
+// normalDialog.setTitle("电金晴");
|
|
|
+ normalDialog.setMessage("掌机认证失败,请联系供应商!");
|
|
|
+ normalDialog.setPositiveButton("确定",
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ System.exit(0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ normalDialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * byte数组转换为16进制字符串
|
|
|
+ *
|
|
|
+ * @param bts 数据源
|
|
|
+ * @return 16进制字符串
|
|
|
+ */
|
|
|
+ public static String bytes2Hex(byte[] bts) {
|
|
|
+ String des = "";
|
|
|
+ String tmp = null;
|
|
|
+ for (int i = 0; i < bts.length; i++) {
|
|
|
+ tmp = (Integer.toHexString(bts[i] & 0xFF));
|
|
|
+ if (tmp.length() == 1) {
|
|
|
+ des += "0";
|
|
|
+ }
|
|
|
+ des += tmp;
|
|
|
+ }
|
|
|
+ return des;
|
|
|
+ }
|
|
|
+
|
|
|
// 初始化声音
|
|
|
HashMap<Integer, Integer> soundMap = new HashMap<Integer, Integer>();
|
|
|
private SoundPool soundPool;
|
|
|
private float volumnRatio;
|
|
|
private AudioManager am;
|
|
|
- private void initSound(){
|
|
|
+
|
|
|
+ private void initSound() {
|
|
|
soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 5);
|
|
|
soundMap.put(1, soundPool.load(this, R.raw.barcodebeep, 1));
|
|
|
soundMap.put(2, soundPool.load(this, R.raw.serror, 1));
|
|
|
am = (AudioManager) this.getSystemService(AUDIO_SERVICE);// 实例化AudioManager对象
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 播放提示音
|
|
|
*
|
|
@@ -143,23 +216,4 @@ public class MainActivity extends ReactActivity {
|
|
|
super.onDestroy();
|
|
|
}
|
|
|
|
|
|
- private void requirePerms() {
|
|
|
- String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE};
|
|
|
- if (!PermissionsUtil.hasPermission(this, permissions)) {
|
|
|
- PermissionsUtil.requestPermission(this, new PermissionListener() {
|
|
|
- @Override
|
|
|
- public void permissionGranted(@NonNull String[] permissions) {
|
|
|
- //用户授予了权限
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void permissionDenied(@NonNull String[] permissions) {
|
|
|
- //用户拒绝了申请
|
|
|
- Toast.makeText(MainActivity.this, "您拒绝了相机相关的权限,将无法使用部分功能!", Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
- }, permissions);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|