diff options
author | Scott Warner <Tortel1210@gmail.com> | 2014-01-05 10:44:53 -0500 |
---|---|---|
committer | Scott Warner <Tortel1210@gmail.com> | 2014-01-13 10:00:40 -0500 |
commit | 134d63405dd5e9a8a54e3d76c0967738a82c4100 (patch) | |
tree | 63d677f37bd9ec72725d335b091ed6b9bcfd5576 | |
parent | f41216136a66830caaf0f40af4019ccd579d4356 (diff) | |
download | android_packages_apps_Gallery2-134d63405dd5e9a8a54e3d76c0967738a82c4100.tar.gz android_packages_apps_Gallery2-134d63405dd5e9a8a54e3d76c0967738a82c4100.tar.bz2 android_packages_apps_Gallery2-134d63405dd5e9a8a54e3d76c0967738a82c4100.zip |
Storage configuration options (2/2)
This adds an intent listener to listen for storage path changes
from the camera app, so that it will display the correct folder
as the main Camera folder.
Change-Id: Ie487323edce58f174b4956a2e832ac4c121309ef
-rw-r--r-- | AndroidManifest.xml | 11 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/AbstractGalleryActivity.java | 13 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/PhotoDataAdapter.java | 2 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/StorageChangeReceiver.java | 42 | ||||
-rw-r--r-- | src/com/android/gallery3d/data/LocalAlbum.java | 6 | ||||
-rw-r--r-- | src/com/android/gallery3d/data/LocalAlbumSet.java | 2 | ||||
-rw-r--r-- | src/com/android/gallery3d/data/SecureAlbum.java | 2 | ||||
-rw-r--r-- | src/com/android/gallery3d/util/MediaSetUtils.java | 21 |
8 files changed, 84 insertions, 15 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ceee22410..900d4adb0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -12,6 +12,9 @@ <permission android:name="com.android.gallery3d.permission.GALLERY_PROVIDER" android:protectionLevel="signatureOrSystem" /> + <permission android:name="com.android.gallery3d.permission.STORAGE_CHANGE" + android:protectionLevel="signatureOrSystem" /> + <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> @@ -361,6 +364,14 @@ </intent-filter> </receiver> + <!-- Receiver to keep the storage path for the camera in sync --> + <receiver android:name="com.android.gallery3d.app.StorageChangeReceiver" + android:permission="com.android.gallery3d.permission.STORAGE_CHANGE" > + <intent-filter> + <action android:name="com.android.gallery3d.STORAGE_CHANGE" /> + </intent-filter> + </receiver> + <service android:name="com.android.camera.MediaSaveService" /> </application> </manifest> diff --git a/src/com/android/gallery3d/app/AbstractGalleryActivity.java b/src/com/android/gallery3d/app/AbstractGalleryActivity.java index 9af1fb8ba..ae9d92d5e 100644 --- a/src/com/android/gallery3d/app/AbstractGalleryActivity.java +++ b/src/com/android/gallery3d/app/AbstractGalleryActivity.java @@ -28,10 +28,13 @@ import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; +import android.os.Environment; import android.os.IBinder; +import android.preference.PreferenceManager; import android.support.v4.print.PrintHelper; import android.view.Menu; import android.view.MenuItem; @@ -45,6 +48,7 @@ import com.android.gallery3d.data.MediaItem; import com.android.gallery3d.filtershow.cache.ImageLoader; import com.android.gallery3d.ui.GLRoot; import com.android.gallery3d.ui.GLRootView; +import com.android.gallery3d.util.MediaSetUtils; import com.android.gallery3d.util.PanoramaViewHelper; import com.android.gallery3d.util.ThreadPool; import com.android.photos.data.GalleryBitmapPool; @@ -73,6 +77,7 @@ public class AbstractGalleryActivity extends Activity implements GalleryContext @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setStoragePath(); mOrientationManager = new OrientationManager(this); toggleStatusBarByOrientation(); getWindow().setBackgroundDrawable(null); @@ -81,6 +86,14 @@ public class AbstractGalleryActivity extends Activity implements GalleryContext doBindBatchService(); } + private void setStoragePath() { + SharedPreferences prefs = PreferenceManager + .getDefaultSharedPreferences(this); + String storagePath = prefs.getString(StorageChangeReceiver.KEY_STORAGE, + Environment.getExternalStorageDirectory().toString()); + MediaSetUtils.setRoot(storagePath); + } + @Override protected void onSaveInstanceState(Bundle outState) { mGLRootView.lockRenderThread(); diff --git a/src/com/android/gallery3d/app/PhotoDataAdapter.java b/src/com/android/gallery3d/app/PhotoDataAdapter.java index fd3a7cf73..6fca527cb 100644 --- a/src/com/android/gallery3d/app/PhotoDataAdapter.java +++ b/src/com/android/gallery3d/app/PhotoDataAdapter.java @@ -747,7 +747,7 @@ public class PhotoDataAdapter implements PhotoPage.Model { // Must be an item in camera roll. if (!(mediaItem instanceof LocalMediaItem)) return false; LocalMediaItem item = (LocalMediaItem) mediaItem; - if (item.getBucketId() != MediaSetUtils.CAMERA_BUCKET_ID) return false; + if (item.getBucketId() != MediaSetUtils.getCameraBucketId()) return false; // Must have no size, but must have width and height information if (item.getSize() != 0) return false; if (item.getWidth() == 0) return false; diff --git a/src/com/android/gallery3d/app/StorageChangeReceiver.java b/src/com/android/gallery3d/app/StorageChangeReceiver.java new file mode 100644 index 000000000..b8a3ad7c4 --- /dev/null +++ b/src/com/android/gallery3d/app/StorageChangeReceiver.java @@ -0,0 +1,42 @@ +/* +* Copyright (C) 2014 The CyanogenMod Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.android.gallery3d.app; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +public class StorageChangeReceiver extends BroadcastReceiver { + public static final String KEY_STORAGE = "pref_camera_storage_key"; + + @Override + public void onReceive(Context context, Intent intent) { + String storagePath = intent.getExtras().getString(KEY_STORAGE, null); + SharedPreferences prefs = PreferenceManager + .getDefaultSharedPreferences(context); + + if (storagePath != null + && !storagePath.equals(prefs.getString(KEY_STORAGE, null))) { + SharedPreferences.Editor editor = prefs.edit(); + editor.putString(KEY_STORAGE, storagePath); + editor.apply(); + } + } + +} diff --git a/src/com/android/gallery3d/data/LocalAlbum.java b/src/com/android/gallery3d/data/LocalAlbum.java index 7b7015af6..0757d8883 100644 --- a/src/com/android/gallery3d/data/LocalAlbum.java +++ b/src/com/android/gallery3d/data/LocalAlbum.java @@ -95,7 +95,7 @@ public class LocalAlbum extends MediaSet { @Override public boolean isCameraRoll() { - return mBucketId == MediaSetUtils.CAMERA_BUCKET_ID; + return mBucketId == MediaSetUtils.getCameraBucketId(); } @Override @@ -279,7 +279,7 @@ public class LocalAlbum extends MediaSet { public static String getLocalizedName(Resources res, int bucketId, String name) { - if (bucketId == MediaSetUtils.CAMERA_BUCKET_ID) { + if (bucketId == MediaSetUtils.getCameraBucketId()) { return res.getString(R.string.folder_camera); } else if (bucketId == MediaSetUtils.DOWNLOAD_BUCKET_ID) { return res.getString(R.string.folder_download); @@ -297,7 +297,7 @@ public class LocalAlbum extends MediaSet { // Relative path is the absolute path minus external storage path public static String getRelativePath(int bucketId) { String relativePath = "/"; - if (bucketId == MediaSetUtils.CAMERA_BUCKET_ID) { + if (bucketId == MediaSetUtils.getCameraBucketId()) { relativePath += BucketNames.CAMERA; } else if (bucketId == MediaSetUtils.DOWNLOAD_BUCKET_ID) { relativePath += BucketNames.DOWNLOAD; diff --git a/src/com/android/gallery3d/data/LocalAlbumSet.java b/src/com/android/gallery3d/data/LocalAlbumSet.java index b2b4b8c5d..877eaff5c 100644 --- a/src/com/android/gallery3d/data/LocalAlbumSet.java +++ b/src/com/android/gallery3d/data/LocalAlbumSet.java @@ -113,7 +113,7 @@ public class LocalAlbumSet extends MediaSet int offset = 0; // Move camera and download bucket to the front, while keeping the // order of others. - int index = findBucket(entries, MediaSetUtils.CAMERA_BUCKET_ID); + int index = findBucket(entries, MediaSetUtils.getCameraBucketId()); if (index != -1) { circularShiftRight(entries, offset++, index); } diff --git a/src/com/android/gallery3d/data/SecureAlbum.java b/src/com/android/gallery3d/data/SecureAlbum.java index 204f848f8..bb505a50f 100644 --- a/src/com/android/gallery3d/data/SecureAlbum.java +++ b/src/com/android/gallery3d/data/SecureAlbum.java @@ -151,7 +151,7 @@ public class SecureAlbum extends MediaSet implements StitchingChangeListener { private boolean isCameraBucketEmpty(Uri baseUri) { Uri uri = baseUri.buildUpon() .appendQueryParameter("limit", "1").build(); - String[] selection = {String.valueOf(MediaSetUtils.CAMERA_BUCKET_ID)}; + String[] selection = {String.valueOf(MediaSetUtils.getCameraBucketId())}; Cursor cursor = mContext.getContentResolver().query(uri, PROJECTION, "bucket_id = ?", selection, null); if (cursor == null) return true; diff --git a/src/com/android/gallery3d/util/MediaSetUtils.java b/src/com/android/gallery3d/util/MediaSetUtils.java index 043800561..5cc1f8626 100644 --- a/src/com/android/gallery3d/util/MediaSetUtils.java +++ b/src/com/android/gallery3d/util/MediaSetUtils.java @@ -28,9 +28,12 @@ import java.util.Comparator; public class MediaSetUtils { public static final Comparator<MediaSet> NAME_COMPARATOR = new NameComparator(); - public static final int CAMERA_BUCKET_ID = GalleryUtils.getBucketId( - Environment.getExternalStorageDirectory().toString() + "/" - + BucketNames.CAMERA); + private static String mRoot = Environment.getExternalStorageDirectory().toString(); + + public static void setRoot(String root) { + mRoot = root; + } + public static final int DOWNLOAD_BUCKET_ID = GalleryUtils.getBucketId( Environment.getExternalStorageDirectory().toString() + "/" + BucketNames.DOWNLOAD); @@ -44,14 +47,14 @@ public class MediaSetUtils { Environment.getExternalStorageDirectory().toString() + "/" + BucketNames.SCREENSHOTS); - private static final Path[] CAMERA_PATHS = { - Path.fromString("/local/all/" + CAMERA_BUCKET_ID), - Path.fromString("/local/image/" + CAMERA_BUCKET_ID), - Path.fromString("/local/video/" + CAMERA_BUCKET_ID)}; + public static int getCameraBucketId() { + return GalleryUtils.getBucketId(mRoot + "/" + BucketNames.CAMERA); + } public static boolean isCameraSource(Path path) { - return CAMERA_PATHS[0] == path || CAMERA_PATHS[1] == path - || CAMERA_PATHS[2] == path; + return path.equalsIgnoreCase("/local/all/" + getCameraBucketId()) + || path.equalsIgnoreCase("/local/image/" + getCameraBucketId()) + || path.equalsIgnoreCase("/local/video/" + getCameraBucketId()); } // Sort MediaSets by name |