Closing Keyboard when clicked in the background (#5437)
This commit is contained in:
parent
8951583a02
commit
5e0b95fa5c
@ -11,6 +11,7 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
@ -158,6 +159,10 @@ public class AddFeedFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void performSearch() {
|
||||
viewBinding.combinedFeedSearchEditText.clearFocus();
|
||||
InputMethodManager in = (InputMethodManager)
|
||||
getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
in.hideSoftInputFromWindow(viewBinding.combinedFeedSearchEditText.getWindowToken(), 0);
|
||||
String query = viewBinding.combinedFeedSearchEditText.getText().toString();
|
||||
if (query.matches("http[s]?://.*")) {
|
||||
addUrl(query);
|
||||
|
@ -1,15 +1,20 @@
|
||||
package de.danoeh.antennapod.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.widget.AbsListView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ProgressBar;
|
||||
@ -110,6 +115,21 @@ public class OnlineSearchFragment extends Fragment {
|
||||
TextView txtvPoweredBy = root.findViewById(R.id.search_powered_by);
|
||||
txtvPoweredBy.setText(getString(R.string.search_powered_by, searchProvider.getName()));
|
||||
setupToolbar(root.findViewById(R.id.toolbar));
|
||||
|
||||
gridView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
if (scrollState == SCROLL_STATE_TOUCH_SCROLL) {
|
||||
InputMethodManager imm = (InputMethodManager)
|
||||
getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||
}
|
||||
});
|
||||
return root;
|
||||
}
|
||||
|
||||
@ -142,6 +162,11 @@ public class OnlineSearchFragment extends Fragment {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
sv.setOnQueryTextFocusChangeListener((view, hasFocus) -> {
|
||||
if (hasFocus) {
|
||||
showInputMethod(view.findFocus());
|
||||
}
|
||||
});
|
||||
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||
@Override
|
||||
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||
@ -192,4 +217,11 @@ public class OnlineSearchFragment extends Fragment {
|
||||
txtvEmpty.setVisibility(View.GONE);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void showInputMethod(View view) {
|
||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (imm != null) {
|
||||
imm.showSoftInput(view, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.danoeh.antennapod.fragment;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@ -9,6 +11,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ProgressBar;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -70,7 +73,6 @@ public class SearchFragment extends Fragment {
|
||||
private SearchView searchView;
|
||||
private Handler automaticSearchDebouncer;
|
||||
private long lastQueryChange = 0;
|
||||
|
||||
/**
|
||||
* Create a new SearchFragment that searches all feeds.
|
||||
*/
|
||||
@ -153,6 +155,22 @@ public class SearchFragment extends Fragment {
|
||||
if (getArguments().getString(ARG_QUERY, null) != null) {
|
||||
search();
|
||||
}
|
||||
searchView.setOnQueryTextFocusChangeListener((view, hasFocus) -> {
|
||||
if (hasFocus) {
|
||||
showInputMethod(view.findFocus());
|
||||
}
|
||||
});
|
||||
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
||||
InputMethodManager imm = (InputMethodManager)
|
||||
getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(recyclerView.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
return layout;
|
||||
}
|
||||
|
||||
@ -320,4 +338,11 @@ public class SearchFragment extends Fragment {
|
||||
List<Feed> feeds = FeedSearcher.searchFeeds(getContext(), query);
|
||||
return new Pair<>(items, feeds);
|
||||
}
|
||||
|
||||
private void showInputMethod(View view) {
|
||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (imm != null) {
|
||||
imm.showSoftInput(view, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user