Search in sources :

Example 81 with TextWatcher

use of android.text.TextWatcher in project WordPress-Android by wordpress-mobile.

the class NewUserFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout containing a title and body text.
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.new_account_user_fragment_screen, container, false);
    WPTextView termsOfServiceTextView = (WPTextView) rootView.findViewById(R.id.l_agree_terms_of_service);
    termsOfServiceTextView.setText(Html.fromHtml(String.format(getString(R.string.agree_terms_of_service), "<u>", "</u>")));
    termsOfServiceTextView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ActivityLauncher.openUrlExternal(getContext(), getString(R.string.wordpresscom_tos_url));
        }
    });
    mSignupButton = (WPTextView) rootView.findViewById(R.id.signup_button);
    mSignupButton.setOnClickListener(mSignupClickListener);
    mSignupButton.setEnabled(false);
    mProgressTextSignIn = (WPTextView) rootView.findViewById(R.id.nux_sign_in_progress_text);
    mProgressBarSignIn = (RelativeLayout) rootView.findViewById(R.id.nux_sign_in_progress_bar);
    mEmailTextField = (EditText) rootView.findViewById(R.id.email_address);
    mEmailTextField.setText(UserEmailUtils.getPrimaryEmail(getActivity()));
    mEmailTextField.setSelection(EditTextUtils.getText(mEmailTextField).length());
    mPasswordTextField = (EditText) rootView.findViewById(R.id.password);
    mUsernameTextField = (EditText) rootView.findViewById(R.id.username);
    mSiteUrlTextField = (EditText) rootView.findViewById(R.id.site_url);
    mEmailTextField.addTextChangedListener(this);
    mPasswordTextField.addTextChangedListener(this);
    mUsernameTextField.addTextChangedListener(this);
    mSiteUrlTextField.setOnKeyListener(mSiteUrlKeyListener);
    mSiteUrlTextField.setOnEditorActionListener(mEditorAction);
    mSiteUrlTextField.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            checkIfFieldsFilled();
        }

        @Override
        public void afterTextChanged(Editable editable) {
            lowerCaseEditable(editable);
        }
    });
    mUsernameTextField.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // auto fill blog address
            mSiteUrlTextField.setError(null);
            if (mAutoCompleteUrl) {
                mSiteUrlTextField.setText(EditTextUtils.getText(mUsernameTextField));
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
            lowerCaseEditable(editable);
        }
    });
    mUsernameTextField.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                mAutoCompleteUrl = EditTextUtils.getText(mUsernameTextField).equals(EditTextUtils.getText(mSiteUrlTextField)) || EditTextUtils.isEmpty(mSiteUrlTextField);
            }
        }
    });
    mEmailTextField.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                autocorrectEmail();
            }
        }
    });
    initPasswordVisibilityButton(rootView, mPasswordTextField);
    initInfoButton(rootView);
    return rootView;
}
Also used : ViewGroup(android.view.ViewGroup) OnClickListener(android.view.View.OnClickListener) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) WPTextView(org.wordpress.android.widgets.WPTextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) WPTextView(org.wordpress.android.widgets.WPTextView)

Example 82 with TextWatcher

use of android.text.TextWatcher in project WordPress-Android by wordpress-mobile.

the class PeopleInviteFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mUsernamesContainer = (ViewGroup) view.findViewById(R.id.usernames);
    mUsernamesContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EditTextUtils.showSoftInput(mUsernameEditText);
        }
    });
    Role role = mRole;
    if (role == null) {
        role = getDefaultRole();
    }
    mUsernameEditText = (MultiUsernameEditText) view.findViewById(R.id.invite_usernames);
    //handle key preses from hardware keyboard
    mUsernameEditText.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            return keyEvent.getKeyCode() == KeyEvent.KEYCODE_DEL && keyEvent.getAction() == KeyEvent.ACTION_DOWN && removeLastEnteredUsername();
        }
    });
    mUsernameEditText.setOnBackspacePressedListener(new MultiUsernameEditText.OnBackspacePressedListener() {

        @Override
        public boolean onBackspacePressed() {
            return removeLastEnteredUsername();
        }
    });
    mUsernameEditText.addTextChangedListener(new TextWatcher() {

        private boolean shouldIgnoreChanges = false;

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (shouldIgnoreChanges) {
                //used to avoid double call after calling setText from this method
                return;
            }
            shouldIgnoreChanges = true;
            if (mUsernameButtons.size() >= MAX_NUMBER_OF_INVITEES && !TextUtils.isEmpty(s)) {
                resetEditTextContent(mUsernameEditText);
            } else if (endsWithDelimiter(mUsernameEditText.getText().toString())) {
                addUsername(mUsernameEditText, null);
            }
            shouldIgnoreChanges = false;
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    mUsernameEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                addUsername(mUsernameEditText, null);
                return true;
            } else {
                return false;
            }
        }
    });
    mUsernameEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus && mUsernameEditText.getText().toString().length() > 0) {
                addUsername(mUsernameEditText, null);
            }
        }
    });
    if (mUsernameButtons.size() > 0) {
        ArrayList<String> usernames = new ArrayList<>(mUsernameButtons.keySet());
        populateUsernameButtons(usernames);
    }
    mRoleTextView = (TextView) view.findViewById(R.id.role);
    setRole(role);
    ImageView imgRoleInfo = (ImageView) view.findViewById(R.id.imgRoleInfo);
    imgRoleInfo.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ActivityLauncher.openUrlExternal(v.getContext(), URL_USER_ROLES_DOCUMENTATION);
        }
    });
    if (Role.inviteRoles(mSite).length > 1) {
        view.findViewById(R.id.role_container).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                RoleSelectDialogFragment.show(PeopleInviteFragment.this, 0, mSite);
            }
        });
    } else {
        // Don't show drop-down arrow or role selector if there's only one role available
        mRoleTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    }
    final int MAX_CHARS = getResources().getInteger(R.integer.invite_message_char_limit);
    final TextView remainingCharsTextView = (TextView) view.findViewById(R.id.message_remaining);
    mCustomMessageEditText = (EditText) view.findViewById(R.id.message);
    mCustomMessageEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mCustomMessage = mCustomMessageEditText.getText().toString();
            updateRemainingCharsView(remainingCharsTextView, mCustomMessage, MAX_CHARS);
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    updateRemainingCharsView(remainingCharsTextView, mCustomMessage, MAX_CHARS);
}
Also used : ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Role(org.wordpress.android.models.Role) KeyEvent(android.view.KeyEvent) MultiUsernameEditText(org.wordpress.android.widgets.MultiUsernameEditText) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 83 with TextWatcher

use of android.text.TextWatcher in project pictureapp by EyeSeeTea.

the class NumberMultiQuestionView method init.

private void init(final Context context) {
    inflate(context, R.layout.multi_question_tab_int_row, this);
    header = (CustomTextView) findViewById(R.id.row_header_text);
    numberPicker = (CustomEditText) findViewById(R.id.answer);
    Validation.getInstance().addInput(numberPicker);
    numberPicker.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            try {
                int value = Integer.parseInt(s.toString());
                notifyAnswerChanged(String.valueOf(value));
            } catch (NumberFormatException e) {
                Validation.getInstance().addinvalidInput(numberPicker, context.getString(R.string.dynamic_error_number));
            //numberPicker.setError(context.getString(R.string.dynamic_error_number));
            }
            notifyAnswerChanged(numberPicker.getText().toString());
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Example 84 with TextWatcher

use of android.text.TextWatcher in project pictureapp by EyeSeeTea.

the class PositiveNumberMultiQuestionView method init.

private void init(final Context context) {
    inflate(context, R.layout.multi_question_tab_positive_int_row, this);
    header = (CustomTextView) findViewById(R.id.row_header_text);
    numberPicker = (CustomEditText) findViewById(R.id.answer);
    Validation.getInstance().addInput(numberPicker);
    numberPicker.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            try {
                positiveNumber = PositiveNumber.parse(numberPicker.getText().toString());
                notifyAnswerChanged(String.valueOf(positiveNumber.getValue()));
                Validation.getInstance().removeInputError(numberPicker);
            } catch (InvalidPositiveNumberException e) {
                Validation.getInstance().addinvalidInput(numberPicker, context.getString(R.string.dynamic_error_age));
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
}
Also used : InvalidPositiveNumberException(org.eyeseetea.malariacare.domain.exception.InvalidPositiveNumberException) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Example 85 with TextWatcher

use of android.text.TextWatcher in project BBS-Android by bdpqchen.

the class ThreadActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    mThreadId = intent.getIntExtra(INTENT_THREAD_ID, 0);
    mThreadFloor = intent.getIntExtra(INTENT_THREAD_FLOOR, 1);
    mThreadTitle = intent.getStringExtra(INTENT_THREAD_TITLE);
    super.onCreate(savedInstanceState);
    mSlideBackLayout.lock(!PrefUtil.isSlideBackMode());
    mContext = this;
    mPresenter.getThread(mThreadId, 0);
    mAdapter = new PostAdapter(mContext);
    mLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
    mRvThreadPost.addItemDecoration(new RecyclerViewItemDecoration(5));
    mRvThreadPost.setLayoutManager(mLayoutManager);
    mRvThreadPost.setAdapter(mAdapter);
    mRvThreadPost.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItemPosition + 1 == mAdapter.getItemCount()) {
                if (!mEnding) {
                    mPage++;
                    mIsLoadingMore = true;
                    mPresenter.getThread(mThreadId, mPage);
                }
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            lastVisibleItemPosition = mLayoutManager.findLastVisibleItemPosition();
        }
    });
    mFbThreadWritePost.setOnClickListener(v -> {
        showCommentInput();
        resetReply();
    });
    mEtComment.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (mEtComment != null && mEtComment.getText().toString().length() > 0) {
                mIvCommentOut.setVisibility(View.GONE);
                mIvCommentSend.setVisibility(View.VISIBLE);
            } else {
                mIvCommentOut.setVisibility(View.VISIBLE);
                mIvCommentSend.setVisibility(View.GONE);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    mIvCommentOut.setOnClickListener(v -> showFab());
    mIvCommentSend.setOnClickListener(v -> sendComment(mReplyId));
    mIvStaredThread.setOnClickListener(v -> {
        if (PrefUtil.hadLogin()) {
            mPresenter.unStarThread(mThreadId);
        }
    });
    mIvStarThread.setOnClickListener(v -> {
        if (PrefUtil.hadLogin()) {
            mPresenter.starThread(mThreadId);
        }
    });
    mSrlThreadList.setColorSchemeColors(getResources().getIntArray(R.array.swipeRefreshColors));
    mSrlThreadList.setOnRefreshListener(() -> {
        mRefreshing = true;
        mPage = 0;
        mPresenter.getThread(mThreadId, mPage);
    });
    mAdapter.setOnItemClickListener((view, position) -> {
        postPosition = position;
        mReplyId = mAdapter.getPostId(position);
        showCommentInput();
    });
    mCbAnonymousComment.setOnCheckedChangeListener((buttonView, isChecked) -> {
        mIsAnonymous = isChecked;
    });
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Intent(android.content.Intent) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerViewItemDecoration(com.twtstudio.bbs.bdpqchen.bbs.commons.helper.RecyclerViewItemDecoration)

Aggregations

TextWatcher (android.text.TextWatcher)177 Editable (android.text.Editable)143 View (android.view.View)86 TextView (android.widget.TextView)67 Paint (android.graphics.Paint)37 TextPaint (android.text.TextPaint)28 ImageView (android.widget.ImageView)27 EditText (android.widget.EditText)26 Intent (android.content.Intent)24 KeyEvent (android.view.KeyEvent)21 AdapterView (android.widget.AdapterView)18 ListView (android.widget.ListView)15 DialogInterface (android.content.DialogInterface)12 Button (android.widget.Button)12 RecyclerView (android.support.v7.widget.RecyclerView)11 AlertDialog (android.app.AlertDialog)10 OnClickListener (android.view.View.OnClickListener)10 InputMethodManager (android.view.inputmethod.InputMethodManager)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)9 SuppressLint (android.annotation.SuppressLint)8