Skip to content

Commit

Permalink
Simplify Meizu fix by forcing creation of a hintLayout
Browse files Browse the repository at this point in the history
GIT_ORIGIN_REV_ID=5545bb3920a651e8a2e1f1a0586fbecdad7c55bb

Resolves #358

PiperOrigin-RevId: 248391866
  • Loading branch information
CmoaToto authored and leticiarossi committed May 16, 2019
1 parent 5ddd08b commit ccb7fbe
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.android.material.R;

import android.content.Context;
import android.os.Build;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatEditText;
import android.util.AttributeSet;
Expand Down Expand Up @@ -48,12 +49,28 @@ public TextInputEditText(Context context, AttributeSet attrs, int defStyleAttr)
super(context, attrs, defStyleAttr);
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();

// Meizu devices expect TextView#mHintLayout to be non-null if TextView#getHint() is non-null.
// In order to avoid crashing, we force the creation of the layout by setting an empty non-null
// hint.
TextInputLayout layout = getTextInputLayout();
if (layout != null
&& layout.isProvidingHint()
&& super.getHint() == null
&& Build.MANUFACTURER.equals("Meizu")) {
setHint("");
}
}

@Override
public CharSequence getHint() {
// Certain test frameworks expect the actionable element to expose its hint as a label. When
// TextInputLayout is providing our hint, retrieve it from the parent layout.
TextInputLayout layout = getTextInputLayout();
if ((layout != null) && layout.isProvidingHint()) {
if (layout != null && layout.isProvidingHint()) {
return layout.getHint();
}
return super.getHint();
Expand Down

0 comments on commit ccb7fbe

Please sign in to comment.