Bug 786826 - Use SharedPrefs.commit in WebAppAllocator for Eclair compatibility r=mfinkle

This commit is contained in:
Wes Johnston 2012-09-24 08:55:52 -07:00
parent 501256d2ba
commit 99e3cf44fb

View File

@ -15,6 +15,7 @@ import android.util.Log;
import java.io.FileOutputStream;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.util.GeckoBackgroundThread;
public class WebAppAllocator {
private final String LOGTAG = "GeckoWebAppAllocator";
@ -67,25 +68,30 @@ public class WebAppAllocator {
return findAndAllocateIndex(app, name, bitmap);
}
public synchronized int findAndAllocateIndex(String app, String name, Bitmap aIcon) {
public synchronized int findAndAllocateIndex(final String app, final String name, final Bitmap aIcon) {
int index = getIndexForApp(app);
if (index != -1)
return index;
int color = 0;
try {
color = BitmapUtils.getDominantColor(aIcon);
} catch (Exception e) {
e.printStackTrace();
}
for (int i = 0; i < MAX_WEB_APPS; ++i) {
if (!mPrefs.contains(appKey(i))) {
// found unused index i
mPrefs.edit()
.putString(appKey(i), app)
.putInt(iconKey(i), color)
.apply();
final int foundIndex = i;
GeckoBackgroundThread.getHandler().post(new Runnable() {
public void run() {
int color = 0;
try {
color = BitmapUtils.getDominantColor(aIcon);
} catch (Exception e) {
e.printStackTrace();
}
mPrefs.edit()
.putString(appKey(foundIndex), app)
.putInt(iconKey(foundIndex), color)
.commit();
}
});
return i;
}
}