Java 类android.text.Selection 实例源码

项目:rgb2hexconverter    文件:MainActivity.java   
private void onConvertHexToRgb() {
    int redValue;
    int greenValue;
    int blueValue;
    String hexValue = editTextHex.getText().toString();
    int colorInt;
    int[] rgb;

    if (isValidHex(hexValue)) {
        colorInt = stringToIntColor(hexValue);
        rgb = inColorToRGB(colorInt);
        viewColor.setBackgroundColor(colorInt);
        redValue = rgb[0];
        greenValue = rgb[1];
        blueValue = rgb[2];
        editTextRed.setText(String.valueOf(redValue));
        editTextGreen.setText(String.valueOf(greenValue));
        editTextBlue.setText(String.valueOf(blueValue));
        inputPositionCursor = editTextHex.length();
        inputEditable = editTextHex.getText();
        Selection.setSelection(inputEditable, inputPositionCursor);
    }
}
项目:LaunchEnr    文件:Folder.java   
@Override
public boolean onBackKey() {
    mFolderName.setHint(sHintText);
    // Convert to a string here to ensure that no other state associated with the text field
    // gets saved.
    String newTitle = mFolderName.getText().toString();
    mInfo.setTitle(newTitle);
    mLauncher.getModelWriter().updateItemInDatabase(mInfo);

    Utilities.sendCustomAccessibilityEvent(
            this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
            getContext().getString(R.string.folder_renamed, newTitle));

    // This ensures that focus is gained every time the field is clicked, which selects all
    // the text and brings up the soft keyboard if necessary.
    mFolderName.clearFocus();

    Selection.setSelection(mFolderName.getText(), 0, 0);
    mIsEditingName = false;
    return true;
}
项目:HiBangClient    文件:EmoteInputView.java   
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String text = null;
if (mIsSelectedDefault) {
    text = BaseApplication.mEmoticons_Zem.get(arg2);
} else {
    text = BaseApplication.mEmoticons_Zemoji.get(arg2);
}
if (mEEtView != null && !TextUtils.isEmpty(text)) {
    int start = mEEtView.getSelectionStart();
    CharSequence content = mEEtView.getText().insert(start, text);
    mEEtView.setText(content);
    // 定位光标位置
    CharSequence info = mEEtView.getText();
    if (info instanceof Spannable) {
        Spannable spanText = (Spannable) info;
        Selection.setSelection(spanText, start + text.length());
    }

}
}
项目:javaide    文件:UndoRedoSupportEditText.java   
public void undo() {
    EditItem edit = mEditHistory.getPrevious();
    if (edit == null) {
        return;
    }

    Editable editable = mTextView.getEditableText();
    int start = edit.start;
    int end = start + (edit.after != null ? edit.after.length() : 0);

    mIsUndoOrRedo = true;
    editable.replace(start, end, edit.before);
    mIsUndoOrRedo = false;

    for (Object o : editable.getSpans(0, editable.length(), UnderlineSpan.class)) {
        editable.removeSpan(o);
    }

    Selection.setSelection(editable, edit.before == null ? start : (start + edit.before.length()));
}
项目:javaide    文件:UndoRedoSupportEditText.java   
public void redo() {
    EditItem edit = mEditHistory.getNext();
    if (edit == null) {
        return;
    }

    Editable text = mTextView.getEditableText();
    int start = edit.start;
    int end = start + (edit.before != null ? edit.before.length() : 0);

    mIsUndoOrRedo = true;
    text.replace(start, end, edit.after);
    mIsUndoOrRedo = false;

    // This will get rid of underlines inserted when editor tries to come
    // up with a suggestion.
    for (Object o : text.getSpans(0, text.length(), UnderlineSpan.class)) {
        text.removeSpan(o);
    }

    Selection.setSelection(text, edit.after == null ? start
            : (start + edit.after.length()));
}
项目:ModPE-IDE-Source    文件:UndoRedoHelper.java   
public void undo() {
    EditItem edit = mEditHistory.getPrevious();
    if (edit == null) {
        return;
    }

    Editable editable = mTextView.getEditableText();
    int start = edit.start;
    int end = start + (edit.after != null ? edit.after.length() : 0);

    mIsUndoOrRedo = true;
    editable.replace(start, end, edit.before);
    mIsUndoOrRedo = false;

    for (Object o : editable.getSpans(0, editable.length(), UnderlineSpan.class)) {
        editable.removeSpan(o);
    }

    Selection.setSelection(editable,
            edit.before == null ? start : (start + edit.before.length()));
}
项目:ModPE-IDE-Source    文件:UndoRedoHelper.java   
public void redo() {
    EditItem edit = mEditHistory.getNext();
    if (edit == null) {
        return;
    }

    Editable text = mTextView.getEditableText();
    int start = edit.start;
    int end = start + (edit.before != null ? edit.before.length() : 0);

    mIsUndoOrRedo = true;
    text.replace(start, end, edit.after);
    mIsUndoOrRedo = false;

    // This will get rid of underlines inserted when editor tries to come
    // up with a suggestion.
    for (Object o : text.getSpans(0, text.length(), UnderlineSpan.class)) {
        text.removeSpan(o);
    }

    Selection.setSelection(text, edit.after == null ? start
            : (start + edit.after.length()));
}
项目:FastTextView    文件:ClickableSpanUtil.java   
public static boolean handleClickableSpan(View view, Layout layout, Spanned buffer, Class<? extends Clickable> spanType, MotionEvent event) {
  int action = event.getAction();

  if (action == MotionEvent.ACTION_UP ||
      action == MotionEvent.ACTION_DOWN) {
    int x = (int) event.getX();
    int y = (int) event.getY();

    x -= view.getPaddingLeft();
    y -= view.getPaddingTop();

    x += view.getScrollX();
    y += view.getScrollY();

    int line = layout.getLineForVertical(y);
    int off = layout.getOffsetForHorizontal(line, x);

    Clickable[] link = buffer.getSpans(off, off, spanType);

    if (link.length != 0) {
      if (action == MotionEvent.ACTION_UP) {
        link[0].onClick(view);
      } else if (buffer instanceof Spannable) {
        Selection.setSelection((Spannable) buffer,
            buffer.getSpanStart(link[0]),
            buffer.getSpanEnd(link[0]));
      }
      return true;
    } else if (buffer instanceof Spannable) {
      Selection.removeSelection((Spannable) buffer);
    }
  }

  return false;
}
项目:FastTextView    文件:ClickableSpanUtil.java   
public static boolean handleClickableSpan(View view, Layout layout, Spannable buffer, MotionEvent event) {
  int action = event.getAction();

  if (action == MotionEvent.ACTION_UP ||
      action == MotionEvent.ACTION_DOWN) {
    int x = (int) event.getX();
    int y = (int) event.getY();

    x -= view.getPaddingLeft();
    y -= view.getPaddingTop();

    x += view.getScrollX();
    y += view.getScrollY();

    int line = layout.getLineForVertical(y);
    int off = layout.getOffsetForHorizontal(line, x);

    ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);

    if (link.length != 0) {
      if (action == MotionEvent.ACTION_UP) {
        link[0].onClick(view);
      } else {
        Selection.setSelection(buffer,
            buffer.getSpanStart(link[0]),
            buffer.getSpanEnd(link[0]));
      }
      return true;
    } else {
      Selection.removeSelection(buffer);
    }
  }

  return false;
}
项目:AdvancedTextView    文件:SelectableTextView.java   
/**
 * 长按弹出菜单
 *
 * @param offsetY
 * @param actionMenu
 * @return 菜单创建成功,返回true
 */
private void showActionMenu(int offsetY, ActionMenu actionMenu) {

    mActionMenuPopupWindow = new PopupWindow(actionMenu, WindowManager.LayoutParams.WRAP_CONTENT,
            mActionMenuHeight, true);
    mActionMenuPopupWindow.setFocusable(true);
    mActionMenuPopupWindow.setOutsideTouchable(false);
    mActionMenuPopupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
    mActionMenuPopupWindow.showAtLocation(this, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, offsetY);

    mActionMenuPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Selection.removeSelection(getEditableText());
            // 如果设置了分散对齐,ActionMenu销毁后,强制刷新一次,防止出现文字背景未消失的情况
            if (isTextJustify)
                SelectableTextView.this.postInvalidate();
        }
    });
}
项目:boohee_v5.6    文件:AddCameraRecordActivity.java   
private void addListener() {
    this.toggle_bingo.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                AddCameraRecordActivity.this.mInputCalory = AddCameraRecordActivity.this
                        .et_calory.getText().toString();
                AddCameraRecordActivity.this.et_calory.getText().clear();
                AddCameraRecordActivity.this.et_calory.setHint("请等待顾问为你估算");
                AddCameraRecordActivity.this.et_calory.setEnabled(false);
                return;
            }
            if (!TextUtils.isEmpty(AddCameraRecordActivity.this.mInputCalory)) {
                AddCameraRecordActivity.this.et_calory.setText(AddCameraRecordActivity.this
                        .mInputCalory);
                Selection.setSelection(AddCameraRecordActivity.this.et_calory.getText(),
                        AddCameraRecordActivity.this.et_calory.getText().length());
            }
            AddCameraRecordActivity.this.et_calory.setHint("所含的热量(可不填)");
            AddCameraRecordActivity.this.et_calory.setEnabled(true);
        }
    });
}
项目:boohee_v5.6    文件:ChangeProfileActivity1.java   
private void init() {
    Intent intent = getIntent();
    this.code = intent.getStringExtra("code");
    this.defaultContent = intent.getStringExtra(EXTRA_DEFAULT_CONTENT);
    Helper.showLog(TAG, "code:" + this.code);
    this.attributeText = (TextView) findViewById(R.id.attribute_text);
    this.attributeText.setText(intent.getStringExtra(EXTRA_CODE_TEXT));
    this.wordNumTips = (TextView) findViewById(R.id.word_number_tips);
    this.contentEdit = (EditText) findViewById(R.id.content);
    this.contentEdit.setText(this.defaultContent);
    if (UserDao.USER_NAME.equals(this.code)) {
        this.contentEdit.setSingleLine();
        this.wordNumTips.setText(R.string.a_j);
    } else if ("description".equals(this.code)) {
        this.contentEdit.setLines(3);
        this.wordNumTips.setText(R.string.lo);
    } else {
        this.contentEdit.setInputType(2);
        this.wordNumTips.setVisibility(8);
    }
    Selection.setSelection(this.contentEdit.getText(), this.contentEdit.length());
}
项目:FlickLauncher    文件:AllAppsContainerView.java   
public AllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    Resources res = context.getResources();

    mLauncher = Launcher.getLauncher(context);
    mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin);
    mApps = new AlphabeticalAppsList(context);
    mAdapter = new AllAppsGridAdapter(mLauncher, mApps, mLauncher, this);
    mApps.setAdapter(mAdapter);
    mLayoutManager = mAdapter.getLayoutManager();
    mItemDecoration = mAdapter.getItemDecoration();
    DeviceProfile grid = mLauncher.getDeviceProfile();
    if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && !grid.isVerticalBarLayout()) {
        mRecyclerViewBottomPadding = 0;
        setPadding(0, 0, 0, 0);
    } else {
        mRecyclerViewBottomPadding =
                res.getDimensionPixelSize(R.dimen.all_apps_list_bottom_padding);
    }
    mSearchQueryBuilder = new SpannableStringBuilder();
    Selection.setSelection(mSearchQueryBuilder, 0);

}
项目:FlickLauncher    文件:Folder.java   
public void doneEditingFolderName(boolean commit) {
    mFolderName.setHint(sHintText);
    // Convert to a string here to ensure that no other state associated with the text field
    // gets saved.
    String newTitle = mFolderName.getText().toString();
    mInfo.setTitle(newTitle);
    LauncherModel.updateItemInDatabase(mLauncher, mInfo);

    if (commit) {
        Utilities.sendCustomAccessibilityEvent(
                this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                getContext().getString(R.string.folder_renamed, newTitle));
    }

    // This ensures that focus is gained every time the field is clicked, which selects all
    // the text and brings up the soft keyboard if necessary.
    mFolderName.clearFocus();

    Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
    mIsEditingName = false;
}
项目:SimpleUILauncher    文件:AllAppsContainerView.java   
public AllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    Resources res = context.getResources();

    mLauncher = Launcher.getLauncher(context);
    mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin);
    mApps = new AlphabeticalAppsList(context);
    mAdapter = new AllAppsGridAdapter(mLauncher, mApps, mLauncher, this);
    mApps.setAdapter(mAdapter);
    mLayoutManager = mAdapter.getLayoutManager();
    mItemDecoration = mAdapter.getItemDecoration();
    DeviceProfile grid = mLauncher.getDeviceProfile();
    if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && !grid.isVerticalBarLayout()) {
        mRecyclerViewBottomPadding = 0;
        setPadding(0, 0, 0, 0);
    } else {
        mRecyclerViewBottomPadding =
                res.getDimensionPixelSize(R.dimen.all_apps_list_bottom_padding);
    }
    mSearchQueryBuilder = new SpannableStringBuilder();
    Selection.setSelection(mSearchQueryBuilder, 0);
}
项目:SimpleUILauncher    文件:Folder.java   
public void doneEditingFolderName(boolean commit) {
    mFolderName.setHint(sHintText);
    // Convert to a string here to ensure that no other state associated with the text field
    // gets saved.
    String newTitle = mFolderName.getText().toString();
    mInfo.setTitle(newTitle);
    LauncherModel.updateItemInDatabase(mLauncher, mInfo);

    if (commit) {
        Utilities.sendCustomAccessibilityEvent(
                this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                getContext().getString(R.string.folder_renamed, newTitle));
    }

    // This ensures that focus is gained every time the field is clicked, which selects all
    // the text and brings up the soft keyboard if necessary.
    mFolderName.clearFocus();

    Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
    mIsEditingName = false;
}
项目:AyoSunny    文件:ExpressionUtil.java   
/**
 * 删除图标执行事件
 * 注:如果删除的是表情,在删除时实际删除的是tempText即图片占位的字符串,所以必需一次性删除掉tempText,才能将图片删除
 * */
public static void delete(EditText input) {
    if (input.getText().length() != 0) {
        int iCursorEnd = Selection.getSelectionEnd(input.getText());
        int iCursorStart = Selection.getSelectionStart(input.getText());
        if (iCursorEnd > 0) {
            if (iCursorEnd == iCursorStart) {
                if (isDeletePng(input,iCursorEnd)) {
                    String st = "[p/_000.png]";
                    ((Editable) input.getText()).delete(
                            iCursorEnd - st.length(), iCursorEnd);
                } else {
                    ((Editable) input.getText()).delete(iCursorEnd - 1,
                            iCursorEnd);
                }
            } else {
                ((Editable) input.getText()).delete(iCursorStart,
                        iCursorEnd);
            }
        }
    }
}
项目:TenguChat    文件:ListSelectionManager.java   
public void onBeforeNotifyDataSetChanged() {
    if (SUPPORTED) {
        HANDLER.removeMessages(MESSAGE_SEND_RESET);
        HANDLER.removeMessages(MESSAGE_RESET);
        HANDLER.removeMessages(MESSAGE_START_SELECTION);
        if (selectionActionMode != null) {
            final CharSequence text = selectionTextView.getText();
            futureSelectionIdentifier = selectionIdentifier;
            futureSelectionStart = Selection.getSelectionStart(text);
            futureSelectionEnd = Selection.getSelectionEnd(text);
            selectionActionMode.finish();
            selectionActionMode = null;
            selectionIdentifier = null;
            selectionTextView = null;
        }
    }
}
项目:MyTravelingDiary    文件:RemarkActivity.java   
private void initView() {
    mTitleView.setText(R.string.mine_friend_remark);
    mRightView.setVisibility(View.VISIBLE);
    //获取当前名片行咖号
    mUserAccount = getIntent().getStringExtra("account");
    //获取备注名
    remark = getIntent().getStringExtra("remark");
    //获取我的行咖号
    myAccount = String.valueOf(AccountInfo.getInstance().loadAccount().getAccount());

    //光标在内容后面
    CharSequence text = mRemark.getText();
    if (text instanceof Spannable) {
        Spannable spanText = (Spannable) text;
        Selection.setSelection(spanText, text.length());
    }

    //判断是否有备注名
    if(!TextUtils.isEmpty(remark) || remark != null){
        mRemark.setText(remark);
    }

}
项目:FMRadio    文件:FmRecordListActivity.java   
private View renameDialogView(String deviceName) {
    View view = LayoutInflater.from(FmRecordListActivity.this).inflate(R.layout.rename_edittext, null);
    mEditText = (EditText) view.findViewById(R.id.et_rename);
    mEditText.setText(deviceName);
    Editable editable = mEditText.getText();
    Selection.setSelection(editable, editable.length());

    mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                if (v.length() != 0 && !(v.getText().toString().trim().isEmpty())) {
                }
                mDialog.dismiss();
                return true;    // action handled
            } else {
                return false;   // not handled
            }
        }
    });
    return view;
}
项目:DevAsimpleApp    文件:PhoneNumWatcher.java   
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    Editable editable = editText.getText();
    int len = editable.length();
    int maxLen = maxLeng;
    if (len > maxLen) {
        int selEndIndex = Selection.getSelectionEnd(editable);
        String str = editable.toString();
        String newStr = str.substring(0, maxLen);
        editText.setText(newStr);
        editable = editText.getText();
        int newLen = editable.length();
        if (selEndIndex > newLen) {
            selEndIndex = editable.length();
        }
        Selection.setSelection(editable, selEndIndex);
    } else if (len == maxLen) {
        btn.setClickable(true);
        btn.setTextColor(Color.BLACK);
    } else if (len < maxLen) {
        btn.setClickable(false);
        btn.setTextColor(Color.GRAY);

    }
}
项目:Derpibooru    文件:CustomFormattingMovementMethod.java   
@Override
public boolean onTouchEvent(TextView textView, Spannable spannable, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        mPressedSpan = getPressedSpan(textView, spannable, event);
        if (mPressedSpan != null) {
            mPressedSpan.unspoiler();
            Selection.setSelection(spannable, spannable.getSpanStart(mPressedSpan),
                                   spannable.getSpanEnd(mPressedSpan));
        }
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        SpoilerSpan touchedSpan = getPressedSpan(textView, spannable, event);
        if (!Objects.equal(touchedSpan, mPressedSpan)) {
            mPressedSpan = null;
            Selection.removeSelection(spannable);
        }
    } else {
        mPressedSpan = null;
        Selection.removeSelection(spannable);
    }
    return super.onTouchEvent(textView, spannable, event);
}
项目:SimplOS    文件:Folder.java   
public void doneEditingFolderName(boolean commit) {
    mFolderName.setHint(sHintText);
    // Convert to a string here to ensure that no other state associated with the text field
    // gets saved.
    String newTitle = mFolderName.getText().toString();
    mInfo.setTitle(newTitle);
    LauncherModel.updateItemInDatabase(mLauncher, mInfo);

    if (commit) {
        sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                String.format(getContext().getString(R.string.folder_renamed), newTitle));
    }
    // In order to clear the focus from the text field, we set the focus on ourself. This
    // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
    requestFocus();

    Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
    mIsEditingName = false;
}
项目:SimplOS    文件:AllAppsContainerView.java   
public AllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    Resources res = context.getResources();

    mLauncher = (Launcher) context;
    mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin);
    mApps = new AlphabeticalAppsList(context);
    mAdapter = new AllAppsGridAdapter(mLauncher, mApps, this, mLauncher, this);
    //mAdapter.setNumAppsPerCol(3);
    mApps.setAdapter(mAdapter);
    mLayoutManager = mAdapter.getLayoutManager();
    mItemDecoration = mAdapter.getItemDecoration();
    mRecyclerViewTopBottomPadding =
            res.getDimensionPixelSize(R.dimen.all_apps_list_top_bottom_padding);

    mSearchQueryBuilder = new SpannableStringBuilder();
    Selection.setSelection(mSearchQueryBuilder, 0);
}
项目:CallMeMaybe    文件:PhoneFormatter.java   
public void format(final Editable to, final int toStart, final int toEnd, final CharSequence from,
    final int fromStart, final int fromEnd) {
  final int selectionStart = Selection.getSelectionStart(to);
  final int selectionEnd = Selection.getSelectionStart(to);

  buffer.clear();
  buffer.append(to);
  if (selectionStart != -1 && selectionEnd != -1) {
    Selection.setSelection(buffer, selectionStart, selectionEnd);
  }
  buffer.replace(toStart, toEnd, from, fromStart, fromEnd);

  if (!TextUtils.isGraphic(buffer)) {
    return;
  }

  formatPhoneNumberInput(buffer);
}
项目:CallMeMaybe    文件:PhoneFormatter.java   
private void formatPhoneNumberInput(final Editable input) {
  final int selection = Selection.getSelectionStart(buffer);
  boolean selectionPositionRemembered = false;

  asYouTypeFormatter.clear();
  String phoneNumberText = "";

  int offset = 0;
  final int length = input.length();
  while (offset < length) {
    final int codePoint = Character.codePointAt(input, offset);
    if (Character.isDigit(codePoint)) {
      final char digit = CodePoint.toDigitChar(codePoint);
      selectionPositionRemembered = selectionPositionRemembered || offset >= selection;
      phoneNumberText = asYouTypeFormatter.inputDigit(digit, !selectionPositionRemembered);
    }
    offset += Character.charCount(codePoint);
  }

  input.replace(0, input.length(), phoneNumberText);
  if (selection != -1) {
    Selection.setSelection(input,
        selectionPositionRemembered ? asYouTypeFormatter.getRememberedPosition() : phoneNumberText.length());
  }
}
项目:memoir    文件:RTEditorMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {

        int index = getCharIndexAt(widget, event);
        if (index != -1) {
            ClickableSpan[] link = buffer.getSpans(index, index, ClickableSpan.class);
            if (link.length != 0) {
                if (action == MotionEvent.ACTION_UP) {
                    link[0].onClick(widget);
                } else if (action == MotionEvent.ACTION_DOWN) {
                    Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
                }
                return true;
            }
        }
        /*else {
            Selection.removeSelection(buffer);
        }*/

    }

    return super.onTouchEvent(widget, buffer, event);
}
项目:memoir    文件:RTEditorMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {

        int index = getCharIndexAt(widget, event);
        if (index != -1) {
            ClickableSpan[] link = buffer.getSpans(index, index, ClickableSpan.class);
            if (link.length != 0) {
                if (action == MotionEvent.ACTION_UP) {
                    link[0].onClick(widget);
                } else if (action == MotionEvent.ACTION_DOWN) {
                    Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
                }
                return true;
            }
        }
        /*else {
            Selection.removeSelection(buffer);
        }*/

    }

    return super.onTouchEvent(widget, buffer, event);
}
项目:BigApp_Discuz_Android    文件:LinkTouchMovementMethod.java   
@Override
public boolean onTouchEvent(TextView textView, Spannable spannable, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        mPressedSpan = getPressedSpan(textView, spannable, event);
        if (mPressedSpan != null) {
            mPressedSpan.setPressed(true);
            Selection.setSelection(spannable, spannable.getSpanStart(mPressedSpan),
                    spannable.getSpanEnd(mPressedSpan));
        }
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        TouchableSpan touchedSpan = getPressedSpan(textView, spannable, event);
        if (mPressedSpan != null && touchedSpan != mPressedSpan) {
            mPressedSpan.setPressed(false);
            mPressedSpan = null;
            Selection.removeSelection(spannable);
        }
    } else {
        if (mPressedSpan != null) {
            mPressedSpan.setPressed(false);
            super.onTouchEvent(textView, spannable, event);
        }
        mPressedSpan = null;
        Selection.removeSelection(spannable);
    }
    return true;
}
项目:ChipView    文件:ChipViewMovementMethod.java   
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
        int x = (int) event.getX();
        int y = (int) event.getY();
        x -= widget.getTotalPaddingLeft();
        y -= widget.getTotalPaddingTop();
        x += widget.getScrollX();
        y += widget.getScrollY();
        Layout layout = widget.getLayout();
        int line = layout.getLineForVertical(y);
        int off = layout.getOffsetForHorizontal(line, x);
        ChipClickSpan[] link = buffer.getSpans(off, off, ChipClickSpan.class);
        if (link.length != 0) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
                Selection.removeSelection(buffer);
            } else if (action == MotionEvent.ACTION_DOWN)
                Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
            return true;
        }
    }
    return super.onTouchEvent(widget, buffer, event);
}
项目:Doctor    文件:RTEditorMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {

        int index = getCharIndexAt(widget, event);
        if (index != -1) {
            ClickableSpan[] link = buffer.getSpans(index, index, ClickableSpan.class);
            if (link.length != 0) {
                if (action == MotionEvent.ACTION_UP) {
                    link[0].onClick(widget);
                } else if (action == MotionEvent.ACTION_DOWN) {
                    Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
                }
                return true;
            }
        }
        /*else {
            Selection.removeSelection(buffer);
        }*/

    }

    return super.onTouchEvent(widget, buffer, event);
}
项目:youkes_vr    文件:ExpressionUtil.java   
/**
 * 删除图标执行事件
 * 注:如果删除的是表情,在删除时实际删除的是tempText即图片占位的字符串,所以必需一次性删除掉tempText,才能将图片删除
 * */
public static void delete(EditText input) {
    if (input.getText().length() != 0) {
        int iCursorEnd = Selection.getSelectionEnd(input.getText());
        int iCursorStart = Selection.getSelectionStart(input.getText());
        if (iCursorEnd > 0) {
            if (iCursorEnd == iCursorStart) {
                if (isDeletePng(input,iCursorEnd)) {
                    String st = "[p/_000.png]";
                    ((Editable) input.getText()).delete(
                            iCursorEnd - st.length(), iCursorEnd);
                } else {
                    ((Editable) input.getText()).delete(iCursorEnd - 1,
                            iCursorEnd);
                }
            } else {
                ((Editable) input.getText()).delete(iCursorStart,
                        iCursorEnd);
            }
        }
    }
}
项目:Trebuchet    文件:Folder.java   
public void doneEditingFolderName(boolean commit) {
    mFolderName.setHint(sHintText);
    // Convert to a string here to ensure that no other state associated with the text field
    // gets saved.
    String newTitle = mFolderName.getText().toString();
    if (!SettingsProvider.getBoolean(mLauncher,
            SettingsProvider.SETTINGS_UI_HOMESCREEN_HIDE_ICON_LABELS,
            R.bool.preferences_interface_homescreen_hide_icon_labels_default)) {
        mInfo.setTitle(newTitle);
    }
    LauncherModel.updateItemInDatabase(mLauncher, mInfo);

    if (commit) {
        sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                String.format(getContext().getString(R.string.folder_renamed), newTitle));
    }
    // In order to clear the focus from the text field, we set the focus on ourself. This
    // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
    requestFocus();

    Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
    mIsEditingName = false;
    mLauncher.notifyFolderNameChanged();
}
项目:Trebuchet    文件:AllAppsContainerView.java   
public AllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    Resources res = context.getResources();

    mLauncher = (Launcher) context;
    mApps = new AlphabeticalAppsList(context);
    mAdapter = new AllAppsGridAdapter(mLauncher, mApps, this, mLauncher,
            this);
    mApps.setAdapter(mAdapter);
    mLayoutManager = mAdapter.getLayoutManager();
    mItemDecoration = mAdapter.getItemDecoration();
    mRecyclerViewTopBottomPadding =
            res.getDimensionPixelSize(R.dimen.all_apps_list_top_bottom_padding);

    mSearchQueryBuilder = new SpannableStringBuilder();
    Selection.setSelection(mSearchQueryBuilder, 0);
}
项目:Demos    文件:TouchLinkMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_DOWN) {
        int x = (int) event.getX();
        int y = (int) event.getY();

        x -= widget.getTotalPaddingLeft();
        y -= widget.getTotalPaddingTop();
        x += widget.getScrollX();
        y += widget.getScrollY();

        Layout layout = widget.getLayout();
        int line = layout.getLineForVertical(y);
        int off = layout.getOffsetForHorizontal(line, x);

        ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
        if (link.length != 0) {
            link[0].onClick(widget);
            return true;
        } else {
            Selection.removeSelection(buffer);
        }
    }

    return super.onTouchEvent(widget, buffer, event);
}
项目:GitHub    文件:ClickableMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {

    int action = event.getActionMasked();
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {

        int x = (int) event.getX();
        int y = (int) event.getY();
        x -= widget.getTotalPaddingLeft();
        y -= widget.getTotalPaddingTop();
        x += widget.getScrollX();
        y += widget.getScrollY();

        Layout layout = widget.getLayout();
        int line = layout.getLineForVertical(y);
        int off = layout.getOffsetForHorizontal(line, x);

        ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
        if (link.length > 0) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else {
                Selection.setSelection(buffer, buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
        }
    }

    return false;
}
项目:rgb2hexconverter    文件:MainActivity.java   
@OnTextChanged(R.id.editTextRed)
public void onTextRedChanged(CharSequence textRed, int start, int count, int after) {

    if (textRed.length() > 0) {
        isInputText = true;
        seekBarRed.setProgress(Integer.parseInt(textRed.toString()));
        inputPositionCursor = editTextRed.length();
        inputEditable = editTextRed.getText();
        Selection.setSelection(inputEditable, inputPositionCursor);
        isInputText = false;
    } else {
        Toast.makeText(getApplicationContext(), "Set RED Value!", Toast.LENGTH_SHORT).show();
    }

}
项目:rgb2hexconverter    文件:MainActivity.java   
@OnTextChanged(R.id.editTextGreen)
public void onTextGreenChanged(CharSequence textGreen, int start, int count, int after) {

    if (textGreen.length() > 0) {
        isInputText = true;
        seekBarGreen.setProgress(Integer.parseInt(textGreen.toString()));
        inputPositionCursor = editTextGreen.length();
        inputEditable = editTextGreen.getText();
        Selection.setSelection(inputEditable, inputPositionCursor);
        isInputText = false;
    } else {
        Toast.makeText(getApplicationContext(), "Set GREEN Value!", Toast.LENGTH_SHORT).show();
    }

}
项目:rgb2hexconverter    文件:MainActivity.java   
@OnTextChanged(R.id.editTextBlue)
public void onTextBlueChanged(CharSequence textBlue, int start, int count, int after) {

    if (textBlue.length() > 0) {
        isInputText = true;
        seekBarBlue.setProgress(Integer.parseInt(textBlue.toString()));
        inputPositionCursor = editTextBlue.length();
        inputEditable = editTextBlue.getText();
        Selection.setSelection(inputEditable, inputPositionCursor);
        isInputText = false;
    } else {
        Toast.makeText(getApplicationContext(), "Set BLUE Value!", Toast.LENGTH_SHORT).show();
    }

}
项目:LaunchEnr    文件:AllAppsContainerView.java   
public AllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mLauncher = Launcher.getLauncher(context);
    mApps = new AlphabeticalAppsList(context);
    mAdapter = new AllAppsGridAdapter(mLauncher, mApps, mLauncher, this);
    mApps.setAdapter(mAdapter);
    mLayoutManager = mAdapter.getLayoutManager();
    mSearchQueryBuilder = new SpannableStringBuilder();
    mSearchContainerMinHeight
            = getResources().getDimensionPixelSize(R.dimen.all_apps_search_bar_height);

    Selection.setSelection(mSearchQueryBuilder, 0);
}