Skip to content

Commit

Permalink
Merge "Add storage selection (1/2)" into cm-10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperb1iss authored and Gerrit Code Review committed Apr 13, 2013
2 parents 5b84d5e + d050f80 commit 9284adf
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 49 deletions.
3 changes: 3 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
<!-- Settings screen, Camcorder setting category title -->
<string name="pref_camcorder_settings_category">Camcorder settings</string>

<!-- More Settings screen, storage title -->
<string name="pref_camera_storage_title">Storage</string>

<!-- Settings screen, Picture size title -->
<string name="pref_camera_picturesize_title">Picture size</string>

Expand Down
3 changes: 3 additions & 0 deletions res/xml/camera_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,7 @@
camera:title="@string/pref_camera_scenemode_entry_hdr"
camera:entries="@array/pref_camera_hdr_entries"
camera:entryValues="@array/pref_camera_hdr_entryvalues" />
<StoragePreference
camera:key="pref_camera_storage_key"
camera:title="@string/pref_camera_storage_title" />
</PreferenceGroup>
3 changes: 3 additions & 0 deletions res/xml/video_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,7 @@
camera:title="@string/pref_camera_jpeg_title"
camera:entries="@array/pref_camera_jpeg_entries"
camera:entryValues="@array/pref_camera_jpeg_entryvalues" />
<StoragePreference
camera:key="pref_camera_storage_key"
camera:title="@string/pref_camera_storage_title" />
</PreferenceGroup>
8 changes: 5 additions & 3 deletions src/com/android/camera/ActivityBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ protected void installIntentFilter() {
}

protected void updateStorageSpace() {
mStorageSpace = Storage.getAvailableSpace();
mStorageSpace = Storage.getStorage().getAvailableSpace();
}

protected long getStorageSpace() {
Expand Down Expand Up @@ -380,7 +380,7 @@ public ScreenNail createCameraScreenNail(boolean getPictures) {
if (mSecureCamera) {
path = "/secure/all/" + sSecureAlbumId;
} else {
path = "/local/all/" + MediaSetUtils.CAMERA_BUCKET_ID;
path = "/local/all/" + Storage.getStorage().generateBucketIdInt();
}
} else {
path = "/local/all/0"; // Use 0 so gallery does not show anything.
Expand Down Expand Up @@ -414,7 +414,7 @@ protected ScreenNail reuseCameraScreenNail(boolean getPictures) {
if (mSecureCamera) {
path = "/secure/all/" + sSecureAlbumId;
} else {
path = "/local/all/" + MediaSetUtils.CAMERA_BUCKET_ID;
path = "/local/all/" + Storage.getStorage().generateBucketIdInt();
}
} else {
path = "/local/all/0"; // Use 0 so gallery does not show anything.
Expand All @@ -430,6 +430,8 @@ protected ScreenNail reuseCameraScreenNail(boolean getPictures) {
data.putParcelable(PhotoPage.KEY_APP_BRIDGE, mAppBridge);
if (getStateManager().getStateCount() == 0) {
getStateManager().startState(PhotoPage.class, data);
} else {
getStateManager().startStateNow(PhotoPage.class, data);
}
mCameraScreenNail = mAppBridge.getCameraScreenNail();
return mCameraScreenNail;
Expand Down
2 changes: 1 addition & 1 deletion src/com/android/camera/CameraPreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class CameraPreference {
private final Context mContext;

static public interface OnPreferenceChangedListener {
public void onSharedPreferenceChanged();
public void onSharedPreferenceChanged(String key);
public void onRestorePreferencesClicked();
public void onOverriddenPreferencesClicked();
public void onCameraPickerClicked(int cameraId);
Expand Down
7 changes: 7 additions & 0 deletions src/com/android/camera/CameraSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class CameraSettings {
public static final String KEY_COLOR_EFFECT = "pref_camera_coloreffect_key";
public static final String KEY_VIDEOCAMERA_COLOR_EFFECT = "pref_camera_video_coloreffect_key";
public static final String KEY_BURST_MODE = "pref_camera_burst_key";
public static final String KEY_STORAGE = "pref_camera_storage_key";

public static final String EXPOSURE_DEFAULT_VALUE = "0";
public static final String VALUE_ON = "on";
Expand Down Expand Up @@ -182,6 +183,7 @@ private void initPreference(PreferenceGroup group) {
ListPreference isoMode = group.findPreference(KEY_ISO_MODE);
ListPreference colorEffect = group.findPreference(KEY_COLOR_EFFECT);
ListPreference videoColorEffect = group.findPreference(KEY_VIDEOCAMERA_COLOR_EFFECT);
ListPreference storage = group.findPreference(KEY_STORAGE);

// Since the screen could be loaded from different resources, we need
// to check if the preference is available here
Expand Down Expand Up @@ -253,6 +255,11 @@ private void initPreference(PreferenceGroup group) {
filterUnsupportedOptions(group,
videoColorEffect, mParameters.getSupportedColorEffects());
}
if (storage != null) {
if (storage.getEntries().length < 2) {
removePreference(group, storage.getKey());
}
}
}

private void buildExposureCompensation(
Expand Down
3 changes: 2 additions & 1 deletion src/com/android/camera/ComboPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ private static boolean isGlobal(String key) {
|| key.equals(CameraSettings.KEY_RECORD_LOCATION)
|| key.equals(CameraSettings.KEY_CAMERA_FIRST_USE_HINT_SHOWN)
|| key.equals(CameraSettings.KEY_VIDEO_FIRST_USE_HINT_SHOWN)
|| key.equals(CameraSettings.KEY_VIDEO_EFFECT);
|| key.equals(CameraSettings.KEY_VIDEO_EFFECT)
|| key.equals(CameraSettings.KEY_STORAGE);
}

@Override
Expand Down
9 changes: 6 additions & 3 deletions src/com/android/camera/PanoramaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ public class PanoramaModule implements CameraModule,
private CameraProxy mCameraDevice;
private boolean mPaused;

private ComboPreferences mPreferences;

private class MosaicJpeg {
public MosaicJpeg(byte[] data, int width, int height) {
this.data = data;
Expand Down Expand Up @@ -228,6 +230,8 @@ public void init(CameraActivity activity, View parent, boolean reuseScreenNail)

createContentView();

mPreferences = new ComboPreferences(activity);

mContentResolver = mActivity.getContentResolver();
if (reuseScreenNail) {
mActivity.reuseCameraScreenNail(true);
Expand Down Expand Up @@ -866,8 +870,7 @@ private Uri savePanorama(byte[] jpegData, int width, int height, int orientation
if (jpegData != null) {
String filename = PanoUtil.createName(
mActivity.getResources().getString(R.string.pano_file_name_format), mTimeTaken);
String filepath = Storage.generateFilepath(filename);
Storage.writeFile(filepath, jpegData);
String filepath = Storage.getStorage().writeFile(filename, jpegData);

// Add Exif tags.
try {
Expand All @@ -886,7 +889,7 @@ private Uri savePanorama(byte[] jpegData, int width, int height, int orientation
}

int jpegLength = (int) (new File(filepath).length());
return Storage.addImage(mContentResolver, filename, mTimeTaken,
return Storage.getStorage().addImage(mContentResolver, filename, mTimeTaken,
null, orientation, jpegLength, filepath, width, height);
}
return null;
Expand Down
1 change: 1 addition & 0 deletions src/com/android/camera/PhotoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void onClick(PieItem item) {
mRenderer.addItem(hdr);
}
mOtherKeys = new String[] {
CameraSettings.KEY_STORAGE,
CameraSettings.KEY_SCENE_MODE,
CameraSettings.KEY_RECORD_LOCATION,
CameraSettings.KEY_POWER_SHUTTER,
Expand Down
30 changes: 18 additions & 12 deletions src/com/android/camera/PhotoModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,6 @@ public void init(CameraActivity activity, View parent, boolean reuseNail) {
// Surface texture is from camera screen nail and startPreview needs it.
// This must be done before startPreview.
mIsImageCaptureIntent = isImageCaptureIntent();
if (reuseNail) {
mActivity.reuseCameraScreenNail(!mIsImageCaptureIntent);
} else {
mActivity.createCameraScreenNail(!mIsImageCaptureIntent);
}

mPreferences.setLocalId(mActivity, mCameraId);
CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());
Expand All @@ -486,6 +481,12 @@ public void init(CameraActivity activity, View parent, boolean reuseNail) {
initializeMiscControls();
mLocationManager = new LocationManager(mActivity, this);
initOnScreenIndicator();

if (reuseNail) {
mActivity.reuseCameraScreenNail(!mIsImageCaptureIntent);
} else {
mActivity.createCameraScreenNail(!mIsImageCaptureIntent);
}
}

// Prompt the user to pick to record location for the very first run of
Expand Down Expand Up @@ -532,7 +533,7 @@ private void setLocationPreference(String value) {
.apply();
// TODO: Fix this to use the actual onSharedPreferencesChanged listener
// instead of invoking manually
onSharedPreferenceChanged();
onSharedPreferenceChanged(RecordLocationPreference.KEY);
}

private void initializeRenderOverlay() {
Expand Down Expand Up @@ -660,7 +661,7 @@ private void addIdleHandler() {
queue.addIdleHandler(new MessageQueue.IdleHandler() {
@Override
public boolean queueIdle() {
Storage.ensureOSXCompatible();
Storage.getStorage().ensureOSXCompatible();
return false;
}
});
Expand Down Expand Up @@ -1171,7 +1172,7 @@ public void finish() {
// Runs in saver thread
private void storeImage(final byte[] data, Uri uri, String title,
Location loc, int width, int height, int orientation) {
boolean ok = Storage.updateImage(mContentResolver, uri, title, loc,
boolean ok = Storage.getStorage().updateImage(mContentResolver, uri, title, loc,
orientation, data, width, height);
if (ok) {
Util.broadcastNewPicture(mActivity, uri);
Expand Down Expand Up @@ -1261,14 +1262,14 @@ public synchronized void finish() {
// Runs in namer thread
private void generateUri() {
mTitle = Util.createJpegName(mDateTaken);
mUri = Storage.newImage(mResolver, mTitle, mDateTaken, mWidth, mHeight);
mUri = Storage.getStorage().newImage(mResolver, mTitle, mDateTaken, mWidth, mHeight);
sHDRShotsPaths.add(mUri);
}

// Runs in namer thread
private void cleanOldUri() {
if (mUri == null) return;
Storage.deleteImage(mResolver, mUri);
Storage.getStorage().deleteImage(mResolver, mUri);
mUri = null;
}
}
Expand Down Expand Up @@ -1724,7 +1725,7 @@ public void run() {

// delete source images
for (int i = 0; i < sHDRShotsPaths.size()-1; i++) {
Storage.deleteImage(mContentResolver, sHDRShotsPaths.get(i));
Storage.getStorage().deleteImage(mContentResolver, sHDRShotsPaths.get(i));
}

// reset exposure
Expand Down Expand Up @@ -2659,14 +2660,19 @@ private void hidePostCaptureAlert() {
}

@Override
public void onSharedPreferenceChanged() {
public void onSharedPreferenceChanged(String key) {
// ignore the events after "onPause()"
if (mPaused) return;

boolean recordLocation = RecordLocationPreference.get(
mPreferences, mContentResolver);
mLocationManager.recordLocation(recordLocation);

if (CameraSettings.KEY_STORAGE.equals(key)) {
mActivity.updateStorageSpaceAndHint();
mActivity.reuseCameraScreenNail(!mIsImageCaptureIntent);
}

setCameraParametersWhenIdle(UPDATE_PARAM_PREFERENCE);
setPreviewFrameLayoutAspectRatio();
updateOnScreenIndicators();
Expand Down
2 changes: 1 addition & 1 deletion src/com/android/camera/PieController.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void initialize(PreferenceGroup group) {

public void onSettingChanged(ListPreference pref) {
if (mListener != null) {
mListener.onSharedPreferenceChanged();
mListener.onSharedPreferenceChanged(pref.getKey());
}
}

Expand Down
Loading

0 comments on commit 9284adf

Please sign in to comment.