X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Futils%2FMisc.java;h=c75b6339ae0fb0b074deed2d2088ed7c0e811fd2;hb=4db312e69578236dbfca979b840222b751da2f8c;hp=16ad9e2c3c933cc769077031170fce86d899101c;hpb=2c000fc2be641f773b764d2040bb5878cc162a83;p=mobile-ledger-staging.git diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java b/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java index 16ad9e2c..c75b6339 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Damyan Ivanov. + * Copyright © 2020 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -18,9 +18,13 @@ package net.ktnx.mobileledger.utils; import android.app.Activity; +import android.content.res.Configuration; +import android.text.Editable; import android.view.WindowManager; +import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; public class Misc { public static boolean isZero(float f) { @@ -28,10 +32,53 @@ public class Misc { } public static void showSoftKeyboard(Activity activity) { // make the keyboard appear - activity.getWindow() - .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + Configuration cf = activity.getResources() + .getConfiguration(); + if (cf.keyboard == Configuration.KEYBOARD_NOKEYS || + cf.keyboardHidden == Configuration.KEYBOARDHIDDEN_YES) + activity.getWindow() + .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } public static void showSoftKeyboard(Fragment fragment) { - showSoftKeyboard(fragment.getActivity()); + final FragmentActivity activity = fragment.getActivity(); + if (activity != null) + showSoftKeyboard(activity); + } + public static void hideSoftKeyboard(Fragment fragment) { + final FragmentActivity activity = fragment.getActivity(); + if (activity != null) + hideSoftKeyboard(activity); + } + public static void hideSoftKeyboard(Activity activity) { + Configuration cf = activity.getResources() + .getConfiguration(); + if (cf.keyboard == Configuration.KEYBOARD_NOKEYS || + cf.keyboardHidden == Configuration.KEYBOARDHIDDEN_NO) + activity.getWindow() + .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); + + } + public static String emptyIsNull(String str) { + return "".equals(str) ? null : str; + } + public static String nullIsEmpty(String str) { + return (str == null) ? "" : str; + } + public static String nullIsEmpty(Editable e) { + if (e == null) + return ""; + return e.toString(); + } + public static boolean equalStrings(String u, CharSequence text) { + return nullIsEmpty(u).equals(text.toString()); + } + public static boolean equalStrings(String a, String b) { + return nullIsEmpty(a).equals(nullIsEmpty(b)); + } + public static String trim(@Nullable String string) { + if (string == null) + return null; + + return string.trim(); } }