Bläddra i källkod

submit: 正式版本1230

huwanxiao 8 månader sedan
förälder
incheckning
958d352154

+ 2 - 2
app/src/main/java/com/naz/sdkdemo/AppConfig.java

@@ -10,11 +10,11 @@ import com.naz.sdkdemo.utils.SPUtils;
 public class AppConfig {
     public static final boolean IS_DEBUG =true;//true打印数据
 
-    public static final String APP_VERSION_CODE = "2.24.0927";//true打印数据
+    public static final String APP_VERSION_CODE = "2.24.1230";//true打印数据
     public static final String APP_VERSION = "正式版本-" + APP_VERSION_CODE;//true打印数据
     public static final String REMARK = "1. 新增: 大小版本更新\n" +
             "2.新增: 添加全局日志的捕获\n" +
-            "3.更新: 打印格式的调整";
+            "3.修复: 修复已知问题";
 
     // public  static String INTERFACE_URL = "http://121.37.173.82:82/";//线上
 //    public  static String INTERFACE_URL = "http://121.41.102.225:82/";//测试

+ 72 - 44
app/src/main/java/com/naz/sdkdemo/MainActivity.java

@@ -55,6 +55,7 @@ import com.naz.sdkdemo.bean.PrintModule3;
 import com.naz.sdkdemo.bean.VersionBean;
 import com.naz.sdkdemo.comm.Constants;
 import com.naz.sdkdemo.dialog.VersionUpdateDialog;
+import com.naz.sdkdemo.dialog.VersionUpdateDialog4Web;
 import com.naz.sdkdemo.helper.SerialPortManager;
 import com.naz.sdkdemo.http.ApiHelper;
 import com.naz.sdkdemo.utils.DownloadService;
@@ -141,7 +142,7 @@ public class MainActivity extends BaseActivity {
     private PreviewView previewView;
     private RelativeLayout previewViewLayout;
     private ProcessCameraProvider cameraProvider;
-    private ImageCapture imageCapture;
+    private ImageCapture imageCapture = null;
 
     private VideoCapture videoCapture;
     private Recording recording;
@@ -404,7 +405,7 @@ public class MainActivity extends BaseActivity {
         Log.e("------->","-------->"+UserCache.getSerialName());
     }
     //region -------------------------------------WebInterface相关方法开始----------------------------
-    String mUrl = "https://dwytbt.qingyaokeji.com/index.html#/";
+    String mUrl = "https://dwytb.qingyaokeji.com/index.html#/";
     private void checkNet() {
         if (!MyTools.isNetworkAvailable(getApplicationContext())) {
             ll_nonet.setVisibility(View.VISIBLE);
@@ -456,14 +457,32 @@ public class MainActivity extends BaseActivity {
         @JavascriptInterface
         public void pushVersion(String currentVersionCode){
             try {
-                Log.e(TAG, "pushVersion");
+                // 弹出版本更新弹窗
                 String preVersionCode = SPUtils.getString("versionCode");
                 if(!preVersionCode.equals(currentVersionCode)) {
-                    // 与之前的非空版本不一致则刷新缓存
-                    runOnUiThread(() -> {
-                        SPUtils.setString("versionCode", currentVersionCode);
-                        toRefreshData();
-                    });
+                    VersionUpdateDialog4Web dialog = new VersionUpdateDialog4Web(MainActivity.this, new VersionUpdateDialog4Web.OnBtnClickListener() {
+                        @Override
+                        public void OnCommitClickListener(VersionUpdateDialog4Web dialog, View clickView) {
+                            Log.e(TAG, "pushVersion");
+                            // 与之前的非空版本不一致则刷新缓存
+                            runOnUiThread(() -> {
+                                SPUtils.setString("versionCode", currentVersionCode);
+                                toRefreshData();
+                                dialog.dismiss();
+                            });
+                        }
+
+                        @Override
+                        public void OnCloseListener(VersionUpdateDialog4Web dialog, View clickView) {
+
+                        }
+
+                        @Override
+                        public void OnNoLongerListener(VersionUpdateDialog4Web dialog, View clickView) {
+
+                        }
+                    }, "您有新的版本可以更新!", false, "立即更新");
+                    dialog.show();
                 }
             }catch (Exception e) {
                 XToast.showToast(e.getMessage());
@@ -632,6 +651,12 @@ public class MainActivity extends BaseActivity {
                 Log.e(TAG, "openCamera");
                 // 打开摄像头
                 toOpenCamera(isShowPreview);
+//                new Handler().postDelayed(new Runnable() {
+//                    @Override
+//                    public void run() {
+//                         toTakePhoto("shangbiaoji/20241225", "test");
+//                    }
+//                }, 10000);
             }catch (Exception e) {
                 XToast.showToast(e.getMessage());
                 uploadLogMessage(Arrays.toString(e.getStackTrace()) + "------>>" + e.getMessage(), "exception");
@@ -928,9 +953,9 @@ public class MainActivity extends BaseActivity {
                     sendCommandhandler.postDelayed(() -> {
                         try {
                             if(command.equals("07C60408008A09FE94")) {
-                                serialPortManager.sendHexData1(command);
+                                serialPortManager.sendHexData(command);
                             } else {
-                                serialPortManager.sendHexData1(command);
+                                serialPortManager.sendHexData2(command);
                             }
                             Log.i(TAG, "向" + seriesName + "发送" + command);
                         }catch (Exception e) {
@@ -1062,43 +1087,46 @@ public class MainActivity extends BaseActivity {
         //创建文件
         File file = new File(dir,savePath);
         ImageCapture.OutputFileOptions outputFileOptions = new ImageCapture.OutputFileOptions.Builder(file).build();
-
-        imageCapture.takePicture(
-                // 第一个参数 OutputFileOptions 指定了照片保存的位置和格式等信息。
-                outputFileOptions,
-                // 第二个参数 Executor 指定了保存照片时要运行的线程。
-                ContextCompat.getMainExecutor(this),
-                // 第三个参数 OnImageSavedCallback 指定了保存照片完成后的回调函数,可以在其中进行一些提示或其他操作。
-                new ImageCapture.OnImageSavedCallback() {
-                    @SuppressLint("RestrictedApi")
-                    @Override
-                    public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
-                        Log.e("takePhoto","------>savePath="+outputFileResults.getSavedUri().getPath());
-                        Log.e("takePhoto","------>保存成功");
-                        Log.e("takePhoto","------>重试数:" + retryCount);
-                        retryCount = 0;
+        if(imageCapture != null) {
+            imageCapture.takePicture(
+                    // 第一个参数 OutputFileOptions 指定了照片保存的位置和格式等信息。
+                    outputFileOptions,
+                    // 第二个参数 Executor 指定了保存照片时要运行的线程。
+                    ContextCompat.getMainExecutor(this),
+                    // 第三个参数 OnImageSavedCallback 指定了保存照片完成后的回调函数,可以在其中进行一些提示或其他操作。
+                    new ImageCapture.OnImageSavedCallback() {
+                        @SuppressLint("RestrictedApi")
+                        @Override
+                        public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
+                            Log.e("takePhoto","------>savePath="+outputFileResults.getSavedUri().getPath());
+                            Log.e("takePhoto","------>保存成功");
+                            Log.e("takePhoto","------>重试数:" + retryCount);
+                            retryCount = 0;
 //                        Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT).show();
-                        savePicture(file, path, name);
-                        mWebView.loadUrl("javascript:uploadPhotoPath('" + outputFileOptions.getFile().getAbsolutePath() + "')");
-                    }
+                            savePicture(file, path, name);
+                            mWebView.loadUrl("javascript:uploadPhotoPath('" + outputFileOptions.getFile().getAbsolutePath() + "')");
+                        }
 
-                    @Override
-                    public void onError(@NonNull ImageCaptureException exception) {
-                        Log.e("takePhoto","------>保存失败: "+exception.getMessage());
-                        Log.e("takePhoto","------>重试数:" + retryCount);
-                        if (retryCount < maxRetries) {
-                            retryCount++;
-                            // 重试拍照
-                            imageCapture.takePicture(
-                                    // 第一个参数 OutputFileOptions 指定了照片保存的位置和格式等信息。
-                                    outputFileOptions,
-                                    // 第二个参数 Executor 指定了保存照片时要运行的线程。
-                                    ContextCompat.getMainExecutor(MainActivity.this),
-                                    this
-                            );
+                        @Override
+                        public void onError(@NonNull ImageCaptureException exception) {
+                            Log.e("takePhoto","------>保存失败: "+exception.getMessage());
+                            Log.e("takePhoto","------>重试数:" + retryCount);
+                            if (retryCount < maxRetries) {
+                                retryCount++;
+                                // 重试拍照
+                                if(imageCapture != null) {
+                                    imageCapture.takePicture(
+                                            // 第一个参数 OutputFileOptions 指定了照片保存的位置和格式等信息。
+                                            outputFileOptions,
+                                            // 第二个参数 Executor 指定了保存照片时要运行的线程。
+                                            ContextCompat.getMainExecutor(MainActivity.this),
+                                            this
+                                    );
+                                }
+                            }
                         }
-                    }
-                });
+                    });
+        }
     }
 
     private void openAndCloseVideo() {

+ 102 - 0
app/src/main/java/com/naz/sdkdemo/dialog/VersionUpdateDialog4Web.java

@@ -0,0 +1,102 @@
+package com.naz.sdkdemo.dialog;
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.Display;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.naz.sdkdemo.R;
+
+
+public class VersionUpdateDialog4Web extends Dialog implements View.OnClickListener {
+
+
+    private final boolean canCancel;
+    private String btnText;
+    private String str;
+    private OnBtnClickListener onBtnClickListener;
+    private Context context;
+    private Button btn_update;
+    private Button btn_close;
+    private Button btn_no_longer;
+    private TextView tv_content;
+
+
+
+    public VersionUpdateDialog4Web(Context context, OnBtnClickListener onBtnClickListener, String str, boolean canCancel, String btnText) {
+        super(context, R.style.bottom_select_dialog);
+        this.context = context;
+        this.onBtnClickListener = onBtnClickListener;
+        this.str = str;
+        this.canCancel = canCancel;
+        this.btnText = btnText;
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        Window window = getWindow();
+        window.setGravity(Gravity.CENTER);
+        LayoutInflater inflater = (LayoutInflater) getContext()
+                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        View view = inflater.inflate(R.layout.dialog_version_update_for_web, null);
+        // 文本提示
+        tv_content = view.findViewById(R.id.tv_content);
+        tv_content.setText(str);
+        // 立即更新按钮
+        btn_update = view.findViewById(R.id.btn_update);
+        btn_update.setText(btnText);
+        btn_update.setOnClickListener(this);
+        // 弹框大小
+        setContentView(view);
+        FullScreen((Activity) context, this, 0.85);
+        setCanceledOnTouchOutside(canCancel);
+    }
+
+
+    /**
+     * 自定义dialog全屏展示
+     *
+     * @param activity
+     * @param dialog
+     */
+    public static void FullScreen(Activity activity, Dialog dialog, double scale) {
+        WindowManager m = activity.getWindowManager();
+        Display d = m.getDefaultDisplay();  //为获取屏幕宽、高
+        WindowManager.LayoutParams p = dialog.getWindow().getAttributes();  //获取对话框当前的参数值
+        p.height = (int) (d.getHeight() * 0.55);   //高度设置为屏幕的0.3
+        p.width = (int) (d.getWidth() * scale);    //宽度设置为全屏
+        dialog.getWindow().setAttributes(p);     //设置生效
+    }
+
+
+    @Override
+    public void onClick(View view) {
+        switch (view.getId()) {
+            case R.id.btn_update:    // 立即更新
+                onBtnClickListener.OnCommitClickListener(this, view);
+                break;
+            case R.id.btn_close:     // 关闭
+                onBtnClickListener.OnCloseListener(this, view);
+                break;
+            case R.id.btn_no_longer: // 不再提醒
+                onBtnClickListener.OnNoLongerListener(this, view);
+                break;
+        }
+    }
+
+    public interface OnBtnClickListener {
+        void OnCommitClickListener(VersionUpdateDialog4Web dialog, View clickView);
+        void OnCloseListener(VersionUpdateDialog4Web dialog, View clickView);
+        void OnNoLongerListener(VersionUpdateDialog4Web dialog, View clickView);
+    }
+}
+

+ 4 - 0
app/src/main/java/com/naz/sdkdemo/helper/SerialPortManager.java

@@ -407,4 +407,8 @@ public class SerialPortManager {
         byte[] bytes = SerialUtil.hexStringToByteArray(data);
         serialHelper.send(bytes);
     }
+
+    public void sendHexData2(String data){
+        serialHelper.send(SerialUtil.hexStringToByteArray(data+SerialUtil.getCRC(Objects.requireNonNull(SerialUtil.hexStringToByteArray(data)))));
+    }
 }

+ 5 - 5
app/src/main/res/layout/dialog_version_update.xml

@@ -7,7 +7,7 @@
     <LinearLayout
         android:layout_width="match_parent"
         android:background="@drawable/bg_white_round_20"
-        android:layout_height="match_parent"
+        android:layout_height="wrap_content"
         android:orientation="vertical">
         <RelativeLayout
             android:layout_width="match_parent"
@@ -24,10 +24,10 @@
         <LinearLayout
             android:layout_gravity="center"
             android:layout_marginHorizontal="15dp"
+            android:layout_marginTop="9dp"
             android:layout_width="match_parent"
             android:orientation="vertical"
-            android:layout_height="0dp"
-            android:layout_weight="1"
+            android:layout_height="wrap_content"
         >
             <ScrollView
                 android:layout_width="match_parent"
@@ -36,7 +36,6 @@
                     android:id="@+id/tv_content"
                     style="@style/wrap_style"
                     android:layout_gravity="left"
-                    android:layout_marginBottom="9dp"
                     android:text=""
                     android:textColor="@color/grey_66"
                     android:textSize="22sp" />
@@ -64,6 +63,7 @@
 <!--                    android:layout_width="10dp"-->
 <!--                    />-->
             <Button
+                android:visibility="gone"
                 android:layout_weight="1"
                 android:id="@+id/btn_no_longer"
                 android:layout_width="match_parent"
@@ -76,6 +76,7 @@
                 android:textSize="18sp" />
 
             <Button
+                android:visibility="gone"
                 android:layout_weight="1"
                 android:id="@+id/btn_close"
                 android:layout_width="match_parent"
@@ -83,7 +84,6 @@
                 android:background="@drawable/shape_e6212a_4dp"
                 android:gravity="center"
                 android:text="关闭"
-                android:visibility="visible"
                 android:textColor="@color/white"
                 android:textSize="18sp" />
         </LinearLayout>

+ 88 - 0
app/src/main/res/layout/dialog_version_update_for_web.xml

@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:background="@drawable/bg_white_round_20"
+        android:layout_height="wrap_content"
+        android:orientation="vertical">
+        <RelativeLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginBottom="10dp"
+            android:background="@drawable/bg_grey_round_20_top_left_top_right">
+            <ImageView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:src="@mipmap/top_logo"
+                android:layout_centerHorizontal="true"/>
+        </RelativeLayout>
+<!--        密码输入框-->
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:layout_marginTop="9dp"
+            android:layout_marginHorizontal="15dp"
+            android:orientation="vertical">
+
+            <TextView
+                android:id="@+id/tv_content"
+                style="@style/wrap_style"
+                android:layout_gravity="center"
+                android:text=""
+                android:textColor="@color/grey_66"
+                android:textSize="22sp" />
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_marginVertical="28dp"
+            android:layout_marginHorizontal="15dp"
+            android:layout_width="match_parent"
+            android:orientation="vertical"
+            android:layout_height="wrap_content">
+            <Button
+                android:layout_weight="1"
+                android:id="@+id/btn_update"
+                android:layout_width="match_parent"
+                android:layout_height="54dp"
+                android:background="@drawable/shape_e6212a_4dp"
+                android:gravity="center"
+                android:text="立即更新"
+                android:textColor="@color/white"
+                android:layout_marginBottom="10dp"
+                android:textSize="18sp" />
+<!--                <View-->
+<!--                    android:layout_height="match_parent"-->
+<!--                    android:layout_width="10dp"-->
+<!--                    />-->
+<!--            <Button-->
+<!--                android:layout_weight="1"-->
+<!--                android:id="@+id/btn_no_longer"-->
+<!--                android:layout_width="match_parent"-->
+<!--                android:layout_height="54dp"-->
+<!--                android:background="@drawable/shape_e6212a_4dp"-->
+<!--                android:gravity="center"-->
+<!--                android:text="不再提醒"-->
+<!--                android:textColor="@color/white"-->
+<!--                android:layout_marginBottom="10dp"-->
+<!--                android:textSize="18sp" />-->
+
+<!--            <Button-->
+<!--                android:layout_weight="1"-->
+<!--                android:id="@+id/btn_close"-->
+<!--                android:layout_width="match_parent"-->
+<!--                android:layout_height="54dp"-->
+<!--                android:background="@drawable/shape_e6212a_4dp"-->
+<!--                android:gravity="center"-->
+<!--                android:text="关闭"-->
+<!--                android:visibility="visible"-->
+<!--                android:textColor="@color/white"-->
+<!--                android:textSize="18sp" />-->
+        </LinearLayout>
+    </LinearLayout>
+
+</RelativeLayout>