Search in sources :

Example 56 with TextWatcher

use of android.text.TextWatcher in project Android-Developers-Samples by johnjohndoe.

the class LogFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View result = inflateViews();
    mLogView.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) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
        }
    });
    return result;
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ScrollView(android.widget.ScrollView) View(android.view.View)

Example 57 with TextWatcher

use of android.text.TextWatcher in project EditTextInListView by Aspsine.

the class LineAdapter method getView.

@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
    final ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_line, parent, false);
        holder.etLine = (EditText) convertView.findViewById(R.id.etLine);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    final Line line = lines.get(position);
    if (holder.etLine.getTag() instanceof TextWatcher) {
        holder.etLine.removeTextChangedListener((TextWatcher) (holder.etLine.getTag()));
    }
    holder.etLine.setHint(position + ".");
    if (TextUtils.isEmpty(line.getText())) {
        holder.etLine.setText("");
    } else {
        holder.etLine.setText(line.getText());
    }
    if (line.isFocus()) {
        if (!holder.etLine.isFocused()) {
            holder.etLine.requestFocus();
        }
        CharSequence text = line.getText();
        holder.etLine.setSelection(TextUtils.isEmpty(text) ? 0 : text.length());
    } else {
        if (holder.etLine.isFocused()) {
            holder.etLine.clearFocus();
        }
    }
    holder.etLine.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(final View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                final boolean focus = line.isFocus();
                check(position);
                if (!focus && !holder.etLine.isFocused()) {
                    holder.etLine.requestFocus();
                    holder.etLine.onWindowFocusChanged(true);
                }
            }
            return false;
        }
    });
    final TextWatcher watcher = new SimpeTextWather() {

        @Override
        public void afterTextChanged(Editable s) {
            if (TextUtils.isEmpty(s)) {
                line.setText(null);
            } else {
                line.setText(String.valueOf(s));
            }
        }
    };
    holder.etLine.addTextChangedListener(watcher);
    holder.etLine.setTag(watcher);
    return convertView;
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 58 with TextWatcher

use of android.text.TextWatcher in project AndroidChromium by JackyAndroid.

the class NewTabPageView method initializeSearchBoxTextView.

/**
     * Sets up the hint text and event handlers for the search box text view.
     */
private void initializeSearchBoxTextView() {
    final TextView searchBoxTextView = (TextView) mSearchBoxView.findViewById(R.id.search_box_text);
    String hintText = getResources().getString(R.string.search_or_type_url);
    if (!DeviceFormFactor.isTablet(getContext()) || mManager.isFakeOmniboxTextEnabledTablet()) {
        searchBoxTextView.setHint(hintText);
    } else {
        searchBoxTextView.setContentDescription(hintText);
    }
    searchBoxTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mManager.focusSearchBox(false, null);
        }
    });
    searchBoxTextView.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) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() == 0)
                return;
            mManager.focusSearchBox(false, s.toString());
            searchBoxTextView.setText("");
        }
    });
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) NewTabPageRecyclerView(org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 59 with TextWatcher

use of android.text.TextWatcher in project AndroidChromium by JackyAndroid.

the class FloatLabelLayout method setEditText.

private void setEditText(EditText editText) {
    // If we already have an EditText, throw an exception
    if (mEditText != null) {
        throw new IllegalArgumentException("We already have an EditText, can only have one");
    }
    mEditText = editText;
    // Update the label visibility with no animation
    updateLabelVisibility(false);
    // Add a TextWatcher so that we know when the text input has changed
    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            updateLabelVisibility(true);
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    // Add focus listener to the EditText so that we can notify the label that it is activated.
    // Allows the use of a ColorStateList for the text color on the label
    mEditText.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean focused) {
            updateLabelVisibility(true);
        }
    });
    // If we do not have a valid hint, try and retrieve it from the EditText
    if (TextUtils.isEmpty(mHint)) {
        setHint(mEditText.getHint());
    }
    // If we do not have a valid content description, set it to the hint text.
    if (TextUtils.isEmpty(mEditText.getContentDescription())) {
        mEditText.setContentDescription(mHint);
    }
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) View(android.view.View)

Example 60 with TextWatcher

use of android.text.TextWatcher in project UltimateAndroid by cymcsg.

the class MarqueeView method initView.

private void initView(Context context) {
    // Scroll View
    LayoutParams sv1lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    sv1lp.gravity = Gravity.CENTER_HORIZONTAL;
    mScrollView = new ScrollView(context);
    // Scroll View 1 - Text Field
    mTextField = (TextView) getChildAt(0);
    removeView(mTextField);
    mScrollView.addView(mTextField, new ScrollView.LayoutParams(TEXTVIEW_VIRTUAL_WIDTH, LayoutParams.WRAP_CONTENT));
    mTextField.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            final boolean continueAnimation = mStarted;
            reset();
            prepareAnimation();
            cutTextView();
            post(new Runnable() {

                @Override
                public void run() {
                    if (continueAnimation) {
                        startMarquee();
                    }
                }
            });
        }
    });
    addView(mScrollView, sv1lp);
}
Also used : ScrollView(android.widget.ScrollView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Paint(android.graphics.Paint)

Aggregations

TextWatcher (android.text.TextWatcher)192 Editable (android.text.Editable)158 View (android.view.View)96 TextView (android.widget.TextView)75 Paint (android.graphics.Paint)37 ImageView (android.widget.ImageView)30 TextPaint (android.text.TextPaint)28 EditText (android.widget.EditText)28 Intent (android.content.Intent)25 KeyEvent (android.view.KeyEvent)24 AdapterView (android.widget.AdapterView)21 ListView (android.widget.ListView)17 RecyclerView (android.support.v7.widget.RecyclerView)15 DialogInterface (android.content.DialogInterface)13 SuppressLint (android.annotation.SuppressLint)12 OnClickListener (android.view.View.OnClickListener)12 Button (android.widget.Button)12 InputMethodManager (android.view.inputmethod.InputMethodManager)11 AlertDialog (android.app.AlertDialog)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)9