Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.webapps; | 5 package org.chromium.chrome.browser.webapps; |
| 6 | 6 |
| 7 import android.content.Intent; | 7 import android.content.Intent; |
| 8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
| 9 import android.graphics.BitmapFactory; | 9 import android.graphics.BitmapFactory; |
| 10 import android.net.Uri; | 10 import android.net.Uri; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 * Stores info about a web app. | 22 * Stores info about a web app. |
| 23 */ | 23 */ |
| 24 public class WebappInfo { | 24 public class WebappInfo { |
| 25 private boolean mIsInitialized; | 25 private boolean mIsInitialized; |
| 26 private String mId; | 26 private String mId; |
| 27 private Bitmap mIcon; | 27 private Bitmap mIcon; |
| 28 private Uri mUri; | 28 private Uri mUri; |
| 29 private String mTitle; | 29 private String mTitle; |
| 30 private int mOrientation; | 30 private int mOrientation; |
| 31 private int mSource; | 31 private int mSource; |
| 32 private long mThemeColor; | |
| 32 | 33 |
| 33 public static WebappInfo createEmpty() { | 34 public static WebappInfo createEmpty() { |
| 34 return new WebappInfo(); | 35 return new WebappInfo(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 /** | 38 /** |
| 38 * Construct a WebappInfo. | 39 * Construct a WebappInfo. |
| 39 * @param intent Intent containing info about the app. | 40 * @param intent Intent containing info about the app. |
| 40 */ | 41 */ |
| 41 public static WebappInfo create(Intent intent) { | 42 public static WebappInfo create(Intent intent) { |
| 42 String id = intent.getStringExtra(ShortcutHelper.EXTRA_ID); | 43 String id = intent.getStringExtra(ShortcutHelper.EXTRA_ID); |
| 43 String icon = intent.getStringExtra(ShortcutHelper.EXTRA_ICON); | 44 String icon = intent.getStringExtra(ShortcutHelper.EXTRA_ICON); |
| 44 String title = intent.getStringExtra(ShortcutHelper.EXTRA_TITLE); | 45 String title = intent.getStringExtra(ShortcutHelper.EXTRA_TITLE); |
| 45 String url = intent.getStringExtra(ShortcutHelper.EXTRA_URL); | 46 String url = intent.getStringExtra(ShortcutHelper.EXTRA_URL); |
| 46 int orientation = intent.getIntExtra( | 47 int orientation = intent.getIntExtra( |
| 47 ShortcutHelper.EXTRA_ORIENTATION, ScreenOrientationValues.DEFAUL T); | 48 ShortcutHelper.EXTRA_ORIENTATION, ScreenOrientationValues.DEFAUL T); |
| 48 int source = intent.getIntExtra( | 49 int source = intent.getIntExtra( |
| 49 ShortcutHelper.EXTRA_SOURCE, ShortcutHelper.SOURCE_UNKNOWN); | 50 ShortcutHelper.EXTRA_SOURCE, ShortcutHelper.SOURCE_UNKNOWN); |
| 50 return create(id, url, icon, title, orientation, source); | 51 long themeColor = intent.getLongExtra(ShortcutHelper.EXTRA_THEME_COLOR, |
| 52 ShortcutHelper.THEME_COLOR_INVALID_OR_MISSING); | |
| 53 return create(id, url, icon, title, orientation, source, themeColor); | |
| 51 } | 54 } |
| 52 | 55 |
| 53 /** | 56 /** |
| 54 * Construct a WebappInfo. | 57 * Construct a WebappInfo. |
| 55 * @param id ID for the webapp. | 58 * @param id ID for the webapp. |
| 56 * @param url URL for the webapp. | 59 * @param url URL for the webapp. |
| 57 * @param icon Icon to show for the webapp. | 60 * @param icon Icon to show for the webapp. |
| 58 * @param title Title of the webapp. | 61 * @param title Title of the webapp. |
| 62 * @param themeColor The theme color of the webapp. | |
| 59 * @param orientation Orientation of the webapp. | 63 * @param orientation Orientation of the webapp. |
| 60 * @param source Source where the webapp was added from. | 64 * @param source Source where the webapp was added from. |
| 61 */ | 65 */ |
| 62 public static WebappInfo create(String id, String url, String icon, String t itle, | 66 public static WebappInfo create(String id, String url, String icon, String t itle, |
| 63 int orientation, int source) { | 67 int orientation, int source, long themeColor) { |
| 64 if (id == null || url == null) { | 68 if (id == null || url == null) { |
| 65 Log.e("WebappInfo", "Data passed in was incomplete: " + id + ", " + url); | 69 Log.e("WebappInfo", "Data passed in was incomplete: " + id + ", " + url); |
| 66 return null; | 70 return null; |
| 67 } | 71 } |
| 68 | 72 |
| 69 Bitmap favicon = null; | 73 Bitmap favicon = null; |
| 70 if (!TextUtils.isEmpty(icon)) { | 74 if (!TextUtils.isEmpty(icon)) { |
| 71 byte[] decoded = Base64.decode(icon, Base64.DEFAULT); | 75 byte[] decoded = Base64.decode(icon, Base64.DEFAULT); |
| 72 favicon = BitmapFactory.decodeByteArray(decoded, 0, decoded.length); | 76 favicon = BitmapFactory.decodeByteArray(decoded, 0, decoded.length); |
| 73 } | 77 } |
| 74 | 78 |
| 75 Uri uri = Uri.parse(url); | 79 Uri uri = Uri.parse(url); |
| 76 return new WebappInfo(id, uri, favicon, title, orientation, source); | 80 return new WebappInfo(id, uri, favicon, title, orientation, source, them eColor); |
| 77 } | 81 } |
| 78 | 82 |
| 79 private WebappInfo(String id, Uri uri, Bitmap icon, String title, int orient ation, int source) { | 83 private WebappInfo(String id, Uri uri, Bitmap icon, String title, |
| 84 int orientation, int source, long themeColor) { | |
| 80 mIcon = icon; | 85 mIcon = icon; |
| 81 mId = id; | 86 mId = id; |
| 82 mTitle = title; | 87 mTitle = title; |
| 83 mUri = uri; | 88 mUri = uri; |
| 84 mOrientation = orientation; | 89 mOrientation = orientation; |
| 85 mSource = source; | 90 mSource = source; |
| 91 mThemeColor = themeColor; | |
| 86 mIsInitialized = mUri != null; | 92 mIsInitialized = mUri != null; |
| 87 } | 93 } |
| 88 | 94 |
| 89 private WebappInfo() { | 95 private WebappInfo() { |
| 90 } | 96 } |
| 91 | 97 |
| 92 /** | 98 /** |
| 93 * Writes all of the data about the webapp into the given Bundle. | 99 * Writes all of the data about the webapp into the given Bundle. |
| 94 * @param outState Bundle to write data into. | 100 * @param outState Bundle to write data into. |
| 95 */ | 101 */ |
| 96 void writeToBundle(Bundle outState) { | 102 void writeToBundle(Bundle outState) { |
| 97 if (!mIsInitialized) return; | 103 if (!mIsInitialized) return; |
| 98 | 104 |
| 99 outState.putString(ShortcutHelper.EXTRA_ID, mId); | 105 outState.putString(ShortcutHelper.EXTRA_ID, mId); |
| 100 outState.putString(ShortcutHelper.EXTRA_URL, mUri.toString()); | 106 outState.putString(ShortcutHelper.EXTRA_URL, mUri.toString()); |
| 101 outState.putParcelable(ShortcutHelper.EXTRA_ICON, mIcon); | 107 outState.putParcelable(ShortcutHelper.EXTRA_ICON, mIcon); |
| 102 outState.putString(ShortcutHelper.EXTRA_TITLE, mTitle); | 108 outState.putString(ShortcutHelper.EXTRA_TITLE, mTitle); |
| 103 outState.putInt(ShortcutHelper.EXTRA_ORIENTATION, mOrientation); | 109 outState.putInt(ShortcutHelper.EXTRA_ORIENTATION, mOrientation); |
| 104 outState.putInt(ShortcutHelper.EXTRA_SOURCE, mSource); | 110 outState.putInt(ShortcutHelper.EXTRA_SOURCE, mSource); |
| 111 outState.putLong(ShortcutHelper.EXTRA_THEME_COLOR, mThemeColor); | |
| 105 } | 112 } |
| 106 | 113 |
| 107 /** | 114 /** |
| 108 * Copies all the fields from the given WebappInfo into this instance. | 115 * Copies all the fields from the given WebappInfo into this instance. |
| 109 * @param newInfo Information about the new webapp. | 116 * @param newInfo Information about the new webapp. |
| 110 */ | 117 */ |
| 111 void copy(WebappInfo newInfo) { | 118 void copy(WebappInfo newInfo) { |
| 112 mIsInitialized = newInfo.mIsInitialized; | 119 mIsInitialized = newInfo.mIsInitialized; |
| 113 mIcon = newInfo.mIcon; | 120 mIcon = newInfo.mIcon; |
| 114 mId = newInfo.mId; | 121 mId = newInfo.mId; |
| 115 mUri = newInfo.mUri; | 122 mUri = newInfo.mUri; |
| 116 mTitle = newInfo.mTitle; | 123 mTitle = newInfo.mTitle; |
| 124 mThemeColor = newInfo.mThemeColor; | |
| 117 mOrientation = newInfo.mOrientation; | 125 mOrientation = newInfo.mOrientation; |
| 118 mSource = newInfo.mSource; | 126 mSource = newInfo.mSource; |
| 127 mThemeColor = newInfo.mThemeColor; | |
|
mlamouri (slow - plz ping)
2015/07/20 13:03:30
You still have one too many mThemeColor here.
Lalit Maganti
2015/07/20 13:15:19
Not sure why the previous patch didn't have that.
| |
| 119 } | 128 } |
| 120 | 129 |
| 121 public boolean isInitialized() { | 130 public boolean isInitialized() { |
| 122 return mIsInitialized; | 131 return mIsInitialized; |
| 123 } | 132 } |
| 124 | 133 |
| 125 public String id() { | 134 public String id() { |
| 126 return mId; | 135 return mId; |
| 127 } | 136 } |
| 128 | 137 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 139 } | 148 } |
| 140 | 149 |
| 141 public int orientation() { | 150 public int orientation() { |
| 142 return mOrientation; | 151 return mOrientation; |
| 143 } | 152 } |
| 144 | 153 |
| 145 public int source() { | 154 public int source() { |
| 146 return mSource; | 155 return mSource; |
| 147 } | 156 } |
| 148 | 157 |
| 158 public long themeColor() { | |
| 159 return mThemeColor; | |
| 160 } | |
| 161 | |
| 149 // This is needed for clients that want to send the icon trough an intent. | 162 // This is needed for clients that want to send the icon trough an intent. |
| 150 public String getEncodedIcon() { | 163 public String getEncodedIcon() { |
| 151 if (mIcon == null) return ""; | 164 if (mIcon == null) return ""; |
| 152 | 165 |
| 153 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream( ); | 166 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream( ); |
| 154 mIcon.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); | 167 mIcon.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); |
| 155 byte[] byteArray = byteArrayOutputStream.toByteArray(); | 168 byte[] byteArray = byteArrayOutputStream.toByteArray(); |
| 156 return Base64.encodeToString(byteArray, Base64.DEFAULT); | 169 return Base64.encodeToString(byteArray, Base64.DEFAULT); |
| 157 } | 170 } |
| 158 } | 171 } |
| OLD | NEW |