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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java

Issue 1286973003: webapps: introduce helper class to store extended set of data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java
new file mode 100644
index 0000000000000000000000000000000000000000..1b6bd4c6330c806f335171895ea154f820957d6a
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDataStorage.java
@@ -0,0 +1,51 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.webapps;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.text.TextUtils;
+import android.util.Base64;
+
+import java.io.ByteArrayOutputStream;
+
+/**
+ * This is a class used to store data about an installed webapp.
+ */
+public class WebappDataStorage {
+
+ private final SharedPreferences mPreferences;
+
+ private WebappDataStorage(Context context, String webappId) {
+ mPreferences = context.getSharedPreferences("webapp_" + webappId,
+ Context.MODE_PRIVATE);
+ }
+
+ public static WebappDataStorage open(Context context, String webappId) {
+ return new WebappDataStorage(context, webappId);
+ }
+
+ public Bitmap getSplashIcon() {
mlamouri (slow - plz ping) 2015/08/13 11:21:01 Is that call synchronous? Is that going to slow do
Lalit Maganti 2015/08/18 12:45:45 Yes and yes. I've made it async and introduced cal
+ String icon = mPreferences.getString("splash_icon", "");
+ Bitmap decodedIcon = null;
+ if (!TextUtils.isEmpty(icon)) {
+ byte[] decoded = Base64.decode(icon, Base64.DEFAULT);
+ decodedIcon = BitmapFactory.decodeByteArray(decoded, 0, decoded.length);
+ }
+ return decodedIcon;
+ }
+
+ public WebappDataStorage putSplashIcon(Bitmap icon) {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ icon.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
+ byte[] byteArray = byteArrayOutputStream.toByteArray();
+ mPreferences.edit()
+ .putString("splash_icon", Base64.encodeToString(byteArray, Base64.DEFAULT))
+ .commit();
gone 2015/08/12 22:32:32 you probably want to use apply() instead. commit(
Lalit Maganti 2015/08/18 12:45:46 Done.
+ return this;
+ }
+}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698