mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-26 03:46:49 +01:00
Fix preference input type enforcement
This commit is contained in:
parent
b6e252c4c1
commit
eb896dcd57
@ -18,17 +18,21 @@
|
|||||||
|
|
||||||
package nodomain.freeyourgadget.gadgetbridge.util.dialogs;
|
package nodomain.freeyourgadget.gadgetbridge.util.dialogs;
|
||||||
|
|
||||||
import static androidx.annotation.RestrictTo.Scope.LIBRARY;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.RestrictTo;
|
|
||||||
import androidx.preference.EditTextPreference;
|
import androidx.preference.EditTextPreference;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class MaterialEditTextPreferenceDialogFragment extends MaterialPreferenceDialogFragment {
|
public class MaterialEditTextPreferenceDialogFragment extends MaterialPreferenceDialogFragment {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(MaterialEditTextPreferenceDialogFragment.class);
|
||||||
|
|
||||||
private static final String SAVE_STATE_TEXT = "EditTextPreferenceDialogFragment.text";
|
private static final String SAVE_STATE_TEXT = "EditTextPreferenceDialogFragment.text";
|
||||||
|
|
||||||
@ -76,9 +80,18 @@ public class MaterialEditTextPreferenceDialogFragment extends MaterialPreference
|
|||||||
mEditText.setText(mText);
|
mEditText.setText(mText);
|
||||||
// Place cursor at the end
|
// Place cursor at the end
|
||||||
mEditText.setSelection(mEditText.getText().length());
|
mEditText.setSelection(mEditText.getText().length());
|
||||||
// if (getEditTextPreference().getOnBindEditTextListener() != null) {
|
// Use reflection to be able to call EditTextPreference.getOnBindEditTextListener(), which is package-private
|
||||||
// getEditTextPreference().getOnBindEditTextListener().onBindEditText(mEditText);
|
Method getOnBindEditTextListener = null;
|
||||||
// }
|
try {
|
||||||
|
getOnBindEditTextListener = EditTextPreference.class.getDeclaredMethod("getOnBindEditTextListener");
|
||||||
|
getOnBindEditTextListener.setAccessible(true);
|
||||||
|
EditTextPreference.OnBindEditTextListener listener = (EditTextPreference.OnBindEditTextListener) getOnBindEditTextListener.invoke(getEditTextPreference());
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onBindEditText(mEditText);
|
||||||
|
}
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||||
|
LOG.error("Error when using reflection to access EditTextPreference.getOnBindEditTextListener()", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private EditTextPreference getEditTextPreference() {
|
private EditTextPreference getEditTextPreference() {
|
||||||
@ -86,7 +99,6 @@ public class MaterialEditTextPreferenceDialogFragment extends MaterialPreference
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@RestrictTo(LIBRARY)
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean needInputMethod() {
|
protected boolean needInputMethod() {
|
||||||
// We want the input method to show, if possible, when dialog is displayed
|
// We want the input method to show, if possible, when dialog is displayed
|
||||||
|
Loading…
Reference in New Issue
Block a user