From 9b5eb1ffe90f12b0e026aa507fa0854232b1f8ef Mon Sep 17 00:00:00 2001 From: animeshk08 Date: Sun, 2 Feb 2020 20:26:59 +0530 Subject: [PATCH 1/2] Fixed soft keyboard bug --- .../nrw/commons/contributions/MainActivity.java | 1 + .../nearby/fragments/NearbyParentFragment.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java index 96c32d5c46..ce4d55bdcf 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java @@ -179,6 +179,7 @@ public void onPageSelected(int position) { Timber.d("Contributions tab selected"); tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select(); isContributionsFragmentVisible = true; + ((NearbyParentFragment)contributionsActivityPagerAdapter.getItem(NEARBY_TAB_POSITION)).hideKeyboard(); updateMenuItem(); break; case NEARBY_TAB_POSITION: diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java index 0b98799e23..602b517a16 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java @@ -1,6 +1,7 @@ package fr.free.nrw.commons.nearby.fragments; import android.Manifest; +import android.app.Activity; import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.Context; @@ -8,6 +9,7 @@ import android.content.IntentFilter; import android.content.res.Configuration; import android.os.Bundle; +import android.os.IBinder; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; @@ -15,6 +17,7 @@ import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationUtils; +import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; @@ -491,6 +494,20 @@ public void centerMapToPlace(Place place) { } } + /** + * Hides the keyboard in case the tab is switched + */ + public void hideKeyboard(){ + if(!searchView.isIconified()) { + searchView.clearFocus(); + InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); + final IBinder windowToken = this.getView().getRootView().getWindowToken(); + if (view != null) { + imm.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS); + } + } + } + /** * Thanks to this method we make sure NearbyMapFragment is ready and attached. So that we can From 5f5732fc6b0bf8cb2e065ca9cbc9223a7a18c06b Mon Sep 17 00:00:00 2001 From: animeshk08 Date: Mon, 3 Feb 2020 01:39:03 +0530 Subject: [PATCH 2/2] removed involvement of nearbyFragment --- .../nrw/commons/contributions/MainActivity.java | 3 ++- .../nearby/fragments/NearbyParentFragment.java | 17 ----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java index ce4d55bdcf..67e67fbf3b 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java @@ -42,6 +42,7 @@ import fr.free.nrw.commons.quiz.QuizChecker; import fr.free.nrw.commons.theme.NavigationBaseActivity; import fr.free.nrw.commons.upload.UploadService; +import fr.free.nrw.commons.utils.ViewUtil; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import timber.log.Timber; @@ -179,7 +180,7 @@ public void onPageSelected(int position) { Timber.d("Contributions tab selected"); tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select(); isContributionsFragmentVisible = true; - ((NearbyParentFragment)contributionsActivityPagerAdapter.getItem(NEARBY_TAB_POSITION)).hideKeyboard(); + ViewUtil.hideKeyboard(tabLayout.getRootView()); updateMenuItem(); break; case NEARBY_TAB_POSITION: diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java index 602b517a16..0b98799e23 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java @@ -1,7 +1,6 @@ package fr.free.nrw.commons.nearby.fragments; import android.Manifest; -import android.app.Activity; import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.Context; @@ -9,7 +8,6 @@ import android.content.IntentFilter; import android.content.res.Configuration; import android.os.Bundle; -import android.os.IBinder; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; @@ -17,7 +15,6 @@ import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationUtils; -import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; @@ -494,20 +491,6 @@ public void centerMapToPlace(Place place) { } } - /** - * Hides the keyboard in case the tab is switched - */ - public void hideKeyboard(){ - if(!searchView.isIconified()) { - searchView.clearFocus(); - InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); - final IBinder windowToken = this.getView().getRootView().getWindowToken(); - if (view != null) { - imm.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS); - } - } - } - /** * Thanks to this method we make sure NearbyMapFragment is ready and attached. So that we can