Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java

Issue 1310223002: webapps: initial addition of splash screen icon downloading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webapps-database-exp
Patch Set: Fix review comments and update code as discussed Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser; 5 package org.chromium.chrome.browser;
6 6
7 import android.app.ActivityManager; 7 import android.app.ActivityManager;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.content.pm.PackageManager; 10 import android.content.pm.PackageManager;
(...skipping 15 matching lines...) Expand all
26 import android.util.Base64; 26 import android.util.Base64;
27 import android.util.DisplayMetrics; 27 import android.util.DisplayMetrics;
28 import android.util.TypedValue; 28 import android.util.TypedValue;
29 29
30 import org.chromium.base.ApiCompatibilityUtils; 30 import org.chromium.base.ApiCompatibilityUtils;
31 import org.chromium.base.ApplicationStatus; 31 import org.chromium.base.ApplicationStatus;
32 import org.chromium.base.Log; 32 import org.chromium.base.Log;
33 import org.chromium.base.VisibleForTesting; 33 import org.chromium.base.VisibleForTesting;
34 import org.chromium.base.annotations.CalledByNative; 34 import org.chromium.base.annotations.CalledByNative;
35 import org.chromium.chrome.R; 35 import org.chromium.chrome.R;
36 import org.chromium.chrome.browser.webapps.WebappDataStorage;
36 import org.chromium.chrome.browser.webapps.WebappLauncherActivity; 37 import org.chromium.chrome.browser.webapps.WebappLauncherActivity;
37 import org.chromium.chrome.browser.widget.RoundedIconGenerator; 38 import org.chromium.chrome.browser.widget.RoundedIconGenerator;
38 import org.chromium.content_public.common.ScreenOrientationConstants; 39 import org.chromium.content_public.common.ScreenOrientationConstants;
39 import org.chromium.ui.widget.Toast; 40 import org.chromium.ui.widget.Toast;
40 41
41 import java.io.ByteArrayOutputStream; 42 import java.io.ByteArrayOutputStream;
42 import java.util.List; 43 import java.util.List;
43 import java.util.UUID;
44 44
45 /** 45 /**
46 * This is a helper class to create shortcuts on the Android home screen. 46 * This is a helper class to create shortcuts on the Android home screen.
47 */ 47 */
48 public class ShortcutHelper { 48 public class ShortcutHelper {
49 public static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp_ icon"; 49 public static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp_ icon";
50 public static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_id "; 50 public static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_id ";
51 public static final String EXTRA_MAC = "org.chromium.chrome.browser.webapp_m ac"; 51 public static final String EXTRA_MAC = "org.chromium.chrome.browser.webapp_m ac";
52 // EXTRA_TITLE is present for backward compatibility reasons 52 // EXTRA_TITLE is present for backward compatibility reasons
53 public static final String EXTRA_TITLE = "org.chromium.chrome.browser.webapp _title"; 53 public static final String EXTRA_TITLE = "org.chromium.chrome.browser.webapp _title";
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 /** 108 /**
109 * Called when we have to fire an Intent to add a shortcut to the homescreen . 109 * Called when we have to fire an Intent to add a shortcut to the homescreen .
110 * If the webpage indicated that it was capable of functioning as a webapp, it is added as a 110 * If the webpage indicated that it was capable of functioning as a webapp, it is added as a
111 * shortcut to a webapp Activity rather than as a general bookmark. User is sent to the 111 * shortcut to a webapp Activity rather than as a general bookmark. User is sent to the
112 * homescreen as soon as the shortcut is created. 112 * homescreen as soon as the shortcut is created.
113 */ 113 */
114 @SuppressWarnings("unused") 114 @SuppressWarnings("unused")
115 @CalledByNative 115 @CalledByNative
116 private static void addShortcut(Context context, String url, String userTitl e, String name, 116 private static void addShortcut(Context context, String id, String url, Stri ng userTitle,
117 String shortName, Bitmap icon, boolean isWebappCapable, int orientat ion, int source, 117 String name, String shortName, Bitmap icon, boolean isWebappCapable, int orientation,
118 long themeColor, long backgroundColor) { 118 int source, long themeColor, long backgroundColor) {
119 Intent shortcutIntent; 119 Intent shortcutIntent;
120 if (isWebappCapable) { 120 if (isWebappCapable) {
121 // Encode the icon as a base64 string (Launcher drops Bitmaps in the Intent). 121 // Encode the icon as a base64 string (Launcher drops Bitmaps in the Intent).
122 String encodedIcon = ""; 122 String encodedIcon = "";
123 if (icon != null) { 123 if (icon != null) {
124 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutpu tStream(); 124 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutpu tStream();
125 icon.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStr eam); 125 icon.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStr eam);
126 byte[] byteArray = byteArrayOutputStream.toByteArray(); 126 byte[] byteArray = byteArrayOutputStream.toByteArray();
127 encodedIcon = Base64.encodeToString(byteArray, Base64.DEFAULT); 127 encodedIcon = Base64.encodeToString(byteArray, Base64.DEFAULT);
128 } 128 }
129 129
130 // Add the shortcut as a launcher icon for a full-screen Activity. 130 // Add the shortcut as a launcher icon for a full-screen Activity.
131 shortcutIntent = new Intent(); 131 shortcutIntent = new Intent();
132 shortcutIntent.setAction(sDelegate.getFullscreenAction()); 132 shortcutIntent.setAction(sDelegate.getFullscreenAction());
133 shortcutIntent.putExtra(EXTRA_ICON, encodedIcon); 133 shortcutIntent.putExtra(EXTRA_ICON, encodedIcon);
134 shortcutIntent.putExtra(EXTRA_ID, UUID.randomUUID().toString()); 134 shortcutIntent.putExtra(EXTRA_ID, id);
135 shortcutIntent.putExtra(EXTRA_NAME, name); 135 shortcutIntent.putExtra(EXTRA_NAME, name);
136 shortcutIntent.putExtra(EXTRA_SHORT_NAME, shortName); 136 shortcutIntent.putExtra(EXTRA_SHORT_NAME, shortName);
137 shortcutIntent.putExtra(EXTRA_URL, url); 137 shortcutIntent.putExtra(EXTRA_URL, url);
138 shortcutIntent.putExtra(EXTRA_ORIENTATION, orientation); 138 shortcutIntent.putExtra(EXTRA_ORIENTATION, orientation);
139 shortcutIntent.putExtra(EXTRA_MAC, getEncodedMac(context, url)); 139 shortcutIntent.putExtra(EXTRA_MAC, getEncodedMac(context, url));
140 shortcutIntent.putExtra(EXTRA_THEME_COLOR, themeColor); 140 shortcutIntent.putExtra(EXTRA_THEME_COLOR, themeColor);
141 shortcutIntent.putExtra(EXTRA_BACKGROUND_COLOR, backgroundColor); 141 shortcutIntent.putExtra(EXTRA_BACKGROUND_COLOR, backgroundColor);
142 } else { 142 } else {
143 // Add the shortcut as a launcher icon to open in the browser Activi ty. 143 // Add the shortcut as a launcher icon to open in the browser Activi ty.
144 shortcutIntent = createShortcutIntent(url); 144 shortcutIntent = createShortcutIntent(url);
(...skipping 14 matching lines...) Expand all
159 public void run() { 159 public void run() {
160 Context applicationContext = ApplicationStatus.getApplicationCon text(); 160 Context applicationContext = ApplicationStatus.getApplicationCon text();
161 String toastText = 161 String toastText =
162 applicationContext.getString(R.string.added_to_homescree n, shortUrl); 162 applicationContext.getString(R.string.added_to_homescree n, shortUrl);
163 Toast toast = Toast.makeText(applicationContext, toastText, Toas t.LENGTH_SHORT); 163 Toast toast = Toast.makeText(applicationContext, toastText, Toas t.LENGTH_SHORT);
164 toast.show(); 164 toast.show();
165 } 165 }
166 }); 166 });
167 } 167 }
168 168
169 /** 169 /**
gone 2015/08/26 02:01:19 TODO what?
Lalit Maganti 2015/08/26 13:11:55 Add javadoc which I have now done.
170 * TODO(lalitm)
171 */
172 @SuppressWarnings("unused")
173 @CalledByNative
174 private static void addSplashscreenIconToWebappData(Context context,
Lalit Maganti 2015/08/26 13:11:55 I've changed the name of this method to be more fu
175 String id, Bitmap splashIcon) {
176 WebappDataStorage.open(context, id).putSplashIcon(splashIcon);
177 }
178
179 /**
170 * Creates an intent that will add a shortcut to the home screen. 180 * Creates an intent that will add a shortcut to the home screen.
171 * @param shortcutIntent Intent to fire when the shortcut is activated. 181 * @param shortcutIntent Intent to fire when the shortcut is activated.
172 * @param url URL of the shortcut. 182 * @param url URL of the shortcut.
173 * @param title Title of the shortcut. 183 * @param title Title of the shortcut.
174 * @param icon Image that represents the shortcut. 184 * @param icon Image that represents the shortcut.
175 * @return Intent for the shortcut. 185 * @return Intent for the shortcut.
176 */ 186 */
177 public static Intent createAddToHomeIntent(String url, String title, 187 public static Intent createAddToHomeIntent(String url, String title,
178 Bitmap icon, Intent shortcutIntent) { 188 Bitmap icon, Intent shortcutIntent) {
179 Intent i = new Intent(INSTALL_SHORTCUT); 189 Intent i = new Intent(INSTALL_SHORTCUT);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 * @return String that can be used to verify that a WebappActivity is being started by Chrome. 337 * @return String that can be used to verify that a WebappActivity is being started by Chrome.
328 */ 338 */
329 public static String getEncodedMac(Context context, String url) { 339 public static String getEncodedMac(Context context, String url) {
330 // The only reason we convert to a String here is because Android inexpl icably eats a 340 // The only reason we convert to a String here is because Android inexpl icably eats a
331 // byte[] when adding the shortcut -- the Bundle received by the launche d Activity even 341 // byte[] when adding the shortcut -- the Bundle received by the launche d Activity even
332 // lacks the key for the extra. 342 // lacks the key for the extra.
333 byte[] mac = WebappAuthenticator.getMacForUrl(context, url); 343 byte[] mac = WebappAuthenticator.getMacForUrl(context, url);
334 return Base64.encodeToString(mac, Base64.DEFAULT); 344 return Base64.encodeToString(mac, Base64.DEFAULT);
335 } 345 }
336 } 346 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698