This source file includes following definitions.
- setFullScreenAction
- addShortcut
- SuppressWarnings
- addShortcut
- nativeAddShortcut
package org.chromium.chrome.browser;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import org.chromium.base.CalledByNative;
import java.util.UUID;
public class ShortcutHelper {
public static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_id";
public static final String EXTRA_MAC = "org.chromium.chrome.browser.webapp_mac";
public static final String EXTRA_URL = "org.chromium.chrome.browser.webapp_url";
private static String sFullScreenAction;
public static void setFullScreenAction(String fullScreenAction) {
sFullScreenAction = fullScreenAction;
}
public static void addShortcut(Context appContext, Tab tab, String userRequestedTitle) {
if (TextUtils.isEmpty(sFullScreenAction)) {
Log.e("ShortcutHelper", "ShortcutHelper is uninitialized. Aborting.");
return;
}
ActivityManager am = (ActivityManager) appContext.getSystemService(
Context.ACTIVITY_SERVICE);
nativeAddShortcut(tab.getNativePtr(), userRequestedTitle, am.getLauncherLargeIconSize());
}
@SuppressWarnings("unused")
@CalledByNative
private static void addShortcut(Context context, String url, String title, Bitmap favicon,
int red, int green, int blue, boolean isWebappCapable) {
assert sFullScreenAction != null;
Intent shortcutIntent = null;
if (isWebappCapable) {
shortcutIntent = new Intent();
shortcutIntent.setAction(sFullScreenAction);
shortcutIntent.putExtra(EXTRA_URL, url);
shortcutIntent.putExtra(EXTRA_ID, UUID.randomUUID().toString());
byte[] mac = WebappAuthenticator.getMacForUrl(context, url);
String encodedMac = Base64.encodeToString(mac, Base64.DEFAULT);
shortcutIntent.putExtra(EXTRA_MAC, encodedMac);
} else {
shortcutIntent = BookmarkUtils.createShortcutIntent(context, url);
}
shortcutIntent.setPackage(context.getPackageName());
context.sendBroadcast(BookmarkUtils.createAddToHomeIntent(context, shortcutIntent, title,
favicon, red, green, blue));
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(homeIntent);
}
private static native void nativeAddShortcut(long tabAndroidPtr, String userRequestedTitle,
int launcherLargeIconSize);
}