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);
}
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);
}
}
}
}
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);
}
}));
}
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);
}
}));
}
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));
}
Aggregations