diff --git a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java index 3bbd0844..fd05b3c5 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -1032,7 +1032,8 @@ public class ExecuteTheRecipe { if (ConfigName.getInstance().PlcIsConnect) { //心跳 WritePLC("心跳位",0,null); - Log.e("心跳", "心跳: "+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + Log.e("心跳", "心跳: "); + //Log.e("心跳", "心跳: "+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); } } catch (Exception ex) { diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/SoftKeyBoardListener.java b/app/src/main/java/com/bonait/bnframework/common/helper/SoftKeyBoardListener.java new file mode 100644 index 00000000..bf594a0f --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/SoftKeyBoardListener.java @@ -0,0 +1,72 @@ +package com.bonait.bnframework.common.helper; + +import android.app.Activity; +import android.graphics.Rect; +import android.view.View; +import android.view.ViewTreeObserver; + +public class SoftKeyBoardListener { + private View rootView;//activity的根视图 + int rootViewVisibleHeight;//纪录根视图的显示高度 + private OnSoftKeyBoardChangeListener onSoftKeyBoardChangeListener; + + public SoftKeyBoardListener(Activity activity) { + //获取activity的根视图 + rootView = activity.getWindow().getDecorView(); + + //监听视图树中全局布局发生改变或者视图树中的某个视图的可视状态发生改变 + rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + //获取当前根视图在屏幕上显示的大小 + Rect r = new Rect(); + rootView.getWindowVisibleDisplayFrame(r); + + int visibleHeight = r.height(); + if (rootViewVisibleHeight == 0) { + rootViewVisibleHeight = visibleHeight; + return; + } + + //根视图显示高度没有变化,可以看作软键盘显示/隐藏状态没有改变 + if (rootViewVisibleHeight == visibleHeight) { + return; + } + + //根视图显示高度变小超过200,可以看作软键盘显示了 + if (rootViewVisibleHeight - visibleHeight > 200) { + if (onSoftKeyBoardChangeListener != null) { + onSoftKeyBoardChangeListener.keyBoardShow(rootViewVisibleHeight - visibleHeight); + } + rootViewVisibleHeight = visibleHeight; + return; + } + + //根视图显示高度变大超过200,可以看作软键盘隐藏了 + if (visibleHeight - rootViewVisibleHeight > 200) { + if (onSoftKeyBoardChangeListener != null) { + onSoftKeyBoardChangeListener.keyBoardHide(visibleHeight - rootViewVisibleHeight); + } + rootViewVisibleHeight = visibleHeight; + return; + } + + } + }); + } + + private void setOnSoftKeyBoardChangeListener(OnSoftKeyBoardChangeListener onSoftKeyBoardChangeListener) { + this.onSoftKeyBoardChangeListener = onSoftKeyBoardChangeListener; + } + + public interface OnSoftKeyBoardChangeListener { + void keyBoardShow(int height); + + void keyBoardHide(int height); + } + + public static void setListener(Activity activity, OnSoftKeyBoardChangeListener onSoftKeyBoardChangeListener) { + SoftKeyBoardListener softKeyBoardListener = new SoftKeyBoardListener(activity); + softKeyBoardListener.setOnSoftKeyBoardChangeListener(onSoftKeyBoardChangeListener); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentPR.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentPR.java index 06f4158f..80f7234f 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentPR.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentPR.java @@ -20,6 +20,7 @@ import android.os.Handler; import android.os.Message; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewTreeObserver; import android.widget.RelativeLayout; import android.widget.TextView; @@ -33,6 +34,7 @@ import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.helper.I.MyClickListener; +import com.bonait.bnframework.common.helper.SoftKeyBoardListener; import com.bonait.bnframework.common.message.MessageLooper; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.model.mode.CloudGood; @@ -122,7 +124,16 @@ public class HomeFragmentPR extends BaseFragment { mTopBar.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.topbj1)); mTopBar.setTitle("菜谱"); mTopBar.addRightTextButton("设备状态:" + (ConfigName.getInstance().PlcIsConnect ? "已连接" : "未连接"), R.id.status_image); + SoftKeyBoardListener.setListener(activity, new SoftKeyBoardListener.OnSoftKeyBoardChangeListener() { + @Override + public void keyBoardShow(int height) { + } + @Override + public void keyBoardHide(int height) { + search_view.clearFocus(); + } + }); new Thread(new Runnable() { @Override public void run() {