summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2010-07-26 20:43:26 -0400
committerMike Lockwood <lockwood@android.com>2010-07-26 20:43:26 -0400
commitad0643a330db13c8f11b1a71fbb7262570114f4d (patch)
treefda7e1e8049e2ab51cd1a67e60231b0eaf7d8f07 /media
parentbc4cb0bc79c0d366d6866fe4054a71e00d169ff9 (diff)
downloadframeworks_base-ad0643a330db13c8f11b1a71fbb7262570114f4d.zip
frameworks_base-ad0643a330db13c8f11b1a71fbb7262570114f4d.tar.gz
frameworks_base-ad0643a330db13c8f11b1a71fbb7262570114f4d.tar.bz2
CameraBrowser: Add support for copying files from camera to internal storage.
Change-Id: I00b765afec0558dfe27961bd0b2e01473c29fc22 Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'media')
-rw-r--r--media/tests/CameraBrowser/AndroidManifest.xml2
-rw-r--r--media/tests/CameraBrowser/res/menu/object_menu.xml2
-rw-r--r--media/tests/CameraBrowser/res/values/strings.xml3
-rw-r--r--media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java45
-rw-r--r--media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java142
5 files changed, 143 insertions, 51 deletions
diff --git a/media/tests/CameraBrowser/AndroidManifest.xml b/media/tests/CameraBrowser/AndroidManifest.xml
index dbbd62a..5a71179 100644
--- a/media/tests/CameraBrowser/AndroidManifest.xml
+++ b/media/tests/CameraBrowser/AndroidManifest.xml
@@ -1,6 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.camerabrowser">
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+
<application android:label="@string/app_label">
<activity android:name="CameraBrowser" android:label="Camera Browser">
<intent-filter>
diff --git a/media/tests/CameraBrowser/res/menu/object_menu.xml b/media/tests/CameraBrowser/res/menu/object_menu.xml
index caea4ab..a0865f0 100644
--- a/media/tests/CameraBrowser/res/menu/object_menu.xml
+++ b/media/tests/CameraBrowser/res/menu/object_menu.xml
@@ -16,6 +16,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/save"
+ android:title="@string/save_item" />
<item android:id="@+id/delete"
android:title="@string/delete_item" />
</menu>
diff --git a/media/tests/CameraBrowser/res/values/strings.xml b/media/tests/CameraBrowser/res/values/strings.xml
index 8f94e6c..56c5111 100644
--- a/media/tests/CameraBrowser/res/values/strings.xml
+++ b/media/tests/CameraBrowser/res/values/strings.xml
@@ -32,9 +32,12 @@
<string name="keywords_label">Keywords: </string>
<!-- menu items -->
+ <string name="save_item">Save</string>
<string name="delete_item">Delete</string>
<!-- toasts -->
+ <string name="object_saved_message">Object saved</string>
+ <string name="save_failed_message">Could not save object</string>
<string name="object_deleted_message">Object deleted</string>
<string name="delete_failed_message">Could not delete object</string>
diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java
index 34f8fff..a002028 100644
--- a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java
+++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java
@@ -26,16 +26,12 @@ import android.net.Uri;
import android.os.Bundle;
import android.provider.Mtp;
import android.util.Log;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;
-import android.widget.Toast;
/**
* A list view displaying all objects within a container (folder or storage unit).
@@ -119,47 +115,6 @@ public class ObjectBrowser extends ListActivity {
}
}
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.object_menu, menu);
- return true;
- }
-
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- int position = mList.getSelectedItemPosition();
- MenuItem item = menu.findItem(R.id.delete);
- item.setEnabled(position != AdapterView.INVALID_POSITION);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.delete:
- deleteSelected();
- return true;
- }
- return false;
- }
-
- private void deleteSelected() {
- int position = mList.getSelectedItemPosition();
- int rowID = (int)mAdapter.getItemId(position);
- Uri uri = Mtp.Object.getContentUri(mDeviceID, rowID);
-
- Log.d(TAG, "deleting " + uri);
-
- int result = getContentResolver().delete(uri, null, null);
- if (result > 0) {
- Toast.makeText(this, R.string.object_deleted_message, Toast.LENGTH_SHORT).show();
- mCursor.requery();
- } else {
- Toast.makeText(this, R.string.delete_failed_message, Toast.LENGTH_SHORT).show();
- }
- }
-
private class ObjectCursorAdapter extends ResourceCursorAdapter {
public ObjectCursorAdapter(Context context, Cursor c) {
diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java
index 3033c54..af18196 100644
--- a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java
+++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java
@@ -22,12 +22,25 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
+import android.os.Environment;
+import android.os.FileUtils;
+import android.os.ParcelFileDescriptor;
+import android.os.Process;
import android.provider.Mtp;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
+import android.widget.Toast;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.Calendar;
import java.util.Date;
/**
@@ -106,18 +119,135 @@ public class ObjectViewer extends Activity {
view.setText(c.getString(12));
byte[] thumbnail = c.getBlob(13);
if (thumbnail != null) {
- Log.d(TAG, "got thumbnail, length: " + thumbnail.length);
- for (int i = 0; i < 50; i++) {
- Log.d(TAG, " " + Integer.toHexString(thumbnail[i]));
- }
-
ImageView thumbView = (ImageView)findViewById(R.id.thumbnail);
Bitmap bitmap = BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length);
- Log.d(TAG, "bitmap: " + bitmap);
if (bitmap != null) {
thumbView.setImageBitmap(bitmap);
}
}
}
}
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.object_menu, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ MenuItem item = menu.findItem(R.id.save);
+ item.setEnabled(true);
+ item = menu.findItem(R.id.delete);
+ item.setEnabled(true);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.save:
+ save();
+ return true;
+ case R.id.delete:
+ delete();
+ return true;
+ }
+ return false;
+ }
+
+ private static String getTimestamp() {
+ Calendar c = Calendar.getInstance();
+ c.setTimeInMillis(System.currentTimeMillis());
+ return String.format("%tY-%tm-%td-%tH-%tM-%tS", c, c, c, c, c, c);
+ }
+
+ private void save() {
+ boolean success = false;
+ Uri uri = Mtp.Object.getContentUri(mDeviceID, mObjectID);
+ File destFile = null;
+ ParcelFileDescriptor pfd = null;
+ FileInputStream fis = null;
+ FileOutputStream fos = null;
+
+ try {
+ pfd = getContentResolver().openFileDescriptor(uri, "r");
+ Log.d(TAG, "save got pfd " + pfd);
+ if (pfd != null) {
+ fis = new FileInputStream(pfd.getFileDescriptor());
+ Log.d(TAG, "save got fis " + fis);
+ File destDir = Environment.getExternalStoragePublicDirectory(
+ Environment.DIRECTORY_DCIM);
+ destDir.mkdirs();
+ destFile = new File(destDir, "CameraBrowser-" + getTimestamp() + ".jpeg");
+
+
+ Log.d(TAG, "save got destFile " + destFile);
+
+ if (destFile.exists()) {
+ destFile.delete();
+ }
+ fos = new FileOutputStream(destFile);
+
+ byte[] buffer = new byte[65536];
+ int bytesRead;
+ while ((bytesRead = fis.read(buffer)) >= 0) {
+ Log.d(TAG, "copying the bytes numbering " + bytesRead);
+ fos.write(buffer, 0, bytesRead);
+ }
+
+ // temporary workaround until we straighten out permissions in /data/media
+ // 1015 is AID_SDCARD_RW
+ FileUtils.setPermissions(destDir.getPath(), 0775, Process.myUid(), 1015);
+ FileUtils.setPermissions(destFile.getPath(), 0664, Process.myUid(), 1015);
+
+ success = true;
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Exception in ObjectView.save", e);
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (Exception e) {
+ }
+ }
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (Exception e) {
+ }
+ }
+ if (pfd != null) {
+ try {
+ pfd.close();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ if (success) {
+ Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ intent.setData(Uri.fromFile(destFile));
+ sendBroadcast(intent);
+ Toast.makeText(this, R.string.object_saved_message, Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(this, R.string.save_failed_message, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ private void delete() {
+ Uri uri = Mtp.Object.getContentUri(mDeviceID, mObjectID);
+
+ Log.d(TAG, "deleting " + uri);
+
+ int result = getContentResolver().delete(uri, null, null);
+ if (result > 0) {
+ Toast.makeText(this, R.string.object_deleted_message, Toast.LENGTH_SHORT).show();
+ finish();
+ } else {
+ Toast.makeText(this, R.string.delete_failed_message, Toast.LENGTH_SHORT).show();
+ }
+ }
}