org.chromium.ui.text.SpanApplier.SpanInfo Java Examples

The following examples show how to use org.chromium.ui.text.SpanApplier.SpanInfo. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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);
                }
            }));
}
 
Example #16
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 #17
Source File: SadTabViewFactory.java    From AndroidChromium 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 #18
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 #19
Source File: GeolocationSnackbarController.java    From AndroidChromium 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 = 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 #20
Source File: BluetoothChooserDialog.java    From AndroidChromium 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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
Source File: UsbChooserDialog.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Shows the UsbChooserDialog.
 *
 * @param activity Activity which is used for launching a dialog.
 * @param origin The origin for the site wanting to connect to the USB device.
 * @param securityLevel The security level of the connection to the site wanting to connect to
 *                      the USB device. For valid values see SecurityStateModel::SecurityLevel.
 */
@VisibleForTesting
void show(Activity activity, String origin, int securityLevel) {
    // Emphasize the origin.
    Profile profile = Profile.getLastUsedProfile();
    SpannableString originSpannableString = new SpannableString(origin);
    OmniboxUrlEmphasizer.emphasizeUrl(originSpannableString, activity.getResources(), profile,
            securityLevel, false /* isInternalPage */, true /* useDarkColors */,
            true /* emphasizeHttpsScheme */);
    // Construct a full string and replace the origin text with emphasized version.
    SpannableString title =
            new SpannableString(activity.getString(R.string.usb_chooser_dialog_prompt, origin));
    int start = title.toString().indexOf(origin);
    TextUtils.copySpansFrom(originSpannableString, 0, originSpannableString.length(),
            Object.class, title, start);

    String searching = "";
    String noneFound = activity.getString(R.string.usb_chooser_dialog_no_devices_found_prompt);
    SpannableString statusActive =
            SpanApplier.applySpans(
                    activity.getString(R.string.usb_chooser_dialog_footnote_text),
                    new SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
                        @Override
                        public void onClick(View view) {
                            if (mNativeUsbChooserDialogPtr == 0) {
                                return;
                            }

                            nativeLoadUsbHelpPage(mNativeUsbChooserDialogPtr);

                            // Get rid of the highlight background on selection.
                            view.invalidate();
                        }
                    }));
    SpannableString statusIdleNoneFound = statusActive;
    SpannableString statusIdleSomeFound = statusActive;
    String positiveButton = activity.getString(R.string.usb_chooser_dialog_connect_button_text);

    ItemChooserDialog.ItemChooserLabels labels =
            new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive,
                    statusIdleNoneFound, statusIdleSomeFound, positiveButton);
    mItemChooserDialog = new ItemChooserDialog(activity, this, labels);
}
 
Example #27
Source File: UsbChooserDialog.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Shows the UsbChooserDialog.
 *
 * @param activity Activity which is used for launching a dialog.
 * @param origin The origin for the site wanting to connect to the USB device.
 * @param securityLevel The security level of the connection to the site wanting to connect to
 *                      the USB device. For valid values see SecurityStateModel::SecurityLevel.
 */
@VisibleForTesting
void show(Activity activity, String origin, int securityLevel) {
    // Emphasize the origin.
    Profile profile = Profile.getLastUsedProfile();
    SpannableString originSpannableString = new SpannableString(origin);
    OmniboxUrlEmphasizer.emphasizeUrl(originSpannableString, activity.getResources(), profile,
            securityLevel, false /* isInternalPage */, true /* useDarkColors */,
            true /* emphasizeHttpsScheme */);
    // Construct a full string and replace the origin text with emphasized version.
    SpannableString title =
            new SpannableString(activity.getString(R.string.usb_chooser_dialog_prompt, origin));
    int start = title.toString().indexOf(origin);
    TextUtils.copySpansFrom(originSpannableString, 0, originSpannableString.length(),
            Object.class, title, start);

    String searching = "";
    String noneFound = activity.getString(R.string.usb_chooser_dialog_no_devices_found_prompt);
    SpannableString statusActive =
            SpanApplier.applySpans(
                    activity.getString(R.string.usb_chooser_dialog_footnote_text),
                    new SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
                        @Override
                        public void onClick(View view) {
                            if (mNativeUsbChooserDialogPtr == 0) {
                                return;
                            }

                            nativeLoadUsbHelpPage(mNativeUsbChooserDialogPtr);

                            // Get rid of the highlight background on selection.
                            view.invalidate();
                        }
                    }));
    SpannableString statusIdleNoneFound = statusActive;
    SpannableString statusIdleSomeFound = statusActive;
    String positiveButton = activity.getString(R.string.usb_chooser_dialog_connect_button_text);

    ItemChooserDialog.ItemChooserLabels labels =
            new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive,
                    statusIdleNoneFound, statusIdleSomeFound, positiveButton);
    mItemChooserDialog = new ItemChooserDialog(activity, this, labels);
}
 
Example #28
Source File: BluetoothChooserDialog.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private boolean checkLocationServicesAndPermission() {
    final boolean havePermission = LocationUtils.getInstance().hasAndroidLocationPermission();
    final boolean locationServicesOn =
            LocationUtils.getInstance().isSystemLocationSettingEnabled();

    if (!havePermission
            && !mWindowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // Immediately close the dialog because the user has asked Chrome not to request the
        // location permission.
        finishDialog(DIALOG_FINISHED_DENIED_PERMISSION, "");
        return false;
    }

    // Compute the message to show the user.
    final SpanInfo permissionSpan = new SpanInfo("<permission_link>", "</permission_link>",
            new BluetoothClickableSpan(LinkType.REQUEST_LOCATION_PERMISSION, mActivity));
    final SpanInfo servicesSpan = new SpanInfo("<services_link>", "</services_link>",
            new BluetoothClickableSpan(LinkType.REQUEST_LOCATION_SERVICES, mActivity));
    final SpannableString needLocationMessage;
    if (havePermission) {
        if (locationServicesOn) {
            // We don't need to request anything.
            return true;
        } else {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(R.string.bluetooth_need_location_services_on),
                    servicesSpan);
        }
    } else {
        if (locationServicesOn) {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(R.string.bluetooth_need_location_permission),
                    permissionSpan);
        } else {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(
                            R.string.bluetooth_need_location_permission_and_services_on),
                    permissionSpan, servicesSpan);
        }
    }

    SpannableString needLocationStatus = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_need_location_permission_help),
            new SpanInfo("<link>", "</link>",
                    new BluetoothClickableSpan(
                                 LinkType.NEED_LOCATION_PERMISSION_HELP, mActivity)));

    mItemChooserDialog.setErrorState(needLocationMessage, needLocationStatus);
    return false;
}
 
Example #29
Source File: BluetoothChooserDialog.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Show the BluetoothChooserDialog.
 */
@VisibleForTesting
void show() {
    // Emphasize the origin.
    Profile profile = Profile.getLastUsedProfile();
    SpannableString origin = new SpannableString(mOrigin);
    OmniboxUrlEmphasizer.emphasizeUrl(
            origin, mActivity.getResources(), profile, mSecurityLevel, false, true, true);
    // Construct a full string and replace the origin text with emphasized version.
    SpannableString title =
            new SpannableString(mActivity.getString(R.string.bluetooth_dialog_title, mOrigin));
    int start = title.toString().indexOf(mOrigin);
    TextUtils.copySpansFrom(origin, 0, origin.length(), Object.class, title, start);

    String noneFound = mActivity.getString(R.string.bluetooth_not_found);

    SpannableString searching = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_searching),
            new SpanInfo("<link>", "</link>",
                    new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)));

    String positiveButton = mActivity.getString(R.string.bluetooth_confirm_button);

    SpannableString statusIdleNoneFound =
            SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_not_seeing_it_idle),
                    new SpanInfo("<link1>", "</link1>",
                            new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)),
                    new SpanInfo("<link2>", "</link2>",
                            new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mActivity)));

    SpannableString statusActive = searching;

    SpannableString statusIdleSomeFound = statusIdleNoneFound;

    ItemChooserDialog.ItemChooserLabels labels =
            new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive,
                    statusIdleNoneFound, statusIdleSomeFound, positiveButton);
    mItemChooserDialog = new ItemChooserDialog(mActivity, this, labels);

    mActivity.registerReceiver(mLocationModeBroadcastReceiver,
            new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
    mIsLocationModeChangedReceiverRegistered = true;
}
 
Example #30
Source File: BluetoothChooserDialog.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private boolean checkLocationServicesAndPermission() {
    final boolean havePermission = LocationUtils.getInstance().hasAndroidLocationPermission();
    final boolean locationServicesOn =
            LocationUtils.getInstance().isSystemLocationSettingEnabled();

    if (!havePermission
            && !mWindowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // Immediately close the dialog because the user has asked Chrome not to request the
        // location permission.
        finishDialog(DIALOG_FINISHED_DENIED_PERMISSION, "");
        return false;
    }

    // Compute the message to show the user.
    final SpanInfo permissionSpan = new SpanInfo("<permission_link>", "</permission_link>",
            new BluetoothClickableSpan(LinkType.REQUEST_LOCATION_PERMISSION, mActivity));
    final SpanInfo servicesSpan = new SpanInfo("<services_link>", "</services_link>",
            new BluetoothClickableSpan(LinkType.REQUEST_LOCATION_SERVICES, mActivity));
    final SpannableString needLocationMessage;
    if (havePermission) {
        if (locationServicesOn) {
            // We don't need to request anything.
            return true;
        } else {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(R.string.bluetooth_need_location_services_on),
                    servicesSpan);
        }
    } else {
        if (locationServicesOn) {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(R.string.bluetooth_need_location_permission),
                    permissionSpan);
        } else {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(
                            R.string.bluetooth_need_location_permission_and_services_on),
                    permissionSpan, servicesSpan);
        }
    }

    SpannableString needLocationStatus = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_need_location_permission_help),
            new SpanInfo("<link>", "</link>",
                    new BluetoothClickableSpan(
                                 LinkType.NEED_LOCATION_PERMISSION_HELP, mActivity)));

    mItemChooserDialog.setErrorState(needLocationMessage, needLocationStatus);
    return false;
}