Java Code Examples for android.text.Selection#removeSelection()

The following examples show how to use android.text.Selection#removeSelection() . 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: ChangeUsernameActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 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 2
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 6 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 3
Source File: TouchableMovementMethod.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
private void handleActionUp(Spannable spannable) {
    if (pressedSpan != null) {
        listener.onClick(pressedSpan, false);
        touchedSpans.remove(pressedSpan);
        pressedSpan = null;

        Selection.removeSelection(spannable);
    }
}
 
Example 4
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 5
Source File: BetterLinkMovementExtended.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
private void highlightUrl(TextView textView, BetterLinkMovementExtended.ClickableSpanWithText spanWithText, Spannable text) {
    if (!this.isUrlHighlighted) {
        this.isUrlHighlighted = true;
        int spanStart = text.getSpanStart(spanWithText.span());
        int spanEnd = text.getSpanEnd(spanWithText.span());
        Selection.removeSelection(text);
        text.setSpan(new BackgroundColorSpan(textView.getHighlightColor()), spanStart, spanEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        textView.setText(text);
        Selection.setSelection(text, spanStart, spanEnd);
    }
}
 
Example 6
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 7
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 8
Source File: RealTimeLocationMessageProvider.java    From sealtalk-android with MIT License 5 votes vote down vote up
@Override
public void onItemLongClick(final View view, int position, final RealTimeLocationStartMessage content, final UIMessage message) {
    ViewHolder holder = (ViewHolder) view.getTag();
    holder.longClick = true;
    if (view instanceof TextView) {
        CharSequence text = ((TextView) view).getText();
        if (text != null && text instanceof Spannable)
            Selection.removeSelection((Spannable) text);
    }

    String name = null;

    if (message.getSenderUserId() != null) {
        UserInfo userInfo = RongUserInfoManager.getInstance().getUserInfo(message.getSenderUserId());
        if (userInfo != null)
            name = userInfo.getName();
    }
    String[] items;

    Resources res = view.getContext().getResources();
    items = new String[]{res.getString(R.string.rc_dialog_item_message_delete)};

    ArraysDialogFragment.newInstance(name, items).setArraysDialogItemListener(new ArraysDialogFragment.OnArraysDialogItemListener() {
        @Override
        public void OnArraysDialogItemClick(DialogInterface dialog, int which) {
            if (which == 0) {
                RongIM.getInstance().getRongIMClient().deleteMessages(new int[]{message.getMessageId()}, null);
            }

        }
    }).show(((FragmentActivity) view.getContext()).getSupportFragmentManager());
}
 
Example 9
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 10
Source File: LongClickableLinkMovementMethod.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTakeFocus(@NonNull 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 11
Source File: StickersAlert.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 12
Source File: ChangeUsernameActivity.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 13
Source File: LinkMovementClickMethod.java    From imsdk-android 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[] link = buffer.getSpans(off, off, ClickableSpan.class);

        if (link.length != 0) {
            if (action == MotionEvent.ACTION_UP) {
                if(System.currentTimeMillis() - lastClickTime < CLICK_DELAY){
                    link[0].onClick(widget);
                }
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
                lastClickTime = System.currentTimeMillis();
            }

            return true;
        } else {
            Selection.removeSelection(buffer);
        }
    }
    return super.onTouchEvent(widget, buffer, event);
}
 
Example 14
Source File: TextViewFixTouchConsume.java    From umeng_community_android with MIT License 4 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]));
            }

            if (widget instanceof TextViewFixTouchConsume) {
                ((TextViewFixTouchConsume) widget).mlinkHit = true;
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
 
Example 15
Source File: TextViewLinkHandler.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(TextView widget, final Spannable buffer, MotionEvent event) {
    comm = (SpoilerRobotoTextView) widget;

    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);

    link = buffer.getSpans(off, off, URLSpan.class);
    if (link.length > 0) {
        comm.setLongClickable(false);

        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            position = event.getY(); //used to see if the user scrolled or not
        }
        if (!(event.getAction() == MotionEvent.ACTION_UP
                || event.getAction() == MotionEvent.ACTION_DOWN)) {
            if (Math.abs((position - event.getY())) > 25) {
                handler.removeCallbacksAndMessages(null);
            }
            return super.onTouchEvent(widget, buffer, event);
        }

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                clickHandled = false;
                this.event = event;
                if (SettingValues.peek) {
                    handler.postDelayed(longClicked,
                            android.view.ViewConfiguration.getTapTimeout() + 50);
                } else {
                    handler.postDelayed(longClicked,
                            android.view.ViewConfiguration.getLongPressTimeout());
                }

                break;
            case MotionEvent.ACTION_UP:
                comm.setLongClickable(true);
                handler.removeCallbacksAndMessages(null);

                if (!clickHandled) {
                    // regular click
                    if (link.length != 0) {
                        int i = 0;
                        if (sequence != null) {
                            i = sequence.getSpanEnd(link[0]);
                        }
                        if (!link[0].getURL().isEmpty()) {
                            clickableText.onLinkClick(link[0].getURL(), i, subreddit, link[0]);
                        }
                    } else {
                        return false;
                    }
                }
                break;
        }
        return true;

    } else {
        Selection.removeSelection(buffer);
        return false;
    }
}
 
Example 16
Source File: LongPressLinkMovementMethod.java    From Markdown with MIT License 4 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
            || action == MotionEvent.ACTION_MOVE
            || action == MotionEvent.ACTION_CANCEL) {
        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[] clickableLinks = buffer.getSpans(off, off, ClickableSpan.class);
        LongPressClickableSpan[] longPressClickableLinks = buffer.getSpans(off, off, LongPressClickableSpan.class);

        switch (action) {
            case MotionEvent.ACTION_UP:
                if (clickableLinks.length != 0) {
                    if (!mIsLongPressed) {
                        clickableLinks[0].onClick(widget);
                    }

                    mIsLongPressed = false;
                    mHandler.removeMessages(LONG_PRESS);
                }

                return true;

            case MotionEvent.ACTION_DOWN:
                if (clickableLinks.length != 0) {
                    if (longPressClickableLinks.length == 0) {
                        Selection.setSelection(buffer,
                                buffer.getSpanStart(clickableLinks[0]),
                                buffer.getSpanEnd(clickableLinks[0]));
                    } else {
                        mX = (int) event.getX();
                        mY = (int) event.getY();

                        mHandler.removeMessages(LONG_PRESS);
                        mHandler.sendMessageAtTime(Message.obtain(mHandler, LONG_PRESS, new Object[]{longPressClickableLinks[0], widget}),
                                event.getDownTime() + ViewConfiguration.getLongPressTimeout());
                    }
                }

                return true;

            case MotionEvent.ACTION_MOVE:
                if (Math.abs(event.getX() - mX) > 50
                        && Math.abs(event.getX() - mY) > 50) {
                    mHandler.removeMessages(LONG_PRESS);
                }

                return super.onTouchEvent(widget, buffer, event);

            case MotionEvent.ACTION_CANCEL:
                mHandler.removeMessages(LONG_PRESS);
                return super.onTouchEvent(widget, buffer, event);
        }

        if (clickableLinks.length == 0) {
            Selection.removeSelection(buffer);
        }
    }

    return super.onTouchEvent(widget, buffer, event);
}
 
Example 17
Source File: WeiboTextView.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
@Override
        public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
            int action = event.getAction();

//            LogUtils.printLog(WeiboTextView.class, "MotionEvent:" + action);

//            if (action == MotionEvent.ACTION_MOVE) {
//                isPressed = false;
//            }
            switch (action) {
                case MotionEvent.ACTION_DOWN:
                    break;
                case MotionEvent.ACTION_UP:
                    break;

                case MotionEvent.ACTION_CANCEL:
                    buffer.setSpan(new BackgroundColorSpan(0x00000000), 0, weiboTextView.length(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    Selection.setSelection(buffer, 0, weiboTextView.length());
                    break;
            }


            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) {

                    int start = buffer.getSpanStart(link[0]);
                    int end = buffer.getSpanEnd(link[0]);

//                    LogUtils.printLog(WebViewUtils.class, "start:" + start + " end:" + end);

                    if (action == MotionEvent.ACTION_UP) {
                        link[0].onClick(widget);
                        buffer.setSpan(new BackgroundColorSpan(0x00000000), start, end,
                                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                        Selection.setSelection(buffer, start, end);
                    } else if (action == MotionEvent.ACTION_DOWN) {
                        buffer.setSpan(new BackgroundColorSpan(weiboTextView.clickBgClolr), start, end,
                                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                        Selection.setSelection(buffer, start, end);
                    }

                    if (widget instanceof WeiboTextView) {
                        ((WeiboTextView) widget).linkHit = true;
                    }
                    return true;
                } else {
                    Selection.removeSelection(buffer);
                    Touch.onTouchEvent(widget, buffer, event);
                    return false;
                }
            }


            return Touch.onTouchEvent(widget, buffer, event);
        }
 
Example 18
Source File: ClickableMovementMethod.java    From BaseRecyclerViewAdapterHelper with MIT License 4 votes vote down vote up
@Override
public void initialize(TextView widget, Spannable text) {
    Selection.removeSelection(text);
}
 
Example 19
Source File: ClickLinkMovementMethod.java    From xifan with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(TextView widget, Spannable text) {
    Selection.removeSelection(text);
}
 
Example 20
Source File: LinkMovement.java    From RefreashTabView with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event) {
    if (!(v instanceof TextView)) {
        return false;
    }
    TextView widget = (TextView) v;

    //widget.getText() is SpannedString
    Spannable buffer = Spannable.Factory.getInstance().newSpannable(widget.getText());

    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) {
                removeLongClick(v);
                links[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer, buffer.getSpanStart(links[0]), buffer.getSpanEnd(links[0]));
                checkForLongClick(v, 0);

            }
            return true;
        } else {
            Selection.removeSelection(buffer);
        }
    } else if (action == MotionEvent.ACTION_CANCEL) {
        removeLongClick(v);
    }

    return false;
}