Search in sources :

Example 11 with SpanInfo

use of org.chromium.ui.text.SpanApplier.SpanInfo in project AndroidChromium by JackyAndroid.

the class GeolocationSnackbarController method maybeShowSnackbar.

/**
     * 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);
}
Also used : Context(android.content.Context) SpannableString(android.text.SpannableString) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) SpannableString(android.text.SpannableString) Uri(android.net.Uri) TypefaceSpan(android.text.style.TypefaceSpan) Snackbar(org.chromium.chrome.browser.snackbar.Snackbar)

Example 12 with SpanInfo

use of org.chromium.ui.text.SpanApplier.SpanInfo in project AndroidChromium by JackyAndroid.

the class SiteSettingsCategory method configurePermissionIsOffPreferences.

/**
     * Configure a preference to show when when the Android permission for this category is
     * disabled.
     * @param osWarning A preference to hold the first permission warning. After calling this
     *                  method, if osWarning has no title, the preference should not be added to the
     *                  preference screen.
     * @param osWarningExtra A preference to hold any additional permission warning (if any). After
     *                       calling this method, if osWarningExtra has no title, the preference
     *                       should not be added to the preference screen.
     * @param activity The current activity.
     * @param category The category associated with the warnings.
     * @param specificCategory Whether the warnings refer to a single category or is an aggregate
     *                         for many permissions.
     */
public void configurePermissionIsOffPreferences(Preference osWarning, Preference osWarningExtra, Activity activity, boolean specificCategory) {
    Intent perAppIntent = getIntentToEnableOsPerAppPermission(activity);
    Intent globalIntent = getIntentToEnableOsGlobalPermission(activity);
    String perAppMessage = getMessageForEnablingOsPerAppPermission(activity, !specificCategory);
    String globalMessage = getMessageForEnablingOsGlobalPermission(activity);
    Resources resources = activity.getResources();
    int color = ApiCompatibilityUtils.getColor(resources, R.color.pref_accent_color);
    ForegroundColorSpan linkSpan = new ForegroundColorSpan(color);
    if (perAppIntent != null) {
        SpannableString messageWithLink = SpanApplier.applySpans(perAppMessage, new SpanInfo("<link>", "</link>", linkSpan));
        osWarning.setTitle(messageWithLink);
        osWarning.setIntent(perAppIntent);
        if (!specificCategory) {
            osWarning.setIcon(getDisabledInAndroidIcon(activity));
        }
    }
    if (globalIntent != null) {
        SpannableString messageWithLink = SpanApplier.applySpans(globalMessage, new SpanInfo("<link>", "</link>", linkSpan));
        osWarningExtra.setTitle(messageWithLink);
        osWarningExtra.setIntent(globalIntent);
        if (!specificCategory) {
            if (perAppIntent == null) {
                osWarningExtra.setIcon(getDisabledInAndroidIcon(activity));
            } else {
                Drawable transparent = new ColorDrawable(Color.TRANSPARENT);
                osWarningExtra.setIcon(transparent);
            }
        }
    }
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) SpannableString(android.text.SpannableString) Resources(android.content.res.Resources)

Example 13 with SpanInfo

use of org.chromium.ui.text.SpanApplier.SpanInfo in project AndroidChromium by JackyAndroid.

the class PassphraseDialogFragment method getResetText.

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);
        }
    }));
}
Also used : Context(android.content.Context) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri)

Example 14 with SpanInfo

use of org.chromium.ui.text.SpanApplier.SpanInfo in project AndroidChromium by JackyAndroid.

the class PassphraseTypeDialogFragment method getResetText.

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);
        }
    }));
}
Also used : Context(android.content.Context) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CheckedTextView(android.widget.CheckedTextView) ListView(android.widget.ListView) Uri(android.net.Uri)

Example 15 with SpanInfo

use of org.chromium.ui.text.SpanApplier.SpanInfo in project AndroidChromium by JackyAndroid.

the class SadTabViewFactory method getHelpMessage.

/**
     * 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));
}
Also used : NoUnderlineClickableSpan(org.chromium.ui.text.NoUnderlineClickableSpan) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) TextView(android.widget.TextView) View(android.view.View)

Aggregations

SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)15 View (android.view.View)10 SpannableString (android.text.SpannableString)9 TextView (android.widget.TextView)9 NoUnderlineClickableSpan (org.chromium.ui.text.NoUnderlineClickableSpan)5 Intent (android.content.Intent)4 Context (android.content.Context)3 Uri (android.net.Uri)3 ClickableSpan (android.text.style.ClickableSpan)3 VisibleForTesting (org.chromium.base.VisibleForTesting)3 Resources (android.content.res.Resources)2 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)2 ForegroundColorSpan (android.text.style.ForegroundColorSpan)2 OnClickListener (android.view.View.OnClickListener)2 Profile (org.chromium.chrome.browser.profiles.Profile)2 IntentFilter (android.content.IntentFilter)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 TextPaint (android.text.TextPaint)1 TypefaceSpan (android.text.style.TypefaceSpan)1