diff options
author | Mike Lockwood <lockwood@android.com> | 2010-11-19 12:31:00 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-11-19 12:31:00 -0800 |
commit | 04ee03d593f9367dad11410bfabc67132a71b0d1 (patch) | |
tree | 51b1a9b69190527cf2dba071e99fc7d0fb12a6c7 | |
parent | 7afe176a22d58dadac5785f8c4e8eaa292147825 (diff) | |
parent | 1d5dedc9e44fdccf0636cedac90529c0c5f6e166 (diff) | |
download | frameworks_base-04ee03d593f9367dad11410bfabc67132a71b0d1.zip frameworks_base-04ee03d593f9367dad11410bfabc67132a71b0d1.tar.gz frameworks_base-04ee03d593f9367dad11410bfabc67132a71b0d1.tar.bz2 |
Merge "CameraBrowser improvements:"
7 files changed, 116 insertions, 73 deletions
diff --git a/media/tests/CameraBrowser/res/layout/object_info.xml b/media/tests/CameraBrowser/res/layout/object_info.xml index ac210b9..a0499f2 100644 --- a/media/tests/CameraBrowser/res/layout/object_info.xml +++ b/media/tests/CameraBrowser/res/layout/object_info.xml @@ -153,5 +153,17 @@ <TableRow> <ImageView android:id="@+id/thumbnail" /> </TableRow> + <TableRow> + <Button android:id="@+id/import_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/import_label"> + </Button> + <Button android:id="@+id/delete_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/delete_label"> + </Button> + </TableRow> </TableLayout> diff --git a/media/tests/CameraBrowser/res/menu/object_menu.xml b/media/tests/CameraBrowser/res/menu/object_menu.xml deleted file mode 100644 index a0865f0..0000000 --- a/media/tests/CameraBrowser/res/menu/object_menu.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2010 The Android Open Source 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. ---> - -<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 cd477f1..7955773 100644 --- a/media/tests/CameraBrowser/res/values/strings.xml +++ b/media/tests/CameraBrowser/res/values/strings.xml @@ -32,9 +32,9 @@ <string name="modified_label">Modified: </string> <string name="keywords_label">Keywords: </string> - <!-- menu items --> - <string name="save_item">Save</string> - <string name="delete_item">Delete</string> + <!-- button labels --> + <string name="import_label">Import</string> + <string name="delete_label">Delete</string> <!-- toasts --> <string name="object_saved_message">Object saved</string> diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/DeviceDisconnectedReceiver.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/DeviceDisconnectedReceiver.java new file mode 100644 index 0000000..fb004c4 --- /dev/null +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/DeviceDisconnectedReceiver.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2010 The Android Open Source 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.camerabrowser; + +import android.app.Activity; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.hardware.Usb; +import android.net.Uri; + +public class DeviceDisconnectedReceiver extends BroadcastReceiver { + + private final Activity mActivity; + private final int mDeviceID; + + public DeviceDisconnectedReceiver(Activity activity, int deviceID) { + mActivity = activity; + mDeviceID = deviceID; + + IntentFilter filter = new IntentFilter(Usb.ACTION_USB_CAMERA_DETACHED); + filter.addDataScheme("content"); + activity.registerReceiver(this, filter); + } + + @Override + public void onReceive(Context context, Intent intent) { + // close our activity if the device it is displaying is disconnected + Uri uri = intent.getData(); + int id = Integer.parseInt(uri.getPathSegments().get(1)); + if (id == mDeviceID) { + mActivity.finish(); + } + } +}
\ No newline at end of file diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java index 6d34fd4..2060657 100644 --- a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java @@ -46,6 +46,7 @@ public class ObjectBrowser extends ListActivity { private int mDeviceID; private long mStorageID; private long mObjectID; + private DeviceDisconnectedReceiver mDisconnectedReceiver; private static final String[] OBJECT_COLUMNS = new String[] { Mtp.Object._ID, Mtp.Object.NAME, Mtp.Object.FORMAT, Mtp.Object.THUMB }; @@ -58,15 +59,17 @@ public class ObjectBrowser extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + mDeviceID = getIntent().getIntExtra("device", 0); + mStorageID = getIntent().getLongExtra("storage", 0); + mObjectID = getIntent().getLongExtra("object", 0); + mDisconnectedReceiver = new DeviceDisconnectedReceiver(this, mDeviceID); } @Override protected void onResume() { super.onResume(); - mDeviceID = getIntent().getIntExtra("device", 0); - mStorageID = getIntent().getLongExtra("storage", 0); - mObjectID = getIntent().getLongExtra("object", 0); if (mDeviceID != 0 && mStorageID != 0) { Cursor c; Uri uri; @@ -87,6 +90,12 @@ public class ObjectBrowser extends ListActivity { } @Override + protected void onDestroy() { + unregisterReceiver(mDisconnectedReceiver); + super.onDestroy(); + } + + @Override protected void onListItemClick(ListView l, View v, int position, long id) { long rowID = mAdapter.getItemId(position); Cursor c = getContentResolver().query( diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java index 2373ee6..4e63128 100644 --- a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java @@ -26,22 +26,19 @@ import android.os.Bundle; import android.os.Environment; 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.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import java.io.File; -import java.util.Calendar; import java.util.Date; /** * A view to display the properties of an object. */ -public class ObjectViewer extends Activity { +public class ObjectViewer extends Activity implements View.OnClickListener { private static final String TAG = "ObjectViewer"; @@ -49,6 +46,9 @@ public class ObjectViewer extends Activity { private long mStorageID; private long mObjectID; private String mFileName; + private Button mImportButton; + private Button mDeleteButton; + private DeviceDisconnectedReceiver mDisconnectedReceiver; private static final String[] OBJECT_COLUMNS = new String[] { Mtp.Object._ID, @@ -73,15 +73,21 @@ public class ObjectViewer extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.object_info); - } - @Override - protected void onResume() { - super.onResume(); + mImportButton = (Button)findViewById(R.id.import_button); + mImportButton.setOnClickListener(this); + mDeleteButton = (Button)findViewById(R.id.delete_button); + mDeleteButton.setOnClickListener(this); mDeviceID = getIntent().getIntExtra("device", 0); mStorageID = getIntent().getLongExtra("storage", 0); mObjectID = getIntent().getLongExtra("object", 0); + mDisconnectedReceiver = new DeviceDisconnectedReceiver(this, mDeviceID); + } + + @Override + protected void onResume() { + super.onResume(); if (mDeviceID != 0 && mObjectID != 0) { Cursor c = getContentResolver().query( @@ -129,41 +135,12 @@ public class ObjectViewer extends Activity { } @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.object_menu, menu); - return true; + protected void onDestroy() { + unregisterReceiver(mDisconnectedReceiver); + super.onDestroy(); } - @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() { + private void importObject() { // copy file to /mnt/sdcard/imported/<filename> File dest = Environment.getExternalStorageDirectory(); dest = new File(dest, "imported"); @@ -177,12 +154,14 @@ public class ObjectViewer extends Activity { if (resultUri != null) { Toast.makeText(this, R.string.object_saved_message, Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(Intent.ACTION_VIEW, resultUri); + startActivity(intent); } else { Toast.makeText(this, R.string.save_failed_message, Toast.LENGTH_SHORT).show(); } } - private void delete() { + private void deleteObject() { Uri uri = Mtp.Object.getContentUri(mDeviceID, mObjectID); Log.d(TAG, "deleting " + uri); @@ -195,4 +174,12 @@ public class ObjectViewer extends Activity { Toast.makeText(this, R.string.delete_failed_message, Toast.LENGTH_SHORT).show(); } } + + public void onClick(View v) { + if (v == mImportButton) { + importObject(); + } else if (v == mDeleteButton) { + deleteObject(); + } + } } diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java index 63e036e..4da88d6 100644 --- a/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java @@ -37,6 +37,7 @@ public class StorageBrowser extends ListActivity { private ListAdapter mAdapter; private int mDeviceID; + private DeviceDisconnectedReceiver mDisconnectedReceiver; private static final String[] STORAGE_COLUMNS = new String[] { Mtp.Storage._ID, Mtp.Storage.DESCRIPTION }; @@ -44,13 +45,14 @@ public class StorageBrowser extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mDeviceID = getIntent().getIntExtra("device", 0); + mDisconnectedReceiver = new DeviceDisconnectedReceiver(this, mDeviceID); } @Override protected void onResume() { super.onResume(); - mDeviceID = getIntent().getIntExtra("device", 0); if (mDeviceID != 0) { Cursor c = getContentResolver().query(Mtp.Storage.getContentUri(mDeviceID), STORAGE_COLUMNS, null, null, null); @@ -67,6 +69,12 @@ public class StorageBrowser extends ListActivity { } @Override + protected void onDestroy() { + unregisterReceiver(mDisconnectedReceiver); + super.onDestroy(); + } + + @Override protected void onListItemClick(ListView l, View v, int position, long id) { Intent intent = new Intent(this, ObjectBrowser.class); intent.putExtra("device", mDeviceID); |