Move 'dismissKeyboard()' to UiUtils class.

This commit is contained in:
Michal 2015-12-21 20:16:27 +01:00
parent 4c34e72fe3
commit 2bd46a42aa
3 changed files with 30 additions and 11 deletions

View file

@ -13,12 +13,12 @@ import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import com.facebook.FacebookSdk;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import com.raizlabs.android.dbflow.config.FlowManager;
import com.squareup.leakcanary.LeakCanary;
import org.solovyev.android.checkout.Billing;
import org.solovyev.android.checkout.Cache;
import org.solovyev.android.checkout.Checkout;
@ -268,12 +268,4 @@ public class HabiticaApplication extends Application {
}
// endregion
public static void dismissKeyboard() {
InputMethodManager imm = (InputMethodManager) currentActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
View currentFocus = currentActivity.getCurrentFocus();
if (currentFocus != null) {
imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}
}
}

View file

@ -0,0 +1,26 @@
package com.habitrpg.android.habitica.ui;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
/**
* Simple utilities class for UI related stuff.
*/
public class UiUtils {
/**
* Hides soft keyboard if it's opened.
*
* @param activity Currently visible activity.
*/
public static void dismissKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
View currentFocus = activity.getCurrentFocus();
if (currentFocus != null) {
imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}
}
}

View file

@ -23,6 +23,7 @@ import com.habitrpg.android.habitica.events.commands.FlagChatMessageCommand;
import com.habitrpg.android.habitica.events.commands.SendNewGroupMessageCommand;
import com.habitrpg.android.habitica.events.commands.ToggleInnCommand;
import com.habitrpg.android.habitica.events.commands.ToggleLikeMessageCommand;
import com.habitrpg.android.habitica.ui.UiUtils;
import com.habitrpg.android.habitica.ui.adapter.ChatRecyclerViewAdapter;
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
@ -213,7 +214,7 @@ public class ChatListFragment extends Fragment implements SwipeRefreshLayout.OnR
}
});
HabiticaApplication.dismissKeyboard();
UiUtils.dismissKeyboard(HabiticaApplication.currentActivity);
}
// If the ChatList is Tavern, we're able to toggle the sleep-mode