MessageListItem.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:androidclient 作者:
public void onClick() {
    TextContentView textContent = mBalloonTheme.getTextContentView();

    if (textContent == null)
        return;

    // Check for links. If none, do nothing; if 1, open it; if >1, ask user to pick one
    final URLSpan[] spans = textContent.getUrls();

    if (spans.length == 0) {
        // show the message details dialog
        MessageUtils.showMessageDetails(getContext(), mMessage, mPeer, mDisplayName);
    }
    else if (spans.length == 1) {
        // show link opener
        spans[0].onClick(textContent);
    }
    else {
        // complex stuff (media)
        URLSpanAdapterCallback click = new URLSpanAdapterCallback(textContent);
        final MaterialSimpleListAdapter adapter = new MaterialSimpleListAdapter(click);
        for (URLSpan span : spans) {
            MaterialSimpleListItem.Builder builder = new MaterialSimpleListItem.Builder(getContext())
                .tag(span);
            try {
                String url = span.getURL();
                Uri uri = Uri.parse(url);

                final String telPrefix = "tel:";
                if (url.startsWith(telPrefix)) {
                    // TODO handle country code
                    url = url.substring(telPrefix.length());
                }

                builder.content(url);

                Drawable d = getContext().getPackageManager().getActivityIcon(
                    new Intent(Intent.ACTION_VIEW, uri));
                if (d != null) {
                    builder.icon(d).iconPadding(10);
                }

            }
            catch (android.content.pm.PackageManager.NameNotFoundException ex) {
                // it's ok if we're unable to set the drawable for this view - the user
                // can still use it
            }

            adapter.add(builder.build());
        }

        new MaterialDialog.Builder(getContext())
            .title(R.string.chooser_select_link)
            .cancelable(true)
            .adapter(adapter, null)
            .negativeText(android.R.string.cancel)
            .onNegative(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    dialog.dismiss();
                }
            })
            .show();
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号