Skip to content

Commit 9b5eb1f

Browse files
committed
Fixed soft keyboard bug
1 parent 61bfe84 commit 9b5eb1f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public void onPageSelected(int position) {
179179
Timber.d("Contributions tab selected");
180180
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
181181
isContributionsFragmentVisible = true;
182+
((NearbyParentFragment)contributionsActivityPagerAdapter.getItem(NEARBY_TAB_POSITION)).hideKeyboard();
182183
updateMenuItem();
183184
break;
184185
case NEARBY_TAB_POSITION:

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package fr.free.nrw.commons.nearby.fragments;
22

33
import android.Manifest;
4+
import android.app.Activity;
45
import android.app.AlertDialog;
56
import android.content.BroadcastReceiver;
67
import android.content.Context;
78
import android.content.Intent;
89
import android.content.IntentFilter;
910
import android.content.res.Configuration;
1011
import android.os.Bundle;
12+
import android.os.IBinder;
1113
import android.util.Log;
1214
import android.view.Gravity;
1315
import android.view.LayoutInflater;
1416
import android.view.View;
1517
import android.view.ViewGroup;
1618
import android.view.animation.Animation;
1719
import android.view.animation.AnimationUtils;
20+
import android.view.inputmethod.InputMethodManager;
1821
import android.widget.Button;
1922
import android.widget.FrameLayout;
2023
import android.widget.ImageView;
@@ -491,6 +494,20 @@ public void centerMapToPlace(Place place) {
491494
}
492495
}
493496

497+
/**
498+
* Hides the keyboard in case the tab is switched
499+
*/
500+
public void hideKeyboard(){
501+
if(!searchView.isIconified()) {
502+
searchView.clearFocus();
503+
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
504+
final IBinder windowToken = this.getView().getRootView().getWindowToken();
505+
if (view != null) {
506+
imm.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
507+
}
508+
}
509+
}
510+
494511

495512
/**
496513
* Thanks to this method we make sure NearbyMapFragment is ready and attached. So that we can

0 commit comments

Comments
 (0)