}
};
- private LocalDataAdapter.LocalDataListener mLocalDataListener =
+ private final LocalDataAdapter.LocalDataListener mLocalDataListener =
new LocalDataAdapter.LocalDataListener() {
@Override
public void onMetadataUpdated(List<Integer> updatedData) {
hideSessionProgress();
updateSessionProgress(0);
}
- mDataAdapter.refresh(CameraActivity.this, uri, /* isInProgress */ false);
+ mDataAdapter.refresh(uri, /* isInProgress */ false);
}
@Override
@Override
public void onSessionUpdated(Uri uri) {
- mDataAdapter.refresh(CameraActivity.this, uri, /* isInProgress */ true);
+ mDataAdapter.refresh(uri, /* isInProgress */ true);
}
};
String mimeType = cr.getType(uri);
if (mimeType.startsWith("video/")) {
sendBroadcast(new Intent(CameraUtil.ACTION_NEW_VIDEO, uri));
- mDataAdapter.addNewVideo(this, uri);
+ mDataAdapter.addNewVideo(uri);
} else if (mimeType.startsWith("image/")) {
CameraUtil.broadcastNewPicture(this, uri);
- mDataAdapter.addNewPhoto(this, uri);
+ mDataAdapter.addNewPhoto(uri);
} else if (mimeType.startsWith(PlaceholderManager.PLACEHOLDER_MIME_TYPE)) {
- mDataAdapter.addNewPhoto(this, uri);
+ mDataAdapter.addNewPhoto(uri);
} else {
android.util.Log.w(TAG, "Unknown new media with MIME type:"
+ mimeType + ", uri:" + uri);
}
private void removeData(int dataID) {
- mDataAdapter.removeData(CameraActivity.this, dataID);
+ mDataAdapter.removeData(dataID);
if (mDataAdapter.getTotalNumber() > 1) {
showUndoDeletionBar();
} else {
mPanoramaViewHelper = new PanoramaViewHelper(this);
mPanoramaViewHelper.onCreate();
// Set up the camera preview first so the preview shows up ASAP.
- mDataAdapter = new CameraDataAdapter(
+ mDataAdapter = new CameraDataAdapter(getApplicationContext(),
new ColorDrawable(getResources().getColor(R.color.photo_placeholder)));
mDataAdapter.setLocalDataListener(mLocalDataListener);
if (!mSecureCamera) {
mFilmstripController.setDataAdapter(mDataAdapter);
if (!isCaptureIntent()) {
- mDataAdapter.requestLoad(this);
+ mDataAdapter.requestLoad();
}
} else {
// Put a lock placeholder as the last image by setting its date to
}
});
mDataAdapter = new FixedLastDataAdapter(
+ getApplicationContext(),
mDataAdapter,
new SimpleViewData(
v,
// If it's secure camera, requestLoad() should not be called
// as it will load all the data.
if (!mFilmstripVisible) {
- mDataAdapter.requestLoad(this);
+ mDataAdapter.requestLoad();
}
}
}
return;
}
hideUndoDeletionBar(false);
- mDataAdapter.executeDeletion(CameraActivity.this);
+ mDataAdapter.executeDeletion();
}
public void showUndoDeletionBar() {
updateBottomControlsByData(currentData);
if (!mDataAdapter.isMetadataUpdated(dataId)) {
- mDataAdapter.updateMetadata(this, dataId);
+ mDataAdapter.updateMetadata(dataId);
}
}
package com.android.camera.data;
-import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
*/
public abstract class AbstractLocalDataAdapterWrapper implements LocalDataAdapter {
+ protected final Context mContext;
protected final LocalDataAdapter mAdapter;
protected int mSuggestedWidth;
protected int mSuggestedHeight;
/**
* Constructor.
*
- * @param wrappedAdapter The {@link LocalDataAdapter} to be wrapped.
+ * @param context A valid Android context.
+ * @param wrappedAdapter The {@link LocalDataAdapter} to be wrapped.
*/
- AbstractLocalDataAdapterWrapper(LocalDataAdapter wrappedAdapter) {
+ AbstractLocalDataAdapterWrapper(Context context, LocalDataAdapter wrappedAdapter) {
if (wrappedAdapter == null) {
throw new AssertionError("data adapter is null");
}
+ mContext = context;
mAdapter = wrappedAdapter;
}
}
@Override
- public void requestLoad(Context context) {
- mAdapter.requestLoad(context);
+ public void requestLoad() {
+ mAdapter.requestLoad();
}
@Override
- public void addNewVideo(Context context, Uri uri) {
- mAdapter.addNewVideo(context, uri);
+ public void addNewVideo(Uri uri) {
+ mAdapter.addNewVideo(uri);
}
@Override
- public void addNewPhoto(Context context, Uri uri) {
- mAdapter.addNewPhoto(context, uri);
+ public void addNewPhoto(Uri uri) {
+ mAdapter.addNewPhoto(uri);
}
@Override
}
@Override
- public boolean executeDeletion(Context context) {
- return mAdapter.executeDeletion(context);
+ public boolean executeDeletion() {
+ return mAdapter.executeDeletion();
}
@Override
}
@Override
- public void refresh(Context context, Uri uri, boolean isInProgressSession) {
- mAdapter.refresh(context, uri, isInProgressSession);
+ public void refresh(Uri uri, boolean isInProgressSession) {
+ mAdapter.refresh(uri, isInProgressSession);
}
@Override
- public void updateMetadata(Context context, int dataId) {
- mAdapter.updateMetadata(context, dataId);
+ public void updateMetadata(int dataId) {
+ mAdapter.updateMetadata(dataId);
}
@Override
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
-import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
private static final int DEFAULT_DECODE_SIZE = 1600;
private static final String[] CAMERA_PATH = { Storage.DIRECTORY + "%" };
+ private final Context mContext;
+
private LocalDataList mImages;
private Listener mListener;
private LocalData mLocalDataToDelete;
- public CameraDataAdapter(Drawable placeHolder) {
+ public CameraDataAdapter(Context context, Drawable placeHolder) {
+ mContext = context;
mImages = new LocalDataList();
mPlaceHolder = placeHolder;
}
}
@Override
- public void requestLoad(Context context) {
- QueryTask qtask = new QueryTask(context);
- qtask.execute(context.getContentResolver());
+ public void requestLoad() {
+ QueryTask qtask = new QueryTask();
+ qtask.execute(mContext.getContentResolver());
}
@Override
- public void updateMetadata(Context context, int dataId) {
- new MetadataUpdateTask(context).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, dataId);
+ public void updateMetadata(int dataId) {
+ new MetadataUpdateTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, dataId);
}
@Override
}
@Override
- public void removeData(Context c, int dataID) {
+ public void removeData(int dataID) {
if (dataID >= mImages.size()) {
return;
}
LocalData d = mImages.remove(dataID);
// Delete previously removed data first.
- executeDeletion(c);
+ executeDeletion();
mLocalDataToDelete = d;
mListener.onDataRemoved(dataID, d);
}
// TODO: put the database query on background thread
@Override
- public void addNewVideo(Context context, Uri uri) {
- Cursor c = context.getContentResolver().query(uri,
+ public void addNewVideo(Uri uri) {
+ Cursor cursor = mContext.getContentResolver().query(uri,
LocalMediaData.VideoData.QUERY_PROJECTION,
MediaStore.Images.Media.DATA + " like ? ", CAMERA_PATH,
LocalMediaData.VideoData.QUERY_ORDER);
- if (c == null || !c.moveToFirst()) {
+ if (cursor == null || !cursor.moveToFirst()) {
return;
}
int pos = findDataByContentUri(uri);
- LocalMediaData.VideoData newData = LocalMediaData.VideoData.buildFromCursor(c);
+ LocalMediaData.VideoData newData = LocalMediaData.VideoData.buildFromCursor(cursor);
if (pos != -1) {
// A duplicate one, just do a substitute.
updateData(pos, newData);
// TODO: put the database query on background thread
@Override
- public void addNewPhoto(Context context, Uri uri) {
- Cursor c = context.getContentResolver().query(uri,
+ public void addNewPhoto(Uri uri) {
+ Cursor cursor = mContext.getContentResolver().query(uri,
LocalMediaData.PhotoData.QUERY_PROJECTION,
MediaStore.Images.Media.DATA + " like ? ", CAMERA_PATH,
LocalMediaData.PhotoData.QUERY_ORDER);
LocalMediaData.PhotoData newData = null;
try {
- if (c == null || !c.moveToFirst()) {
+ if (cursor == null || !cursor.moveToFirst()) {
return;
}
- newData = LocalMediaData.PhotoData.buildFromCursor(context, c);
+ newData = LocalMediaData.PhotoData.buildFromCursor(mContext, cursor);
} finally {
// Ensure cursor is closed before returning
- if (c != null) {
- c.close();
+ if (cursor != null) {
+ cursor.close();
}
}
int pos = findDataByContentUri(uri);
}
@Override
- public boolean executeDeletion(Context c) {
+ public boolean executeDeletion() {
if (mLocalDataToDelete == null) return false;
- DeletionTask task = new DeletionTask(c);
+ DeletionTask task = new DeletionTask();
task.execute(mLocalDataToDelete);
mLocalDataToDelete = null;
return true;
}
@Override
- public void refresh(Context context, Uri contentUri,
- boolean isInProgressSession) {
+ public void refresh(Uri contentUri, boolean isInProgressSession) {
int pos = findDataByContentUri(contentUri);
if (pos == -1) {
return;
}
LocalData data = mImages.get(pos);
- LocalData refreshedData = data.refresh(context);
+ LocalData refreshedData = data.refresh(mContext);
// Wrap the data item if this represents a session that is in progress.
if (isInProgressSession) {
}
private class QueryTask extends AsyncTask<ContentResolver, Void, LocalDataList> {
- private Context mContext;
-
- public QueryTask(Context context) {
- super();
- mContext = context;
- }
-
/**
* Loads all the photo and video data in the camera folder in background
* and combine them into one single list.
}
private class DeletionTask extends AsyncTask<LocalData, Void, Void> {
- Context mContext;
-
- DeletionTask(Context context) {
- mContext = context;
- }
-
@Override
protected Void doInBackground(LocalData... data) {
for (int i = 0; i < data.length; i++) {
}
private class MetadataUpdateTask extends AsyncTask<Integer, Void, List<Integer> > {
- Context mContext;
-
- MetadataUpdateTask(Context context) {
- mContext = context;
- }
-
@Override
protected List<Integer> doInBackground(Integer... dataId) {
List<Integer> updatedList = new ArrayList<Integer>();
implements DataAdapter.Listener {
@SuppressWarnings("unused")
- private static final String TAG = "CAM_FixedFirstDataAdapter";
+ private static final String TAG = "FixedFirstDataAdapter";
private LocalData mFirstData;
private Listener mListener;
/**
* Constructor.
*
+ * @param context Valid Android context.
* @param wrappedAdapter The {@link LocalDataAdapter} to be wrapped.
- * @param firstData The {@link LocalData} to be placed at the first
- * position.
+ * @param firstData The {@link LocalData} to be placed at the first
+ * position.
*/
public FixedFirstDataAdapter(
+ Context context,
LocalDataAdapter wrappedAdapter,
LocalData firstData) {
- super(wrappedAdapter);
+ super(context, wrappedAdapter);
if (firstData == null) {
throw new AssertionError("data is null");
}
}
@Override
- public void removeData(Context context, int dataID) {
+ public void removeData(int dataID) {
if (dataID > 0) {
- mAdapter.removeData(context, dataID - 1);
+ mAdapter.removeData(dataID - 1);
}
}
}
@Override
- public void updateMetadata(Context context, int dataId) {
+ public void updateMetadata(int dataId) {
if (dataId > 0) {
- mAdapter.updateMetadata(context, dataId);
+ mAdapter.updateMetadata(dataId);
} else {
- MetadataLoader.loadMetadata(context, mFirstData);
+ MetadataLoader.loadMetadata(mContext, mFirstData);
}
}
/**
* Constructor.
*
- * @param wrappedAdapter The {@link LocalDataAdapter} to be wrapped.
- * @param lastData The {@link LocalData} to be placed at the last position.
+ * @param context A valid Android context.
+ * @param wrappedAdapter The {@link LocalDataAdapter} to be wrapped.
+ * @param lastData The {@link LocalData} to be placed at the last position.
*/
public FixedLastDataAdapter(
+ Context context,
LocalDataAdapter wrappedAdapter,
LocalData lastData) {
- super(wrappedAdapter);
+ super(context, wrappedAdapter);
if (lastData == null) {
throw new AssertionError("data is null");
}
}
@Override
- public void removeData(Context context, int dataID) {
+ public void removeData(int dataID) {
if (dataID < mAdapter.getTotalNumber()) {
- mAdapter.removeData(context, dataID);
+ mAdapter.removeData(dataID);
}
}
}
@Override
- public void updateMetadata(Context context, int dataId) {
+ public void updateMetadata(int dataId) {
if (dataId < mAdapter.getTotalNumber()) {
- mAdapter.updateMetadata(context, dataId);
+ mAdapter.updateMetadata(dataId);
} else {
- MetadataLoader.loadMetadata(context, mLastData);
+ MetadataLoader.loadMetadata(mContext, mLastData);
}
}
package com.android.camera.data;
-import android.content.Context;
import android.net.Uri;
import com.android.camera.filmstrip.DataAdapter;
import java.util.List;
/**
- * An interface which extends {@link com.android.camera.filmstrip.DataAdapter} and defines operations on
- * the data in the local camera folder.
+ * An interface which extends {@link com.android.camera.filmstrip.DataAdapter}
+ * and defines operations on the data in the local camera folder.
*/
public interface LocalDataAdapter extends DataAdapter {
public interface LocalDataListener {
/**
- * Metadata of a {@link com.android.camera.data.LocalData} is loaded
- * on demand. Once the metadata is loaded this listener is notified.
+ * Metadata of a {@link com.android.camera.data.LocalData} is loaded on
+ * demand. Once the metadata is loaded this listener is notified.
*
* @param updatedData The IDs of the data whose metadata has been
- * updated.
+ * updated.
*/
public void onMetadataUpdated(List<Integer> updatedData);
}
/**
* Request for loading the local data.
- *
- * @param context The Android {@link android.content.Context} this data
- * adapter is used in.
*/
- public void requestLoad(Context context);
+ public void requestLoad();
/**
* Returns the specified {@link LocalData}.
/**
* Remove the data in the local camera folder.
*
- * @param context {@link Context} used to remove the data.
- * @param dataID ID of data to be deleted.
+ * @param dataID ID of data to be deleted.
*/
- public void removeData(Context context, int dataID);
+ public void removeData(int dataID);
/**
* Add new local video data.
*
- * @param context The Android {@link android.content.Context} this data
- * adapter is used in.
- * @param uri {@link Uri} of the video.
+ * @param uri {@link Uri} of the video.
*/
- public void addNewVideo(Context context, Uri uri);
+ public void addNewVideo(Uri uri);
/**
* Adds new local photo data.
*
- * @param context The Android {@link android.content.Context} this data
- * adapter is used in.
- * @param uri {@link Uri} of the photo.
+ * @param uri {@link Uri} of the photo.
*/
- public void addNewPhoto(Context context, Uri uri);
+ public void addNewPhoto(Uri uri);
/**
* Refresh the data by {@link Uri}.
*
- * @param context The Android {@link android.content.Context}.
* @param uri The {@link Uri} of the data to refresh.
* @param isInProgressSession Whether this data item has a session in
* progress associated with it.
*/
- public void refresh(Context context, Uri uri, boolean isInProgressSession);
+ public void refresh(Uri uri, boolean isInProgressSession);
/**
* Finds the {@link LocalData} of the specified content Uri.
*
- * @param uri The content Uri of the {@link LocalData}.
- * @return The index of the data. {@code -1} if not found.
+ * @param uri The content Uri of the {@link LocalData}.
+ * @return The index of the data. {@code -1} if not found.
*/
public int findDataByContentUri(Uri uri);
public void flush();
/**
- * Executes the deletion task. Delete the data waiting in the deletion queue.
+ * Executes the deletion task. Delete the data waiting in the deletion
+ * queue.
*
- * @param context The {@link Context} from the caller.
- * @return {@code true} if task has been executed, {@code false}
- * otherwise.
+ * @return Whether the task has been executed
*/
- public boolean executeDeletion(Context context);
+ public boolean executeDeletion();
/**
* Undo a deletion. If there is any data waiting to be deleted in the queue,
* move it out of the deletion queue.
*
- * @return {@code true} if there are items in the queue, {@code false} otherwise.
+ * @return Whether there are items in the queue.
*/
public boolean undoDataRemoval();
* will be notified through
* {@link com.android.camera.data.LocalDataAdapter.LocalDataListener}.
*
- * @param context The Android {@link android.content.Context} to update
- * the metadata.
* @param dataId The ID of the data to update the metadata for.
*/
- public void updateMetadata(Context context, int dataId);
+ public void updateMetadata(int dataId);
/**
* @return whether the metadata is already updated.
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
if (mNeedsRefresh && mAdapter != null) {
- mAdapter.refresh(mContext, getContentUri(), mIsInProgressSession);
+ mAdapter.refresh(getContentUri(), mIsInProgressSession);
}
}
}