List of usage examples for android.text Selection setSelection
public static final void setSelection(Spannable text, int index)
index
. From source file:com.cognizant.trumobi.PersonaLauncher.java
@SuppressWarnings("unused") private void clearTypedText() { mDefaultKeySsb.clear(); mDefaultKeySsb.clearSpans(); Selection.setSelection(mDefaultKeySsb, 0); }
From source file:com.iiordanov.bVNC.RemoteCanvas.java
@Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { android.util.Log.d(TAG, "onCreateInputConnection called"); int version = android.os.Build.VERSION.SDK_INT; BaseInputConnection bic = null;/*from w ww .j a va 2 s .c om*/ if (!bb && version >= Build.VERSION_CODES.JELLY_BEAN) { bic = new BaseInputConnection(this, false) { final static String junk_unit = "%%%%%%%%%%"; final static int multiple = 1000; Editable e; @Override public Editable getEditable() { if (e == null) { int numTotalChars = junk_unit.length() * multiple; String junk = new String(); for (int i = 0; i < multiple; i++) { junk += junk_unit; } e = Editable.Factory.getInstance().newEditable(junk); Selection.setSelection(e, numTotalChars); if (RemoteCanvas.this.keyboard != null) { RemoteCanvas.this.keyboard.skippedJunkChars = false; } } return e; } }; } else { bic = new BaseInputConnection(this, false); } outAttrs.actionLabel = null; outAttrs.inputType = InputType.TYPE_NULL; // Workaround for IME's that don't support InputType.TYPE_NULL. if (version >= 21) { outAttrs.inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN; } return bic; }
From source file:com.sxt.superqq.activity.ChatActivity.java
/** * ?gridview?view/* ww w. j a v a2 s .com*/ * * @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; }
From source file:com.android.launcher3.Launcher.java
@Override public void clearTypedText() { mDefaultKeySsb.clear(); mDefaultKeySsb.clearSpans(); Selection.setSelection(mDefaultKeySsb, 0); }
From source file:com.sonetel.ui.dialpad.DialerFragment.java
/** * Set the value of the text field and put caret at the end * // w w w.j a v a2 s . co m * @param value the new text to see in the text field */ public void setTextFieldValue(CharSequence value) { digits.setText(value); // make sure we keep the caret at the end of the text view Editable spannable = digits.getText(); Selection.setSelection(spannable, spannable.length()); }
From source file:android.app.Activity.java
/** * Select the default key handling for this activity. This controls what * will happen to key events that are not otherwise handled. The default * mode ({@link #DEFAULT_KEYS_DISABLE}) will simply drop them on the * floor. Other modes allow you to launch the dialer * ({@link #DEFAULT_KEYS_DIALER}), execute a shortcut in your options * menu without requiring the menu key be held down * ({@link #DEFAULT_KEYS_SHORTCUT}), or launch a search ({@link #DEFAULT_KEYS_SEARCH_LOCAL} * and {@link #DEFAULT_KEYS_SEARCH_GLOBAL}). * /*from w ww . j av a 2s.c om*/ * <p>Note that the mode selected here does not impact the default * handling of system keys, such as the "back" and "menu" keys, and your * activity and its views always get a first chance to receive and handle * all application keys. * * @param mode The desired default key mode constant. * * @see #DEFAULT_KEYS_DISABLE * @see #DEFAULT_KEYS_DIALER * @see #DEFAULT_KEYS_SHORTCUT * @see #DEFAULT_KEYS_SEARCH_LOCAL * @see #DEFAULT_KEYS_SEARCH_GLOBAL * @see #onKeyDown */ public final void setDefaultKeyMode(int mode) { mDefaultKeyMode = mode; // Some modes use a SpannableStringBuilder to track & dispatch input events // This list must remain in sync with the switch in onKeyDown() switch (mode) { case DEFAULT_KEYS_DISABLE: case DEFAULT_KEYS_SHORTCUT: mDefaultKeySsb = null; // not used in these modes break; case DEFAULT_KEYS_DIALER: case DEFAULT_KEYS_SEARCH_LOCAL: case DEFAULT_KEYS_SEARCH_GLOBAL: mDefaultKeySsb = new SpannableStringBuilder(); Selection.setSelection(mDefaultKeySsb, 0); break; default: throw new IllegalArgumentException(); } }
From source file:android.app.Activity.java
/** * Called when a key was pressed down and not handled by any of the views * inside of the activity. So, for example, key presses while the cursor * is inside a TextView will not trigger the event (unless it is a navigation * to another object) because TextView handles its own key presses. * //from w w w . ja v a 2 s . c o m * <p>If the focused view didn't want this event, this method is called. * * <p>The default implementation takes care of {@link KeyEvent#KEYCODE_BACK} * by calling {@link #onBackPressed()}, though the behavior varies based * on the application compatibility mode: for * {@link android.os.Build.VERSION_CODES#ECLAIR} or later applications, * it will set up the dispatch to call {@link #onKeyUp} where the action * will be performed; for earlier applications, it will perform the * action immediately in on-down, as those versions of the platform * behaved. * * <p>Other additional default key handling may be performed * if configured with {@link #setDefaultKeyMode}. * * @return Return <code>true</code> to prevent this event from being propagated * further, or <code>false</code> to indicate that you have not handled * this event and it should continue to be propagated. * @see #onKeyUp * @see android.view.KeyEvent */ public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.ECLAIR) { event.startTracking(); } else { onBackPressed(); } return true; } if (mDefaultKeyMode == DEFAULT_KEYS_DISABLE) { return false; } else if (mDefaultKeyMode == DEFAULT_KEYS_SHORTCUT) { if (getWindow().performPanelShortcut(Window.FEATURE_OPTIONS_PANEL, keyCode, event, Menu.FLAG_ALWAYS_PERFORM_CLOSE)) { return true; } return false; } else { // Common code for DEFAULT_KEYS_DIALER & DEFAULT_KEYS_SEARCH_* boolean clearSpannable = false; boolean handled; if ((event.getRepeatCount() != 0) || event.isSystem()) { clearSpannable = true; handled = false; } else { handled = TextKeyListener.getInstance().onKeyDown(null, mDefaultKeySsb, keyCode, event); if (handled && mDefaultKeySsb.length() > 0) { // something useable has been typed - dispatch it now. final String str = mDefaultKeySsb.toString(); clearSpannable = true; switch (mDefaultKeyMode) { case DEFAULT_KEYS_DIALER: Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + str)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); break; case DEFAULT_KEYS_SEARCH_LOCAL: startSearch(str, false, null, false); break; case DEFAULT_KEYS_SEARCH_GLOBAL: startSearch(str, false, null, true); break; } } } if (clearSpannable) { mDefaultKeySsb.clear(); mDefaultKeySsb.clearSpans(); Selection.setSelection(mDefaultKeySsb, 0); } return handled; } }