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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.webapps;
6
7 import android.content.Context;
8 import android.content.SharedPreferences;
9 import android.graphics.Bitmap;
10 import android.graphics.BitmapFactory;
11 import android.text.TextUtils;
12 import android.util.Base64;
13
14 import java.io.ByteArrayOutputStream;
15
16 /**
17 * This is a class used to store data about an installed webapp.
18 */
19 public class WebappDataStorage {
20
21 private final SharedPreferences mPreferences;
22
23 private WebappDataStorage(Context context, String webappId) {
24 mPreferences = context.getSharedPreferences("webapp_" + webappId,
25 Context.MODE_PRIVATE);
26 }
27
28 public static WebappDataStorage open(Context context, String webappId) {
29 return new WebappDataStorage(context, webappId);
30 }
31
32 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
33 String icon = mPreferences.getString("splash_icon", "");
34 Bitmap decodedIcon = null;
35 if (!TextUtils.isEmpty(icon)) {
36 byte[] decoded = Base64.decode(icon, Base64.DEFAULT);
37 decodedIcon = BitmapFactory.decodeByteArray(decoded, 0, decoded.leng th);
38 }
39 return decodedIcon;
40 }
41
42 public WebappDataStorage putSplashIcon(Bitmap icon) {
43 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream( );
44 icon.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
45 byte[] byteArray = byteArrayOutputStream.toByteArray();
46 mPreferences.edit()
47 .putString("splash_icon", Base64.encodeToString(byteArray, Base64.DE FAULT))
48 .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.
49 return this;
50 }
51 }
OLDNEW
« 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