android.text.method.MovementMethod Java Examples

The following examples show how to use android.text.method.MovementMethod. 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: AppListFragment.java    From EventApp with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    int padding = (int) (getResources().getDisplayMetrics().density * 8); // 8dip
    ListView listView = getListView();
    listView.setPadding(padding, 0, padding, 0);
    listView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
    listView.setDivider(null);

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View header = inflater.inflate(R.layout.list_header_footer, listView, false);
    View footer = inflater.inflate(R.layout.list_footer, listView, false);

    TextView tv = (TextView) footer.findViewById(R.id.footer);
    String str = getResources().getString(R.string.footer);
    MovementMethod method = LinkMovementMethod.getInstance();
    tv.setMovementMethod(method);
    CharSequence html = Html.fromHtml(str);
    tv.setText(html);

    listView.addHeaderView(header, null, false);
    listView.addFooterView(footer, null, false);

    setTrack(7);
}
 
Example #2
Source File: CorePluginTest.java    From Markwon with Apache License 2.0 6 votes vote down vote up
@Test
public void implicit_movement_method_after_set_text_added() {
    // validate that CorePlugin will implicitly add LinkMovementMethod if one is missing
    final TextView textView = mock(TextView.class);
    when(textView.getMovementMethod()).thenReturn(null);

    final CorePlugin plugin = CorePlugin.create();

    assertNull(textView.getMovementMethod());

    plugin.afterSetText(textView);

    final ArgumentCaptor<MovementMethod> captor = ArgumentCaptor.forClass(MovementMethod.class);
    verify(textView, times(1)).setMovementMethod(captor.capture());

    assertNotNull(captor.getValue());
}
 
Example #3
Source File: AboutUsActivity.java    From Password-Storage with MIT License 6 votes vote down vote up
private void onClickURL(){
    MovementMethod contributors_descMovementMethod = contributors_desc.getMovementMethod();
    if ((contributors_descMovementMethod == null) || !(contributors_descMovementMethod instanceof LinkMovementMethod)) {
        if (contributors_desc.getLinksClickable()) {
            contributors_desc.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
    MovementMethod app_report_issues_descMovementMethod = app_report_issues_desc.getMovementMethod();
    if ((app_report_issues_descMovementMethod == null) || !(app_report_issues_descMovementMethod instanceof LinkMovementMethod)) {
        if (app_report_issues_desc.getLinksClickable()) {
            app_report_issues_desc.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
    MovementMethod app_license_info_descMovementMethod = app_license_info_desc.getMovementMethod();
    if ((app_license_info_descMovementMethod == null) || !(app_license_info_descMovementMethod instanceof LinkMovementMethod)) {
        if (app_license_info_desc.getLinksClickable()) {
            app_license_info_desc.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
}
 
Example #4
Source File: LinkifyCompat.java    From fanfouapp-opensource with Apache License 2.0 5 votes vote down vote up
private static final void addLinkMovementMethod(final TextView t) {
    final MovementMethod m = t.getMovementMethod();

    if ((m == null) || !(m instanceof LinkMovementMethod)) {
        if (t.getLinksClickable()) {
            t.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
}
 
Example #5
Source File: UrlFieldView.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
protected void onFinishInflate()
{
    super.onFinishInflate();
    mText = (TextView) findViewById(android.R.id.text1);

    if (mText == null)
    {
        // on older Android version onFinishInflate can be called multiple times if the view contains includes
        return;
    }

    MovementMethod mMethod = LinkMovementMethod.getInstance();
    mText.setMovementMethod(mMethod);
}
 
Example #6
Source File: LinkMovementMethod.java    From KlyphMessenger with MIT License 5 votes vote down vote up
public static MovementMethod getInstance()
{
	if (sInstance == null)
		sInstance = new LinkMovementMethod();

	return sInstance;
}
 
Example #7
Source File: LinkMovementMethodExt.java    From TextViewWithLinks with Apache License 2.0 5 votes vote down vote up
public static MovementMethod getInstance(LinkMovementListener _listener, Class _spanClass) {
	if (sInstance == null) {
		sInstance = new LinkMovementMethodExt();
		listener = _listener;
		((LinkMovementMethodExt) sInstance).spanClass = _spanClass;
	}

	return sInstance;
}
 
Example #8
Source File: Linkify.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static final void addLinkMovementMethod(@NonNull TextView t) {
    MovementMethod m = t.getMovementMethod();

    if ((m == null) || !(m instanceof LinkMovementMethod)) {
        if (t.getLinksClickable()) {
            t.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
}
 
Example #9
Source File: DefaultMovementMethod.java    From PinView with Apache License 2.0 5 votes vote down vote up
public static MovementMethod getInstance() {
    if (sInstance == null) {
        sInstance = new DefaultMovementMethod();
    }

    return sInstance;
}
 
Example #10
Source File: LongPressLinkMovementMethod.java    From Markdown with MIT License 5 votes vote down vote up
public static MovementMethod getInstance() {
    if (sInstance == null) {
        sInstance = new LongPressLinkMovementMethod();
    }

    return sInstance;
}
 
Example #11
Source File: LinkMovementMethod.java    From Klyph with MIT License 5 votes vote down vote up
public static MovementMethod getInstance()
{
	if (sInstance == null)
		sInstance = new LinkMovementMethod();

	return sInstance;
}
 
Example #12
Source File: DefaultMovementMethod.java    From android-otpview-pinview with MIT License 5 votes vote down vote up
public static MovementMethod getInstance() {
  if (sInstance == null) {
    sInstance = new DefaultMovementMethod();
  }

  return sInstance;
}
 
Example #13
Source File: HackyTextView.java    From BlackLight with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
	boolean ret = super.onTouchEvent(event);
	
	MovementMethod method = getMovementMethod();
	if (method instanceof HackyMovementMethod) {
		return ((HackyMovementMethod) method).isLinkHit();
	}
	
	return ret;
}
 
Example #14
Source File: MentionsEditText.java    From Spyglass with Apache License 2.0 5 votes vote down vote up
@NonNull
public static MovementMethod getInstance() {
    if (sInstance == null)
        sInstance = new MentionsMovementMethod();

    return sInstance;
}
 
Example #15
Source File: LinkTouchMovementMethod.java    From materialup with Apache License 2.0 4 votes vote down vote up
public static MovementMethod getInstance() {
    if (instance == null)
        instance = new LinkTouchMovementMethod();

    return instance;
}
 
Example #16
Source File: TextViewUtils.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
/**
     * 变换字符串中符合pattern字体颜色并展示
     *
     * @param textView
     * @param text
     * @param patternStrings
     * @param highlightColor
     */
    public static void setSomeTextChangeColor(TextView textView, String text,
                                              String[] patternStrings, int normalColor, int highlightColor, int highlightClickBgColor, int backgoundColor,
                                              boolean isChangeBackground, ClickableSpanExtend.SetClickableSpan clickableSpan, MovementMethod movementMethod) {


        SpannableStringBuilder builder = new SpannableStringBuilder(text);
//

        //设置一个全局的文本监听,防止点击文本没有反应。
//        builder.setSpan(new ForegroundColorSpan(normalColor), 0, text.length()-1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        builder.setSpan(new ClickableSpanExtend(text,text, clickableSpan,color,normalColor), 0, text.length() -1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        for (String patternStr : patternStrings) {
            if (StringUtils.isNullOrEmpty(patternStr)) {
                return;
            }
            Pattern pattern = Pattern.compile(patternStr);
            Matcher m = pattern.matcher(text);

            int start = 0;
            int end = 0;
            String findText;

            while (m.find()) {
                start = m.start();
                end = m.end();
                findText = text.substring(start, end);
//                System.out.println(start + "");
//                System.out.println(end + "");
//                System.out.println(text.substring(start, end));

                if (isChangeBackground) {
                    if (backgoundColor < 1) {
                        //求反色
                        backgoundColor = 0xFF - highlightColor;
                    }

                    builder.setSpan(new BackgroundColorSpan(backgoundColor), start, end,
                            Spannable.SPAN_EXCLUSIVE_INCLUSIVE);     //设置指定位置textview的背景颜色
                }

//                builder.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

                if (clickableSpan != null)
                    builder.setSpan(new ClickableSpanExtend(text, findText, clickableSpan,
                                    normalColor, highlightColor, highlightClickBgColor), start, end,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

        }
        if (movementMethod != null) {
//            textView.setMovementMethod(LinkMovementMethod.getInstance());
            textView.setMovementMethod(movementMethod);
        }


        textView.setText(builder);
//        textView.setClickable(false);
//        textView.setFocusable(false);

//
//        SpannableStringBuilder builder2 = new SpannableStringBuilder(text);
//
//        //ForegroundColorSpan 为文字前景色,BackgroundColorSpan为文字背景色
//        ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
//        ForegroundColorSpan whiteSpan = new ForegroundColorSpan(Color.WHITE);
//        ForegroundColorSpan blueSpan = new ForegroundColorSpan(Color.BLUE);
//        ForegroundColorSpan greenSpan = new ForegroundColorSpan(Color.GREEN);
//        ForegroundColorSpan yellowSpan = new ForegroundColorSpan(Color.YELLOW);
//
//        builder2.setSpan(redSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        builder2.setSpan(whiteSpan, 1, 2, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//        builder2.setSpan(blueSpan, 2, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        builder2.setSpan(greenSpan, 3, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        builder2.setSpan(yellowSpan, 4,5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//
//        textView.setText(builder2);
    }
 
Example #17
Source File: PasswordInput.java    From PasswordInput with Apache License 2.0 4 votes vote down vote up
@Override
protected MovementMethod getDefaultMovementMethod() {
    //关闭 copy/paste/cut 长按文字菜单,使文字不可长按选中
    //Note: 需 setTextIsSelectable(false) 才会生效
    return null;
}
 
Example #18
Source File: LinkTouchMovementMethod.java    From android-proguards with Apache License 2.0 4 votes vote down vote up
public static MovementMethod getInstance() {
    if (instance == null)
        instance = new LinkTouchMovementMethod();

    return instance;
}
 
Example #19
Source File: RTEditorMovementMethod.java    From Android-RTEditor with Apache License 2.0 4 votes vote down vote up
public static synchronized  MovementMethod getInstance() {
    if (sInstance == null) {
        sInstance = new RTEditorMovementMethod();
    }
    return sInstance;
}
 
Example #20
Source File: FixedLinkMovementMethod.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
public static MovementMethod getInstance() {
    if (sInstance == null) sInstance = new FixedLinkMovementMethod();
    return sInstance;
}
 
Example #21
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void movementMethod(MovementMethod arg) {
  return BaseDSL.attr("movementMethod", arg);
}
 
Example #22
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void movementMethod(MovementMethod arg) {
  return BaseDSL.attr("movementMethod", arg);
}
 
Example #23
Source File: DescriptionView.java    From KernelAdiutor with GNU General Public License v3.0 4 votes vote down vote up
public void setMovementMethod(MovementMethod movementMethod) {
    mLinkMovementMethod = movementMethod;
    refresh();
}
 
Example #24
Source File: LinkMovementMethod2.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
public static MovementMethod getInstance() {
    if (sInstance == null)
        sInstance = new LinkMovementMethod2();

    return sInstance;
}
 
Example #25
Source File: HtmlTextView.java    From v2ex with Apache License 2.0 4 votes vote down vote up
public static MovementMethod getInstance() {
    if (sInstance == null)
        sInstance = new LinkMovementCheck();

    return sInstance;
}
 
Example #26
Source File: LogTextBox.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected MovementMethod getDefaultMovementMethod() {
    return ScrollingMovementMethod.getInstance();
}
 
Example #27
Source File: RTEditorMovementMethod.java    From memoir with Apache License 2.0 4 votes vote down vote up
public static synchronized  MovementMethod getInstance() {
    if (sInstance == null) {
        sInstance = new RTEditorMovementMethod();
    }
    return sInstance;
}
 
Example #28
Source File: AlertDialog.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/** @hide */
public void setMessageMovementMethod(MovementMethod movementMethod) {
    mAlert.setMessageMovementMethod(movementMethod);
}
 
Example #29
Source File: EditText.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
protected MovementMethod getDefaultMovementMethod() {
    return ArrowKeyMovementMethod.getInstance();
}
 
Example #30
Source File: LinkMovementMethod2.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
public static MovementMethod getInstance() {
    if (sInstance == null)
        sInstance = new LinkMovementMethod2();

    return sInstance;
}