use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.
the class ChromeMediaRouter method sendStringMessage.
/**
* Sends a string message to the specified route.
* @param routeId The id of the route to send the message to.
* @param message The message to send.
* @param callbackId The id of the result callback tracked by the native side.
*/
@CalledByNative
public void sendStringMessage(String routeId, String message, int callbackId) {
MediaRouteProvider provider = mRouteIdsToProviders.get(routeId);
if (provider == null) {
nativeOnMessageSentResult(mNativeMediaRouterAndroid, false, callbackId);
return;
}
provider.sendStringMessage(routeId, message, callbackId);
}
use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.
the class ChromeMediaRouterDialogController method openRouteControllerDialog.
/**
* Shows the {@link MediaRouteControllerDialogFragment} if it's not shown yet.
* @param sourceUrn the URN identifying the media source of the current media route.
* @param mediaRouteId the identifier of the route to be controlled.
*/
@CalledByNative
public void openRouteControllerDialog(String sourceUrn, String mediaRouteId) {
if (isShowingDialog())
return;
MediaSource source = MediaSource.from(sourceUrn);
if (source == null)
return;
mDialogManager = new MediaRouteControllerDialogManager(source, mediaRouteId, mApplicationContext, this);
mDialogManager.openDialog();
}
use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.
the class AppBannerInfoBarDelegateAndroid method determineInstallState.
@CalledByNative
private int determineInstallState(AppData data) {
if (mInstallTask != null || mIsInstallingWebApk) {
return AppBannerInfoBarAndroid.INSTALL_STATE_INSTALLING;
}
PackageManager pm = getPackageManager(ContextUtils.getApplicationContext());
String packageName = (data != null) ? data.packageName() : mWebApkPackage;
boolean isInstalled = InstallerDelegate.isInstalled(pm, packageName);
return isInstalled ? AppBannerInfoBarAndroid.INSTALL_STATE_INSTALLED : AppBannerInfoBarAndroid.INSTALL_STATE_NOT_INSTALLED;
}
use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.
the class DataReductionPromoInfoBarDelegate method accept.
/**
* Enables the data reduction proxy, records uma, and shows a confirmation toast.
*
* @param isPrimaryButton Whether the primary infobar button was clicked.
* @param context An Android context.
*/
@CalledByNative
private static void accept() {
Context context = ContextUtils.getApplicationContext();
DataReductionProxyUma.dataReductionProxyUIAction(DataReductionProxyUma.ACTION_INFOBAR_ENABLED);
DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(context, true);
Toast.makeText(context, context.getString(R.string.data_reduction_enabled_toast), Toast.LENGTH_LONG).show();
}
use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.
the class NotificationPlatformBridge method displayNotification.
/**
* Displays a notification with the given details.
*
* TODO(crbug.com/650302): Combine the 'action*' parameters into a single array of objects.
* @param notificationId The id of the notification.
* @param origin Full text of the origin, including the protocol, owning this notification.
* @param profileId Id of the profile that showed the notification.
* @param incognito if the session of the profile is an off the record one.
* @param tag A string identifier for this notification. If the tag is not empty, the new
* notification will replace the previous notification with the same tag and origin,
* if present. If no matching previous notification is present, the new one will just
* be added.
* @param webApkPackage The package of the WebAPK associated with the notification. Empty if
* the notification is not associated with a WebAPK.
* @param title Title to be displayed in the notification.
* @param body Message to be displayed in the notification. Will be trimmed to one line of
* text by the Android notification system.
* @param image Content image to be prominently displayed when the notification is expanded.
* @param icon Icon to be displayed in the notification. Valid Bitmap icons will be scaled to
* the platforms, whereas a default icon will be generated for invalid Bitmaps.
* @param badge An image to represent the notification in the status bar. It is also displayed
* inside the notification.
* @param vibrationPattern Vibration pattern following the Web Vibration syntax.
* @param timestamp The timestamp of the event for which the notification is being shown.
* @param renotify Whether the sound, vibration, and lights should be replayed if the
* notification is replacing another notification.
* @param silent Whether the default sound, vibration and lights should be suppressed.
* @param actionTitles Titles of actions to display alongside the notification.
* @param actionIcons Icons of actions to display alongside the notification.
* @param actionTypes Types of actions to display alongside the notification.
* @param actionPlaceholders Placeholders of actions to display alongside the notification.
* @see https://developer.android.com/reference/android/app/Notification.html
*/
@CalledByNative
private void displayNotification(String notificationId, String origin, String profileId, boolean incognito, String tag, String webApkPackage, String title, String body, Bitmap image, Bitmap icon, Bitmap badge, int[] vibrationPattern, long timestamp, boolean renotify, boolean silent, String[] actionTitles, Bitmap[] actionIcons, String[] actionTypes, String[] actionPlaceholders) {
if (actionTitles.length != actionIcons.length) {
throw new IllegalArgumentException("The number of action titles and icons must match.");
}
Resources res = mAppContext.getResources();
// Record whether it's known whether notifications can be shown to the user at all.
RecordHistogram.recordEnumeratedHistogram("Notifications.AppNotificationStatus", NotificationSystemStatusUtil.determineAppNotificationStatus(mAppContext), NotificationSystemStatusUtil.APP_NOTIFICATIONS_STATUS_BOUNDARY);
// Set up a pending intent for going to the settings screen for |origin|.
Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(mAppContext, SingleWebsitePreferences.class.getName());
settingsIntent.setData(makeIntentData(notificationId, origin, -1));
settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, SingleWebsitePreferences.createFragmentArgsForSite(origin));
PendingIntent pendingSettingsIntent = PendingIntent.getActivity(mAppContext, PENDING_INTENT_REQUEST_CODE, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent clickIntent = makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFICATION, notificationId, origin, profileId, incognito, tag, webApkPackage, -1);
PendingIntent closeIntent = makePendingIntent(NotificationConstants.ACTION_CLOSE_NOTIFICATION, notificationId, origin, profileId, incognito, tag, webApkPackage, -1);
boolean hasImage = image != null;
NotificationBuilderBase notificationBuilder = createNotificationBuilder(hasImage).setTitle(title).setBody(body).setImage(image).setLargeIcon(icon).setSmallIcon(R.drawable.ic_chrome).setSmallIcon(badge).setContentIntent(clickIntent).setDeleteIntent(closeIntent).setTicker(createTickerText(title, body)).setTimestamp(timestamp).setRenotify(renotify).setOrigin(UrlFormatter.formatUrlForSecurityDisplay(origin, false));
for (int actionIndex = 0; actionIndex < actionTitles.length; actionIndex++) {
PendingIntent intent = makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFICATION, notificationId, origin, profileId, incognito, tag, webApkPackage, actionIndex);
// Don't show action button icons when there's an image, as then action buttons go on
// the same row as the Site Settings button, so icons wouldn't leave room for text.
Bitmap actionIcon = hasImage ? null : actionIcons[actionIndex];
// TODO(crbug.com/650302): Encode actionTypes with an enum, not a magic string!
if (actionTypes[actionIndex].equals("text")) {
notificationBuilder.addTextAction(actionIcon, actionTitles[actionIndex], intent, actionPlaceholders[actionIndex]);
} else {
notificationBuilder.addButtonAction(actionIcon, actionTitles[actionIndex], intent);
}
}
// If action buttons are displayed, there isn't room for the full Site Settings button
// label and icon, so abbreviate it. This has the unfortunate side-effect of unnecessarily
// abbreviating it on Android Wear also (crbug.com/576656). If custom layouts are enabled,
// the label and icon provided here only affect Android Wear, so don't abbreviate them.
boolean abbreviateSiteSettings = actionTitles.length > 0 && !useCustomLayouts(hasImage);
int settingsIconId = abbreviateSiteSettings ? 0 : R.drawable.settings_cog;
CharSequence settingsTitle = abbreviateSiteSettings ? res.getString(R.string.notification_site_settings_button) : res.getString(R.string.page_info_site_settings_button);
// If the settings button is displayed together with the other buttons it has to be the last
// one, so add it after the other actions.
notificationBuilder.addSettingsAction(settingsIconId, settingsTitle, pendingSettingsIntent);
// The Android framework applies a fallback vibration pattern for the sound when the device
// is in vibrate mode, there is no custom pattern, and the vibration default has been
// disabled. To truly prevent vibration, provide a custom empty pattern.
boolean vibrateEnabled = PrefServiceBridge.getInstance().isNotificationsVibrateEnabled();
if (!vibrateEnabled) {
vibrationPattern = EMPTY_VIBRATION_PATTERN;
}
notificationBuilder.setDefaults(makeDefaults(vibrationPattern.length, silent, vibrateEnabled));
notificationBuilder.setVibrate(makeVibrationPattern(vibrationPattern));
String platformTag = makePlatformTag(notificationId, origin, tag);
if (webApkPackage.isEmpty()) {
mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilder.build());
} else {
WebApkNotificationClient.notifyNotification(webApkPackage, notificationBuilder, platformTag, PLATFORM_ID);
}
}
Aggregations