Java Code Examples for com.google.android.material.textfield.TextInputLayout#getEditText()

The following examples show how to use com.google.android.material.textfield.TextInputLayout#getEditText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignInScene.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView2(LayoutInflater inflater, @Nullable ViewGroup container,
                          @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_login, container, false);

    View loginForm = ViewUtils.$$(view, R.id.login_form);
    mProgress = ViewUtils.$$(view, R.id.progress);
    mUsernameLayout = (TextInputLayout) ViewUtils.$$(loginForm, R.id.username_layout);
    mUsername = mUsernameLayout.getEditText();
    AssertUtils.assertNotNull(mUsername);
    mPasswordLayout = (TextInputLayout) ViewUtils.$$(loginForm, R.id.password_layout);
    mPassword = mPasswordLayout.getEditText();
    AssertUtils.assertNotNull(mPassword);
    mSignIn = ViewUtils.$$(loginForm, R.id.sign_in);
    mSkipSigningIn = (TextView) ViewUtils.$$(loginForm, R.id.skip_signing_in);

    mSkipSigningIn.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
    mPassword.setOnEditorActionListener(this);
    mSignIn.setOnClickListener(this);
    mSkipSigningIn.setOnClickListener(this);
    return view;
}
 
Example 2
Source File: DynamicInputUtils.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
/**
 * Tint the {@link TextInputLayout} by changing its label and focus colors according to the
 * supplied color.
 *
 * @param textInputLayout The text input layout to be colorized.
 * @param color The color to be used.
 */
public static void setColor(@NonNull TextInputLayout textInputLayout, @ColorInt int color) {
    try {
        Field fFocusedTextColor = TextInputLayout.class.getDeclaredField("focusedTextColor");
        fFocusedTextColor.setAccessible(true);
        fFocusedTextColor.set(textInputLayout, ColorStateList.valueOf(color));
        Method mUpdateLabelState = TextInputLayout.class.getDeclaredMethod(
                "updateLabelState", boolean.class, boolean.class);
        mUpdateLabelState.setAccessible(true);
        mUpdateLabelState.invoke(textInputLayout, false, true);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (textInputLayout.getEditText() != null) {
        setColor(textInputLayout.getEditText(), textInputLayout.getBoxBackgroundColor(), color);
        textInputLayout.setHintTextColor(textInputLayout.getEditText().getHintTextColors());
    }
}
 
Example 3
Source File: FilterActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public void setDialog(AlertDialog dialog) {
    mDialog = dialog;
    mSpinner = (Spinner) ViewUtils.$$(dialog, R.id.spinner);
    mInputLayout = (TextInputLayout) ViewUtils.$$(dialog, R.id.text_input_layout);
    mEditText = mInputLayout.getEditText();
    View button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if (null != button) {
        button.setOnClickListener(this);
    }
}
 
Example 4
Source File: TimePickerTextInputKeyController.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/** Prepare Text inputs to receive key events and IME actions. */
public void bind() {
  TextInputLayout hourLayout = hourLayoutComboView.getTextInput();
  TextInputLayout minuteLayout = minuteLayoutComboView.getTextInput();
  EditText hourEditText = hourLayout.getEditText();
  EditText minuteEditText = minuteLayout.getEditText();

  hourEditText.setImeOptions(IME_ACTION_NEXT | IME_FLAG_NO_EXTRACT_UI);
  minuteEditText.setImeOptions(IME_ACTION_DONE | IME_FLAG_NO_EXTRACT_UI);

  hourEditText.setOnEditorActionListener(this);
  hourEditText.setOnKeyListener(this);
  minuteEditText.setOnKeyListener(this);
}
 
Example 5
Source File: ChipTextInputComboView.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
public ChipTextInputComboView(
    @NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  LayoutInflater inflater = LayoutInflater.from(context);
  chip = (Chip) inflater.inflate(R.layout.material_time_chip, this, false);
  textInputLayout = (TextInputLayout) inflater.inflate(R.layout.material_time_input, this, false);
  editText = textInputLayout.getEditText();
  editText.setVisibility(INVISIBLE);
  watcher = new HintSetterTextWatcher();
  editText.addTextChangedListener(watcher);
  addView(chip);
  addView(textInputLayout);
}
 
Example 6
Source File: FilterActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public void setDialog(AlertDialog dialog) {
    mDialog = dialog;
    mSpinner = (Spinner) ViewUtils.$$(dialog, R.id.spinner);
    mInputLayout = (TextInputLayout) ViewUtils.$$(dialog, R.id.text_input_layout);
    mEditText = mInputLayout.getEditText();
    View button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if (null != button) {
        button.setOnClickListener(this);
    }
}
 
Example 7
Source File: CookieSignInScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView2(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_cookie_sign_in, container, false);
    mIpbMemberIdLayout = (TextInputLayout) ViewUtils.$$(view, R.id.ipb_member_id_layout);
    mIpbMemberId = mIpbMemberIdLayout.getEditText();
    AssertUtils.assertNotNull(mIpbMemberId);
    mIpbPassHashLayout = (TextInputLayout) ViewUtils.$$(view, R.id.ipb_pass_hash_layout);
    mIpbPassHash = mIpbPassHashLayout.getEditText();
    AssertUtils.assertNotNull(mIpbPassHash);
    mIgneousLayout = (TextInputLayout) ViewUtils.$$(view, R.id.igneous_layout);
    mIgneous = mIgneousLayout.getEditText();
    AssertUtils.assertNotNull(mIgneous);
    mOk = ViewUtils.$$(view, R.id.ok);

    mIpbPassHash.setOnEditorActionListener(this);

    mOk.setOnClickListener(this);

    // Try to get old version cookie info
    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    SharedPreferences sharedPreferences = context.getSharedPreferences("eh_info", 0);
    String ipbMemberId = sharedPreferences.getString("ipb_member_id", null);
    String ipbPassHash = sharedPreferences.getString("ipb_pass_hash", null);
    String igneous = sharedPreferences.getString("igneous", null);
    boolean getIt = false;
    if (!TextUtils.isEmpty(ipbMemberId)) {
        mIpbMemberId.setText(ipbMemberId);
        getIt = true;
    }
    if (!TextUtils.isEmpty(ipbPassHash)) {
        mIpbPassHash.setText(ipbPassHash);
        getIt = true;
    }
    if (!TextUtils.isEmpty(igneous)) {
        mIgneous.setText(igneous);
        getIt = true;
    }
    if (getIt) {
        showTip(R.string.found_cookies, LENGTH_SHORT);
    }

    return view;
}
 
Example 8
Source File: CommonUtils.java    From CommonUtils with Apache License 2.0 4 votes vote down vote up
@NonNull
public static EditText getEditText(@NonNull TextInputLayout layout) {
    if (layout.getEditText() == null)
        throw new IllegalStateException("TextInputLayout hasn't a TextInputEditText");
    return layout.getEditText();
}
 
Example 9
Source File: CommonUtils.java    From CommonUtils with Apache License 2.0 4 votes vote down vote up
@NonNull
public static String getText(@NonNull TextInputLayout layout) {
    if (layout.getEditText() == null)
        throw new IllegalStateException("TextInputLayout hasn't a TextInputEditText");
    return layout.getEditText().getText().toString();
}
 
Example 10
Source File: CommonUtils.java    From CommonUtils with Apache License 2.0 4 votes vote down vote up
public static void setText(@NonNull TextInputLayout layout, CharSequence val) {
    if (layout.getEditText() != null) layout.getEditText().setText(val);
}
 
Example 11
Source File: SingleDateSelector.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateTextInputView(
    @NonNull LayoutInflater layoutInflater,
    @Nullable ViewGroup viewGroup,
    @Nullable Bundle bundle,
    CalendarConstraints constraints,
    final @NonNull OnSelectionChangedListener<Long> listener) {
  View root = layoutInflater.inflate(R.layout.mtrl_picker_text_input_date, viewGroup, false);

  TextInputLayout dateTextInput = root.findViewById(R.id.mtrl_picker_text_input_date);
  EditText dateEditText = dateTextInput.getEditText();
  if (ManufacturerUtils.isDateInputKeyboardMissingSeparatorCharacters()) {
    // Using the URI variation places the '/' and '.' in more prominent positions
    dateEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
  }
  SimpleDateFormat format = UtcDates.getTextInputFormat();
  String formatHint = UtcDates.getTextInputHint(root.getResources(), format);

  if (selectedItem != null) {
    dateEditText.setText(format.format(selectedItem));
  }

  dateEditText.addTextChangedListener(
      new DateFormatTextWatcher(formatHint, format, dateTextInput, constraints) {

        @Override
        void onValidDate(@Nullable Long day) {
          if (day == null) {
            clearSelection();
          } else {
            select(day);
          }
          listener.onSelectionChanged(getSelection());
        }

        @Override
        void onInvalidDate() {
          listener.onIncompleteSelectionChanged();
        }
      });

  ViewUtils.requestFocusAndShowKeyboard(dateEditText);

  return root;
}
 
Example 12
Source File: SignInScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView2(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_login, container, false);

    View loginForm = ViewUtils.$$(view, R.id.login_form);
    mProgress = ViewUtils.$$(view, R.id.progress);
    mUsernameLayout = (TextInputLayout) ViewUtils.$$(loginForm, R.id.username_layout);
    mUsername = mUsernameLayout.getEditText();
    AssertUtils.assertNotNull(mUsername);
    mPasswordLayout = (TextInputLayout) ViewUtils.$$(loginForm, R.id.password_layout);
    mPassword = mPasswordLayout.getEditText();
    AssertUtils.assertNotNull(mPassword);
    mRegister = ViewUtils.$$(loginForm, R.id.register);
    mSignIn = ViewUtils.$$(loginForm, R.id.sign_in);
    mSignInViaWebView = (TextView) ViewUtils.$$(loginForm, R.id.sign_in_via_webview);
    mSignInViaCookies = (TextView) ViewUtils.$$(loginForm, R.id.sign_in_via_cookies);
    mSkipSigningIn = (TextView) ViewUtils.$$(loginForm, R.id.skip_signing_in);

    mSignInViaWebView.setPaintFlags(mSignInViaWebView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    mSignInViaCookies.setPaintFlags(mSignInViaCookies.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    mSkipSigningIn.setPaintFlags(mSignInViaCookies.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

    mPassword.setOnEditorActionListener(this);

    mRegister.setOnClickListener(this);
    mSignIn.setOnClickListener(this);
    mSignInViaWebView.setOnClickListener(this);
    mSignInViaCookies.setOnClickListener(this);
    mSkipSigningIn.setOnClickListener(this);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    EhApplication application = (EhApplication) context.getApplicationContext();
    if (application.containGlobalStuff(mRequestId)) {
        mSigningIn = true;
        // request exist
        showProgress(false);
    }

    return view;
}
 
Example 13
Source File: CookieSignInScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView2(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_cookie_sign_in, container, false);
    mIpbMemberIdLayout = (TextInputLayout) ViewUtils.$$(view, R.id.ipb_member_id_layout);
    mIpbMemberId = mIpbMemberIdLayout.getEditText();
    AssertUtils.assertNotNull(mIpbMemberId);
    mIpbPassHashLayout = (TextInputLayout) ViewUtils.$$(view, R.id.ipb_pass_hash_layout);
    mIpbPassHash = mIpbPassHashLayout.getEditText();
    AssertUtils.assertNotNull(mIpbPassHash);
    mIgneousLayout = (TextInputLayout) ViewUtils.$$(view, R.id.igneous_layout);
    mIgneous = mIgneousLayout.getEditText();
    AssertUtils.assertNotNull(mIgneous);
    mOk = ViewUtils.$$(view, R.id.ok);

    mIpbPassHash.setOnEditorActionListener(this);

    mOk.setOnClickListener(this);

    // Try to get old version cookie info
    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    SharedPreferences sharedPreferences = context.getSharedPreferences("eh_info", 0);
    String ipbMemberId = sharedPreferences.getString("ipb_member_id", null);
    String ipbPassHash = sharedPreferences.getString("ipb_pass_hash", null);
    String igneous = sharedPreferences.getString("igneous", null);
    boolean getIt = false;
    if (!TextUtils.isEmpty(ipbMemberId)) {
        mIpbMemberId.setText(ipbMemberId);
        getIt = true;
    }
    if (!TextUtils.isEmpty(ipbPassHash)) {
        mIpbPassHash.setText(ipbPassHash);
        getIt = true;
    }
    if (!TextUtils.isEmpty(igneous)) {
        mIgneous.setText(igneous);
        getIt = true;
    }
    if (getIt) {
        showTip(R.string.found_cookies, LENGTH_SHORT);
    }

    return view;
}