[Quick search] Hide keyboard when click on categories or when user scrolls history
This commit is contained in:
parent
c119e5849e
commit
0f9370d20b
3 changed files with 38 additions and 0 deletions
|
@ -7,6 +7,7 @@ import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
|
@ -50,6 +51,19 @@ public class AndroidUtils {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void hideSoftKeyboard(final Activity activity, final View input) {
|
||||||
|
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||||
|
if (inputMethodManager != null) {
|
||||||
|
if (input != null) {
|
||||||
|
IBinder windowToken = input.getWindowToken();
|
||||||
|
if (windowToken != null) {
|
||||||
|
inputMethodManager.hideSoftInputFromWindow(windowToken, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static String formatDate(Context ctx, long time) {
|
public static String formatDate(Context ctx, long time) {
|
||||||
return DateFormat.getDateFormat(ctx).format(new Date(time));
|
return DateFormat.getDateFormat(ctx).format(new Date(time));
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentPagerAdapter;
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v4.content.FileProvider;
|
import android.support.v4.content.FileProvider;
|
||||||
|
import android.support.v4.view.ViewPager;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -263,6 +264,20 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
|
|
||||||
tabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
|
tabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
|
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {
|
||||||
|
hideKeyboard();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrollStateChanged(int state) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
searchEditText = (EditText) view.findViewById(R.id.searchEditText);
|
searchEditText = (EditText) view.findViewById(R.id.searchEditText);
|
||||||
searchEditText.addTextChangedListener(new TextWatcher() {
|
searchEditText.addTextChangedListener(new TextWatcher() {
|
||||||
|
@ -333,6 +348,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
return searchEditText.getText().toString();
|
return searchEditText.getText().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hideKeyboard() {
|
||||||
|
if (searchEditText.hasFocus()) {
|
||||||
|
AndroidUtils.hideSoftKeyboard(getActivity(), searchEditText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void show() {
|
public void show() {
|
||||||
getMapActivity().setQuickSearchTopbarActive(false);
|
getMapActivity().setQuickSearchTopbarActive(false);
|
||||||
if (useMapCenter) {
|
if (useMapCenter) {
|
||||||
|
|
|
@ -64,6 +64,9 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
||||||
|
|
||||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||||
scrolling = (scrollState != AbsListView.OnScrollListener.SCROLL_STATE_IDLE);
|
scrolling = (scrollState != AbsListView.OnScrollListener.SCROLL_STATE_IDLE);
|
||||||
|
if (scrolling) {
|
||||||
|
dialogFragment.hideKeyboard();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
View header = getLayoutInflater(savedInstanceState).inflate(R.layout.list_shadow_header, null);
|
View header = getLayoutInflater(savedInstanceState).inflate(R.layout.list_shadow_header, null);
|
||||||
|
|
Loading…
Reference in a new issue