Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.theme.NavigationBaseActivity;
import fr.free.nrw.commons.ui.widget.HtmlTextView;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
Expand Down Expand Up @@ -109,14 +110,14 @@ public void onCreate(Bundle savedInstanceState) {
usernameEdit.addTextChangedListener(textWatcher);
usernameEdit.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus) {
hideKeyboard(v);
ViewUtil.hideKeyboard(v);
}
});

passwordEdit.addTextChangedListener(textWatcher);
passwordEdit.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus) {
hideKeyboard(v);
ViewUtil.hideKeyboard(v);
}
});

Expand Down Expand Up @@ -144,16 +145,6 @@ void onPrivacyPolicyClicked() {
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\"));
}

public void hideKeyboard(View view) {
if (view != null) {
InputMethodManager inputMethodManager = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}


@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.free.nrw.commons.category;


import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
Expand All @@ -16,7 +15,6 @@
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;
Expand All @@ -43,6 +41,7 @@
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.upload.MwVolleyApi;
import fr.free.nrw.commons.utils.StringSortingUtils;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
Expand Down Expand Up @@ -116,7 +115,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

categoriesFilter.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus) {
hideKeyboard(v);
ViewUtil.hideKeyboard(v);
}
});

Expand All @@ -128,16 +127,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return rootView;
}

public void hideKeyboard(View view) {

if (view != null) {
InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}

@Override
public void onDestroyView() {
categoriesFilter.removeTextChangedListener(textWatcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.Contribution;
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
import fr.free.nrw.commons.utils.ViewUtil;

public class MultipleUploadListFragment extends Fragment {

Expand Down Expand Up @@ -129,7 +130,7 @@ public void onStop() {

// FIXME: Stops the keyboard from being shown 'stale' while moving out of this fragment into the next
View target = getActivity().getCurrentFocus();
hideKeyboard(target);
ViewUtil.hideKeyboard(target);
}

// FIXME: Wrong result type
Expand Down Expand Up @@ -178,22 +179,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

baseTitle.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus) {
hideKeyboard(v);
ViewUtil.hideKeyboard(v);
}
});

return view;
}

public void hideKeyboard(View view) {
if (view != null) {
InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}

@Override
public void onDestroyView() {
baseTitle.removeTextChangedListener(textWatcher);
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

import fr.free.nrw.commons.utils.ImageUtils;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.utils.ViewUtil;
import timber.log.Timber;


Expand Down Expand Up @@ -735,7 +736,7 @@ private void zoomImageFromThumb(final View thumbView, Uri imageuri ) {
if (CurrentAnimator != null) {
CurrentAnimator.cancel();
}
hideKeyboard(ShareActivity.this);
ViewUtil.hideKeyboard(ShareActivity.this.findViewById(R.id.titleEdit | R.id.descEdit));
InputStream input = null;
Bitmap scaled = null;
try {
Expand Down Expand Up @@ -905,12 +906,5 @@ public void onAnimationCancel(Animator animation) {

});
}
public static void hideKeyboard(Activity activity) {
View view = activity.findViewById(R.id.titleEdit | R.id.descEdit);
if (view != null) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package fr.free.nrw.commons.upload;

import android.annotation.SuppressLint;
import android.app.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
Expand All @@ -11,20 +9,17 @@
import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AlertDialog;

import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;

import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
Expand All @@ -47,9 +42,9 @@
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.settings.Prefs;
import fr.free.nrw.commons.utils.ViewUtil;
import timber.log.Timber;

import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_UP;

public class SingleUploadFragment extends CommonsDaggerSupportFragment {
Expand Down Expand Up @@ -168,13 +163,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

titleEdit.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus) {
hideKeyboard(v);
ViewUtil.hideKeyboard(v);
}
});

descEdit.setOnFocusChangeListener((v, hasFocus) -> {
if(!hasFocus){
hideKeyboard(v);
ViewUtil.hideKeyboard(v);
}
});

Expand All @@ -183,15 +178,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return rootView;
}

public void hideKeyboard(View view) {
if (view != null) {
InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}

@Override
public void onDestroyView() {
titleEdit.removeTextChangedListener(textWatcher);
Expand Down Expand Up @@ -305,7 +291,7 @@ public void onStop() {

// FIXME: Stops the keyboard from being shown 'stale' while moving out of this fragment into the next
View target = getActivity().getCurrentFocus();
hideKeyboard(target);
ViewUtil.hideKeyboard(target);
}

@NonNull
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/utils/ViewUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.design.widget.Snackbar;
import android.view.Display;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

public class ViewUtil {
Expand All @@ -27,4 +28,14 @@ public static boolean isPortrait(Context context) {
}
}

public static void hideKeyboard(View view){
if (view != null) {
InputMethodManager manager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
view.clearFocus();
if (manager != null) {
manager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}

}