org.chromium.ui.text.SpanApplier Java Examples

The following examples show how to use org.chromium.ui.text.SpanApplier. 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: TextMessageWithLinkAndIconPreference.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void setSummary(CharSequence summary) {
    // If there is no link in the summary, invoke the default behavior.
    String summaryString = summary.toString();
    if (!summaryString.contains("<link>") || !summaryString.contains("</link>")) {
        super.setSummary(summary);
        return;
    }

    // Linkify <link></link> span.
    final SpannableString summaryWithLink = SpanApplier.applySpans(summaryString,
            new SpanApplier.SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
                @Override
                public void onClick(View widget) {
                    if (mLinkClickDelegate != null) mLinkClickDelegate.run();
                }
            }));

    super.setSummary(summaryWithLink);
}
 
Example #2
Source File: PassphraseDialogFragment.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    recordPassphraseDialogDismissal(PASSPHRASE_DIALOG_RESET_LINK);
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName());
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #3
Source File: PassphraseTypeDialogFragment.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_encryption_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName());
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #4
Source File: ClearBrowsingDataTabCheckBoxPreference.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void setSummary(CharSequence summary) {
    // If there is no link in the summary, invoke the default behavior.
    String summaryString = summary.toString();
    if (!summaryString.contains("<link>") || !summaryString.contains("</link>")) {
        super.setSummary(summary);
        return;
    }

    // Linkify <link></link> span.
    final SpannableString summaryWithLink = SpanApplier.applySpans(summaryString,
            new SpanApplier.SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
                @Override
                public void onClick(View widget) {
                    if (mLinkClickDelegate != null) mLinkClickDelegate.run();
                }
            }));

    mHasClickableSpans = true;
    super.setSummary(summaryWithLink);
}
 
Example #5
Source File: TextMessageWithLinkAndIconPreference.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void setSummary(CharSequence summary) {
    // If there is no link in the summary, invoke the default behavior.
    String summaryString = summary.toString();
    if (!summaryString.contains("<link>") || !summaryString.contains("</link>")) {
        super.setSummary(summary);
        return;
    }

    // Linkify <link></link> span.
    final SpannableString summaryWithLink = SpanApplier.applySpans(summaryString,
            new SpanApplier.SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
                @Override
                public void onClick(View widget) {
                    if (mLinkClickDelegate != null) mLinkClickDelegate.run();
                }
            }));

    super.setSummary(summaryWithLink);
}
 
Example #6
Source File: SadTabViewFactory.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Construct and return help message to be displayed on R.id.sad_tab_message.
 * @param context Context of the resulting Sad Tab view. This is needed to load the strings.
 * @param suggestionAction Action to be executed when user clicks "try these suggestions"
 *                         or "learn more".
 * @return Help message to be displayed on R.id.sad_tab_message.
 */
private static CharSequence getHelpMessage(
        Context context, final Runnable suggestionAction, final boolean showSendFeedback) {
    NoUnderlineClickableSpan linkSpan = new NoUnderlineClickableSpan() {
        @Override
        public void onClick(View view) {
            SadTabViewFactory.recordEvent(showSendFeedback, SadTabEvent.HELP_LINK_CLICKED);
            suggestionAction.run();
        }
    };

    if (showSendFeedback) {
        SpannableString learnMoreLink =
                new SpannableString(context.getString(R.string.sad_tab_reload_learn_more));
        learnMoreLink.setSpan(linkSpan, 0, learnMoreLink.length(), 0);
        return learnMoreLink;
    } else {
        String helpMessage = context.getString(R.string.sad_tab_message) + "\n\n"
                + context.getString(R.string.sad_tab_suggestions);
        return SpanApplier.applySpans(helpMessage, new SpanInfo("<link>", "</link>", linkSpan));
    }
}
 
Example #7
Source File: Footer.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public ViewHolder(ViewGroup root, final SuggestionsNavigationDelegate navigationDelegate) {
    super(LayoutInflater.from(root.getContext())
                    .inflate(R.layout.new_tab_page_footer, root, false));

    NoUnderlineClickableSpan link = new NoUnderlineClickableSpan() {
        @Override
        public void onClick(View view) {
            // TODO(mvanouwerkerk): Ensure this can be activated when using TalkBack.
            navigationDelegate.navigateToHelpPage();
        }
    };

    TextView textView = (TextView) itemView.findViewById(R.id.text);
    textView.setText(SpanApplier.applySpans(
            root.getResources().getString(R.string.ntp_learn_more_about_suggested_content),
            new SpanApplier.SpanInfo("<link>", "</link>", link)));
    textView.setMovementMethod(LinkMovementMethod.getInstance());
}
 
Example #8
Source File: SogouPromoDialog.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Do not allow this dialog to be reconstructed because it requires native side loaded.
    if (savedInstanceState != null) {
        dismiss();
        return;
    }

    StyleSpan boldSpan = new StyleSpan(android.graphics.Typeface.BOLD);
    TextView textView = (TextView) findViewById(R.id.subheader);
    SpannableString description = SpanApplier.applySpans(
            getContext().getString(R.string.sogou_explanation),
            new SpanInfo("<link>", "</link>", mSpan), new SpanInfo("<b>", "</b>", boldSpan));
    textView.setText(description);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
}
 
Example #9
Source File: PassphraseDialogFragment.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    recordPassphraseDialogDismissal(PASSPHRASE_DIALOG_RESET_LINK);
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #10
Source File: PassphraseTypeDialogFragment.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_encryption_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #11
Source File: PhysicalWebOptInActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
private SpannableString getDescriptionText() {
    return SpanApplier.applySpans(
            getString(R.string.physical_web_optin_description),
            new SpanInfo("<learnmore>", "</learnmore>", new ClickableSpan() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse(PHYSICAL_WEB_LEARN_MORE_URL));
                    // Add the SESSION extra to indicate we want a Chrome custom tab. This
                    // allows the help page to open in the same task as the opt-in activity so
                    // they can share a back stack.
                    String session = null;
                    intent.putExtra(EXTRA_CUSTOM_TABS_SESSION, session);
                    PhysicalWebOptInActivity.this.startActivity(intent);
                }

                @Override
                public void updateDrawState(TextPaint ds) {
                    // Color links but do not underline them.
                    ds.setColor(ds.linkColor);
                }
            }));
}
 
Example #12
Source File: Footer.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
public ViewHolder(ViewGroup root, final NewTabPageManager manager) {
    super(LayoutInflater.from(root.getContext())
                    .inflate(R.layout.new_tab_page_footer, root, false));

    NoUnderlineClickableSpan link = new NoUnderlineClickableSpan() {
        @Override
        public void onClick(View view) {
            // TODO(mvanouwerkerk): Ensure this can be activated when using TalkBack.
            manager.onLearnMoreClicked();
        }
    };

    TextView textView = (TextView) itemView.findViewById(R.id.text);
    textView.setText(SpanApplier.applySpans(
            root.getResources().getString(R.string.ntp_learn_more_about_suggested_content),
            new SpanApplier.SpanInfo("<link>", "</link>", link)));
    textView.setMovementMethod(LinkMovementMethod.getInstance());
}
 
Example #13
Source File: AccountSigninView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void showConfirmSigninPage() {
    mSignedIn = true;

    updateSignedInAccountInfo();

    mSigninChooseView.setVisibility(View.GONE);
    mSigninConfirmationView.setVisibility(View.VISIBLE);

    setButtonsEnabled(true);
    setUpConfirmButton();
    setUpUndoButton();

    NoUnderlineClickableSpan settingsSpan = new NoUnderlineClickableSpan() {
        @Override
        public void onClick(View widget) {
            mListener.onAccountSelected(getSelectedAccountName(), true);
            RecordUserAction.record("Signin_Signin_WithAdvancedSyncSettings");
        }
    };
    mSigninSettingsControl.setText(
            SpanApplier.applySpans(getSettingsControlDescription(mIsChildAccount),
                    new SpanInfo(SETTINGS_LINK_OPEN, SETTINGS_LINK_CLOSE, settingsSpan)));
}
 
Example #14
Source File: PhysicalWebOptInActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private SpannableString getDescriptionText() {
    return SpanApplier.applySpans(
            getString(R.string.physical_web_optin_description),
            new SpanInfo("<learnmore>", "</learnmore>", new ClickableSpan() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse(PHYSICAL_WEB_LEARN_MORE_URL));
                    // Add the SESSION extra to indicate we want a Chrome custom tab. This
                    // allows the help page to open in the same task as the opt-in activity so
                    // they can share a back stack.
                    String session = null;
                    intent.putExtra(EXTRA_CUSTOM_TABS_SESSION, session);
                    PhysicalWebOptInActivity.this.startActivity(intent);
                }

                @Override
                public void updateDrawState(TextPaint ds) {
                    // Color links but do not underline them.
                    ds.setColor(ds.linkColor);
                }
            }));
}
 
Example #15
Source File: AccountSigninView.java    From delion with Apache License 2.0 6 votes vote down vote up
private void showConfirmSigninPage() {
    mSignedIn = true;

    updateSignedInAccountInfo();

    mSigninChooseView.setVisibility(View.GONE);
    mSigninConfirmationView.setVisibility(View.VISIBLE);

    setButtonsEnabled(true);
    setUpConfirmButton();
    setPositiveButtonDisabled();
    setUpUndoButton();

    NoUnderlineClickableSpan settingsSpan = new NoUnderlineClickableSpan() {
        @Override
        public void onClick(View widget) {
            mListener.onAccountSelected(getSelectedAccountName(), true);
        }
    };
    mSigninSettingsControl.setText(
            SpanApplier.applySpans(getSettingsControlDescription(mIsChildAccount),
                    new SpanInfo(SETTINGS_LINK_OPEN, SETTINGS_LINK_CLOSE, settingsSpan)));
}
 
Example #16
Source File: TextMessageWithLinkAndIconPreference.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void setSummary(CharSequence summary) {
    // If there is no link in the summary, invoke the default behavior.
    String summaryString = summary.toString();
    if (!summaryString.contains("<link>") || !summaryString.contains("</link>")) {
        super.setSummary(summary);
        return;
    }

    // Linkify <link></link> span.
    final SpannableString summaryWithLink = SpanApplier.applySpans(summaryString,
            new SpanApplier.SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
                @Override
                public void onClick(View widget) {
                    if (mLinkClickDelegate != null) mLinkClickDelegate.run();
                }
            }));

    super.setSummary(summaryWithLink);
}
 
Example #17
Source File: PassphraseTypeDialogFragment.java    From delion with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_encryption_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #18
Source File: PassphraseDialogFragment.java    From delion with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    recordPassphraseDialogDismissal(PASSPHRASE_DIALOG_RESET_LINK);
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #19
Source File: PassphraseCreationDialogFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
private SpannableString getInstructionsText() {
    final Activity activity = getActivity();
    return SpanApplier.applySpans(
            activity.getString(R.string.sync_custom_passphrase),
            new SpanInfo("<learnmore>", "</learnmore>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    HelpAndFeedback.getInstance(activity).show(activity,
                            activity.getString(R.string.help_context_change_sync_passphrase),
                            Profile.getLastUsedProfile(), null);
                }
            }));
}
 
Example #20
Source File: GeolocationSnackbarController.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the geolocation snackbar if it hasn't already been shown and the geolocation snackbar
 * is currently relevant: i.e. the default search engine is Google, location is enabled
 * for Chrome, the tab is not incognito, etc.
 *
 * @param snackbarManager The SnackbarManager used to show the snackbar.
 * @param view Any view that's attached to the view hierarchy.
 * @param isIncognito Whether the currently visible tab is incognito.
 * @param delayMs The delay in ms before the snackbar should be shown. This is intended to
 *                give the keyboard time to animate in.
 */
public static void maybeShowSnackbar(final SnackbarManager snackbarManager, View view,
        boolean isIncognito, int delayMs) {
    final Context context = view.getContext();
    if (getGeolocationSnackbarShown(context)) return;

    // If in incognito mode, don't show the snackbar now, but maybe show it later.
    if (isIncognito) return;

    if (neverShowSnackbar(context)) {
        setGeolocationSnackbarShown(context);
        return;
    }

    Uri searchUri = Uri.parse(TemplateUrlService.getInstance().getUrlForSearchQuery("foo"));
    TypefaceSpan robotoMediumSpan = new TypefaceSpan("sans-serif-medium");
    String messageWithoutSpans = context.getResources().getString(
            R.string.omnibox_geolocation_disclosure, "<b>" + searchUri.getHost() + "</b>");
    SpannableString message = SpanApplier.applySpans(messageWithoutSpans,
            new SpanInfo("<b>", "</b>", robotoMediumSpan));
    String settings = context.getResources().getString(R.string.preferences);
    int durationMs = DeviceClassManager.isAccessibilityModeEnabled(view.getContext())
            ? ACCESSIBILITY_SNACKBAR_DURATION_MS : SNACKBAR_DURATION_MS;
    final GeolocationSnackbarController controller = new GeolocationSnackbarController();
    final Snackbar snackbar = Snackbar
            .make(message, controller, Snackbar.TYPE_ACTION, Snackbar.UMA_OMNIBOX_GEOLOCATION)
            .setAction(settings, view)
            .setSingleLine(false)
            .setDuration(durationMs);

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            snackbarManager.dismissSnackbars(controller);
            snackbarManager.showSnackbar(snackbar);
            setGeolocationSnackbarShown(context);
        }
    }, delayMs);
}
 
Example #21
Source File: IncognitoNewTabPageViewMD.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @param element Resource ID of the element to be populated with the bulletpoints.
 * @param content String ID to serve as the text of |element|. Must contain an <em></em> span,
 *         which will be emphasized, and three <li> items, which will be converted to
 *         bulletpoints.
 * Populates |element| with |content|.
 */
private void populateBulletpoints(@IdRes int element, @StringRes int content) {
    TextView view = (TextView) findViewById(element);
    String text = mContext.getResources().getString(content);

    // TODO(msramek): Unfortunately, our strings are missing the closing "</li>" tag, which
    // is not a problem when they're used in the Desktop WebUI (omitting the tag is valid in
    // HTML5), but it is a problem for SpanApplier. Update the strings and remove this regex.
    // Note that modifying the strings is a non-trivial operation as they went through a special
    // translation process.
    text = text.replaceAll("<li>([^<]+)\n", "<li>$1</li>\n");

    // Disambiguate the <li><li> spans for SpanApplier.
    text = text.replaceFirst("<li>(.*)</li>", "<li1>$1</li1>");
    text = text.replaceFirst("<li>(.*)</li>", "<li2>$1</li2>");
    text = text.replaceFirst("<li>(.*)</li>", "<li3>$1</li3>");

    // Remove the <ul></ul> tags which serve no purpose here.
    text = text.replaceAll("</?ul>", "");

    view.setText(SpanApplier.applySpans(text,
            new SpanApplier.SpanInfo("<em>", "</em>",
                    new ForegroundColorSpan(ApiCompatibilityUtils.getColor(
                            mContext.getResources(), R.color.incognito_emphasis))),
            new SpanApplier.SpanInfo("<li1>", "</li1>", new BulletSpan()),
            new SpanApplier.SpanInfo("<li2>", "</li2>", new BulletSpan()),
            new SpanApplier.SpanInfo("<li3>", "</li3>", new BulletSpan())));
}
 
Example #22
Source File: AccountSigninView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void showConfirmSigninPage() {
    mSignedIn = true;

    updateSignedInAccountInfo();

    mSigninChooseView.setVisibility(View.GONE);
    mSigninConfirmationView.setVisibility(View.VISIBLE);

    setButtonsEnabled(true);
    setUpConfirmButton();
    setUpUndoButton();

    NoUnderlineClickableSpan settingsSpan = new NoUnderlineClickableSpan() {
        @Override
        public void onClick(View widget) {
            mListener.onAccountSelected(
                    getSelectedAccountName(), isDefaultAccountSelected(), true);
            RecordUserAction.record("Signin_Signin_WithAdvancedSyncSettings");
        }
    };
    if (mIsChildAccount) {
        mSigninPersonalizeServiceDescription.setText(
                R.string.sync_confirmation_personalize_services_body_child_account);
    }
    mSigninSettingsControl.setText(
            SpanApplier.applySpans(getSettingsControlDescription(mIsChildAccount),
                    new SpanInfo(SETTINGS_LINK_OPEN, SETTINGS_LINK_CLOSE, settingsSpan)));
}
 
Example #23
Source File: GeolocationSnackbarController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the geolocation snackbar if it hasn't already been shown and the geolocation snackbar
 * is currently relevant: i.e. the default search engine is Google, location is enabled
 * for Chrome, the tab is not incognito, etc.
 *
 * @param snackbarManager The SnackbarManager used to show the snackbar.
 * @param view Any view that's attached to the view hierarchy.
 * @param isIncognito Whether the currently visible tab is incognito.
 * @param delayMs The delay in ms before the snackbar should be shown. This is intended to
 *                give the keyboard time to animate in.
 */
public static void maybeShowSnackbar(final SnackbarManager snackbarManager, View view,
        boolean isIncognito, int delayMs) {
    final Context context = view.getContext();
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) return;
    if (getGeolocationSnackbarShown(context)) return;

    // If in incognito mode, don't show the snackbar now, but maybe show it later.
    if (isIncognito) return;

    if (neverShowSnackbar(context)) {
        setGeolocationSnackbarShown(context);
        return;
    }

    Uri searchUri = Uri.parse(TemplateUrlService.getInstance().getUrlForSearchQuery("foo"));
    TypefaceSpan robotoMediumSpan = new TypefaceSpan("sans-serif-medium");
    String messageWithoutSpans = context.getResources().getString(
            R.string.omnibox_geolocation_disclosure, "<b>" + searchUri.getHost() + "</b>");
    SpannableString message = SpanApplier.applySpans(messageWithoutSpans,
            new SpanInfo("<b>", "</b>", robotoMediumSpan));
    String settings = context.getResources().getString(R.string.preferences);
    int durationMs = AccessibilityUtil.isAccessibilityEnabled()
            ? ACCESSIBILITY_SNACKBAR_DURATION_MS : SNACKBAR_DURATION_MS;
    final GeolocationSnackbarController controller = new GeolocationSnackbarController();
    final Snackbar snackbar = Snackbar
            .make(message, controller, Snackbar.TYPE_ACTION, Snackbar.UMA_OMNIBOX_GEOLOCATION)
            .setAction(settings, view)
            .setSingleLine(false)
            .setDuration(durationMs);

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            snackbarManager.dismissSnackbars(controller);
            snackbarManager.showSnackbar(snackbar);
            setGeolocationSnackbarShown(context);
        }
    }, delayMs);
}
 
Example #24
Source File: BluetoothChooserDialog.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
@CalledByNative
void notifyAdapterTurnedOff() {
    SpannableString adapterOffMessage = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_adapter_off),
            new SpanInfo("<link>", "</link>",
                    new BluetoothClickableSpan(LinkType.ADAPTER_OFF, mActivity)));

    mItemChooserDialog.setErrorState(adapterOffMessage, mAdapterOffStatus);
}
 
Example #25
Source File: BluetoothChooserDialog.java    From delion with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
@CalledByNative
void notifyAdapterTurnedOff() {
    SpannableString adapterOffMessage = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_adapter_off),
            new SpanInfo("<link>", "</link>",
                    new BluetoothClickableSpan(LinkType.ADAPTER_OFF, mActivity)));
    SpannableString adapterOffStatus = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_adapter_off_help),
            new SpanInfo("<link>", "</link>",
                    new BluetoothClickableSpan(LinkType.ADAPTER_OFF_HELP, mActivity)));

    mItemChooserDialog.setErrorState(adapterOffMessage, adapterOffStatus);
}
 
Example #26
Source File: OtherFormsOfHistoryDialogFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.other_forms_of_history_dialog, null);

    // Linkify the <link></link> span in the dialog text.
    TextView textView = (TextView) view.findViewById(R.id.text);
    final SpannableString textWithLink = SpanApplier.applySpans(
            textView.getText().toString(),
            new SpanApplier.SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
                @Override
                public void onClick(View widget) {
                    new TabDelegate(false /* incognito */).launchUrl(
                            WEB_HISTORY_URL, TabLaunchType.FROM_CHROME_UI);
                }
            }));

    textView.setText(textWithLink);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    // Construct the dialog.
    AlertDialog dialog = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
            .setView(view)
            .setTitle(R.string.clear_browsing_data_history_dialog_title)
            .setPositiveButton(
                    R.string.ok_got_it, this)
            .create();

    dialog.setCanceledOnTouchOutside(false);
    return dialog;
}
 
Example #27
Source File: SadTabViewFactory.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Construct and return help message to be displayed on R.id.sad_tab_message.
 * @param context Context of the resulting Sad Tab view. This is needed to load the strings.
 * @param suggestionAction Action to be executed when user clicks "try these suggestions".
 * @return Help message to be displayed on R.id.sad_tab_message.
 */
private static CharSequence getHelpMessage(
        Context context, final OnClickListener suggestionAction) {
    String helpMessage = context.getString(R.string.sad_tab_message)
            + "\n\n" + context.getString(R.string.sad_tab_suggestions);
    NoUnderlineClickableSpan span = new NoUnderlineClickableSpan() {
        @Override
        public void onClick(View view) {
            suggestionAction.onClick(view);
        }
    };
    return SpanApplier.applySpans(helpMessage, new SpanInfo("<link>", "</link>", span));
}
 
Example #28
Source File: PaymentRequestUI.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void addCardAndAddressOptionsSettingsView(LinearLayout parent) {
    String message;
    if (!mShowDataSource) {
        message = mContext.getString(R.string.payments_card_and_address_settings);
    } else if (ChromeSigninController.get().isSignedIn()) {
        message = mContext.getString(R.string.payments_card_and_address_settings_signed_in,
                ChromeSigninController.get().getSignedInAccountName());
    } else {
        message = mContext.getString(R.string.payments_card_and_address_settings_signed_out);
    }

    NoUnderlineClickableSpan settingsSpan = new NoUnderlineClickableSpan() {
        @Override
        public void onClick(View widget) {
            mClient.onCardAndAddressSettingsClicked();
        }
    };
    SpannableString spannableMessage = SpanApplier.applySpans(
            message, new SpanInfo("BEGIN_LINK", "END_LINK", settingsSpan));

    TextView view = new TextViewWithClickableSpans(mContext);
    view.setText(spannableMessage);
    view.setMovementMethod(LinkMovementMethod.getInstance());
    ApiCompatibilityUtils.setTextAppearance(view, R.style.PaymentsUiSectionDescriptiveText);

    // Add paddings instead of margin to let getMeasuredHeight return correct value for section
    // resize animation.
    int paddingSize = mContext.getResources().getDimensionPixelSize(
            R.dimen.payments_section_large_spacing);
    ApiCompatibilityUtils.setPaddingRelative(
            view, paddingSize, paddingSize, paddingSize, paddingSize);
    parent.addView(view);
}
 
Example #29
Source File: PassphraseCreationDialogFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private SpannableString getInstructionsText() {
    final Activity activity = getActivity();
    return SpanApplier.applySpans(
            activity.getString(R.string.sync_custom_passphrase),
            new SpanInfo("<learnmore>", "</learnmore>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    HelpAndFeedback.getInstance(activity).show(activity,
                            activity.getString(R.string.help_context_change_sync_passphrase),
                            Profile.getLastUsedProfile(), null);
                }
            }));
}
 
Example #30
Source File: PassphraseCreationDialogFragment.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private SpannableString getInstructionsText() {
    final Activity activity = getActivity();
    return SpanApplier.applySpans(
            activity.getString(R.string.sync_custom_passphrase),
            new SpanInfo("<learnmore>", "</learnmore>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    HelpAndFeedback.getInstance(activity).show(activity,
                            activity.getString(R.string.help_context_change_sync_passphrase),
                            Profile.getLastUsedProfile(), null);
                }
            }));
}