Commit 523354cf authored by Varun Patil's avatar Varun Patil

Hide keyboard in explore

parent 549093af
package app.insti; package app.insti;
import android.Manifest; import android.Manifest;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
...@@ -19,6 +20,7 @@ import android.util.Log; ...@@ -19,6 +20,7 @@ import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
...@@ -352,4 +354,15 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -352,4 +354,15 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
return false; return false;
return true; return true;
} }
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view = activity.getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
} }
package app.insti.fragment; package app.insti.fragment;
import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
...@@ -11,6 +12,7 @@ import android.text.TextWatcher; ...@@ -11,6 +12,7 @@ import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import com.google.gson.Gson; import com.google.gson.Gson;
...@@ -211,6 +213,7 @@ public class ExploreFragment extends Fragment { ...@@ -211,6 +213,7 @@ public class ExploreFragment extends Fragment {
} }
public void updateFragment(Fragment fragment, Bundle bundle) { public void updateFragment(Fragment fragment, Bundle bundle) {
MainActivity.hideKeyboard(getActivity());
fragment.setArguments(bundle); fragment.setArguments(bundle);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_right, R.anim.slide_out_right); ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_right, R.anim.slide_out_right);
......
...@@ -68,6 +68,7 @@ import java.util.List; ...@@ -68,6 +68,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import app.insti.MainActivity;
import app.insti.R; import app.insti.R;
import app.insti.api.RetrofitInterface; import app.insti.api.RetrofitInterface;
import app.insti.api.ServiceGenerator; import app.insti.api.ServiceGenerator;
...@@ -955,14 +956,7 @@ public class MapFragment extends Fragment implements TextWatcher, ...@@ -955,14 +956,7 @@ public class MapFragment extends Fragment implements TextWatcher,
} }
private void hideKeyboard() { private void hideKeyboard() {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); MainActivity.hideKeyboard(getActivity());
//Find the currently focused view, so we can grab the correct window token from it.
View view = getActivity().getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = new View(getActivity());
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment