android.text.Selection Java Examples

The following examples show how to use android.text.Selection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArticleReportFragment.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    String content = etDescription.getText().toString().trim();

    //判断是否显示按钮为可点击
    if (content.length() > 0 && adapter.getReportType() != null){
        btnReport.setBackgroundResource(R.drawable.selector_btn_blue_bg);
        btnReport.setClickable(true);
    }else{
        btnReport.setBackgroundColor(getResources().getColor(R.color.shadow_black_color));
        btnReport.setClickable(false);
    }
    if (content.length() > 50){
        String newStr = content.substring(0,50);
        etDescription.setText(newStr);
        Selection.setSelection(etDescription.getText(), 50);
        ToastUtils.show(getString(R.string.resume_change_num_max));
        content = newStr;
    }
    int num = 50 - content.length();
    tvNum.setText(""+ num);
}
 
Example #2
Source File: FragmentCreateChannelViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
private void getInfo(Bundle arguments) {

        G.onChannelCheckUsername = this;

        if (arguments != null) {
            roomId = arguments.getLong("ROOMID");
            inviteLink = "https://" + arguments.getString("INVITE_LINK");
            token = arguments.getString("TOKEN");
        }

        edtSetLink.set(Config.IGAP_LINK_PREFIX);
        wordtoSpan = new SpannableString(edtSetLink.get());
        Selection.setSelection(wordtoSpan, edtSetLink.get().length());

        setInviteLink();
    }
 
Example #3
Source File: AllAppsContainerView.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: ArrowKeyMovementMethod.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean pageDown(TextView widget, Spannable buffer) {
    final Layout layout = widget.getLayout();
    final boolean selecting = isSelecting(buffer);
    final int targetY = getCurrentLineTop(buffer, layout) + getPageHeight(widget);
    boolean handled = false;
    for (;;) {
        final int previousSelectionEnd = Selection.getSelectionEnd(buffer);
        if (selecting) {
            Selection.extendDown(buffer, layout);
        } else {
            Selection.moveDown(buffer, layout);
        }
        if (Selection.getSelectionEnd(buffer) == previousSelectionEnd) {
            break;
        }
        handled = true;
        if (getCurrentLineTop(buffer, layout) >= targetY) {
            break;
        }
    }
    return handled;
}
 
Example #5
Source File: Folder.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example #6
Source File: ListSelectionManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
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;
        }
    }
}
 
Example #7
Source File: CustomLinkMovementMethod.java    From SimplifySpan with MIT License 6 votes vote down vote up
@Override
public boolean onTouchEvent(TextView textView, Spannable spannable, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        mCustomClickableSpan = getPressedSpan(textView, spannable, event);
        if (mCustomClickableSpan != null) {
            mCustomClickableSpan.setPressed(true);
            Selection.setSelection(spannable, spannable.getSpanStart(mCustomClickableSpan), spannable.getSpanEnd(mCustomClickableSpan));
        }
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        CustomClickableSpan touchedSpan = getPressedSpan(textView, spannable, event);
        if (mCustomClickableSpan != null && touchedSpan != mCustomClickableSpan) {
            mCustomClickableSpan.setPressed(false);
            mCustomClickableSpan = null;
            Selection.removeSelection(spannable);
        }
    } else {
        if (mCustomClickableSpan != null) {
            mCustomClickableSpan.setPressed(false);
            super.onTouchEvent(textView, spannable, event);
        }
        mCustomClickableSpan = null;
        Selection.removeSelection(spannable);
    }
    return true;
}
 
Example #8
Source File: UndoRedo.java    From ShaderEditor with MIT License 6 votes vote down vote up
public void redo() {
	EditItem edit = editHistory.getNext();
	if (edit == null) {
		return;
	}

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

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

	removeUnderlineSpans(text);

	Selection.setSelection(text, edit.after == null ? start
			: (start + edit.after.length()));
}
 
Example #9
Source File: EmoteInputView.java    From WifiChat with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    String text = null;
    text = BaseApplication.mEmoticons_Zem.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());
        }

    }
}
 
Example #10
Source File: PhoneFormatter.java    From CallMeMaybe with Apache License 2.0 6 votes vote down vote up
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());
  }
}
 
Example #11
Source File: UndoRedo.java    From ShaderEditor with MIT License 6 votes vote down vote up
public void undo() {
	EditItem edit = editHistory.getPrevious();
	if (edit == null) {
		return;
	}

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

	isUndoOrRedo = true;
	text.replace(start, end, edit.before);
	isUndoOrRedo = false;

	removeUnderlineSpans(text);

	Selection.setSelection(text, edit.before == null ? start
			: (start + edit.before.length()));
}
 
Example #12
Source File: FindActionModeCallback.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    if (!mode.isUiFocusable()) {
        // If the action mode we're running in is not focusable the user
        // will not be able to type into the find on page field. This
        // should only come up when we're running in a dialog which is
        // already less than ideal; disable the option for now.
        return false;
    }

    mode.setCustomView(mCustomView);
    mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_find,
            menu);
    mActionMode = mode;
    Editable edit = mEditText.getText();
    Selection.setSelection(edit, edit.length());
    mMatches.setVisibility(View.GONE);
    mMatchesFound = false;
    mMatches.setText("0");
    mEditText.requestFocus();
    return true;
}
 
Example #13
Source File: ValorMonetarioWatcher.java    From canarinho with Apache License 2.0 6 votes vote down vote up
private void atualizaTexto(Editable editable, String valor) {
    mudancaInterna = true;

    final InputFilter[] oldFilters = editable.getFilters();

    editable.setFilters(new InputFilter[] {});
    editable.replace(0, editable.length(), valor);

    editable.setFilters(oldFilters);

    if (valor.equals(editable.toString())) {
        // TODO: estudar implantar a manutenção da posição do cursor
        Selection.setSelection(editable, valor.length());
    }

    mudancaInterna = false;
}
 
Example #14
Source File: CommentListActivity.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
private View getGridView(int i) {
    View emotionView = LayoutInflater.from(this).inflate(R.layout.view_activity_chat_emotion, null);
    SuperRecyclerView superRecyclerView = emotionView.findViewById(R.id.srcv_view_activity_chat_emotion_display);
    superRecyclerView.setLayoutManager(new WrappedGridLayoutManager(this, 7));
    EmotionViewAdapter emotionViewAdapter = new EmotionViewAdapter();
    superRecyclerView.setAdapter(emotionViewAdapter);
    emotionViewAdapter.addData(i == 0 ? emotionFaceList.subList(0, 21) : emotionFaceList.subList(21, emotionFaceList.size()));
    emotionViewAdapter.setOnItemClickListener(new OnSimpleItemClickListener() {
        @Override
        public void onItemClick(int position, View view) {
            FaceText faceText = emotionViewAdapter.getData(position);
            String content = faceText.getText();
            if (input != null) {
                int startIndex = input.getSelectionStart();
                CharSequence content1 = input.getText().insert(startIndex, content);
                input.setText(FaceTextUtil.toSpannableString(CommentListActivity.this.getApplicationContext(), content1.toString()));
                //                                        重新定位光标位置
                CharSequence info = input.getText();
                if (info != null) {
                    Spannable spannable = (Spannable) info;
                    Selection.setSelection(spannable, startIndex + content.length());
                }
            }
        }
    });
    return emotionView;
}
 
Example #15
Source File: CountLinkMovementMethod.java    From timecat with Apache License 2.0 5 votes vote down vote up
@Override
public void onTakeFocus(TextView view, Spannable text, int dir) {
    Selection.removeSelection(text);

    if ((dir & View.FOCUS_BACKWARD) != 0) {
        text.setSpan(FROM_BELOW, 0, 0, Spannable.SPAN_POINT_POINT);
    } else {
        text.removeSpan(FROM_BELOW);
    }
}
 
Example #16
Source File: AdapterInputConnection.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@VisibleForTesting
ImeState getImeStateForTesting() {
    Editable editable = getEditable();
    String text = editable.toString();
    int selectionStart = Selection.getSelectionStart(editable);
    int selectionEnd = Selection.getSelectionEnd(editable);
    int compositionStart = getComposingSpanStart(editable);
    int compositionEnd = getComposingSpanEnd(editable);
    return new ImeState(text, selectionStart, selectionEnd, compositionStart, compositionEnd);
}
 
Example #17
Source File: TextProcessor.java    From CodeEditor with Apache License 2.0 5 votes vote down vote up
public void undo() {
    TextChange textChange = mUndoStack.pop();
    if (textChange == null) {
        Logger.debug(TAG, mContext.getString(R.string.nothing_to_undo));
        codeEditor.showToast(mContext.getString(R.string.nothing_to_undo), true);
    } else if (textChange.start >= 0) {
        isDoingUndoRedo = true;
        if (textChange.start < 0) {
            textChange.start = 0;
        }
        if (textChange.start > getText().length()) {
            textChange.start = getText().length();
        }
        int end = textChange.start + textChange.newText.length();
        if (end < 0) {
            end = 0;
        }
        if (end > getText().length()) {
            end = getText().length();
        }
        getText().replace(textChange.start, end, textChange.oldText);
        Selection.setSelection(getText(), textChange.start + textChange.oldText.length());
        mRedoStack.push(textChange);
        isDoingUndoRedo = false;
    } else {
        Logger.error(TAG, "undo(): unknown error", null);
        mUndoStack.clear();
    }
}
 
Example #18
Source File: FindToolbar.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTextContextMenuItem(int id) {
    if (id == android.R.id.paste) {
        ClipboardManager clipboard = (ClipboardManager) getContext()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clipData = clipboard.getPrimaryClip();
        if (clipData != null) {
            // Convert the clip data to a simple string
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < clipData.getItemCount(); i++) {
                builder.append(clipData.getItemAt(i).coerceToText(getContext()));
            }

            // Identify how much of the original text should be replaced
            int min = 0;
            int max = getText().length();

            if (isFocused()) {
                final int selStart = getSelectionStart();
                final int selEnd = getSelectionEnd();

                min = Math.max(0, Math.min(selStart, selEnd));
                max = Math.max(0, Math.max(selStart, selEnd));
            }

            Selection.setSelection(getText(), max);
            getText().replace(min, max, builder.toString());
            return true;
        }
    }
    return super.onTextContextMenuItem(id);
}
 
Example #19
Source File: ThemeSetUrlActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    try {
        boolean result = super.onTouchEvent(widget, buffer, event);
        if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
            Selection.removeSelection(buffer);
        }
        return result;
    } catch (Exception e) {
        FileLog.e(e);
    }
    return false;
}
 
Example #20
Source File: LinkTouchMovementMethod.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(TextView textView, Spannable spannable, MotionEvent event) {
    boolean handled = false;
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        pressedSpan = getPressedSpan(textView, spannable, event);
        if (pressedSpan != null) {
            pressedSpan.setPressed(true);
            Selection.setSelection(spannable, spannable.getSpanStart(pressedSpan),
                    spannable.getSpanEnd(pressedSpan));
            handled = true;
        }
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        TouchableUrlSpan touchedSpan = getPressedSpan(textView, spannable, event);
        if (pressedSpan != null && touchedSpan != pressedSpan) {
            pressedSpan.setPressed(false);
            pressedSpan = null;
            Selection.removeSelection(spannable);
        }
    } else {
        if (pressedSpan != null) {
            pressedSpan.setPressed(false);
            super.onTouchEvent(textView, spannable, event);
            handled = true;
        }
        pressedSpan = null;
        Selection.removeSelection(spannable);
    }
    return handled;
}
 
Example #21
Source File: PersonResumeChangeFragment.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    String content = etResume.getText().toString().trim();
    if (content.length() > 50) {
        String newStr = content.substring(0, 50);
        etResume.setText(newStr);
        Selection.setSelection(etResume.getText(), 50);
        content = newStr;
        ToastUtils.show(getString(R.string.resume_change_num_max));
    }
    tvNum.setText("" + content.length());
}
 
Example #22
Source File: JotaTextKeyListener.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
/**
 * Performs the action that happens when you press the DEL key in
 * a TextView.  If there is a selection, deletes the selection;
 * otherwise, DEL alone deletes the character before the cursor,
 * if any;
 * ALT+DEL deletes everything on the line the cursor is on.
 *
 * @return true if anything was deleted; false otherwise.
 */
public boolean forwardDelete(View view, Editable content, int keyCode,
                         KeyEvent event) {
    int selStart, selEnd;
    boolean result = true;

    {
        int a = Selection.getSelectionStart(content);
        int b = Selection.getSelectionEnd(content);

        selStart = Math.min(a, b);
        selEnd = Math.max(a, b);
    }

    if (selStart != selEnd) {
        content.delete(selStart, selEnd);
    } else {
        int to = TextUtils.getOffsetAfter(content, selEnd);

        if (to != selEnd) {
            content.delete(Math.min(to, selEnd), Math.max(to, selEnd));
        }
        else {
            result = false;
        }
    }

    if (result)
        adjustMetaAfterKeypress(content);

    return result;
}
 
Example #23
Source File: MyLinkMovementMethod.java    From FoldText_Java with MIT License 5 votes vote down vote up
@Override
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);

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

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

    return super.onTouchEvent(widget, buffer, event);
}
 
Example #24
Source File: JotaTextKeyListener.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Performs the action that happens when you press the DEL key in
 * a TextView.  If there is a selection, deletes the selection;
 * otherwise, DEL alone deletes the character before the cursor,
 * if any;
 * ALT+DEL deletes everything on the line the cursor is on.
 *
 * @return true if anything was deleted; false otherwise.
 */
public boolean forwardDelete(View view, Editable content, int keyCode,
                         KeyEvent event) {
    int selStart, selEnd;
    boolean result = true;

    {
        int a = Selection.getSelectionStart(content);
        int b = Selection.getSelectionEnd(content);

        selStart = Math.min(a, b);
        selEnd = Math.max(a, b);
    }

    if (selStart != selEnd) {
        content.delete(selStart, selEnd);
    } else {
        int to = TextUtils.getOffsetAfter(content, selEnd);

        if (to != selEnd) {
            content.delete(Math.min(to, selEnd), Math.max(to, selEnd));
        }
        else {
            result = false;
        }
    }

    if (result)
        adjustMetaAfterKeypress(content);

    return result;
}
 
Example #25
Source File: ThemeSetUrlActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    try {
        boolean result = super.onTouchEvent(widget, buffer, event);
        if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
            Selection.removeSelection(buffer);
        }
        return result;
    } catch (Exception e) {
        FileLog.e(e);
    }
    return false;
}
 
Example #26
Source File: LinkTouchMovementMethod.java    From materialup with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(TextView textView, Spannable spannable, MotionEvent event) {
    boolean handled = false;
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        pressedSpan = getPressedSpan(textView, spannable, event);
        if (pressedSpan != null) {
            pressedSpan.setPressed(true);
            Selection.setSelection(spannable, spannable.getSpanStart(pressedSpan),
                    spannable.getSpanEnd(pressedSpan));
            handled = true;
        }
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        TouchableUrlSpan touchedSpan = getPressedSpan(textView, spannable, event);
        if (pressedSpan != null && touchedSpan != pressedSpan) {
            pressedSpan.setPressed(false);
            pressedSpan = null;
            Selection.removeSelection(spannable);
        }
    } else {
        if (pressedSpan != null) {
            pressedSpan.setPressed(false);
            super.onTouchEvent(textView, spannable, event);
            handled = true;
        }
        pressedSpan = null;
        Selection.removeSelection(spannable);
    }
    return handled;
}
 
Example #27
Source File: SelectableLinkMovementMethod.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
@Override
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);

        ClickableSpan[] link = buffer.getSpans(off, off, 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 {
            that's the line we need to remove
            Selection.removeSelection(buffer);
        }*/
    }

    return super.onTouchEvent(widget, buffer, event);
}
 
Example #28
Source File: LinkMovementMethod.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
@Override
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);

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

        if (link.length != 0) {
            if (action == MotionEvent.ACTION_UP) {
                String url = ((URLSpan) link[0]).getURL();
                if (!IntentHandler.handle(url))
                    link[0].onClick(widget);
            } else {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
        }
    }
    return super.onTouchEvent(widget, buffer, event);
}
 
Example #29
Source File: StickersAlert.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    try {
        boolean result = super.onTouchEvent(widget, buffer, event);
        if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
            Selection.removeSelection(buffer);
        }
        return result;
    } catch (Exception e) {
        FileLog.e(e);
    }
    return false;
}
 
Example #30
Source File: FixedLinkMovementMethod.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(TextView widget, final Spannable text) {
    widget.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            skipNextClick = true;
            Selection.removeSelection(text);
            return false;
        }
    });
    super.initialize(widget, text);
}