Search in sources :

Example 36 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project android_packages_apps_Settings by LineageOS.

the class LinkablePreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder view) {
    super.onBindViewHolder(view);
    TextView textView = (TextView) view.findViewById(android.R.id.title);
    if (textView == null) {
        return;
    }
    textView.setSingleLine(false);
    if (mContentTitle == null || mClickListener == null) {
        return;
    }
    StringBuilder contentBuilder = new StringBuilder().append(mContentTitle);
    if (mContentDescription != null) {
        contentBuilder.append("\n\n");
        contentBuilder.append(mContentDescription);
    }
    boolean linked = LinkifyUtils.linkify(textView, contentBuilder, mClickListener);
    if (linked && mContentTitle != null) {
        // Embolden and enlarge the title.
        Spannable boldSpan = (Spannable) textView.getText();
        boldSpan.setSpan(new TextAppearanceSpan(getContext(), android.R.style.TextAppearance_Medium), 0, mContentTitle.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        textView.setText(boldSpan);
        textView.setMovementMethod(new LinkMovementMethod());
    }
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) LinkMovementMethod(android.text.method.LinkMovementMethod) TextView(android.widget.TextView) Spannable(android.text.Spannable)

Example 37 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project twicalico by moko256.

the class ShowTweetActivity method updateView.

private void updateView(Status item) {
    TextView tweetIsReply = findViewById(R.id.tweet_show_is_reply_text);
    long replyTweetId = item.getInReplyToStatusId();
    if (replyTweetId != -1) {
        tweetIsReply.setVisibility(VISIBLE);
        tweetIsReply.setOnClickListener(v -> startActivity(getIntent(this, replyTweetId)));
    } else {
        tweetIsReply.setVisibility(GONE);
    }
    StatusView statusView = new StatusView(this);
    statusView.setStatus(item);
    ViewGroup cview = (ViewGroup) statusView.getChildAt(0);
    ViewGroup sview = (ViewGroup) cview.getChildAt(0);
    cview.removeView(sview);
    FrameLayout statusViewFrame = findViewById(R.id.tweet_show_tweet);
    statusViewFrame.removeAllViews();
    statusViewFrame.addView(sview);
    ((TextView) findViewById(R.id.tweet_show_timestamp)).setText(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(item.getCreatedAt()));
    TextView viaText = findViewById(R.id.tweet_show_via);
    viaText.setText(TwitterStringUtils.convertUrlSpanToCustomTabs(Html.fromHtml("via:" + item.getSource()), this));
    viaText.setMovementMethod(new LinkMovementMethod());
    AppCompatEditText replyText = findViewById(R.id.tweet_show_tweet_reply_text);
    AppCompatButton replyButton = findViewById(R.id.tweet_show_tweet_reply_button);
    UserMentionEntity[] users = item.getUserMentionEntities();
    replyText.setText(TwitterStringUtils.convertToReplyTopString(GlobalApplication.userCache.get(GlobalApplication.userId).getScreenName(), item.getUser().getScreenName(), users));
    replyButton.setOnClickListener(v -> {
        replyButton.setEnabled(false);
        PostTweetModel model = PostTweetModelCreator.getInstance(GlobalApplication.twitter, getContentResolver());
        model.setTweetText(replyText.getText().toString());
        model.setInReplyToStatusId(item.getId());
        subscriptions.add(model.postTweet().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(it -> {
            replyText.setText(TwitterStringUtils.convertToReplyTopString(GlobalApplication.userCache.get(GlobalApplication.userId).getScreenName(), item.getUser().getScreenName(), users));
            replyButton.setEnabled(true);
            Toast.makeText(ShowTweetActivity.this, R.string.succeeded, Toast.LENGTH_SHORT).show();
        }, e -> {
            e.printStackTrace();
            Toast.makeText(ShowTweetActivity.this, R.string.error_occurred, Toast.LENGTH_SHORT).show();
            replyButton.setEnabled(true);
        }));
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) PostTweetModel(com.github.moko256.twicalico.model.base.PostTweetModel) FrameLayout(android.widget.FrameLayout) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) LinkMovementMethod(android.text.method.LinkMovementMethod) TwitterStringUtils(com.github.moko256.twicalico.text.TwitterStringUtils) UserMentionEntity(twitter4j.UserMentionEntity) MenuItem(android.view.MenuItem) AppCompatButton(android.support.v7.widget.AppCompatButton) Single(rx.Single) AppCustomTabsKt(com.github.moko256.twicalico.intent.AppCustomTabsKt) Toast(android.widget.Toast) Menu(android.view.Menu) Schedulers(rx.schedulers.Schedulers) TwitterException(twitter4j.TwitterException) VISIBLE(android.view.View.VISIBLE) ActionBar(android.support.v7.app.ActionBar) DateFormat(java.text.DateFormat) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) StatusCacheMap(com.github.moko256.twicalico.cacheMap.StatusCacheMap) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) CompositeSubscription(rx.subscriptions.CompositeSubscription) TextView(android.widget.TextView) GONE(android.view.View.GONE) Html(android.text.Html) Status(twitter4j.Status) PostTweetModelCreator(com.github.moko256.twicalico.model.impl.PostTweetModelCreator) AppCompatEditText(android.support.v7.widget.AppCompatEditText) AppCompatEditText(android.support.v7.widget.AppCompatEditText) UserMentionEntity(twitter4j.UserMentionEntity) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) LinkMovementMethod(android.text.method.LinkMovementMethod) TextView(android.widget.TextView) PostTweetModel(com.github.moko256.twicalico.model.base.PostTweetModel) AppCompatButton(android.support.v7.widget.AppCompatButton)

Example 38 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project Camera-Roll-Android-App by kollerlukas.

the class AboutActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setEnterTransition(new Slide(Gravity.BOTTOM));
        getWindow().setReturnTransition(new Slide(Gravity.BOTTOM));
    }
    SwipeBackCoordinatorLayout swipeBackView = findViewById(R.id.swipeBackView);
    swipeBackView.setOnSwipeListener(this);
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle("");
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    final View header = findViewById(R.id.header);
    header.setBackgroundColor(theme.getAccentColor(this));
    TextView version = findViewById(R.id.version);
    try {
        String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        final int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
        // noinspection deprecation
        version.setText(Html.fromHtml(versionName));
        version.setTextColor(theme.getAccentTextColor(this));
        version.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                Toast.makeText(view.getContext(), "versionCode: " + String.valueOf(versionCode), Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    final TextView aboutText = findViewById(R.id.about_text);
    // noinspection deprecation
    aboutText.setText(Html.fromHtml(getString(R.string.about_text)));
    aboutText.setMovementMethod(new LinkMovementMethod());
    final View rootView = findViewById(R.id.root_view);
    final NestedScrollView scrollView = findViewById(R.id.scroll_view);
    scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

        @Override
        public void onScrollChange(NestedScrollView nestedScrollView, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            int statusBarHeight = toolbar.getPaddingTop();
            if (scrollY > header.getHeight() - statusBarHeight / 2) {
                if (theme.darkStatusBarIcons()) {
                    Util.setDarkStatusBarIcons(rootView);
                } else {
                    Util.setLightStatusBarIcons(rootView);
                }
            } else {
                if (theme.darkStatusBarIconsInSelectorMode()) {
                    Util.setDarkStatusBarIcons(rootView);
                } else {
                    Util.setLightStatusBarIcons(rootView);
                }
            }
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
            @Override
            public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
                toolbar.setPadding(toolbar.getPaddingStart(), /*+ insets.getSystemWindowInsetLeft()*/
                toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(), toolbar.getPaddingEnd(), /*+ insets.getSystemWindowInsetRight()*/
                toolbar.getPaddingBottom());
                aboutText.setPadding(aboutText.getPaddingStart(), aboutText.getPaddingTop(), aboutText.getPaddingEnd(), aboutText.getPaddingBottom() + insets.getSystemWindowInsetBottom());
                View viewGroup = findViewById(R.id.swipeBackView);
                ViewGroup.MarginLayoutParams viewGroupParams = (ViewGroup.MarginLayoutParams) viewGroup.getLayoutParams();
                viewGroupParams.leftMargin += insets.getSystemWindowInsetLeft();
                viewGroupParams.rightMargin += insets.getSystemWindowInsetRight();
                viewGroup.setLayoutParams(viewGroupParams);
                // clear this listener so insets aren't re-applied
                rootView.setOnApplyWindowInsetsListener(null);
                return insets.consumeSystemWindowInsets();
            }
        });
        // set status bar icon color
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    } else {
        rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                // hacky way of getting window insets on pre-Lollipop
                // somewhat works...
                int[] screenSize = Util.getScreenSize(AboutActivity.this);
                int[] windowInsets = new int[] { Math.abs(screenSize[0] - rootView.getLeft()), Math.abs(screenSize[1] - rootView.getTop()), Math.abs(screenSize[2] - rootView.getRight()), Math.abs(screenSize[3] - rootView.getBottom()) };
                toolbar.setPadding(toolbar.getPaddingStart(), toolbar.getPaddingTop() + windowInsets[1], toolbar.getPaddingEnd(), toolbar.getPaddingBottom());
                View viewGroup = findViewById(R.id.swipeBackView);
                ViewGroup.MarginLayoutParams viewGroupParams = (ViewGroup.MarginLayoutParams) viewGroup.getLayoutParams();
                viewGroupParams.leftMargin += windowInsets[0];
                viewGroupParams.rightMargin += windowInsets[2];
                viewGroup.setLayoutParams(viewGroupParams);
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        if (toolbar.getChildAt(i) instanceof ImageView) {
            ImageView imageView = ((ImageView) toolbar.getChildAt(i));
            int color;
            if (!theme.darkStatusBarIconsInSelectorMode()) {
                color = ContextCompat.getColor(this, R.color.white_translucent1);
            } else {
                color = ContextCompat.getColor(this, R.color.black_translucent2);
            }
            imageView.setColorFilter(color, PorterDuff.Mode.SRC_IN);
            break;
        }
    }
    // needed for transparent statusBar
    setSystemUiFlags();
}
Also used : ViewGroup(android.view.ViewGroup) LinkMovementMethod(android.text.method.LinkMovementMethod) ImageView(android.widget.ImageView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) WindowInsets(android.view.WindowInsets) PackageManager(android.content.pm.PackageManager) Slide(android.transition.Slide) SwipeBackCoordinatorLayout(us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout) RequiresApi(android.support.annotation.RequiresApi) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NestedScrollView(android.support.v4.widget.NestedScrollView) ViewTreeObserver(android.view.ViewTreeObserver) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 39 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project android_packages_apps_Settings by DirtyUnicorns.

the class LinkablePreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder view) {
    super.onBindViewHolder(view);
    TextView textView = (TextView) view.findViewById(android.R.id.title);
    if (textView == null) {
        return;
    }
    textView.setSingleLine(false);
    if (mContentTitle == null || mClickListener == null) {
        return;
    }
    StringBuilder contentBuilder = new StringBuilder().append(mContentTitle);
    if (mContentDescription != null) {
        contentBuilder.append("\n\n");
        contentBuilder.append(mContentDescription);
    }
    boolean linked = LinkifyUtils.linkify(textView, contentBuilder, mClickListener);
    if (linked && mContentTitle != null) {
        // Embolden and enlarge the title.
        Spannable boldSpan = (Spannable) textView.getText();
        boldSpan.setSpan(new TextAppearanceSpan(getContext(), android.R.style.TextAppearance_Medium), 0, mContentTitle.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        textView.setText(boldSpan);
        textView.setMovementMethod(new LinkMovementMethod());
    }
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) LinkMovementMethod(android.text.method.LinkMovementMethod) TextView(android.widget.TextView) Spannable(android.text.Spannable)

Example 40 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project apps-android-wikipedia by wikimedia.

the class DescriptionEditView method init.

private void init() {
    inflate(getContext(), R.layout.view_description_edit, this);
    ButterKnife.bind(this);
    licenseText.setText(StringUtil.fromHtml(String.format(getContext().getString(R.string.description_edit_license_notice), getContext().getString(R.string.terms_of_use_url), getContext().getString(R.string.cc_0_url))));
    licenseText.setMovementMethod(new LinkMovementMethod());
    FeedbackUtil.setToolbarButtonLongPressToast(saveButton, cancelButton, helpButton);
    setOrientation(VERTICAL);
}
Also used : LinkMovementMethod(android.text.method.LinkMovementMethod)

Aggregations

LinkMovementMethod (android.text.method.LinkMovementMethod)50 TextView (android.widget.TextView)40 SmallTest (android.test.suitebuilder.annotation.SmallTest)18 View (android.view.View)12 Spannable (android.text.Spannable)8 TextAppearanceSpan (android.text.style.TextAppearanceSpan)7 ImageView (android.widget.ImageView)7 SpannableStringBuilder (android.text.SpannableStringBuilder)6 SpannableString (android.text.SpannableString)4 ActivityNotFoundException (android.content.ActivityNotFoundException)3 Context (android.content.Context)3 ViewGroup (android.view.ViewGroup)3 SystemUIDialog (com.android.systemui.statusbar.phone.SystemUIDialog)3 Intent (android.content.Intent)2 PackageManager (android.content.pm.PackageManager)2 Resources (android.content.res.Resources)2 Paint (android.graphics.Paint)2 Bundle (android.os.Bundle)2 ActionBar (android.support.v7.app.ActionBar)2 AlertDialog (android.support.v7.app.AlertDialog)2