Chromium Code Reviews| 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; |
| + } |
| +} |