Search in sources :

Example 21 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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) {
        Spannable spannableContent = (Spannable) textView.getText();
        spannableContent.setSpan(new TextAppearanceSpan(getContext(), android.R.style.TextAppearance_Small), 0, mContentTitle.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        textView.setText(spannableContent);
        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 22 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project FBReaderJ by geometer.

the class NetworkBookInfoActivity method setupDescription.

private final void setupDescription() {
    setTextFromResource(R.id.network_book_description_title, "description");
    CharSequence description = myBook.getSummary();
    if (description == null) {
        description = myResource.getResource("noDescription").getValue();
    }
    final TextView descriptionView = (TextView) findViewById(R.id.network_book_description);
    descriptionView.setText(description);
    descriptionView.setMovementMethod(new LinkMovementMethod());
    descriptionView.setTextColor(ColorStateList.valueOf(descriptionView.getTextColors().getDefaultColor()));
}
Also used : LinkMovementMethod(android.text.method.LinkMovementMethod)

Example 23 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project FBReaderJ by geometer.

the class DisplayBookPopupAction method run.

@Override
protected void run(Object... params) {
    if (params.length != 1 || !(params[0] instanceof ZLTextRegion)) {
        return;
    }
    final ZLTextRegion region = (ZLTextRegion) params[0];
    if (!(region.getSoul() instanceof ExtensionRegionSoul)) {
        return;
    }
    final ExtensionElement e = ((ExtensionRegionSoul) region.getSoul()).Element;
    if (!(e instanceof BookElement)) {
        return;
    }
    final BookElement element = (BookElement) e;
    if (!element.isInitialized()) {
        return;
    }
    final View mainView = (View) BaseActivity.getViewWidget();
    final View bookView = BaseActivity.getLayoutInflater().inflate(ColorProfile.NIGHT.equals(Reader.ViewOptions.ColorProfileName.getValue()) ? R.layout.book_popup_night : R.layout.book_popup, null);
    final int inch = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_IN, 1, BaseActivity.getResources().getDisplayMetrics());
    final PopupWindow popup = new PopupWindow(bookView, Math.min(4 * inch, mainView.getWidth() * 9 / 10), Math.min(3 * inch, mainView.getHeight() * 9 / 10));
    popup.setFocusable(true);
    popup.setOutsideTouchable(true);
    final ImageView coverView = (ImageView) bookView.findViewById(R.id.book_popup_cover);
    if (coverView != null) {
        final ZLAndroidImageData imageData = (ZLAndroidImageData) element.getImageData();
        if (imageData != null) {
            coverView.setImageBitmap(imageData.getFullSizeBitmap());
        }
    }
    final OPDSBookItem item = element.getItem();
    final TextView headerView = (TextView) bookView.findViewById(R.id.book_popup_header_text);
    final StringBuilder text = new StringBuilder();
    for (OPDSBookItem.AuthorData author : item.Authors) {
        text.append("<p><i>").append(author.DisplayName).append("</i></p>");
    }
    text.append("<h3>").append(item.Title).append("</h3>");
    headerView.setText(Html.fromHtml(text.toString()));
    final TextView descriptionView = (TextView) bookView.findViewById(R.id.book_popup_description_text);
    descriptionView.setText(item.getSummary());
    descriptionView.setMovementMethod(new LinkMovementMethod());
    final ZLResource buttonResource = ZLResource.resource("dialog").getResource("button");
    final View buttonsView = bookView.findViewById(R.id.book_popup_buttons);
    final Button downloadButton = (Button) buttonsView.findViewById(R.id.ok_button);
    downloadButton.setText(buttonResource.getResource("download").getValue());
    final List<UrlInfo> infos = item.getAllInfos(UrlInfo.Type.Book);
    if (infos.isEmpty() || !(infos.get(0) instanceof BookUrlInfo)) {
        downloadButton.setEnabled(false);
    } else {
        final BookUrlInfo bookInfo = (BookUrlInfo) infos.get(0);
        final String fileName = bookInfo.makeBookFileName(UrlInfo.Type.Book);
        final Book book = Reader.Collection.getBookByFile(fileName);
        if (book != null) {
            downloadButton.setText(buttonResource.getResource("openBook").getValue());
            downloadButton.setOnClickListener(new Button.OnClickListener() {

                public void onClick(View v) {
                    openBook(popup, book);
                }
            });
        } else {
            final File file = new File(fileName);
            if (file.exists()) {
                file.delete();
            }
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
            downloadButton.setOnClickListener(new Button.OnClickListener() {

                public void onClick(View v) {
                    UIUtil.wait("downloadingBook", item.Title.toString(), new Runnable() {

                        public void run() {
                            try {
                                new QuietNetworkContext().downloadToFile(bookInfo.Url, file);
                                openBook(popup, Reader.Collection.getBookByFile(fileName));
                            } catch (ZLNetworkException e) {
                                UIMessageUtil.showErrorMessage(BaseActivity, "downloadFailed");
                                e.printStackTrace();
                            }
                        }
                    }, BaseActivity);
                }
            });
        }
    }
    final Button cancelButton = (Button) buttonsView.findViewById(R.id.cancel_button);
    cancelButton.setText(buttonResource.getResource("cancel").getValue());
    cancelButton.setOnClickListener(new Button.OnClickListener() {

        public void onClick(View v) {
            popup.dismiss();
        }
    });
    downloadButton.setTextColor(0xFF777777);
    cancelButton.setTextColor(0xFF777777);
    popup.setOnDismissListener(new PopupWindow.OnDismissListener() {

        public void onDismiss() {
        }
    });
    popup.showAtLocation(BaseActivity.getCurrentFocus(), Gravity.CENTER, 0, 0);
}
Also used : BookElement(org.geometerplus.fbreader.fbreader.BookElement) PopupWindow(android.widget.PopupWindow) ZLResource(org.geometerplus.zlibrary.core.resources.ZLResource) BookUrlInfo(org.geometerplus.fbreader.network.urlInfo.BookUrlInfo) ZLAndroidImageData(org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageData) BookUrlInfo(org.geometerplus.fbreader.network.urlInfo.BookUrlInfo) UrlInfo(org.geometerplus.fbreader.network.urlInfo.UrlInfo) Book(org.geometerplus.fbreader.book.Book) ZLNetworkException(org.geometerplus.zlibrary.core.network.ZLNetworkException) OPDSBookItem(org.geometerplus.fbreader.network.opds.OPDSBookItem) LinkMovementMethod(android.text.method.LinkMovementMethod) View(android.view.View) QuietNetworkContext(org.geometerplus.zlibrary.core.network.QuietNetworkContext) File(java.io.File)

Example 24 with LinkMovementMethod

use of android.text.method.LinkMovementMethod in project FBReaderJ by geometer.

the class ThirdPartyLibrariesPreference method onCreateDialogView.

@Override
protected View onCreateDialogView() {
    final TextView textView = new TextView(getContext());
    final StringBuilder html = new StringBuilder();
    try {
        final BufferedReader reader = new BufferedReader(new InputStreamReader(ZLFile.createFileByPath("data/licences.html").getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            html.append(line);
        }
        reader.close();
    } catch (IOException e) {
    }
    textView.setText(Html.fromHtml(html.toString()));
    textView.setPadding(10, 10, 10, 10);
    textView.setMovementMethod(new LinkMovementMethod());
    return textView;
}
Also used : LinkMovementMethod(android.text.method.LinkMovementMethod) TextView(android.widget.TextView)

Example 25 with LinkMovementMethod

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

the class DescriptionEditRevertHelpView method init.

@SuppressWarnings("checkstyle:magicnumber")
private void init(@NonNull String qNumber) {
    inflate(getContext(), R.layout.view_description_edit_revert_help, this);
    ButterKnife.bind(this);
    helpText.setMovementMethod(new LinkMovementMethod());
    Spanned helpStr = StringUtil.fromHtml(getString(R.string.description_edit_revert_help_body).replaceAll(":revertSubtitle", getString(R.string.description_edit_revert_subtitle)).replaceAll(":revertIntro", getString(R.string.description_edit_revert_intro)).replaceAll(":revertHistory", String.format(getString(R.string.description_edit_revert_history), getHistoryUri(qNumber))));
    int gapWidth = DimenUtil.roundedDpToPx(8);
    SpannableString revertReason1 = new SpannableString(StringUtil.fromHtml(String.format(getString(R.string.description_edit_revert_reason1), getString(R.string.wikidata_description_guide_url))));
    SpannableString revertReason2 = new SpannableString(StringUtil.fromHtml(getString(R.string.description_edit_revert_reason2)));
    revertReason1.setSpan(new BulletSpan(gapWidth), 0, revertReason1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    revertReason2.setSpan(new BulletSpan(gapWidth), 0, revertReason2.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    SpannableString helpSpan = new SpannableString(TextUtils.expandTemplate(helpStr, revertReason1, revertReason2));
    helpText.setText(helpSpan);
}
Also used : SpannableString(android.text.SpannableString) BulletSpan(android.text.style.BulletSpan) LinkMovementMethod(android.text.method.LinkMovementMethod) Spanned(android.text.Spanned)

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