summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2012-12-04 17:35:11 -0500
committerChris Wren <cwren@android.com>2012-12-10 10:48:47 -0500
commit2ccf92a79a2749a6fdaf5c1242f5d72de48ef111 (patch)
treef1cb3df449c936501913735d09da38ec8dd642b9 /src
parent387363c426e097c358bd41367e0a8f4339fc8dc3 (diff)
downloadandroid_packages_screensavers_PhotoTable-2ccf92a79a2749a6fdaf5c1242f5d72de48ef111.tar.gz
android_packages_screensavers_PhotoTable-2ccf92a79a2749a6fdaf5c1242f5d72de48ef111.tar.bz2
android_packages_screensavers_PhotoTable-2ccf92a79a2749a6fdaf5c1242f5d72de48ef111.zip
Add 'select all' to photo dream settings.
Bug: 7269182 Change-Id: I78898bb9e76d6233487b4888e56f896f3c6ea72d
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dreams/phototable/AlbumDataAdapter.java28
-rw-r--r--src/com/android/dreams/phototable/AlbumSettings.java21
-rw-r--r--src/com/android/dreams/phototable/FlipperDreamSettings.java56
-rw-r--r--src/com/android/dreams/phototable/PhotoTableDreamSettings.java30
-rw-r--r--src/com/android/dreams/phototable/SectionedAlbumDataAdapter.java10
5 files changed, 113 insertions, 32 deletions
diff --git a/src/com/android/dreams/phototable/AlbumDataAdapter.java b/src/com/android/dreams/phototable/AlbumDataAdapter.java
index a0c039b..699fe14 100644
--- a/src/com/android/dreams/phototable/AlbumDataAdapter.java
+++ b/src/com/android/dreams/phototable/AlbumDataAdapter.java
@@ -45,6 +45,7 @@ public class AlbumDataAdapter extends ArrayAdapter<PhotoSource.AlbumData> {
private final LayoutInflater mInflater;
private final int mLayout;
private final ItemClickListener mListener;
+ private final HashSet<String> mValidAlbumIds;
public AlbumDataAdapter(Context context, SharedPreferences settings,
int resource, List<PhotoSource.AlbumData> objects) {
@@ -54,11 +55,29 @@ public class AlbumDataAdapter extends ArrayAdapter<PhotoSource.AlbumData> {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mListener = new ItemClickListener();
- HashSet<String> validAlbumIds = new HashSet<String>(objects.size());
+ mValidAlbumIds = new HashSet<String>(objects.size());
for (PhotoSource.AlbumData albumData: objects) {
- validAlbumIds.add(albumData.id);
+ mValidAlbumIds.add(albumData.id);
}
- mSettings.pruneObsoleteSettings(validAlbumIds);
+ mSettings.pruneObsoleteSettings(mValidAlbumIds);
+ }
+
+ public boolean isSelected(int position) {
+ PhotoSource.AlbumData data = getItem(position);
+ return mSettings.isAlbumEnabled(data.id);
+ }
+
+ public boolean areAllSelected() {
+ return mSettings.areAllEnabled(mValidAlbumIds);
+ }
+
+ public void selectAll(boolean select) {
+ if (select) {
+ mSettings.enableAllAlbums(mValidAlbumIds);
+ } else {
+ mSettings.disableAllAlbums();
+ }
+ notifyDataSetChanged();
}
@Override
@@ -72,7 +91,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(mSettings.isAlbumEnabled(data.id));
+ checkBox.setChecked(isSelected(position));
checkBox.setTag(R.id.data_payload, data);
}
@@ -159,6 +178,7 @@ public class AlbumDataAdapter extends ArrayAdapter<PhotoSource.AlbumData> {
final boolean isChecked = !checkBox.isChecked();
checkBox.setChecked(isChecked);
mSettings.setAlbumEnabled(data.id, isChecked);
+ notifyDataSetChanged();
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 23dda46..069948b 100644
--- a/src/com/android/dreams/phototable/AlbumSettings.java
+++ b/src/com/android/dreams/phototable/AlbumSettings.java
@@ -56,6 +56,12 @@ public class AlbumSettings {
}
}
+ public boolean areAllEnabled(Collection<String> validAlbums) {
+ synchronized (mEnabledAlbums) {
+ return mEnabledAlbums.containsAll(validAlbums);
+ }
+ }
+
public void setAlbumEnabled(String albumId, boolean enabled) {
if (isAlbumEnabled(albumId) != enabled) {
synchronized (mEnabledAlbums) {
@@ -70,6 +76,21 @@ public class AlbumSettings {
}
}
+ public void disableAllAlbums() {
+ synchronized (mEnabledAlbums) {
+ mEnabledAlbums.clear();
+ writeEnabledAlbumsLocked();
+ }
+ }
+
+ public void enableAllAlbums(Collection<String> validAlbums) {
+ synchronized (mEnabledAlbums) {
+ mEnabledAlbums.clear();
+ mEnabledAlbums.addAll(validAlbums);
+ writeEnabledAlbumsLocked();
+ }
+ }
+
public void pruneObsoleteSettings(Collection<String> validAlbums) {
if (!validAlbums.containsAll(mEnabledAlbums)) {
synchronized (mEnabledAlbums) {
diff --git a/src/com/android/dreams/phototable/FlipperDreamSettings.java b/src/com/android/dreams/phototable/FlipperDreamSettings.java
index 1252846..8e6fac4 100644
--- a/src/com/android/dreams/phototable/FlipperDreamSettings.java
+++ b/src/com/android/dreams/phototable/FlipperDreamSettings.java
@@ -16,9 +16,13 @@
package com.android.dreams.phototable;
import android.content.SharedPreferences;
+import android.database.DataSetObserver;
import android.app.ListActivity;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.widget.ListAdapter;
@@ -31,15 +35,20 @@ public class FlipperDreamSettings extends ListActivity {
private static final String TAG = "FlipperDreamSettings";
public static final String PREFS_NAME = FlipperDream.TAG;
+ protected SharedPreferences mSettings;
+
private PhotoSourcePlexor mPhotoSource;
- private ListAdapter mAdapter;
- private SharedPreferences mSettings;
+ private SectionedAlbumDataAdapter mAdapter;
+ private MenuItem mSelectAll;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
-
mSettings = getSharedPreferences(PREFS_NAME, 0);
+ init();
+ }
+
+ protected void init() {
mPhotoSource = new PhotoSourcePlexor(this, mSettings);
setContentView(R.layout.settingslist);
@@ -56,11 +65,52 @@ public class FlipperDreamSettings extends ListActivity {
@Override
public void onPostExecute(Void unused) {
+ mAdapter.registerDataSetObserver(new DataSetObserver () {
+ @Override
+ public void onChanged() {
+ updateActionItem();
+ }
+ @Override
+ public void onInvalidated() {
+ updateActionItem();
+ }
+ });
setListAdapter(mAdapter);
+ updateActionItem();
if (mAdapter.getCount() == 0) {
findViewById(android.R.id.empty).setVisibility(View.GONE);
}
}
}.execute();
}
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.photodream_settings_menu, menu);
+ mSelectAll = menu.findItem(R.id.photodream_menu_all);
+ updateActionItem();
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.photodream_menu_all:
+ mAdapter.selectAll(!mAdapter.areAllSelected());
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ private void updateActionItem() {
+ if (mAdapter != null && mSelectAll != null) {
+ if (mAdapter.areAllSelected()) {
+ mSelectAll.setTitle(R.string.photodream_select_none);
+ } else {
+ mSelectAll.setTitle(R.string.photodream_select_all);
+ }
+ }
+ }
}
diff --git a/src/com/android/dreams/phototable/PhotoTableDreamSettings.java b/src/com/android/dreams/phototable/PhotoTableDreamSettings.java
index 6f7e9f1..a42d4a6 100644
--- a/src/com/android/dreams/phototable/PhotoTableDreamSettings.java
+++ b/src/com/android/dreams/phototable/PhotoTableDreamSettings.java
@@ -19,6 +19,9 @@ import android.content.SharedPreferences;
import android.app.ListActivity;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.widget.ListAdapter;
import java.util.LinkedList;
@@ -26,37 +29,14 @@ import java.util.LinkedList;
/**
* Settings panel for photo flipping dream.
*/
-public class PhotoTableDreamSettings extends ListActivity {
+public class PhotoTableDreamSettings extends FlipperDreamSettings {
private static final String TAG = "PhotoTableDreamSettings";
public static final String PREFS_NAME = PhotoTableDream.TAG;
- private PhotoSourcePlexor mPhotoSource;
- private ListAdapter mAdapter;
- private SharedPreferences mSettings;
-
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
-
mSettings = getSharedPreferences(PREFS_NAME, 0);
- mPhotoSource = new PhotoSourcePlexor(this, mSettings);
- 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();
+ init();
}
}
diff --git a/src/com/android/dreams/phototable/SectionedAlbumDataAdapter.java b/src/com/android/dreams/phototable/SectionedAlbumDataAdapter.java
index 6dc3ddf..6c5a88a 100644
--- a/src/com/android/dreams/phototable/SectionedAlbumDataAdapter.java
+++ b/src/com/android/dreams/phototable/SectionedAlbumDataAdapter.java
@@ -53,6 +53,16 @@ public class SectionedAlbumDataAdapter extends DataSetObserver implements ListAd
mAlbumData.registerDataSetObserver(this);
}
+ boolean areAllSelected() {
+ return mAlbumData != null && mAlbumData.areAllSelected();
+ }
+
+ void selectAll(boolean select) {
+ if (mAlbumData != null) {
+ mAlbumData.selectAll(select);
+ }
+ }
+
// DataSetObserver
@Override