mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Hide Keypad when EditText out of focus (#1168)
* Hide Keypad when EditText out of focus
This commit is contained in:
parent
45aab1ce76
commit
9aceaca95d
6 changed files with 120 additions and 35 deletions
|
|
@ -4,6 +4,7 @@ import android.accounts.Account;
|
|||
import android.accounts.AccountAuthenticatorActivity;
|
||||
import android.accounts.AccountAuthenticatorResponse;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
|
@ -17,10 +18,12 @@ import android.support.v4.content.ContextCompat;
|
|||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
|
@ -91,7 +94,19 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
ButterKnife.bind(this);
|
||||
|
||||
usernameEdit.addTextChangedListener(textWatcher);
|
||||
usernameEdit.setOnFocusChangeListener((v, hasFocus) -> {
|
||||
if (!hasFocus) {
|
||||
hideKeyboard(v);
|
||||
}
|
||||
});
|
||||
|
||||
passwordEdit.addTextChangedListener(textWatcher);
|
||||
passwordEdit.setOnFocusChangeListener((v, hasFocus) -> {
|
||||
if (!hasFocus) {
|
||||
hideKeyboard(v);
|
||||
}
|
||||
});
|
||||
|
||||
twoFactorEdit.addTextChangedListener(textWatcher);
|
||||
passwordEdit.setOnEditorActionListener(newLoginInputActionListener());
|
||||
|
||||
|
|
@ -99,6 +114,13 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
|||
signupButton.setOnClickListener(view -> signUp());
|
||||
}
|
||||
|
||||
|
||||
public void hideKeyboard(View view) {
|
||||
InputMethodManager inputMethodManager =(InputMethodManager)this.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,22 @@
|
|||
package fr.free.nrw.commons.category;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
|
@ -37,6 +42,7 @@ import fr.free.nrw.commons.R;
|
|||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import fr.free.nrw.commons.upload.MwVolleyApi;
|
||||
import fr.free.nrw.commons.upload.SingleUploadFragment;
|
||||
import fr.free.nrw.commons.utils.StringSortingUtils;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
|
|
@ -72,6 +78,7 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
|
|||
private OnCategoriesSaveHandler onCategoriesSaveHandler;
|
||||
private HashMap<String, ArrayList<String>> categoriesCache;
|
||||
private List<CategoryItem> selectedCategories = new ArrayList<>();
|
||||
private TitleTextWatcher textWatcher = new TitleTextWatcher();
|
||||
|
||||
private final CategoriesAdapterFactory adapterFactory = new CategoriesAdapterFactory(item -> {
|
||||
if (item.isSelected()) {
|
||||
|
|
@ -102,6 +109,15 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
|
|||
categoriesAdapter = adapterFactory.create(items);
|
||||
categoriesList.setAdapter(categoriesAdapter);
|
||||
|
||||
|
||||
categoriesFilter.addTextChangedListener(textWatcher);
|
||||
|
||||
categoriesFilter.setOnFocusChangeListener((v, hasFocus) -> {
|
||||
if (!hasFocus) {
|
||||
hideKeyboard(v);
|
||||
}
|
||||
});
|
||||
|
||||
RxTextView.textChanges(categoriesFilter)
|
||||
.takeUntil(RxView.detaches(categoriesFilter))
|
||||
.debounce(500, TimeUnit.MILLISECONDS)
|
||||
|
|
@ -110,6 +126,18 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
|
|||
return rootView;
|
||||
}
|
||||
|
||||
public void hideKeyboard(View view) {
|
||||
InputMethodManager inputMethodManager =(InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
categoriesFilter.removeTextChangedListener(textWatcher);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.clear();
|
||||
|
|
@ -351,4 +379,21 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
|
|||
.create()
|
||||
.show();
|
||||
}
|
||||
|
||||
private class TitleTextWatcher implements TextWatcher {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if (getActivity() != null) {
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.upload;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.net.Uri;
|
||||
|
|
@ -10,6 +11,7 @@ import android.text.Editable;
|
|||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
|
@ -177,9 +179,21 @@ public class MultipleUploadListFragment extends Fragment {
|
|||
photosGrid.setColumnWidth(photoSize.x);
|
||||
|
||||
baseTitle.addTextChangedListener(textWatcher);
|
||||
|
||||
baseTitle.setOnFocusChangeListener((v, hasFocus) -> {
|
||||
if (!hasFocus) {
|
||||
hideKeyboard(v);
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public void hideKeyboard(View view) {
|
||||
InputMethodManager inputMethodManager =(InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
baseTitle.removeTextChangedListener(textWatcher);
|
||||
|
|
|
|||
|
|
@ -19,12 +19,16 @@
|
|||
android:layout_marginRight="@dimen/standard_gap"
|
||||
android:layout_marginStart="@dimen/standard_gap"
|
||||
android:layout_marginTop="@dimen/large_gap"
|
||||
android:clickable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
app:cardCornerRadius="4dp"
|
||||
app:cardElevation="4dp">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
|
@ -149,8 +153,8 @@
|
|||
|
||||
<Button
|
||||
android:id="@+id/signupButton"
|
||||
android:layout_width="0dp"
|
||||
style="@style/Widget.AppCompat.Button.Borderless.Colored"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginEnd="@dimen/small_gap"
|
||||
|
|
@ -160,8 +164,8 @@
|
|||
|
||||
<Button
|
||||
android:id="@+id/loginButton"
|
||||
android:layout_width="0dp"
|
||||
style="@style/Widget.AppCompat.Button.Colored"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/small_gap"
|
||||
android:layout_marginStart="@dimen/small_gap"
|
||||
|
|
@ -188,19 +192,19 @@
|
|||
<android.support.v7.widget.AppCompatImageView
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:elevation="8dp"
|
||||
tools:ignore="UnusedAttribute"
|
||||
android:layout_gravity="center_horizontal"
|
||||
app:srcCompat="@drawable/blue_rinse_circle" />
|
||||
android:elevation="8dp"
|
||||
app:srcCompat="@drawable/blue_rinse_circle"
|
||||
tools:ignore="UnusedAttribute" />
|
||||
|
||||
<android.support.v7.widget.AppCompatImageView
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="42dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
tools:ignore="UnusedAttribute"
|
||||
android:elevation="8dp"
|
||||
app:srcCompat="@drawable/commons_logo_large" />
|
||||
app:srcCompat="@drawable/commons_logo_large"
|
||||
tools:ignore="UnusedAttribute" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,70 +1,67 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/fragmentCategorisationBackground"
|
||||
android:clickable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/small_gap"
|
||||
android:paddingLeft="@dimen/standard_gap"
|
||||
android:paddingStart="@dimen/standard_gap"
|
||||
android:paddingRight="@dimen/standard_gap"
|
||||
android:paddingEnd="@dimen/standard_gap"
|
||||
android:paddingLeft="@dimen/standard_gap"
|
||||
android:paddingRight="@dimen/standard_gap"
|
||||
android:paddingStart="@dimen/standard_gap"
|
||||
android:paddingTop="@dimen/small_gap"
|
||||
android:theme="@style/DarkAppTheme"
|
||||
>
|
||||
android:theme="@style/DarkAppTheme">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
>
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:focusableInTouchMode="true">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/categoriesSearchBox"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/categories_search_text_hint"
|
||||
android:maxLines="1"
|
||||
android:inputType="textCapWords"
|
||||
android:imeOptions="flagNoExtractUi"
|
||||
/>
|
||||
android:inputType="textCapWords"
|
||||
android:maxLines="1" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/categoriesSearchInProgress"
|
||||
style="?android:progressBarStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:layout_marginEnd="@dimen/tiny_gap"
|
||||
android:layout_marginRight="@dimen/tiny_gap"
|
||||
android:indeterminate="true"
|
||||
android:indeterminateOnly="true"
|
||||
android:layout_marginRight="@dimen/tiny_gap"
|
||||
android:layout_marginEnd="@dimen/tiny_gap"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
style="?android:progressBarStyleSmall"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
android:visibility="gone" />
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/categoriesNotFound"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:visibility="gone"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
/>
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/categoriesExplanation"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/huge_gap"
|
||||
android:gravity="center"
|
||||
android:focusable="true"
|
||||
android:gravity="center"
|
||||
android:text="@string/categories_skip_explanation"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
android:visibility="gone" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/categoriesListBox"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:fadingEdge="none"
|
||||
/>
|
||||
android:layout_height="wrap_content"
|
||||
android:fadingEdge="none" />
|
||||
</LinearLayout>
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
>
|
||||
|
||||
<EditText
|
||||
|
|
@ -23,4 +25,5 @@
|
|||
android:fadingEdge="none"
|
||||
android:fastScrollEnabled="false"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue