summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/CameraActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/camera/CameraActivity.java')
-rw-r--r--src/com/android/camera/CameraActivity.java103
1 files changed, 95 insertions, 8 deletions
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index 18c4237db..cf5b0cffc 100644
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -44,9 +44,13 @@ import android.nfc.NfcEvent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
+import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
+import android.os.storage.StorageEventListener;
+import android.os.storage.StorageManager;
+import android.os.storage.StorageVolume;
import android.provider.MediaStore;
import android.provider.Settings;
import android.text.TextUtils;
@@ -125,6 +129,7 @@ import com.android.camera.settings.Keys;
import com.android.camera.settings.PictureSizeLoader;
import com.android.camera.settings.ResolutionSetting;
import com.android.camera.settings.ResolutionUtil;
+import com.android.camera.settings.SettingsUtil;
import com.android.camera.settings.SettingsManager;
import com.android.camera.stats.UsageStatistics;
import com.android.camera.stats.profiler.Profile;
@@ -183,6 +188,8 @@ public class CameraActivity extends QuickActivity
"android.media.action.STILL_IMAGE_CAMERA_SECURE";
public static final String ACTION_IMAGE_CAPTURE_SECURE =
"android.media.action.IMAGE_CAPTURE_SECURE";
+ public static final String INTENT_GALLERY3D_STORAGE_CHANGE =
+ "com.android.gallery3d.STORAGE_CHANGE";
// The intent extra for camera from secure lock screen. True if the gallery
// should only show newly captured pictures. sSecureAlbumId does not
@@ -240,6 +247,8 @@ public class CameraActivity extends QuickActivity
private Intent mResultDataForTesting;
private OnScreenHint mStorageHint;
private final Object mStorageSpaceLock = new Object();
+ private String mStoragePath;
+ private StorageManager mStorageManager;
private long mStorageSpaceBytes = Storage.LOW_STORAGE_THRESHOLD_BYTES;
private boolean mAutoRotateScreen;
private boolean mSecureCamera;
@@ -580,6 +589,10 @@ public class CameraActivity extends QuickActivity
initPowerShutter();
} else if (key.equals(Keys.KEY_MAX_BRIGHTNESS)) {
initMaxBrightness();
+ } else if (key.equals(Keys.KEY_STORAGE)) {
+ if (setStoragePath()) {
+ updateStorageSpaceAndHint(null);
+ }
}
}
@@ -1679,6 +1692,8 @@ public class CameraActivity extends QuickActivity
mMotionManager = getServices().getMotionManager();
+ syncStorageSettings();
+
mFirstRunDialog = new FirstRunDialog(this,
getAndroidContext(),
mResolutionSetting,
@@ -1882,6 +1897,8 @@ public class CameraActivity extends QuickActivity
@Override
public void onResumeTasks() {
mPaused = false;
+
+ setStoragePath();
checkPermissions();
if (!mHasCriticalPermissions) {
Log.v(TAG, "onResume: Missing critical permissions.");
@@ -1946,14 +1963,6 @@ public class CameraActivity extends QuickActivity
mDataAdapter);
if (!mSecureCamera) {
mFilmstripController.setDataAdapter(mDataAdapter);
- if (!isCaptureIntent()) {
- mDataAdapter.requestLoad(new Callback<Void>() {
- @Override
- public void onCallback(Void result) {
- fillTemporarySessions();
- }
- });
- }
} else {
// Put a lock placeholder as the last image by setting its date to
// 0.
@@ -2186,6 +2195,9 @@ public class CameraActivity extends QuickActivity
if (mSecureCamera) {
unregisterReceiver(mShutdownReceiver);
}
+ if (mStorageManager != null) {
+ mStorageManager.unregisterListener(mStorageEventListener);
+ }
// Ensure anything that checks for "isPaused" returns true.
mPaused = true;
@@ -3063,4 +3075,79 @@ public class CameraActivity extends QuickActivity
boolean showDetails = data.getAttributes().hasDetailedCaptureInfo();
detailsMenuItem.setVisible(showDetails);
}
+
+ protected boolean setStoragePath() {
+ String storagePath = mSettingsManager.getString(SettingsManager.SCOPE_GLOBAL,
+ Keys.KEY_STORAGE);
+ Storage.setRoot(storagePath);
+ if (storagePath.equals(mStoragePath)) {
+ return false;
+ }
+ mStoragePath = storagePath;
+
+ // Sync the swipe preview with the right path
+ if (mDataAdapter != null) {
+ if (!mSecureCamera) {
+ mDataAdapter.requestLoad(new Callback<Void>() {
+ @Override
+ public void onCallback(Void result) {
+ fillTemporarySessions();
+ }
+ });
+ }
+ }
+
+ // Update the gallery app
+ Intent intent = new Intent(INTENT_GALLERY3D_STORAGE_CHANGE);
+ intent.putExtra(Keys.KEY_STORAGE, mStoragePath);
+ sendBroadcast(intent);
+ return true;
+ }
+
+ protected void syncStorageSettings() {
+ if (mStorageManager == null) {
+ mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
+ mStorageManager.registerListener(mStorageEventListener);
+ }
+ StorageVolume[] volumes = mStorageManager.getVolumeList();
+ List<String> values = new ArrayList<String>(volumes.length);
+ List<StorageVolume> mountedVolumes = new ArrayList<StorageVolume>(volumes.length);
+
+ // Find all mounted volumes
+ String defaultValue = Environment.getExternalStorageDirectory().toString();
+ for (int i = 0; i < volumes.length; i++) {
+ StorageVolume v = volumes[i];
+ if (mStorageManager.getVolumeState(v.getPath()).equals(Environment.MEDIA_MOUNTED)) {
+ values.add(v.getPath());
+ mountedVolumes.add(v);
+ if (v.isPrimary()) {
+ defaultValue = v.getPath();
+ }
+ }
+ }
+ SettingsUtil.setMountedStorageVolumes(mountedVolumes);
+
+ mSettingsManager.setDefaults(Keys.KEY_STORAGE, defaultValue,
+ values.toArray(new String[values.size()]));
+
+ // Check if current volume is mounted. If not, restore the default storage path.
+ try {
+ mSettingsManager.getIndexOfCurrentValue(SettingsManager.SCOPE_GLOBAL,
+ Keys.KEY_STORAGE);
+ } catch (IllegalStateException e) {
+ mSettingsManager.setToDefault(SettingsManager.SCOPE_GLOBAL, Keys.KEY_STORAGE);
+ }
+
+ if (setStoragePath()) {
+ updateStorageSpaceAndHint(null);
+ }
+ }
+
+ private StorageEventListener mStorageEventListener = new StorageEventListener () {
+ @Override
+ public void onStorageStateChanged(String path, String oldState, String newState) {
+ Log.v(TAG, "onStorageStateChanged: " + path + "(" + oldState + "->" + newState + ")");
+ syncStorageSettings();
+ }
+ };
}