Example usage for android.text Editable insert

List of usage examples for android.text Editable insert

Introduction

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

Prototype

public Editable insert(int where, CharSequence text);

Source Link

Document

Convenience for replace(where, where, text, 0, text.length());

Usage

From source file:com.forrestguice.suntimeswidget.settings.ColorChooser.java

private void changeColor() {
    Editable editable = edit.getText();
    int i = editable.toString().indexOf('#');
    if (i != -1) // should start with a #
    {//from   www . j a  v a  2 s.  c  o m
        editable.delete(i, i + 1);
    }
    editable.insert(0, "#");

    while (editable.length() < 3) // supply an alpha value (FF)
    {
        editable.insert(1, "F");
    }
    if (editable.length() == 7) {
        editable.insert(1, "FF");
    }

    while (editable.length() < 9) // fill rest with "0"
    {
        editable.append("0");
    }

    //Log.d("DEBUG", "color is " + editable.toString());
    edit.setText(editable);
    setColor(editable.toString());
    onColorChanged(getColor());
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java

private void processKeyInput(TextView textView) {
    if (mEditText != null) {
        if (!mEditText.isFocused())
            mEditText.requestFocus();/*ww w.  ja v a  2  s. c o m*/
        Editable editableText = mEditText.getText();
        int start = mEditText.getSelectionStart();
        if (start == -1)
            return;
        editableText.insert(start, textView.getText());
        KeyboardKey tag = (KeyboardKey) textView.getTag();
        List<String> modifierList = tag.getKeyModifiers();
        handleModifiers(modifierList);
    }
}

From source file:tv.acfun.video.CommentsActivity.java

private void initCommentsBar() {
    mCommentBar = findViewById(R.id.comments_bar);
    mBtnSend = (ImageButton) findViewById(R.id.comments_send_btn);
    mCommentText = (EditText) findViewById(R.id.comments_edit);
    mBtnEmotion = findViewById(R.id.comments_emotion_btn);
    mEmotionGrid = (GridView) findViewById(R.id.emotions);
    mBtnSend.setOnClickListener(this);
    mBtnEmotion.setOnClickListener(this);
    mEmotionGrid.setAdapter(mEmotionAdapter);
    mEmotionGrid.setOnItemClickListener(new OnItemClickListener() {

        @Override/*from   w ww  .  j  a v a 2  s . com*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            int index = mCommentText.getSelectionEnd();
            Editable text = mCommentText.getText();
            String emotion = parent.getItemAtPosition(position).toString();
            text.insert(index, emotion);
            EmotionView v = (EmotionView) parent.getAdapter().getView(position, null, null);
            Drawable drawable = TextViewUtils.convertViewToDrawable(v);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth() / 2, drawable.getIntrinsicHeight() / 2);
            text.setSpan(new ImageSpan(drawable), index, index + emotion.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

    });
}

From source file:com.forrestguice.suntimeswidget.settings.ColorChooser.java

@Override
public void afterTextChanged(Editable editable) {
    if (isRunning || isRemoving)
        return;/*from w  w  w  .  ja va2s . c  o m*/
    isRunning = true;

    String text = editable.toString(); // should consist of [#][0-9][a-f]
    for (int j = text.length() - 1; j >= 0; j--) {
        if (!inputSet.contains(text.charAt(j))) {
            editable.delete(j, j + 1);
        }
    }

    text = editable.toString(); // should start with a #
    int i = text.indexOf('#');
    if (i != -1) {
        editable.delete(i, i + 1);
    }
    editable.insert(0, "#");

    if (editable.length() > 8) // should be no longer than 8
    {
        editable.delete(9, editable.length());
    }

    text = editable.toString();
    String toCaps = text.toUpperCase(Locale.US);
    editable.clear();
    editable.append(toCaps);

    isRunning = false;
}

From source file:tv.acfun.a63.CommentsActivity.java

private void initCommentsBar() {
    mCommentBar = findViewById(R.id.comments_bar);

    if (ActionBarUtil.hasSB()
            && getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
        RelativeLayout.LayoutParams params = (LayoutParams) mCommentBar.getLayoutParams();
        params.bottomMargin = getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_height);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        mCommentBar.setLayoutParams(params);
    }//from www  .j av a  2 s  .  c  o m
    mBtnSend = (ImageButton) findViewById(R.id.comments_send_btn);
    mCommentText = (EditText) findViewById(R.id.comments_edit);
    mBtnEmotion = findViewById(R.id.comments_emotion_btn);
    mEmotionGrid = (GridView) findViewById(R.id.emotions);
    mBtnSend.setOnClickListener(this);
    mBtnEmotion.setOnClickListener(this);
    mEmotionGrid.setAdapter(mEmotionAdapter);
    mEmotionGrid.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            int index = mCommentText.getSelectionEnd();
            Editable text = mCommentText.getText();
            String emotion = parent.getItemAtPosition(position).toString();
            text.insert(index, emotion);
            EmotionView v = (EmotionView) parent.getAdapter().getView(position, null, null);
            Drawable drawable = TextViewUtils.convertViewToDrawable(v);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth() / 2, drawable.getIntrinsicHeight() / 2);
            text.setSpan(new ImageSpan(drawable), index, index + emotion.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

    });
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java

private void handleModifiers(List<String> typographyList) {
    modifiersContainer.removeAllViews();

    for (int i = 0; i < typographyList.size(); i++) {
        String typography = typographyList.get(i);
        TextView modifierKey = new TextView(getContext());
        modifierKey.setText(typography);
        modifierKey.setTextColor(Color.WHITE);
        modifierKey.setIncludeFontPadding(false);
        modifierKey.setTypeface(mCharTypeface, Typeface.BOLD);
        modifierKey.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        modifierKey.setBackgroundDrawable(
                ContextCompat.getDrawable(getContext(), R.drawable.keyboard_modifierkey_bg));
        modifierKey.setTextSize(18f);//w w w  .j  a v a  2  s . c  o  m
        modifierKey.setGravity(Gravity.CENTER);

        modifierKey.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mEditText == null) {
                    return;
                }
                TextView textView = (TextView) v;
                if (!mEditText.isFocused())
                    mEditText.requestFocus();
                Editable editableText = mEditText.getText();
                int start = mEditText.getSelectionStart();
                if (start == 0)
                    return;

                CharSequence textViewText = textView.getText();
                if (mEnableModifierFlag) {
                    mEnableModifierFlag = false;
                    editableText.replace(start - 1, start, textViewText);
                } else {
                    editableText.insert(start, textViewText);
                }
            }
        });

        LayoutParams params = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
        int margin = getCustomSize(1.5f);
        params.setMargins(margin, margin, margin, margin);
        modifiersContainer.addView(modifierKey, params);
    }
}

From source file:com.zhenlaidian.ui.InputCarNumberActivity.java

public void setView2() {
    final GridView gv_number = (GridView) view2.findViewById(R.id.input_gridview_dialog);
    gv_number.setSelector(new ColorDrawable(Color.TRANSPARENT));
    final String[] number = new String[] { "A", "B", "C", "D", "0", "5", "E", "F", "G", "H", "1", "6", "J", "K",
            "L", "M", "2", "7", "N", "P", "Q", "R", "3", "8", "S", "T", "U", "V", "4", "9", "W", "X", "Y",
            "Z" };
    ArrayList<String> numbers = new ArrayList<String>();
    for (int i = 0; i < number.length; i++) {
        numbers.add(number[i]);/*from   w  ww . ja v a  2s  .c o m*/
    }
    InputCarNumberGridAdapter adapter = new InputCarNumberGridAdapter(context, numbers, true);
    gv_number.setAdapter(adapter);
    gv_number.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
            final int index = et_carnumber.getSelectionStart();
            final Editable editable = et_carnumber.getText();
            editable.insert(index, number[position]);
        }
    });
}

From source file:com.zhenlaidian.ui.InputCarNumberActivity.java

public void setView1() {
    final GridView gv_province = (GridView) view1.findViewById(R.id.input_gridview_dialog);
    gv_province.setSelector(new ColorDrawable(Color.TRANSPARENT));
    final String[] province = new String[] { "", "", "", "?", "", "?", "", "", "",
            "?", "?", "", "?", "", "", "", "", "", "", "", "", "?", "",
            "", "", "", "", "?", "?", "", "?", "", "" };
    ArrayList<String> provinces = new ArrayList<String>();
    for (int i = 0; i < province.length; i++) {
        provinces.add(province[i]);//from w  w  w .  java  2 s.c o  m
    }
    InputCarNumberGridAdapter adapter = new InputCarNumberGridAdapter(context, provinces, false);
    gv_province.setAdapter(adapter);
    gv_province.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @SuppressLint("ClickableViewAccessibility")
        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
            final int index = et_carnumber.getSelectionStart();
            final Editable editable = et_carnumber.getText();
            editable.insert(index, province[position]);
        }
    });
}

From source file:com.zhenlaidian.ui.InputCarNumberActivity.java

public void sheView3() {
    final GridView gv_police = (GridView) view3.findViewById(R.id.input_gridview_dialog);
    gv_police.setSelector(new ColorDrawable(Color.TRANSPARENT));
    final String[] police = new String[] { "", "", "", "", "", "", "", "?", "", "?",
            "WJ", "", "", "", "", "", "", "", "", "", "" };
    ArrayList<String> polices = new ArrayList<String>();
    for (int i = 0; i < police.length; i++) {
        polices.add(police[i]);/*  w  w w .  j a v a 2  s .  c o m*/
    }

    InputCarNumberGridAdapter adapter = new InputCarNumberGridAdapter(context, polices, false);
    gv_police.setAdapter(adapter);
    gv_police.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
            final int index = et_carnumber.getSelectionStart();
            final Editable editable = et_carnumber.getText();
            editable.insert(index, police[position]);

        }
    });
}

From source file:com.sxt.superqq.activity.ChatActivity.java

/**
 * ?gridview?view//from   www  .  j  av a  2s.  c om
 * 
 * @param i
 * @return
 */
private View getGridChildView(int i) {
    View view = View.inflate(this, R.layout.expression_gridview, null);
    ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview);
    List<String> list = new ArrayList<String>();
    if (i == 1) {
        List<String> list1 = reslist.subList(0, 20);
        list.addAll(list1);
    } else if (i == 2) {
        list.addAll(reslist.subList(20, reslist.size()));
    }
    list.add("delete_expression");
    final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list);
    gv.setAdapter(expressionAdapter);
    gv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String filename = expressionAdapter.getItem(position);
            try {
                // ????
                // ?????
                if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) {

                    if (filename != "delete_expression") { // ?
                        Editable text = mEditTextContent.getText();
                        int start = Selection.getSelectionStart(text);
                        text = text.insert(start, filename);
                        mEditTextContent.setText(EmotionUtils.replace(ChatActivity.this, text));
                        text = mEditTextContent.getText();
                        Selection.setSelection(text, start + filename.length());
                    } else { // 
                        if (!TextUtils.isEmpty(mEditTextContent.getText())) {

                            int selectionStart = mEditTextContent.getSelectionStart();// ??
                            if (selectionStart > 0) {
                                String body = mEditTextContent.getText().toString();
                                String tempStr = body.substring(0, selectionStart);
                                int i = tempStr.lastIndexOf("[");// ???
                                if (i != -1) {
                                    CharSequence cs = tempStr.substring(i, selectionStart);
                                    if (SmileUtils.containsKey(cs.toString()))
                                        mEditTextContent.getEditableText().delete(i, selectionStart);
                                    else
                                        mEditTextContent.getEditableText().delete(selectionStart - 1,
                                                selectionStart);
                                } else {
                                    mEditTextContent.getEditableText().delete(selectionStart - 1,
                                            selectionStart);
                                }
                            }
                        }

                    }
                }
            } catch (Exception e) {
            }
        }
    });
    return view;
}