From 30859ca8f2175475d2c666353bc27f3b2ceede53 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 22 八月 2024 13:43:47 +0800 Subject: [PATCH] 2024年08月22日13:43:45 --- app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java | 66 +++++++++++++++++++++++++++++++- 1 files changed, 63 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java index 067e6f3..6268561 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java @@ -1,12 +1,14 @@ package com.hdl.photovoltaic.ui.message; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.view.View; +import android.view.inputmethod.InputMethodManager; import androidx.annotation.NonNull; import androidx.recyclerview.widget.LinearLayoutManager; @@ -20,6 +22,7 @@ import com.hdl.photovoltaic.base.CustomBaseActivity; import com.hdl.photovoltaic.databinding.ActivitySearchMessgeBinding; import com.hdl.photovoltaic.listener.CloudCallBeak; +import com.hdl.photovoltaic.other.HdlCommonLogic; import com.hdl.photovoltaic.other.HdlFileLogic; import com.hdl.photovoltaic.other.HdlLogLogic; import com.hdl.photovoltaic.other.HdlMessageLogic; @@ -27,6 +30,7 @@ import com.hdl.photovoltaic.ui.adapter.SearchHistoryAdapter; import com.hdl.photovoltaic.ui.adapter.SearchMessageAdapter; import com.hdl.photovoltaic.ui.bean.MessageBean; +import com.hdl.photovoltaic.utils.KeyboardStateObserverUtils; import java.util.ArrayList; import java.util.Collections; @@ -106,6 +110,8 @@ HdlThreadLogic.toast(_mActivity, R.string.search_content_null); return; } + viewBinding.messageSearchEt.clearFocus(); + hideSoftInputFromWindow(); viewBinding.historyListParent.setVisibility(View.GONE); viewBinding.listParent.setVisibility(View.VISIBLE); addSearchTextToList(); @@ -151,17 +157,23 @@ currSearchText = ""; viewBinding.messageSearchEt.setText(""); viewBinding.historyListParent.setVisibility(View.VISIBLE); + viewBinding.deviceNullDataIc.getRoot().setVisibility(View.GONE); viewBinding.listParent.setVisibility(View.GONE); searchHistoryAdapter.setList(searchHistoryTitleList); clearCacheData(); + viewBinding.messageSearchEt.requestFocus(); + showSoftInput(); } }); //鍒犻櫎 viewBinding.messageDelIv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + viewBinding.messageSearchEt.clearFocus(); + hideSoftInputFromWindow(); searchHistoryTitleList = new ArrayList<>(); searchHistoryAdapter.setList(searchHistoryTitleList); + viewBinding.deviceNullDataIc.getRoot().setVisibility(View.GONE); HdlFileLogic.getInstance().deleteFile(getHistoryFileNamePath()); } }); @@ -176,6 +188,8 @@ HdlThreadLogic.toast(_mActivity, R.string.search_content_null); return; } + viewBinding.messageSearchEt.clearFocus(); + hideSoftInputFromWindow(); viewBinding.historyListParent.setVisibility(View.GONE); viewBinding.listParent.setVisibility(View.VISIBLE); addSearchTextToList(); @@ -195,6 +209,23 @@ } + /** + * 鏄剧ず杞敭鐩� + */ + public void showSoftInput() { + InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.showSoftInput(viewBinding.messageSearchEt, 0); + + } + + /** + * 闅愯棌杞敭鐩� + */ + public void hideSoftInputFromWindow() { + InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.hideSoftInputFromWindow(viewBinding.getRoot().getWindowToken(), 0); + } + private void initView() { viewBinding.historyListParent.setVisibility(View.VISIBLE); viewBinding.listParent.setVisibility(View.GONE); @@ -208,6 +239,29 @@ searchMessageAdapter = new SearchMessageAdapter(_mActivity); viewBinding.listRcv.setLayoutManager(new LinearLayoutManager(_mActivity)); viewBinding.listRcv.setAdapter(searchMessageAdapter); + viewBinding.messageSearchEt.post(new Runnable() { + @Override + public void run() { + viewBinding.messageSearchEt.requestFocus(); + } + }); + + //鍦ㄧ晫闈腑浣跨敤 + KeyboardStateObserverUtils.getKeyboardStateObserver(_mActivity).setKeyboardVisibilityListener(new KeyboardStateObserverUtils.OnKeyboardVisibilityListener() { + @Override + public void onKeyboardShow(int h) { + //Toast.makeText(MainActivity.this,"閿洏寮瑰嚭",Toast.LENGTH_SHORT).show(); +// viewBinding.messageSearchEt.requestFocus(); + + } + + @Override + + public void onKeyboardHide(int h) { + viewBinding.messageSearchEt.clearFocus(); + } + + }); } @@ -247,6 +301,7 @@ if (searchMessageAdapter != null) { searchMessageAdapter.setList(mList); } + nullDataUpdateUi(); } }); } @@ -394,14 +449,19 @@ searchHistoryTitleList.remove(searchHistoryTitleList.get(i)); } } - searchHistoryTitleList.add(currSearchText); - // 鍊掑簭鎺掑垪鏁版嵁(鎼滅储鏈�鍚庢帓鍦ㄥ墠闈�) - Collections.reverse(searchHistoryTitleList); + searchHistoryTitleList.add(0, currSearchText); if (searchHistoryTitleList.size() > maxValue) { //鍘嗗彶璁板綍涓嶈兘瓒呭嚭10 searchHistoryTitleList.remove(searchHistoryTitleList.get(maxValue)); } + } + /** + * 娌℃湁娑堟伅鍒楄〃鐨勬牱寮� + */ + private void nullDataUpdateUi() { + boolean is_data = mList != null && mList.size() > 0; + HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, viewBinding.deviceNullDataIc.getRoot(), viewBinding.deviceNullDataIc.nullDataGifAnimationIv, viewBinding.deviceNullDataIc.nullDataTv, getString(R.string.message_alarm_data_null), is_data); } /** -- Gitblit v1.8.0