Example usage for android.text Editable length

List of usage examples for android.text Editable length

Introduction

In this page you can find the example usage for android.text Editable length.

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditExpenseActivity.java

@Override
public void afterTextChanged(Editable s) {
    // TODO Auto-generated method stub
    switch (getCurrentFocus().getId()) {
    case R.id.Edit_Expense_Name2:
        if (s.length() == 0) {
            Toast.makeText(this, "Expense name cannot be null", Toast.LENGTH_LONG).show();
        } else {//from  www .  java 2  s.c om
            expense.setName(expenseNameInput.getText().toString());
        }
    case R.id.Edit_Expense_Date2:
        try {
            expense.setDate(sdf.parse(date.getText().toString()));
        } catch (ParseException e) {
            //do nothing 
        }

    case R.id.Edit_Expense_Cost2:
        try {
            expense.setCost(Integer.parseInt(expenseCostInput.getText().toString()));
        } catch (NumberFormatException e) {
            //do nothing
        }
    case R.id.Edit_Expense_Description2:
        expense.setDes(expenseDescriptionInput.getText().toString());
    }
}

From source file:com.todoroo.astrid.notes.EditNoteActivity.java

private void setUpInterface() {
    timerView = commentsBar.findViewById(R.id.timer_container);
    commentButton = commentsBar.findViewById(R.id.commentButton);
    commentField = (EditText) commentsBar.findViewById(R.id.commentField);

    final boolean showTimerShortcut = preferences.getBoolean(R.string.p_show_timer_shortcut, false);

    if (showTimerShortcut) {
        commentField.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override/*www  .  ja  v a  2 s .c  om*/
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    timerView.setVisibility(View.GONE);
                    commentButton.setVisibility(View.VISIBLE);
                } else {
                    timerView.setVisibility(View.VISIBLE);
                    commentButton.setVisibility(View.GONE);
                }
            }
        });
    }
    commentField.setHorizontallyScrolling(false);
    commentField.setMaxLines(Integer.MAX_VALUE);
    commentField.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                AndroidUtilities.hideSoftInputForViews(activity, commentField);
                return true;
            }
            return false;
        }
    });
    commentField.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            commentField.setCursorVisible(true);
        }
    });

    commentField.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            commentButton.setVisibility(
                    (s.length() > 0 || pendingCommentPicture != null) ? View.VISIBLE : View.GONE);
            if (showTimerShortcut) {
                timerView.setVisibility(
                        (s.length() > 0 || pendingCommentPicture != null) ? View.GONE : View.VISIBLE);
            }
        }

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

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

    commentField.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (commentField.getText().length() > 0) {
                if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_NULL) {
                    //                        commentField.setCursorVisible(false);
                    addComment();
                }
            }
            return false;
        }
    });

    commentButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            addComment();
        }
    });

    final ClearImageCallback clearImage = new ClearImageCallback() {
        @Override
        public void clearImage() {
            pendingCommentPicture = null;
            pictureButton.setImageResource(cameraButton);
        }
    };
    pictureButton = (ImageButton) commentsBar.findViewById(R.id.picture);
    pictureButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (pendingCommentPicture != null) {
                actFmCameraModule.showPictureLauncher(clearImage);
            } else {
                actFmCameraModule.showPictureLauncher(null);
            }
            respondToPicture = true;
        }
    });
    if (!TextUtils.isEmpty(task.getNotes())) {
        TextView notes = new TextView(getContext());
        notes.setLinkTextColor(Color.rgb(100, 160, 255));
        notes.setTextSize(18);
        notes.setText(task.getNotes());
        notes.setPadding(5, 10, 5, 10);
        Linkify.addLinks(notes, Linkify.ALL);
    }

    if (activity != null) {
        String uri = activity.getIntent().getStringExtra(TaskEditFragment.TOKEN_PICTURE_IN_PROGRESS);
        if (uri != null) {
            pendingCommentPicture = Uri.parse(uri);
            setPictureButtonToPendingPicture();
        }
    }
}

From source file:com.bofsoft.laio.customerservice.Fragment.CarListFragment.java

private void set_eSearch_TextChanged() {
    et_carlist_search.addTextChangedListener(new TextWatcher() {

        @Override/*from   www  .j  av  a  2  s.  c om*/
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub
            //handler.post(eChanged);
            new Handler(Looper.getMainLooper()).post(eChanged);
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            /**?? 
             * ????listview???
             * ??
             */
            if (s.length() == 0) {
                //                    ivDeleteText.setVisibility(View.GONE);//??
            } else {
                //                    ivDeleteText.setVisibility(View.VISIBLE);//???

            }
        }
    });

}

From source file:org.mozilla.gecko.sync.setup.activities.SetupSyncActivity.java

/**
 * Displays layout for entering a PIN from another device.
 * A Sync Account has already been set up.
 *//*w  w w  .  ja  v  a 2 s  . c o m*/
private void displayPairWithPin() {
    Logger.debug(LOG_TAG, "PairWithPin initiated.");
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            setContentView(R.layout.sync_setup_pair);
            connectButton = (Button) findViewById(R.id.pair_button_connect);
            pinError = (LinearLayout) findViewById(R.id.pair_error);

            row1 = (EditText) findViewById(R.id.pair_row1);
            row2 = (EditText) findViewById(R.id.pair_row2);
            row3 = (EditText) findViewById(R.id.pair_row3);

            row1.addTextChangedListener(new TextWatcher() {
                @Override
                public void afterTextChanged(Editable s) {
                    activateButton(connectButton, pinEntryCompleted());
                    if (s.length() == 4) {
                        row2.requestFocus();
                    }
                }

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

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

            });
            row2.addTextChangedListener(new TextWatcher() {
                @Override
                public void afterTextChanged(Editable s) {
                    activateButton(connectButton, pinEntryCompleted());
                    if (s.length() == 4) {
                        row3.requestFocus();
                    }
                }

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

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

            });

            row3.addTextChangedListener(new TextWatcher() {
                @Override
                public void afterTextChanged(Editable s) {
                    activateButton(connectButton, pinEntryCompleted());
                }

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

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

From source file:com.example.feedback.ActivityFeedback.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feedback);

    // Set action bar title to Feedback.
    actionBar = getActionBar();/*from  w w  w  .  j a  v  a  2 s .c o  m*/
    actionBar.setTitle(getResources().getString(R.string.title_feedback));

    // Set views.
    spinnerFrom = (Spinner) findViewById(R.id.spinner_from);
    inputText = (EditText) findViewById(R.id.input_test);
    checkScreen = (CheckBox) findViewById(R.id.check_screen);
    layoutScreen = (LinearLayout) findViewById(R.id.layout_screen);
    imageCrop = (ImageView) findViewById(R.id.image_crop);
    textPreview = (TextView) findViewById(R.id.text_preview);

    // Get screenshot from previous activity.
    getScreen();

    // Get device account(s) for spinner (select primary by default).
    getAccounts();
    spinnerFrom.setAdapter(accountAdapter);
    spinnerFrom.setSelection(1);

    // Set feedback to include screenshot/logs by default.
    checkScreen.setChecked(true);

    // Set text listener for feedback text.
    inputText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

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

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() > 0) {
                menuActionBar.findItem(R.id.action_send_disabled).setVisible(false);
                menuActionBar.findItem(R.id.action_send_enabled).setVisible(true);
            } else {
                menuActionBar.findItem(R.id.action_send_disabled).setVisible(true);
                menuActionBar.findItem(R.id.action_send_enabled).setVisible(false);
            }
        }
    });

    // Set click listener for checkbox.
    checkScreen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (checkScreen.isChecked()) {
                layoutScreen.setVisibility(View.VISIBLE);
            } else {
                layoutScreen.setVisibility(View.INVISIBLE);
            }
        }
    });

    // Set click listener for screenshot image.
    imageCrop.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            displayScreen();
        }
    });
}

From source file:de.questmaster.fatremote.fragments.RemoteFragment.java

private TextWatcher determineKeyboardTextChangedListener() {
    TextWatcher tw = null;/*from w ww . ja v a  2s  . c o  m*/

    //check for bad keyboards
    boolean hwKeyboardShown = getActivity().getResources()
            .getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
    String swKeyboardName = Settings.Secure.getString(getActivity().getContentResolver(),
            Settings.Secure.DEFAULT_INPUT_METHOD);

    if (!hwKeyboardShown && swKeyboardName.contains("nuance.xt9")) { // ASUS Transformer Prime SoftKeyboard
        tw = new TextWatcher() {
            public void afterTextChanged(Editable s) {
            }

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

            public void onTextChanged(CharSequence s, int start, int before, int count) {
                int diff = count - before;

                if (s.length() > 0) {
                    // Send Character
                    keyCode = 0xf9;
                    if (diff > 0) { // +1
                        keyModifier = (short) Character.codePointAt(s, before);
                    } else if (diff < 0) { // -1
                        keyModifier = (short) 0x7f; // backspace
                    } else {
                        keyModifier = (short) 0x0a; // enter
                    }

                    // send keyCode
                    invokeSend();
                }
            }
        };
    } else { // Android Default Behaviour                
        tw = new TextWatcher() {
            public void afterTextChanged(Editable s) {
            }

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

            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.length() > 0 || before != 0) {
                    // Send Character
                    keyCode = 0xf9;
                    if (before == 0) {
                        keyModifier = (short) Character.codePointAt(s, start);
                    } else if (start == 0) {
                        keyModifier = 0x0a; // enter
                    } else {
                        keyModifier = (short) 0x7f; // backspace
                    }

                    // send keyCode
                    invokeSend();
                }
            }
        };
    }

    return tw;
}

From source file:com.easemob.chatuidemo.activity.GroupPickContactsActivity.java

private void initContactList(final List<User> contacts) {
    query.setAdapter(//from w  w w.  j  av  a2s . c  o  m
            new PickContactsAutoCompleteAdapter(mContext, contacts, departments, roles, new ArrayList<>()));
    query.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            isTargeted = true;
            Object object = adapterView.getAdapter().getItem(i);
            if (object instanceof Role) {
                Role role = (Role) object;
                contactAdapter.setFilter(role, PickContactsAdapter.TYPE_ROLE);
                query.setText(role.getName());
            } else if (object instanceof Department) {
                Department department = (Department) object;
                contactAdapter.setFilter(department, PickContactsAdapter.TYPE_DEPARTMENT);
                query.setText(department.getName());
            } else if (object instanceof User) {
                User user = (User) object;
                contactAdapter.setFilter(user, PickContactsAdapter.TYPE_USER);
                query.setText(user.getNick());
            }
        }
    });
    query.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

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

        }

        @Override
        public void afterTextChanged(Editable editable) {
            handler.removeCallbacks(searchRunnable);
            if (!isTargeted) {
                if (editable.length() == 0) {
                    contactAdapter.setFilter(null, PickContactsAdapter.TYPE_ALL);
                } else {
                    clearSearch.setVisibility(View.VISIBLE);
                    handler.postDelayed(searchRunnable, 1000);
                }
            }
            isTargeted = false;
            selectedFilterCheckBox.setChecked(false);
        }
    });

    // list?
    Collections.sort(contacts, new Comparator<User>() {
        @Override
        public int compare(User lhs, User rhs) {
            int headerResult = lhs.getHeader().compareTo(rhs.getHeader());
            if (headerResult == 0) { // ??nick
                return (lhs.getNick().compareTo(rhs.getNick()));
            } else {
                return headerResult;
            }
        }
    });

    contactAdapter = new PickContactsAdapter(this, contacts, exitingMembers);
    listView.setAdapter(contactAdapter);
    listView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            InputMethodManager imm = (InputMethodManager) mContext
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(query.getWindowToken(), 0);
            return false;
        }
    });
    contactAdapter.setOnSelectedCountChangeListener(new PickContactsAdapter.OnSelectedCountChangeListener() {
        @Override
        public void onSelectedCountChange(int count) {
            setSelectedNumber(count);
            setAllSelectedStatus(contactAdapter.getAllSelectedStatus());
        }
    });
    contactAdapter.setOnDataSetChangedListener(new PickContactsAdapter.OnDataSetChangedListener() {
        @Override
        public void onDataSetChanged() {
            if (contactAdapter.getCount() > 0) {
                findViewById(R.id.none_result_view).setVisibility(View.GONE);
            } else {
                if (selectedFilterCheckBox.isChecked()) {

                } else {
                    findViewById(R.id.none_result_view).setVisibility(View.VISIBLE);
                }
            }
        }
    });

    // ??
    InputMethodManager inputMethodManager = (InputMethodManager) mActivity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (mActivity.getWindow()
            .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
        if (mActivity.getCurrentFocus() != null)
            inputMethodManager.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:xyz.berial.textinputlayout.TextInputLayout.java

/**
 * /*from  w  w w.  j  av  a 2 s  .c om*/
 *
 * @param text 
 */
private void updateCounterText(Editable text) {
    if (mCounterView != null) {
        final int currentLength = text.length();
        mCounterView.setText(mResources.getString(R.string.counterMaxLength, currentLength, mCounterMaxLength));

        if (currentLength == mCounterMaxLength + 1) {
            mCounterView.setTextAppearance(getContext(), mErrorTextAppearance);
            ViewCompat.setBackgroundTintList(mEditText,
                    ColorStateList.valueOf(mResources.getColor(R.color.design_textinput_error_color)));
        } else if (currentLength == mCounterMaxLength) {
            if (!mErrorEnabled) {
                ViewCompat.setBackgroundTintList(mEditText, mFocusedTextColor);
            }
            mCounterView.setTextAppearance(getContext(), R.style.TextAppearance_Design_Counter);
        }
    }
}

From source file:org.miaowo.miaowo.util.Html.java

private static void startImg(Editable text, Attributes attributes, Html.ImageGetter img, Context context) {
    String src = attributes.getValue("", "src");
    Drawable d = null;//from  w  w  w  .  j  ava  2s  . c  om

    if (img != null) {
        d = img.getDrawable(src);
    }

    if (d == null) {
        d = ResourcesCompat.getDrawable(context.getResources(), R.drawable.unknown_image, null);
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    }

    int len = text.length();
    text.append("\uFFFC");

    text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:de.azapps.mirakel.main_activity.tasks_fragment.TasksFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    this.main = (MainActivity) getActivity();
    this.listId = this.main.getCurrentList().getId();
    this.view = inflater.inflate(R.layout.layout_tasks_fragment, container, false);
    this.adapter = null;
    this.created = true;
    this.listView = (ListView) this.view.findViewById(R.id.tasks_list);
    this.listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
    // Events//w w  w  .  j  a  va  2 s.c  o m
    this.newTask = (EditText) this.view.findViewById(R.id.tasks_new);
    if (MirakelCommonPreferences.isTablet()) {
        this.newTask.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);
    }
    this.newTask.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEND
                    || actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN) {
                newTask(v.getText().toString());
                v.setText(null);
            }
            return false;
        }
    });
    this.newTask.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(final Editable s) {
            final ImageButton send = (ImageButton) TasksFragment.this.view.findViewById(R.id.btnEnter);
            if (s.length() > 0) {
                send.setVisibility(View.VISIBLE);
            } else {
                send.setVisibility(View.GONE);
            }
        }

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

        @Override
        public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
            // Nothing
        }
    });
    update(true);
    final ImageButton btnEnter = (ImageButton) this.view.findViewById(R.id.btnEnter);
    btnEnter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            newTask(TasksFragment.this.newTask.getText().toString());
            TasksFragment.this.newTask.setText(null);
        }
    });
    updateButtons();
    return this.view;
}