From 3da57d493d767b33aa0f4d9d00de3001af6aaa0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Thu, 22 Aug 2024 13:57:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=88=E6=9D=83=E5=8A=9F=E8=83=BD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 8 + .../bonait/bnframework/business/MainInit.java | 4 + .../common/constant/ConfigName.java | 20 +- .../bnframework/common/db/file/DBHelper.java | 2 + .../common/db/mode/BPA_AUTHORIZE.java | 11 + .../bonait/bnframework/common/helper/AES.java | 33 +- .../common/helper/AuthorizeHelper.java | 425 ++++++++++++++++++ .../bnframework/common/helper/SdCart.java | 8 + .../activity/BottomNavigation2Activity.java | 61 ++- .../activity/BottomNavigationNewActivity.java | 3 + .../modules/home/fragment/Home2Fragment.java | 16 +- .../modules/home/fragment/Home4Fragment.java | 27 +- .../home/fragment/HomeFragmentSBKZ.java | 11 + .../ui/dialog/EditGoodsDialog.java | 2 + .../ui/fragment/goods/LocalGoodsFragment.java | 9 +- app/src/main/res/drawable/btn_authorize.xml | 10 + app/src/main/res/drawable/input_bj.xml | 2 +- app/src/main/res/layout/fragment_home4.xml | 17 + .../layout/item/layout/layout_authority.xml | 116 +++++ 19 files changed, 732 insertions(+), 53 deletions(-) create mode 100644 app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_AUTHORIZE.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/AuthorizeHelper.java create mode 100644 app/src/main/res/drawable/btn_authorize.xml create mode 100644 app/src/main/res/layout/item/layout/layout_authority.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index e9a58ca7..cae5d557 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/business/MainInit.java b/app/src/main/java/com/bonait/bnframework/business/MainInit.java index c0e305b8..cd19c7d5 100644 --- a/app/src/main/java/com/bonait/bnframework/business/MainInit.java +++ b/app/src/main/java/com/bonait/bnframework/business/MainInit.java @@ -31,6 +31,7 @@ import com.bonait.bnframework.common.db.mode.BPA_SILOS_CALIBRATE; import com.bonait.bnframework.common.db.mode.BPA_USER; import com.bonait.bnframework.common.db.res.AlertLogEnum; import com.bonait.bnframework.common.db.res.UserLogEnum; +import com.bonait.bnframework.common.helper.AuthorizeHelper; import com.bonait.bnframework.common.helper.CrashHandler; import com.bonait.bnframework.common.helper.I.IMessageLogNotify; import com.bonait.bnframework.common.helper.LogcatHelper; @@ -84,6 +85,9 @@ public class MainInit { //2.初始化SD卡,数据库DB SdCart.getInstance().initSD(); + //3.授权检查 + AuthorizeHelper.AuthorizeVerify(); + //4.初始化Main,并且增加本地图片库 ConfigData.getInstance().AddImage(app); // activity生命周期管理 diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java index 4b23b9e0..dade58b0 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java @@ -97,7 +97,25 @@ public class ConfigName { /** * Db文件路径 */ - public static String dbPath = ""; + public String dbPath = ""; + /** + * 授权文件路径 + */ + public String AuthorizeCodePath=""; + + /** + * 当前授权码 + */ + public String CurrentAuthorizeCode=""; + + /** + * 验证是否已经授权 + */ + public boolean IsAuthorize=false; + /** + * 是否显示授权提醒 + */ + public boolean IsVisibleAuthorize=false; //endregion //region 店铺配置 diff --git a/app/src/main/java/com/bonait/bnframework/common/db/file/DBHelper.java b/app/src/main/java/com/bonait/bnframework/common/db/file/DBHelper.java index 113bb81e..56c4227b 100644 --- a/app/src/main/java/com/bonait/bnframework/common/db/file/DBHelper.java +++ b/app/src/main/java/com/bonait/bnframework/common/db/file/DBHelper.java @@ -9,6 +9,7 @@ import com.apkfuns.logutils.LogUtils; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_ATTRIBUTE; +import com.bonait.bnframework.common.db.mode.BPA_AUTHORIZE; import com.bonait.bnframework.common.db.mode.BPA_CLOUDDATA; import com.bonait.bnframework.common.db.mode.BPA_GOODS_CLASSIFY; import com.bonait.bnframework.common.db.mode.BPA_GOODS_PROCESS_DETAIL; @@ -153,6 +154,7 @@ public class DBHelper extends SQLiteOpenHelper { CreateTablesAll(BPA_ORDER_LIST.class,null);//子属性 CreateTablesAll(BPA_PROPERTY_CLASSIFY.class,null);//属性分类表 CreateTablesAll(BPA_MATERIAL_TYPE.class,null);//物料分类表 + CreateTablesAll(BPA_AUTHORIZE.class,null);//物料分类表 ForeignKeys(); } /** diff --git a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_AUTHORIZE.java b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_AUTHORIZE.java new file mode 100644 index 00000000..7ebca990 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_AUTHORIZE.java @@ -0,0 +1,11 @@ +package com.bonait.bnframework.common.db.mode; + +/** + * 授权数据库 + */ +public class BPA_AUTHORIZE extends ModeBase{ + /** + * 授权码 + */ + public String authorizeCode; +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/AES.java b/app/src/main/java/com/bonait/bnframework/common/helper/AES.java index ec5c9c81..158e431f 100644 --- a/app/src/main/java/com/bonait/bnframework/common/helper/AES.java +++ b/app/src/main/java/com/bonait/bnframework/common/helper/AES.java @@ -16,21 +16,24 @@ public class AES { * 加密 * @return 加密后的字符串 */ - public static String Encrypt(String src) throws Exception { - // 判断密钥是否为空 - if (key == null) { - System.out.print("密钥不能为空"); - return null; - } - - byte[] data = key.getBytes("utf-8"); - SecretKeySpec skeySpec = new SecretKeySpec(data, "AES"); - Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); // 算法/模式/补码方式 - cipher.init(Cipher.ENCRYPT_MODE, skeySpec); - byte[] encrypted = cipher.doFinal(src.getBytes("utf-8")); - - //return new Base64().encodeToString(encrypted);//base64 - return binary(encrypted, 16); //十六进制 + public static String Encrypt(String src) { + try{ + // 判断密钥是否为空 + if (key == null) { + System.out.print("密钥不能为空"); + return null; + } + + byte[] data = key.getBytes("utf-8"); + SecretKeySpec skeySpec = new SecretKeySpec(data, "AES"); + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); // 算法/模式/补码方式 + cipher.init(Cipher.ENCRYPT_MODE, skeySpec); + byte[] encrypted = cipher.doFinal(src.getBytes("utf-8")); + //return new Base64().encodeToString(encrypted);//base64 + return binary(encrypted, 16); //十六进制 + }catch (Exception e){ + return e.getMessage(); + } } /** diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/AuthorizeHelper.java b/app/src/main/java/com/bonait/bnframework/common/helper/AuthorizeHelper.java new file mode 100644 index 00000000..a5a3aa6d --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/AuthorizeHelper.java @@ -0,0 +1,425 @@ +package com.bonait.bnframework.common.helper; + +import android.os.Build; + +import androidx.appcompat.app.AppCompatActivity; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.utils.AlertDialogUtils; +import com.bonait.bnframework.databinding.LayoutAuthorityBinding; +import com.bonait.bnframework.ui.util.DisplayManager; +import com.bonait.bnframework.ui.widget.NewToastUtil; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import java.util.UUID; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; + +public class AuthorizeHelper { + + + // 加密方法,将字符串每个字符向右移动offset位 + public static String encrypt(String input, int offset) { + if (input == null || input.isEmpty()) { + return input; + } + StringBuilder encrypted = new StringBuilder(); + for (char c : input.toCharArray()) { + encrypted.append((char)(c + offset)); + } + return toHex(encrypted.toString().getBytes()); + } + + + // 解密方法,将字符串每个字符向左移动同样的offset位 + public static String decrypt(String encrypted, int offset) { + if (encrypted == null || encrypted.isEmpty()) { + return encrypted; + } + encrypted = new String(toByte(encrypted)); + StringBuilder decrypted = new StringBuilder(); + for (char c : encrypted.toCharArray()) { + decrypted.append((char)(c - offset)); + } + return decrypted.toString(); + } + + private static String CurrentRegistraCode=""; + + public static String getRegistraCode(){ + CurrentRegistraCode = UUID.randomUUID().toString().replace("-","").substring(0,16).toUpperCase(); + return CurrentRegistraCode; + } + + /** + * 获取授权码 + * @return + */ + public static String getAuthorizeCode(){ + String data = ""; + try{ + File AuthorizeCodePathFile = new File(ConfigName.getInstance().AuthorizeCodePath); + byte[] buffer = new byte[1024]; + int bytesRead; + FileInputStream fis = new FileInputStream(AuthorizeCodePathFile); + while ((bytesRead = fis.read(buffer)) != -1) { + data += new String(buffer, 0, bytesRead); + } + fis.close(); + return data; + }catch (Exception e){ + } + return data; + } + + /** + * 授权验证 + */ + public static void AuthorizeVerify(){ + String AuthorizeCode= getAuthorizeCode(); + try{ + StringBuffer sb = new StringBuffer(AuthorizeCode); + sb.insert(4,";"); + sb.insert(7,";"); + String[] date = sb.toString().split("[;]"); + if(date!=null && date.length==3){ + int year=Integer.parseInt(date[0]); + int month=Integer.parseInt(date[1]); + int day=Integer.parseInt(date[2]); + LocalDate authorizeDate=LocalDate.of(year,month,day); + LocalDate currentDate=LocalDate.now(); + //compareTo 等于0表示两个时间相等 + //compareTo 大于0,authorizeDate 时间在 currentDate 之后 + //compareTo 小于0,authorizeDate 时间在 currentDate 之前 + //如果授权时间小于当前时间,授权过期 + //如果授权时间大于当前时间,在授权时间内 + ConfigName.getInstance().IsAuthorize=authorizeDate.compareTo(currentDate)>=0; + }else{ + ConfigName.getInstance().IsAuthorize=Integer.parseInt(AuthorizeCode)==0; + } + }catch (Exception e){ + + } + } + + public static void AuthorizeInAdvanceNotify(AppCompatActivity activity){ + if(!ConfigName.getInstance().IsAuthorize)return; + String AuthorizeCode= getAuthorizeCode(); + try{ + StringBuffer sb = new StringBuffer(AuthorizeCode); + sb.insert(4,";"); + sb.insert(7,";"); + String[] date = sb.toString().split("[;]"); + if(date!=null && date.length==3){ + int year=Integer.parseInt(date[0]); + int month=Integer.parseInt(date[1]); + int day=Integer.parseInt(date[2]); + LocalDate authorizeDate=LocalDate.of(year,month,day); + LocalDate currentDate=LocalDate.now(); + long daysBetween = ChronoUnit.DAYS.between( currentDate,authorizeDate)+1; + if(daysBetween<=5&&daysBetween>0){ + AlertDialogUtils.showDialog(activity,"授权提醒","您的【黑菠萝小炒】授权即将到期,为避免影响后期使用,请您及时联系黑菠萝科技有限公司进行重新授权!\r\n"+"剩余 "+daysBetween+" 天"); + ConfigName.getInstance().IsVisibleAuthorize=true; + } + } + }catch (Exception e){ + + } + } + + public static void AuthorizeDialog(AppCompatActivity activity){ + AlertDialogUtils.showCancelAndConfirmDialog(activity, R.layout.layout_authority, (layoutView, xCom) -> { + LayoutAuthorityBinding binding = LayoutAuthorityBinding.bind(layoutView); + DisplayManager.scaleViewGroup(binding.getRoot()); + binding.authorityCode.setText(getRegistraCode()); + binding.submit.setOnClickListener(view1 -> { + try{ + String code = binding.editName.getText().toString().toUpperCase(); + if(code==null||code.isEmpty()||code.length()==0){ + NewToastUtil.getInstance().showToast("请输入有效的授权码!","Please enter a valid authorization code!"); + return; + } + + String dataBlock1 = ""; + String dataBlock2 = "";//拼接首字符 + String dataBlock3 = "";//拼接最后一个字符 + int count = 0; + for (int i = 0; i < CurrentRegistraCode.length(); i += 4) + { + dataBlock1 =dataBlock1+ CurrentRegistraCode.substring(i + count, i + count+1); + dataBlock2 =dataBlock2+ CurrentRegistraCode.substring(i, i +1); + dataBlock3 =dataBlock3+ CurrentRegistraCode.substring(i + 3, i + 3+1); + count++; + } + String res = decrypt(code,6); + if(res.substring(0,4).equals(dataBlock1)){ + + if(res.substring(4).equals(dataBlock2+dataBlock3)){ + //永久授权码设置 + File AuthorizeCodePathFile = new File(ConfigName.getInstance().AuthorizeCodePath); + FileOutputStream fos = new FileOutputStream(AuthorizeCodePathFile); + fos.write("0000".getBytes()); + fos.close(); + }else{ + //到期授权码设置 + File AuthorizeCodePathFile = new File(ConfigName.getInstance().AuthorizeCodePath); + FileOutputStream fos = new FileOutputStream(AuthorizeCodePathFile); + fos.write(res.substring(4).getBytes()); + fos.close(); + } + }else{ + NewToastUtil.getInstance().showToast("无效的授权码!","Authorization code error!"); + return; + } + + +// String[] resArray = res.split("[@]"); +// if(resArray.length==2 && resArray[0].equals(getId())){ +// String[] date = resArray[1].split("[;]"); +// if(date!=null && date.length==4){ +// int year=Integer.parseInt(date[0]); +// int month=Integer.parseInt(date[1]); +// int day=Integer.parseInt(date[2]); +// int currentDay = Integer.parseInt(date[3]); +// if(LocalDate.now().getDayOfMonth()==currentDay){ +// String tempValue =year+";"+month+";"+day; +// File AuthorizeCodePathFile = new File(ConfigName.getInstance().AuthorizeCodePath); +// FileOutputStream fos = new FileOutputStream(AuthorizeCodePathFile); +// fos.write(tempValue.getBytes()); +// fos.close(); +// }else{ +// NewToastUtil.getInstance().showToast("无效的授权码!","Authorization code error!"); +// } +// } +// else{ +// if(Integer.parseInt(resArray[1])==LocalDate.now().getDayOfMonth()) { +// File AuthorizeCodePathFile = new File(ConfigName.getInstance().AuthorizeCodePath); +// FileOutputStream fos = new FileOutputStream(AuthorizeCodePathFile); +// fos.write(resArray[1].getBytes()); +// fos.close(); +// }else{ +// NewToastUtil.getInstance().showToast("无效的授权码!","Authorization code error!"); +// } +// } +// } + AuthorizeVerify(); + xCom.dismissX(); + }catch (Exception e){ + NewToastUtil.getInstance().showToast("授权码错误!","Authorization code error!"); + } + }); + binding.btnClose1.setOnClickListener(view->{ + xCom.dismissX(); + }); + binding.btnLast1.setOnClickListener(view->{ + xCom.dismissX(); + }); + + }); + } + + /** + * 授权通知 + * @param activity + */ + public static void AuthorizeNotify(AppCompatActivity activity){ + if(ConfigName.getInstance().IsAuthorize)return; + if(!ConfigName.getInstance().versionSelectionEnum.equals("800炒锅带投料"))return; + AuthorizeDialog(activity); + } + + //region 获取Android 硬件信息 + public static String getModel() { + return Build.MODEL; + } + + public static String getManufacturer() { + return Build.MANUFACTURER; + } + + public static String getBrand() { + return Build.BRAND; + } + + public static String getBoard() { + return Build.BOARD; + } + + public static String getDevice() { + return Build.DEVICE; + } + + public static String getHardware() { + return Build.HARDWARE; + } + + public static String getProduct() { + return Build.PRODUCT; + } + + public static String getSerial() { + return Build.SERIAL; + } + + public static String getUser() { + return Build.USER; + } + + public static String getId() { + return Build.ID; + } + + public static String getBootloader() { + return Build.BOOTLOADER; + } + + public static String getRadioVersion() { + return Build.getRadioVersion(); + } + + public static String getAllInformation() { + return "Model: " + getModel() + "\n" + + "Manufacturer: " + getManufacturer() + "\n" + + "Brand: " + getBrand() + "\n" + + "Board: " + getBoard() + "\n" + + "Device: " + getDevice() + "\n" + + "Hardware: " + getHardware() + "\n" + + "Product: " + getProduct() + "\n" + + "Serial: " + getSerial() + "\n" + + "User: " + getUser() + "\n" + + "ID: " + getId() + "\n" + + "Bootloader: " + getBootloader() + "\n" + + "Radio Version: " + getRadioVersion(); + } + //endregion + + //region AES加密辅助方法 + private static byte[] getRawKey(byte[] seed) { + + try { + //获取密钥生成器 + KeyGenerator kgen = KeyGenerator.getInstance("AES"); + SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); + sr.setSeed(seed); + //生成位的AES密码生成器 + kgen.init(128, sr); + //生成密钥 + SecretKey skey = kgen.generateKey(); + //编码格式 + byte[] raw = skey.getEncoded(); + return raw; + + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return null; + + } + + private static byte[] encrypt(byte[] raw, byte[] clear) { + + try { + //生成一系列扩展密钥,并放入一个数组中 + SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); + Cipher cipher = Cipher.getInstance("AES"); + //使用ENCRYPT_MODE模式,用skeySpec密码组,生成AES加密方法 + cipher.init(Cipher.ENCRYPT_MODE, skeySpec); + //得到加密数据 + byte[] encrypted = cipher.doFinal(clear); + return encrypted; + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (NoSuchPaddingException e) { + e.printStackTrace(); + } catch (InvalidKeyException e) { + e.printStackTrace(); + } catch (BadPaddingException e) { + e.printStackTrace(); + } catch (IllegalBlockSizeException e) { + e.printStackTrace(); + } + return null; + } + + private static byte[] decrypt(byte[] raw, byte[] encrypted) { + + try { + //生成一系列扩展密钥,并放入一个数组中 + SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); + Cipher cipher = null; + cipher = Cipher.getInstance("AES"); + //使用DECRYPT_MODE模式,用skeySpec密码组,生成AES解密方法 + cipher.init(Cipher.DECRYPT_MODE, skeySpec); + //得到加密数据 + byte[] decrypted = cipher.doFinal(encrypted); + return decrypted; + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (NoSuchPaddingException e) { + e.printStackTrace(); + } catch (BadPaddingException e) { + e.printStackTrace(); + } catch (IllegalBlockSizeException e) { + e.printStackTrace(); + } catch (InvalidKeyException e) { + e.printStackTrace(); + } + return null; + + } + + //将十进制数转为十六进制 + public static String toHex(String txt) { + return toHex(txt.getBytes()); + } + + //将十六进制字符串转换位十进制字符串 + public static String fromHex(String hex) { + return new String(toByte(hex)); + } + + //将十六进制字符串转为十进制字节数组 + public static byte[] toByte(String hexString) { + int len = hexString.length() / 2; + byte[] result = new byte[len]; + for (int i = 0; i < len; i++) { + result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2), 16).byteValue(); + } + return result; + } + + //将十进制字节数组转换为十六进制 + public static String toHex(byte[]buf){ + if(buf==null){ + return ""; + } + StringBuffer result=new StringBuffer(2*buf.length); + for(int i=0;i>4)&0x0f)).append(HEX.charAt(b&0x0f)); + } +//endregion + +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java b/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java index 411a320d..cb85892a 100644 --- a/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java +++ b/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java @@ -44,6 +44,7 @@ public class SdCart { ConfigName.getInstance().appResRoot = ConfigName.getInstance().sdCardPath +ConfigName.dataPath; ConfigName.getInstance().dbPath = ConfigName.getInstance().appResRoot + "/hbl.db"; + File rootFile = new File(ConfigName.getInstance().appResRoot); if (!rootFile.exists()) //创建目录 { Log.i("日志",ConfigName.getInstance().sdCardPath); @@ -58,6 +59,13 @@ public class SdCart { //2.创建数据库结构 DBHelper.getInstance(ConfigName.getInstance().dishesCon).CreateTables(); } + + ConfigName.getInstance(). AuthorizeCodePath=ConfigName.getInstance().appResRoot + "/AuthorizeCode.aes"; + File AuthorizeCodePathFile = new File(ConfigName.getInstance().AuthorizeCodePath); + if (!AuthorizeCodePathFile.exists()) //创建目录 + { +// AuthorizeCodePathFile.mkdirs(); + } Log.i("日志","初始化数据库目录:"+ConfigName.getInstance().dbPath); } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigation2Activity.java b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigation2Activity.java index 107b89c4..be17c155 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigation2Activity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigation2Activity.java @@ -5,36 +5,24 @@ import android.os.Bundle; import androidx.annotation.NonNull; import com.bonait.bnframework.business.ConfigData; -import com.bonait.bnframework.business.UpDataModel; import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; -import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; +import com.bonait.bnframework.common.helper.AES; +import com.bonait.bnframework.common.helper.AuthorizeHelper; import com.bonait.bnframework.common.helper.BatchSync; import com.bonait.bnframework.common.helper.HttpServer; -import com.bonait.bnframework.common.helper.I.IRunT; import com.bonait.bnframework.common.helper.I.IThread; import com.bonait.bnframework.common.helper.MessageLog; import com.bonait.bnframework.common.helper.TcpClient; import com.bonait.bnframework.common.helper.ThreadManager; -import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback; import com.bonait.bnframework.common.modbus.ModbusTcpMainServer; import com.bonait.bnframework.common.modbus.ModbusTcpServer; -import com.bonait.bnframework.common.model.ResAPI; -import com.bonait.bnframework.common.model.mode.ActionJsonMode; -import com.bonait.bnframework.common.model.mode.BPA_GoodsTechnologyAction; -import com.bonait.bnframework.common.model.mode.BatchingInfo; -import com.bonait.bnframework.common.model.mode.BomTechnologyActionInfo; -import com.bonait.bnframework.common.model.mode.CloudGood; -import com.bonait.bnframework.common.model.mode.GoodsTechnology; -import com.bonait.bnframework.common.model.mode.TechnologyAction; -import com.bonait.bnframework.common.model.mode.UpdateBomInfo; -import com.bonait.bnframework.common.model.mode.UpdateCloudGood; -import com.bonait.bnframework.common.oss.OssHelper; +import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.NetworkUtils; import com.google.android.material.bottomnavigation.BottomNavigationView; +import androidx.appcompat.app.AppCompatActivity; import androidx.viewpager.widget.ViewPager; import android.util.Log; @@ -52,24 +40,22 @@ import com.bonait.bnframework.modules.home.fragment.Home1Fragment; import com.bonait.bnframework.modules.home.fragment.Home2Fragment; import com.bonait.bnframework.modules.home.adapter.FragmentAdapter; import com.bonait.bnframework.modules.mine.fragment.MyFragment; -import com.google.gson.Gson; import com.lzy.okgo.OkGo; -import com.lzy.okgo.model.HttpHeaders; -import com.lzy.okgo.model.Response; import com.qmuiteam.qmui.widget.QMUIViewPager; +import org.apache.commons.codec.binary.Base32; +import org.litepal.util.BaseUtility; + +import java.time.LocalDate; import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import java.util.Date; +import java.util.InvalidPropertiesFormatException; +import java.util.UUID; import butterknife.BindView; import butterknife.ButterKnife; -import okhttp3.MediaType; -import okhttp3.RequestBody; public class BottomNavigation2Activity extends BaseActivity { - - @BindView(R.id.navigation) BottomNavigationView bottomNavigationView; @BindView(R.id.viewpager) @@ -90,12 +76,21 @@ public class BottomNavigation2Activity extends BaseActivity { viewPager.setOffscreenPageLimit(3); bottomNavigationView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); Init(); -// new Thread(()->{ -// try{ -// Thread.sleep(10000); -// test(); -// }catch (Exception e){} -// }).start(); + + String info = AuthorizeHelper.getId(); + String aa = AES.Encrypt(info); + + Base32 bb = new Base32(); + String ba = bb.encodeAsString(info.getBytes()); + + String guid = UUID.randomUUID().toString(); + +// Date dt = new Date(); + LocalDate currentDate=LocalDate.now(); + String info2 = info+"@"+currentDate.getYear()+";"+currentDate.getMonthValue()+";"+currentDate.getDayOfMonth(); + String s1 = AuthorizeHelper.encrypt(info2,5); + String s2 = AuthorizeHelper.decrypt(s1,5); + if(ConfigName.getInstance().versionSelectionEnum.contains("一拖")){ hs = new HttpServer(); new Thread(()->{ @@ -105,6 +100,8 @@ public class BottomNavigation2Activity extends BaseActivity { }catch (Exception e){} }).start(); } + + } @Override @@ -146,6 +143,8 @@ public class BottomNavigation2Activity extends BaseActivity { } } }); + + } //-------------------------配置viewPager与fragment关联----------------------------// diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java index 75ccd10a..f3f1c7a4 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java @@ -1,5 +1,6 @@ package com.bonait.bnframework.modules.home.activity; +import androidx.appcompat.app.AppCompatActivity; import androidx.viewpager.widget.ViewPager; import android.app.Activity; @@ -23,6 +24,7 @@ import com.bonait.bnframework.common.db.mode.BPA_GOODS_PROCESS_DETAIL; import com.bonait.bnframework.common.db.mode.BPA_GOODS_SUBATTRIBUTE_GROUP; import com.bonait.bnframework.common.db.util.GoodsProcessDetailDBUtil; import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil; +import com.bonait.bnframework.common.helper.AuthorizeHelper; import com.bonait.bnframework.common.helper.CountDownTimerExt; import com.bonait.bnframework.common.helper.HttpServer; import com.bonait.bnframework.common.helper.I.IRunT; @@ -225,6 +227,7 @@ public class BottomNavigationNewActivity extends BaseActivity { @Override public void onPageSelected(int position) { + bottomNavigationView.SelectIndexTab(position); } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home2Fragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home2Fragment.java index 0ccd57d5..e9ff6744 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home2Fragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home2Fragment.java @@ -10,6 +10,7 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.GridLayoutManager; import android.view.LayoutInflater; @@ -19,6 +20,7 @@ import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.MessageName; +import com.bonait.bnframework.common.helper.AuthorizeHelper; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.ScreenUtils; import com.bonait.bnframework.common.utils.ToastUtils; @@ -65,10 +67,22 @@ public class Home2Fragment extends BaseFragment { super.onViewCreated(view, savedInstanceState); context = getContext(); initTopBar(); - appbarlayout.setExpanded(ConfigName.getInstance().IsPortraitScreen); + new Thread(()->{ + try { + Thread.sleep(3000); + getActivity().runOnUiThread(()->{ + AuthorizeHelper.AuthorizeNotify((AppCompatActivity) getActivity()); + AuthorizeHelper.AuthorizeInAdvanceNotify((AppCompatActivity) getActivity()); + }); + }catch (Exception e){ + + } + }).start(); } + + private void initTopBar() { mCollapsingTopBarLayout.setTitle("功能菜单"); } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home4Fragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home4Fragment.java index 7ff0cc5c..480993e2 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home4Fragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home4Fragment.java @@ -10,6 +10,7 @@ import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; +import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; @@ -18,6 +19,7 @@ import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.MessageName; +import com.bonait.bnframework.common.helper.AuthorizeHelper; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; @@ -41,6 +43,9 @@ public class Home4Fragment extends BaseFragment { @BindView(R.id.yauser_gn) LinearLayout yauser_gn;// + + @BindView(R.id.authorize) + Button authorize; private Context context; @Override @@ -56,6 +61,21 @@ public class Home4Fragment extends BaseFragment { context = getContext(); initTopBar(); initData(); + + new Thread(()->{ + try { + Thread.sleep(3000); + getActivity().runOnUiThread(()->{ + AuthorizeHelper.AuthorizeNotify((AppCompatActivity) getActivity()); + AuthorizeHelper.AuthorizeInAdvanceNotify((AppCompatActivity) getActivity()); + authorize.setVisibility(ConfigName.getInstance().IsVisibleAuthorize?View.VISIBLE:View.GONE); + }); + }catch (Exception e){ + + } + }).start(); + + } /** @@ -70,7 +90,7 @@ public class Home4Fragment extends BaseFragment { * * @param view */ - @OnClick({R.id.kaishipengren, R.id.shebeikongzhi, R.id.zhuxiaodenglu + @OnClick({R.id.kaishipengren, R.id.shebeikongzhi, R.id.zhuxiaodenglu,R.id.authorize , R.id.liaochangshezhi, R.id.caipinyanfa,}) public void onViewClicked(View view) { switch (view.getId()) { @@ -78,8 +98,13 @@ public class Home4Fragment extends BaseFragment { MessageManager.getInstance().sendMessage(MessageName.SelectZY, 0); break; case R.id.shebeikongzhi: + AuthorizeHelper.AuthorizeNotify((AppCompatActivity)getActivity()); + if(!ConfigName.getInstance().IsAuthorize&&ConfigName.getInstance().versionSelectionEnum.equals("800炒锅带投料"))return; MessageManager.getInstance().sendMessage(MessageName.SelectZY, 2); break; + case R.id.authorize: + AuthorizeHelper.AuthorizeDialog((AppCompatActivity)getActivity()); + break; case R.id.liaochangshezhi: OpenActivity(BunkerSetupActivity.class); break; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java index 55ca7e30..3d5d3ba3 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java @@ -31,6 +31,7 @@ import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_SILOS; import com.bonait.bnframework.common.db.res.lcMode; +import com.bonait.bnframework.common.helper.AuthorizeHelper; import com.bonait.bnframework.common.helper.I.IRun; import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; @@ -42,6 +43,7 @@ import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3; import com.bonait.bnframework.modules.home.fragment.mode.newhuoli_control; +import com.bonait.bnframework.ui.widget.NewToastUtil; import com.orhanobut.logger.Logger; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; @@ -502,6 +504,8 @@ public class HomeFragmentSBKZ extends BaseFragment { public MyClickListener myClickListener = new MyClickListener() { @Override public void clickListener(View v, Object data) { + AuthorizeHelper.AuthorizeNotify((AppCompatActivity)activity); + if(!ConfigName.getInstance().IsAuthorize&&ConfigName.getInstance().versionSelectionEnum.equals("800炒锅带投料"))return; boolean isclick = false; int hl = 0; if (v.getId() == R.id.huoli) { @@ -577,6 +581,8 @@ public class HomeFragmentSBKZ extends BaseFragment { } }; + private boolean IsOpen=false; + /** * 设置是否按下 * @@ -584,6 +590,11 @@ public class HomeFragmentSBKZ extends BaseFragment { * @param ismode */ public void SetIDTouch(int id, boolean ismode) { + if(ismode){ + if(ConfigName.getInstance().isFastClick())return; + AuthorizeHelper.AuthorizeNotify((AppCompatActivity)activity); + if(!ConfigName.getInstance().IsAuthorize&&ConfigName.getInstance().versionSelectionEnum.equals("800炒锅带投料"))return; + } switch (id) { case R.id.chushui: //PumpWater(ismode); diff --git a/app/src/main/java/com/bonait/bnframework/ui/dialog/EditGoodsDialog.java b/app/src/main/java/com/bonait/bnframework/ui/dialog/EditGoodsDialog.java index c476a884..3132ec45 100644 --- a/app/src/main/java/com/bonait/bnframework/ui/dialog/EditGoodsDialog.java +++ b/app/src/main/java/com/bonait/bnframework/ui/dialog/EditGoodsDialog.java @@ -18,6 +18,7 @@ import android.widget.AdapterView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.DialogFragment; import com.apkfuns.logutils.LogUtils; @@ -36,6 +37,7 @@ import com.bonait.bnframework.common.db.util.GoodsDBUtil; import com.bonait.bnframework.common.db.util.GoodsProcessDetailDBUtil; import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil; +import com.bonait.bnframework.common.helper.AuthorizeHelper; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.ProcessValueUtil; import com.bonait.bnframework.common.utils.ToastUtils; diff --git a/app/src/main/java/com/bonait/bnframework/ui/fragment/goods/LocalGoodsFragment.java b/app/src/main/java/com/bonait/bnframework/ui/fragment/goods/LocalGoodsFragment.java index 90068cf8..dd335508 100644 --- a/app/src/main/java/com/bonait/bnframework/ui/fragment/goods/LocalGoodsFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ui/fragment/goods/LocalGoodsFragment.java @@ -21,17 +21,15 @@ import com.bonait.bnframework.R; import com.bonait.bnframework.business.RecordManager; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.db.mode.BPA_ATTRIBUTE; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODS_CLASSIFY; import com.bonait.bnframework.common.db.mode.BPA_PROPERTY_CLASSIFY; -import com.bonait.bnframework.common.db.util.AttributeDBUtil; import com.bonait.bnframework.common.db.util.GoodsClassifyDBUtil; import com.bonait.bnframework.common.db.util.GoodsDBUtil; import com.bonait.bnframework.common.db.util.GoodsProcessDetailDBUtil; import com.bonait.bnframework.common.db.util.PropClassifyDBUtil; -import com.bonait.bnframework.common.db.util.SubAttributeDBUtil; import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil; +import com.bonait.bnframework.common.helper.AuthorizeHelper; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.databinding.DialogDeleteClassifyBinding; @@ -119,6 +117,7 @@ public class LocalGoodsFragment extends BaseFragment { @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + initView(); updateData(); EventBus.getDefault().register(this); @@ -239,6 +238,8 @@ public class LocalGoodsFragment extends BaseFragment { return; } try { + AuthorizeHelper.AuthorizeNotify((AppCompatActivity)getActivity()); + if(!ConfigName.getInstance().IsAuthorize&&ConfigName.getInstance().versionSelectionEnum.equals("800炒锅带投料"))return; if(!ConfigName.getInstance().user.name.equals("一般用户")){ if(editGoodsDialog == null){ editGoodsDialog = new EditGoodsDialog(); @@ -378,6 +379,8 @@ public class LocalGoodsFragment extends BaseFragment { }; goodClassifyAdapter.setCurrentPosition(0); viewBinding.recyclerClassify.setAdapter(goodClassifyAdapter); + + } /** diff --git a/app/src/main/res/drawable/btn_authorize.xml b/app/src/main/res/drawable/btn_authorize.xml new file mode 100644 index 00000000..2f90d5e5 --- /dev/null +++ b/app/src/main/res/drawable/btn_authorize.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/input_bj.xml b/app/src/main/res/drawable/input_bj.xml index e2273fcd..1e24be4c 100644 --- a/app/src/main/res/drawable/input_bj.xml +++ b/app/src/main/res/drawable/input_bj.xml @@ -6,7 +6,7 @@ \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home4.xml b/app/src/main/res/layout/fragment_home4.xml index a083d95f..b54f36b7 100644 --- a/app/src/main/res/layout/fragment_home4.xml +++ b/app/src/main/res/layout/fragment_home4.xml @@ -178,5 +178,22 @@ android:textColor="@color/white" android:background="@drawable/btn_exit" android:elevation="40dp"> + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item/layout/layout_authority.xml b/app/src/main/res/layout/item/layout/layout_authority.xml new file mode 100644 index 00000000..84f9a945 --- /dev/null +++ b/app/src/main/res/layout/item/layout/layout_authority.xml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file