Merge "CameraBrowser improvements:"

This commit is contained in:
Mike Lockwood
2010-11-19 12:31:00 -08:00
committed by Android (Google) Code Review
7 changed files with 116 additions and 73 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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();
}
}
}

View File

@ -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;
@ -86,6 +89,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);

View File

@ -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,16 +73,22 @@ public class ObjectViewer extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.object_info);
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();
mDeviceID = getIntent().getIntExtra("device", 0);
mStorageID = getIntent().getLongExtra("storage", 0);
mObjectID = getIntent().getLongExtra("object", 0);
if (mDeviceID != 0 && mObjectID != 0) {
Cursor c = getContentResolver().query(
Mtp.Object.getContentUri(mDeviceID, mObjectID),
@ -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();
}
}
}

View File

@ -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);
@ -66,6 +68,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);