Browse Source

烹饪界面怎么输入法关闭,去掉收索框的焦点

燃气自翻炒锅
fyf 1 year ago
parent
commit
339a2afb6c
3 changed files with 85 additions and 1 deletions
  1. +2
    -1
      app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java
  2. +72
    -0
      app/src/main/java/com/bonait/bnframework/common/helper/SoftKeyBoardListener.java
  3. +11
    -0
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentPR.java

+ 2
- 1
app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java View File

@@ -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) {


+ 72
- 0
app/src/main/java/com/bonait/bnframework/common/helper/SoftKeyBoardListener.java View File

@@ -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);
}
}

+ 11
- 0
app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentPR.java View File

@@ -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() {


Loading…
Cancel
Save