Jelajahi Sumber

监利分支修改

weizhengliang 1 tahun lalu
induk
melakukan
3c4221776b

+ 0 - 1
android_bed/src/main/h7_3128/AndroidManifest.xml

@@ -11,7 +11,6 @@
     <uses-permission android:name="android.permission.STATUS_BAR" />
 
     <application
-        android:hardwareAccelerated="false"
         android:allowBackup="true"
         android:label="@string/app_name"
         android:supportsRtl="true" >

+ 54 - 2
android_bed/src/main/h7_3128/java/com/wdkl/app/ncs/callingbed/activity/CallingbedActivity.kt

@@ -72,6 +72,7 @@ import org.greenrobot.eventbus.ThreadMode
 import serialporttest.utils.SerialPortUtil
 import java.io.File
 import java.io.FileOutputStream
+import java.lang.ref.WeakReference
 import java.util.*
 import java.util.concurrent.Executors
 import java.util.concurrent.TimeUnit
@@ -127,6 +128,56 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
     private var broadcastChannelId: String = ""
     private var playing = false
 
+    private val timeHandler = MyHandler(this)
+    private var timeThread: TimeThread? = null
+    private val TIME_WHAT = 1000
+
+    inner class TimeThread : Thread() {
+        override fun run() {
+            do {
+                try {
+                    sleep(1000)
+
+                    val msg: Message = timeHandler.obtainMessage()
+                    msg.what = TIME_WHAT
+                    timeHandler.sendMessage(msg)
+                } catch (e: InterruptedException) {
+                    e.printStackTrace()
+                }
+            } while (true)
+        }
+    }
+
+    private val weakReference: WeakReference<CallingbedActivity?>? = null
+
+    fun getWeakReference(): WeakReference<CallingbedActivity?>? {
+        return weakReference
+    }
+
+    internal class MyHandler(activity: CallingbedActivity) : Handler() {
+
+        private val weakReference = WeakReference<CallingbedActivity>(activity)
+
+        override fun handleMessage(msg: Message) {
+            super.handleMessage(msg)
+            // 通过软引用看能否得到activity示例
+            val handlerMemoryActivity: CallingbedActivity? = weakReference.get()
+            // 防止内存泄露
+            if (handlerMemoryActivity != null) {
+                when (msg.what) {
+                    handlerMemoryActivity.TIME_WHAT -> {
+                        try {
+                            //刷新时间 如果当前Activity,进行UI的更新
+                            handlerMemoryActivity.time_view.setText(TimeHandle.getDateTime())
+                        } catch (e: java.lang.Exception) {
+                            e.printStackTrace()
+                        }
+                    }
+                }
+            }
+        }
+    }
+
     private var sleepCountdown = false
     private val updateHandler: Handler = object : Handler(Looper.getMainLooper()) {
         override fun handleMessage(msg: Message) {
@@ -171,8 +222,9 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
     override fun init() {
         //日期时间格式: 默认yyyy-MM-dd HH:mm EEEE
         //监利第二人民医院:MM月dd日 HH:mm:ss
-        time_view.format12Hour = "MM月dd日 HH:mm:ss"
-        time_view.format24Hour = "MM月dd日 HH:mm:ss"
+
+        timeThread = TimeThread()
+        timeThread?.start()
 
         //获取mac地址
         if ("rk3128".equals(Build.MODEL)) {

+ 15 - 4
android_bed/src/main/h7_3128/java/com/wdkl/app/ncs/callingbed/helper/XCrashUtils.java

@@ -39,7 +39,7 @@ public class XCrashUtils {
     private final ICrashCallback callback = new ICrashCallback() {
         @Override
         public void onCrash(String logPath, String emergency) {
-            Log.d(TAG, "log path: " + (logPath != null ? logPath : "(null)") + ", emergency: " + (emergency != null ? emergency : "(null)"));
+            Log.d(TAG, "java crash log path: " + (logPath != null ? logPath : "(null)") + ", emergency: " + (emergency != null ? emergency : "(null)"));
 
             if (emergency != null) {
                 debug(logPath, emergency);
@@ -71,11 +71,22 @@ public class XCrashUtils {
         }
     };
 
+    //native crash
+    private final ICrashCallback nativeCallback = new ICrashCallback() {
+        @Override
+        public void onCrash(String logPath, String emergency) {
+            Log.d(TAG, "native crash log path: " + (logPath != null ? logPath : "(null)") + ", emergency: " + (emergency != null ? emergency : "(null)"));
+
+            //native crash to restart app
+            restartApp();
+        }
+    };
+
     //ANR Catcher
     private final ICrashCallback anrCallback = new ICrashCallback() {
         @Override
         public void onCrash(String logPath, String emergency) {
-            Log.d(TAG, "log path: " + (logPath != null ? logPath : "(null)") + ", emergency: " + (emergency != null ? emergency : "(null)"));
+            Log.d(TAG, "anr log path: " + (logPath != null ? logPath : "(null)") + ", emergency: " + (emergency != null ? emergency : "(null)"));
 
             if (emergency != null) {
                 debug(logPath, emergency);
@@ -98,7 +109,7 @@ public class XCrashUtils {
             if (Build.MODEL.equals("rk3128") || Build.MODEL.equals("rk3288")) {
                 AppUpdateHelper.reboot(app, false);
             } else {
-                AppUpdateHelper.restartApp(app);
+                restartApp();
             }
         }
     };
@@ -119,7 +130,7 @@ public class XCrashUtils {
                 .setNativeLogCountMax(10)
                 .setNativeDumpAllThreadsWhiteList(new String[]{"^xcrash\\.sample$", "^Signal Catcher$", "^Jit thread pool$", ".*(R|r)ender.*", ".*Chrome.*"})
                 .setNativeDumpAllThreadsCountMax(10)
-                .setNativeCallback(callback)
+                .setNativeCallback(nativeCallback)
                 .setAnrRethrow(true)
                 .setAnrLogCountMax(10)
                 .setAnrCallback(anrCallback)

+ 14 - 7
android_bed/src/main/h7_3128/res/layout/view_title_layout.xml

@@ -27,14 +27,21 @@
         android:textSize="@dimen/font_size_20" />
 
     <!--日期时间-->
-    <TextClock
-        android:id="@+id/time_view"
-        android:layout_width="wrap_content"
+    <LinearLayout
+        android:layout_width="300dp"
         android:layout_height="wrap_content"
-        android:layout_centerHorizontal="true"
-        android:layout_centerVertical="true"
-        android:textColor="@color/main_color"
-        android:textSize="@dimen/font_size_20" />
+        android:layout_centerInParent="true"
+        android:gravity="center"
+        android:orientation="horizontal">
+
+        <TextView
+            android:id="@+id/time_view"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:gravity="center"
+            android:textColor="@color/main_color"
+            android:textSize="@dimen/font_size_20" />
+    </LinearLayout>
 
     <!--设备号-->
     <TextView

+ 6 - 0
common/src/main/code/com/wdkl/ncs/android/lib/utils/TimeHandle.kt

@@ -8,6 +8,7 @@ import java.util.*
  *  事件处理器
  */
 object TimeHandle {
+    const val timeFormat = "MM月dd日 HH:mm:ss"
 
     fun getCurrentDay24Mill() :Long{
         val cal = Calendar.getInstance()
@@ -62,6 +63,11 @@ object TimeHandle {
         return time / (60 * 60 * 24)
     }
 
+    fun getDateTime(): String {
+        val date = Date()
+        return SimpleDateFormat(timeFormat).format(date)
+    }
+
     //按指定格式获取当前日期时间
     fun getDateTime(format: String): String {
         val date = Date(System.currentTimeMillis())

+ 106 - 0
common/src/main/code/com/wdkl/ncs/android/lib/widget/MyClockView.java

@@ -0,0 +1,106 @@
+package com.wdkl.ncs.android.lib.widget;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.SystemClock;
+import android.text.format.DateFormat;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.widget.TextView;
+
+import java.util.Calendar;
+import java.util.TimeZone;
+
+public class MyClockView extends TextView {
+
+    private CharSequence mFormat = "MM-dd HH:mm";
+
+    private Calendar mTime;
+    private String mTimeZone;
+
+    private boolean mStopTicking;
+    private final Handler handler = new Handler(Looper.myLooper());
+
+    private final Runnable mTicker = new Runnable() {
+        public void run() {
+            if (mStopTicking) {
+                return;
+            }
+            onTimeChanged();
+
+            long now = SystemClock.uptimeMillis();
+            long next = now + (1000 - now % 1000);
+
+            handler.postAtTime(mTicker, next);
+        }
+    };
+
+    public MyClockView(Context context) {
+        super(context);
+        init();
+    }
+
+    public MyClockView(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public MyClockView(Context context, AttributeSet attrs, int defStyleAttr) {
+        this(context, attrs, defStyleAttr, 0);
+    }
+
+    public MyClockView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+        super(context, attrs, defStyleAttr, defStyleRes);
+
+        init();
+    }
+
+    private void init() {
+        createTime(mTimeZone);
+    }
+
+    private void createTime(String timeZone) {
+        if (timeZone != null) {
+            mTime = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
+        } else {
+            mTime = Calendar.getInstance();
+        }
+    }
+
+    public String getTimeZone() {
+        return mTimeZone;
+    }
+
+    public CharSequence getFormat() {
+        return mFormat;
+    }
+
+    public void setFormat(CharSequence format) {
+        mFormat = format;
+    }
+
+    @Override
+    protected void onAttachedToWindow() {
+        super.onAttachedToWindow();
+
+        mStopTicking = false;
+    }
+
+    @Override
+    protected void onDetachedFromWindow() {
+        super.onDetachedFromWindow();
+
+        mStopTicking = true;
+        handler.removeCallbacks(mTicker);
+    }
+
+    public void startTick() {
+        mTicker.run();
+    }
+
+    private void onTimeChanged() {
+        mTime.setTimeInMillis(System.currentTimeMillis());
+        setText(DateFormat.format(mFormat, mTime));
+        invalidate();
+    }
+}