summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2012-10-01 15:59:01 -0400
committerChris Wren <cwren@android.com>2012-10-01 16:31:36 -0400
commitd9b659aa5dfa4a3af96582ae49ba9ae145854a84 (patch)
tree7cca09ba4fbec7473c3950e6b5affdc9b9403939 /src
parentc225e17265676fe3a6c8848e54f4859492df9d1a (diff)
downloadandroid_packages_screensavers_PhotoTable-d9b659aa5dfa4a3af96582ae49ba9ae145854a84.tar.gz
android_packages_screensavers_PhotoTable-d9b659aa5dfa4a3af96582ae49ba9ae145854a84.tar.bz2
android_packages_screensavers_PhotoTable-d9b659aa5dfa4a3af96582ae49ba9ae145854a84.zip
find the disappearing settings, plus some layout.
Bug: 7242287 Bug: 7194713 Change-Id: I362c2ffa0d4cbc3be45d14ede1de5dbf39ec4d7f
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dreams/phototable/AlbumDataAdapter.java18
-rw-r--r--src/com/android/dreams/phototable/AlbumSettings.java75
-rw-r--r--src/com/android/dreams/phototable/FlipperDream.java6
-rw-r--r--src/com/android/dreams/phototable/FlipperDreamSettings.java27
-rw-r--r--src/com/android/dreams/phototable/LocalSource.java14
-rw-r--r--src/com/android/dreams/phototable/PhotoSource.java4
-rw-r--r--src/com/android/dreams/phototable/PhotoTableDream.java6
-rw-r--r--src/com/android/dreams/phototable/PhotoTableDreamSettings.java27
-rw-r--r--src/com/android/dreams/phototable/PicasaSource.java14
9 files changed, 135 insertions, 56 deletions
diff --git a/src/com/android/dreams/phototable/AlbumDataAdapter.java b/src/com/android/dreams/phototable/AlbumDataAdapter.java
index 099fd90..8682cd5 100644
--- a/src/com/android/dreams/phototable/AlbumDataAdapter.java
+++ b/src/com/android/dreams/phototable/AlbumDataAdapter.java
@@ -41,21 +41,18 @@ public class AlbumDataAdapter extends ArrayAdapter<PhotoSource.AlbumData> {
public static final String ALBUM_SET = "Enabled Album Set";
- private final SharedPreferences mSettings;
+ private final AlbumSettings mSettings;
private final LayoutInflater mInflater;
private final int mLayout;
private final ItemClickListener mListener;
- private Set<String> mEnabledAlbums;
-
public AlbumDataAdapter(Context context, SharedPreferences settings,
int resource, List<PhotoSource.AlbumData> objects) {
super(context, resource, objects);
- mSettings = settings;
+ mSettings = AlbumSettings.getAlbumSettings(settings);
mLayout = resource;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mListener = new ItemClickListener();
- mEnabledAlbums = AlbumSettings.getEnabledAlbums(mSettings);
}
@Override
@@ -69,7 +66,7 @@ public class AlbumDataAdapter extends ArrayAdapter<PhotoSource.AlbumData> {
View vCheckBox = item.findViewById(R.id.enabled);
if (vCheckBox != null && vCheckBox instanceof CheckBox) {
CheckBox checkBox = (CheckBox) vCheckBox;
- checkBox.setChecked(mEnabledAlbums.contains(data.id));
+ checkBox.setChecked(mSettings.isAlbumEnabled(data.id));
checkBox.setTag(R.id.data_payload, data);
}
@@ -155,14 +152,7 @@ public class AlbumDataAdapter extends ArrayAdapter<PhotoSource.AlbumData> {
(PhotoSource.AlbumData) checkBox.getTag(R.id.data_payload);
final boolean isChecked = !checkBox.isChecked();
checkBox.setChecked(isChecked);
-
- if (isChecked) {
- mEnabledAlbums.add(data.id);
- } else {
- mEnabledAlbums.remove(data.id);
- }
-
- AlbumSettings.setEnabledAlbums(mSettings , mEnabledAlbums);
+ mSettings.setAlbumEnabled(data.id, isChecked);
if (DEBUG) Log.i(TAG, data.title + " is " +
(isChecked ? "" : "not") + " enabled");
} else {
diff --git a/src/com/android/dreams/phototable/AlbumSettings.java b/src/com/android/dreams/phototable/AlbumSettings.java
index 502cd3f..a719d4f 100644
--- a/src/com/android/dreams/phototable/AlbumSettings.java
+++ b/src/com/android/dreams/phototable/AlbumSettings.java
@@ -17,6 +17,7 @@ package com.android.dreams.phototable;
import android.content.SharedPreferences;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
@@ -26,22 +27,72 @@ import java.util.Set;
public class AlbumSettings {
public static final String ALBUM_SET = "Enabled Album Set V2";
- public static Set<String> getEnabledAlbums(SharedPreferences settings) {
- Set<String> enabled = settings.getStringSet(ALBUM_SET, null);
- if (enabled == null) {
- enabled = new HashSet<String>();
- setEnabledAlbums(settings, enabled);
+ private static HashMap<SharedPreferences, AlbumSettings> singletons;
+
+ private final SharedPreferences mSettings;
+ private final HashSet<String> mEnabledAlbums;
+
+ public static AlbumSettings getAlbumSettings(SharedPreferences settings) {
+ if (singletons == null) {
+ singletons = new HashMap<SharedPreferences, AlbumSettings>();
+ }
+ if (!singletons.containsKey(settings)) {
+ singletons.put(settings, new AlbumSettings(settings));
+ }
+ return singletons.get(settings);
+ }
+
+ public void readEnabledAlbums() {
+ synchronized (mEnabledAlbums) {
+ readEnabledAlbumsLocked();
+ }
+ }
+
+ public boolean isAlbumEnabled(String albumId) {
+ synchronized (mEnabledAlbums) {
+ boolean isEnabled = mEnabledAlbums.contains(albumId);
+ return mEnabledAlbums.contains(albumId);
}
- return enabled;
}
- public static void setEnabledAlbums(SharedPreferences settings, Set<String> value) {
- SharedPreferences.Editor editor = settings.edit();
- editor.putStringSet(ALBUM_SET, value);
- editor.apply();
+ public void setAlbumEnabled(String albumId, boolean enabled) {
+ if (isAlbumEnabled(albumId) != enabled) {
+ synchronized (mEnabledAlbums) {
+ readEnabledAlbumsLocked();
+ if (enabled) {
+ mEnabledAlbums.add(albumId);
+ } else {
+ mEnabledAlbums.remove(albumId);
+ }
+ writeEnabledAlbumsLocked();
+ }
+ }
+ }
+
+ public boolean isConfigured() {
+ synchronized (mEnabledAlbums) {
+ return mEnabledAlbums.size() != 0;
+ }
+ }
+
+ private AlbumSettings(SharedPreferences settings) {
+ mSettings = settings;
+ mEnabledAlbums = new HashSet<String>();
+ readEnabledAlbums();
+ }
+
+ private void readEnabledAlbumsLocked() {
+ Set<String> enabledAlbums = mSettings.getStringSet(ALBUM_SET, null);
+ mEnabledAlbums.clear();
+ if (enabledAlbums != null) {
+ mEnabledAlbums.addAll(enabledAlbums);
+ }
}
- public static boolean isConfigured(SharedPreferences settings) {
- return getEnabledAlbums(settings).size() != 0;
+ private void writeEnabledAlbumsLocked() {
+ SharedPreferences.Editor editor = mSettings.edit();
+ // Give SharedSettings a copy, so that we are free to manipulate ours.
+ editor.putStringSet(ALBUM_SET, new HashSet<String>(mEnabledAlbums));
+ editor.commit();
}
}
diff --git a/src/com/android/dreams/phototable/FlipperDream.java b/src/com/android/dreams/phototable/FlipperDream.java
index bbcdfb0..9953f32 100644
--- a/src/com/android/dreams/phototable/FlipperDream.java
+++ b/src/com/android/dreams/phototable/FlipperDream.java
@@ -33,9 +33,9 @@ public class FlipperDream extends DreamService {
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
-
- SharedPreferences settings = getSharedPreferences(FlipperDreamSettings.PREFS_NAME, 0);
- if (AlbumSettings.isConfigured(settings)) {
+ AlbumSettings settings = AlbumSettings.getAlbumSettings(
+ getSharedPreferences(FlipperDreamSettings.PREFS_NAME, 0));
+ if (settings.isConfigured()) {
setContentView(R.layout.carousel);
} else {
setContentView(R.layout.bummer);
diff --git a/src/com/android/dreams/phototable/FlipperDreamSettings.java b/src/com/android/dreams/phototable/FlipperDreamSettings.java
index cac415c..d0d37bb 100644
--- a/src/com/android/dreams/phototable/FlipperDreamSettings.java
+++ b/src/com/android/dreams/phototable/FlipperDreamSettings.java
@@ -17,6 +17,7 @@ package com.android.dreams.phototable;
import android.content.SharedPreferences;
import android.app.ListActivity;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ListAdapter;
@@ -37,17 +38,25 @@ public class FlipperDreamSettings extends ListActivity {
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
- //setContentView(R.layout.custom_list_activity_view);
-
mSettings = getSharedPreferences(PREFS_NAME, 0);
-
mPhotoSource = new PhotoSourcePlexor(this, mSettings);
- mAdapter = new SectionedAlbumDataAdapter(this,
- mSettings,
- R.layout.header,
- R.layout.album,
- new LinkedList<PhotoSource.AlbumData>(mPhotoSource.findAlbums()));
- setListAdapter(mAdapter);
setContentView(R.layout.settingslist);
+
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ public Void doInBackground(Void... unused) {
+ mAdapter = new SectionedAlbumDataAdapter(FlipperDreamSettings.this,
+ mSettings,
+ R.layout.header,
+ R.layout.album,
+ new LinkedList<PhotoSource.AlbumData>(mPhotoSource.findAlbums()));
+ return null;
+ }
+
+ @Override
+ public void onPostExecute(Void unused) {
+ setListAdapter(mAdapter);
+ }
+ }.execute();
}
}
diff --git a/src/com/android/dreams/phototable/LocalSource.java b/src/com/android/dreams/phototable/LocalSource.java
index e453378..1614bb9 100644
--- a/src/com/android/dreams/phototable/LocalSource.java
+++ b/src/com/android/dreams/phototable/LocalSource.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
+import java.util.Set;
/**
* Loads images from the local store.
@@ -34,6 +35,7 @@ public class LocalSource extends PhotoSource {
private final String mUnknownAlbumName;
private final String mLocalSourceName;
+ private Set<String> mFoundAlbumIds;
private int mNextPosition;
public LocalSource(Context context, SharedPreferences settings) {
@@ -45,6 +47,13 @@ public class LocalSource extends PhotoSource {
fillQueue();
}
+ private Set<String> getFoundAlbums() {
+ if (mFoundAlbumIds == null) {
+ findAlbums();
+ }
+ return mFoundAlbumIds;
+ }
+
@Override
public Collection<AlbumData> findAlbums() {
log(TAG, "finding albums");
@@ -100,6 +109,7 @@ public class LocalSource extends PhotoSource {
}
log(TAG, "found " + foundAlbums.size() + " items.");
+ mFoundAlbumIds = foundAlbums.keySet();
return foundAlbums.values();
}
@@ -111,8 +121,8 @@ public class LocalSource extends PhotoSource {
String[] projection = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.ORIENTATION,
MediaStore.Images.Media.BUCKET_ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME};
String selection = "";
- for (String id : AlbumSettings.getEnabledAlbums(mSettings)) {
- if (id.startsWith(TAG)) {
+ for (String id : getFoundAlbums()) {
+ if (mSettings.isAlbumEnabled(id)) {
String[] parts = id.split(":");
if (parts.length > 1) {
if (selection.length() > 0) {
diff --git a/src/com/android/dreams/phototable/PhotoSource.java b/src/com/android/dreams/phototable/PhotoSource.java
index 366ce20..06dd816 100644
--- a/src/com/android/dreams/phototable/PhotoSource.java
+++ b/src/com/android/dreams/phototable/PhotoSource.java
@@ -79,7 +79,7 @@ public abstract class PhotoSource {
protected final Context mContext;
protected final Resources mResources;
protected final Random mRNG;
- protected final SharedPreferences mSettings;
+ protected final AlbumSettings mSettings;
protected final ContentResolver mResolver;
protected String mSourceName;
@@ -91,7 +91,7 @@ public abstract class PhotoSource {
public PhotoSource(Context context, SharedPreferences settings, PhotoSource fallbackSource) {
mSourceName = TAG;
mContext = context;
- mSettings = settings;
+ mSettings = AlbumSettings.getAlbumSettings(settings);
mResolver = mContext.getContentResolver();
mResources = context.getResources();
mImageQueue = new LinkedList<ImageData>();
diff --git a/src/com/android/dreams/phototable/PhotoTableDream.java b/src/com/android/dreams/phototable/PhotoTableDream.java
index ba79769..20fd566 100644
--- a/src/com/android/dreams/phototable/PhotoTableDream.java
+++ b/src/com/android/dreams/phototable/PhotoTableDream.java
@@ -42,9 +42,9 @@ public class PhotoTableDream extends DreamService {
super.onAttachedToWindow();
LayoutInflater inflater =
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- SharedPreferences settings = getSharedPreferences(PhotoTableDreamSettings.PREFS_NAME, 0);
- Set<String> enabledAlbums = AlbumSettings.getEnabledAlbums(settings);
- if (AlbumSettings.isConfigured(settings)) {
+ AlbumSettings settings = AlbumSettings.getAlbumSettings(
+ getSharedPreferences(PhotoTableDreamSettings.PREFS_NAME, 0));
+ if (settings.isConfigured()) {
ViewGroup view = (ViewGroup) inflater.inflate(R.layout.table, null);
PhotoTable table = (PhotoTable) view.findViewById(R.id.table);
table.setDream(this);
diff --git a/src/com/android/dreams/phototable/PhotoTableDreamSettings.java b/src/com/android/dreams/phototable/PhotoTableDreamSettings.java
index 4340eba..6f7e9f1 100644
--- a/src/com/android/dreams/phototable/PhotoTableDreamSettings.java
+++ b/src/com/android/dreams/phototable/PhotoTableDreamSettings.java
@@ -17,6 +17,7 @@ package com.android.dreams.phototable;
import android.content.SharedPreferences;
import android.app.ListActivity;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ListAdapter;
@@ -37,17 +38,25 @@ public class PhotoTableDreamSettings extends ListActivity {
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
- //setContentView(R.layout.custom_list_activity_view);
-
mSettings = getSharedPreferences(PREFS_NAME, 0);
-
mPhotoSource = new PhotoSourcePlexor(this, mSettings);
- mAdapter = new SectionedAlbumDataAdapter(this,
- mSettings,
- R.layout.header,
- R.layout.album,
- new LinkedList<PhotoSource.AlbumData>(mPhotoSource.findAlbums()));
- setListAdapter(mAdapter);
setContentView(R.layout.settingslist);
+
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ public Void doInBackground(Void... unused) {
+ mAdapter = new SectionedAlbumDataAdapter(PhotoTableDreamSettings.this,
+ mSettings,
+ R.layout.header,
+ R.layout.album,
+ new LinkedList<PhotoSource.AlbumData>(mPhotoSource.findAlbums()));
+ return null;
+ }
+
+ @Override
+ public void onPostExecute(Void unused) {
+ setListAdapter(mAdapter);
+ }
+ }.execute();
}
}
diff --git a/src/com/android/dreams/phototable/PicasaSource.java b/src/com/android/dreams/phototable/PicasaSource.java
index 92adfa6..bb1f1ec 100644
--- a/src/com/android/dreams/phototable/PicasaSource.java
+++ b/src/com/android/dreams/phototable/PicasaSource.java
@@ -26,6 +26,7 @@ import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
+import java.util.Set;
/**
* Loads images from Picasa.
@@ -65,6 +66,7 @@ public class PicasaSource extends PhotoSource {
private final String mUploadsAlbumName;
private final String mUnknownAlbumName;
+ private Set<String> mFoundAlbumIds;
private int mNextPosition;
public PicasaSource(Context context, SharedPreferences settings) {
@@ -85,8 +87,8 @@ public class PicasaSource extends PhotoSource {
String[] projection = {PICASA_ID, PICASA_URL, PICASA_ROTATION, PICASA_ALBUM_ID};
boolean usePosts = false;
LinkedList<String> albumIds = new LinkedList<String>();
- for (String id : AlbumSettings.getEnabledAlbums(mSettings)) {
- if (id.startsWith(TAG)) {
+ for (String id : getFoundAlbums()) {
+ if (mSettings.isAlbumEnabled(id)) {
String[] parts = id.split(":");
if (parts.length > 2) {
albumIds.addAll(resolveAlbumIds(id));
@@ -225,6 +227,13 @@ public class PicasaSource extends PhotoSource {
return albumIds;
}
+ private Set<String> getFoundAlbums() {
+ if (mFoundAlbumIds == null) {
+ findAlbums();
+ }
+ return mFoundAlbumIds;
+ }
+
@Override
public Collection<AlbumData> findAlbums() {
log(TAG, "finding albums");
@@ -319,6 +328,7 @@ public class PicasaSource extends PhotoSource {
}
log(TAG, "found " + foundAlbums.size() + " items.");
+ mFoundAlbumIds = foundAlbums.keySet();
return foundAlbums.values();
}