diff --git a/app/src/main/java/com/hippo/widget/HackyTextInputEditText.java b/app/src/main/java/com/hippo/widget/HackyTextInputEditText.java new file mode 100644 index 000000000..c053c9aee --- /dev/null +++ b/app/src/main/java/com/hippo/widget/HackyTextInputEditText.java @@ -0,0 +1,56 @@ +/* + * Copyright 2018 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.widget; + +import android.content.Context; +import android.os.Build; +import android.support.design.widget.TextInputEditText; +import android.util.AttributeSet; +import android.widget.TextView; +import java.lang.reflect.Field; + +// Avoid crash on some Meizu devices +// https://github.com/android-in-china/Compatibility/issues/11 +// https://stackoverflow.com/questions/51891415/nullpointerexception-on-meizu-devices-in-editor-updatecursorpositionmz/52001305 +public class HackyTextInputEditText extends TextInputEditText { + + public HackyTextInputEditText(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public CharSequence getHint() { + boolean isMeizu = Build.MANUFACTURER.toLowerCase().contains("meizu"); + boolean isPreP = Build.VERSION.SDK_INT < Build.VERSION_CODES.P; + + if (isMeizu && isPreP) { + try { + return getSuperHint(); + } catch (Exception e) { + return super.getHint(); + } + } else { + return super.getHint(); + } + } + + public CharSequence getSuperHint() throws NoSuchFieldException, IllegalAccessException { + Field field = TextView.class.getDeclaredField("mHint"); + field.setAccessible(true); + return (CharSequence) field.get(this); + } +} diff --git a/app/src/main/res/layout/dialog_add_filter.xml b/app/src/main/res/layout/dialog_add_filter.xml index 1ab987bba..6a1a1a25d 100644 --- a/app/src/main/res/layout/dialog_add_filter.xml +++ b/app/src/main/res/layout/dialog_add_filter.xml @@ -37,7 +37,7 @@ android:layout_gravity="center_horizontal" android:layout_marginTop="16dp"> - - - - - - - - - - - - -