am 65d2a4cb: Remove CameraBrowser test app
* commit '65d2a4cb5f10a3964f66628be859bc150ec8921e': Remove CameraBrowser test app
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-subdir-java-files)
|
||||
|
||||
LOCAL_PACKAGE_NAME := CameraBrowser
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
@@ -1,28 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.camerabrowser">
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_USB" />
|
||||
|
||||
<application android:label="@string/app_label">
|
||||
<activity android:name="CameraBrowser" android:label="Camera Browser">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name="StorageBrowser" />
|
||||
<activity android:name="ObjectBrowser" />
|
||||
<activity android:name="ObjectViewer" />
|
||||
|
||||
<receiver android:name="UsbReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.hardware.action.USB_CAMERA_ATTACHED" />
|
||||
<data android:scheme="content"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
|
||||
|
||||
</manifest>
|
||||
@@ -1,169 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
** Copyright 2008, 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.
|
||||
*/
|
||||
-->
|
||||
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/object_info"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/name_label"
|
||||
android:text="@string/name_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/name"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/size_label"
|
||||
android:text="@string/size_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/size"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/format_label"
|
||||
android:text="@string/format_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/format"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/thumb_width_label"
|
||||
android:text="@string/thumb_width_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/thumb_width"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/thumb_height_label"
|
||||
android:text="@string/thumb_height_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/thumb_height"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/thumb_size_label"
|
||||
android:text="@string/thumb_size_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/thumb_size"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/width_label"
|
||||
android:text="@string/width_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/width"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/height_label"
|
||||
android:text="@string/height_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/height"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/depth_label"
|
||||
android:text="@string/depth_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/depth"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/sequence_label"
|
||||
android:text="@string/sequence_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/sequence"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/created_label"
|
||||
android:text="@string/created_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/created"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/modified_label"
|
||||
android:text="@string/modified_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/modified"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView android:id="@+id/keywords_label"
|
||||
android:text="@string/keywords_label"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="8dip"
|
||||
style="@style/info_label" />
|
||||
|
||||
<TextView android:id="@+id/keywords"
|
||||
style="@style/info_value" />
|
||||
</TableRow>
|
||||
<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>
|
||||
|
||||
@@ -1,33 +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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<ImageView android:id="@+id/thumbnail"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="6dip"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight" />
|
||||
</LinearLayout>
|
||||
@@ -1,46 +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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<string name="app_label">Camera Browser</string>
|
||||
|
||||
<!-- for object info -->
|
||||
<string name="name_label">Name: </string>
|
||||
<string name="size_label">Size: </string>
|
||||
<string name="format_label">Format: </string>
|
||||
<string name="thumb_width_label">Thumb Width: </string>
|
||||
<string name="thumb_height_label">Thumb Height: </string>
|
||||
<string name="thumb_size_label">Thumb Size: </string>
|
||||
<string name="width_label">Width: </string>
|
||||
<string name="height_label">Height: </string>
|
||||
<string name="depth_label">Depth: </string>
|
||||
<string name="sequence_label">Sequence: </string>
|
||||
<string name="created_label">Created: </string>
|
||||
<string name="modified_label">Modified: </string>
|
||||
<string name="keywords_label">Keywords: </string>
|
||||
|
||||
<!-- button labels -->
|
||||
<string name="import_label">Import</string>
|
||||
<string name="delete_label">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>
|
||||
<string name="start_activity_failed_message">Import succeeded, but could not display object</string>
|
||||
|
||||
</resources>
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2008 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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<style name="info_label">
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:textSize">14sp</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
<item name="android:paddingRight">4dip</item>
|
||||
</style>
|
||||
|
||||
<style name="info_value">
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:textSize">14sp</item>
|
||||
<item name="android:textStyle">normal</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* 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.ListActivity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.database.ContentObserver;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Ptp;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleCursorAdapter;
|
||||
|
||||
/**
|
||||
* A list view displaying all connected cameras.
|
||||
*/
|
||||
public class CameraBrowser extends ListActivity {
|
||||
|
||||
private static final String TAG = "CameraBrowser";
|
||||
|
||||
private ListAdapter mAdapter;
|
||||
private ContentResolver mResolver;
|
||||
private DeviceObserver mDeviceObserver;
|
||||
private Cursor mCursor;
|
||||
|
||||
private class DeviceObserver extends ContentObserver {
|
||||
DeviceObserver(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
Log.d(TAG, "DeviceObserver.onChange");
|
||||
if (mCursor != null) {
|
||||
mCursor.requery();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String[] DEVICE_COLUMNS =
|
||||
new String[] { Ptp.Device._ID, Ptp.Device.MANUFACTURER, Ptp.Device.MODEL };
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mResolver = getContentResolver();
|
||||
mDeviceObserver = new DeviceObserver(new Handler());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Cursor c = getContentResolver().query(Ptp.Device.CONTENT_URI,
|
||||
DEVICE_COLUMNS, null, null, null);
|
||||
Log.d(TAG, "query returned " + c);
|
||||
startManagingCursor(c);
|
||||
mCursor = c;
|
||||
|
||||
// Map Cursor columns to views defined in simple_list_item_2.xml
|
||||
mAdapter = new SimpleCursorAdapter(this,
|
||||
android.R.layout.simple_list_item_2, c,
|
||||
new String[] { Ptp.Device.MANUFACTURER, Ptp.Device.MODEL },
|
||||
new int[] { android.R.id.text1, android.R.id.text2 });
|
||||
setListAdapter(mAdapter);
|
||||
|
||||
// register for changes to the device list
|
||||
mResolver.registerContentObserver(Ptp.Device.CONTENT_URI, true, mDeviceObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mResolver.unregisterContentObserver(mDeviceObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
Intent intent = new Intent(this, StorageBrowser.class);
|
||||
intent.putExtra("device", (int)mAdapter.getItemId(position));
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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.UsbManager;
|
||||
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(UsbManager.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* 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.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.mtp.MtpConstants;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Ptp;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ResourceCursorAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* A list view displaying all objects within a container (folder or storage unit).
|
||||
*/
|
||||
public class ObjectBrowser extends ListActivity {
|
||||
|
||||
private static final String TAG = "ObjectBrowser";
|
||||
|
||||
private Cursor mCursor;
|
||||
private ObjectCursorAdapter mAdapter;
|
||||
private int mDeviceID;
|
||||
private long mStorageID;
|
||||
private long mObjectID;
|
||||
private DeviceDisconnectedReceiver mDisconnectedReceiver;
|
||||
|
||||
private static final String[] OBJECT_COLUMNS =
|
||||
new String[] { Ptp.Object._ID, Ptp.Object.NAME, Ptp.Object.FORMAT, Ptp.Object.THUMB };
|
||||
|
||||
static final int ID_COLUMN = 0;
|
||||
static final int NAME_COLUMN = 1;
|
||||
static final int FORMAT_COLUMN = 2;
|
||||
static final int THUMB_COLUMN = 3;
|
||||
|
||||
@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();
|
||||
|
||||
if (mDeviceID != 0 && mStorageID != 0) {
|
||||
Cursor c;
|
||||
Uri uri;
|
||||
if (mObjectID == 0) {
|
||||
uri = Ptp.Object.getContentUriForStorageChildren(mDeviceID, mStorageID);
|
||||
} else {
|
||||
uri = Ptp.Object.getContentUriForObjectChildren(mDeviceID, mObjectID);
|
||||
}
|
||||
Log.d(TAG, "query " + uri);
|
||||
c = getContentResolver().query(uri, OBJECT_COLUMNS, null, null, null);
|
||||
startManagingCursor(c);
|
||||
mCursor = c;
|
||||
|
||||
// Map Cursor columns to views defined in simple_list_item_1.xml
|
||||
mAdapter = new ObjectCursorAdapter(this, c);
|
||||
setListAdapter(mAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
@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(
|
||||
Ptp.Object.getContentUri(mDeviceID, rowID),
|
||||
OBJECT_COLUMNS, null, null, null);
|
||||
Log.d(TAG, "query returned " + c + " count: " + c.getCount());
|
||||
long format = 0;
|
||||
if (c != null && c.getCount() == 1) {
|
||||
c.moveToFirst();
|
||||
long rowId = c.getLong(ID_COLUMN);
|
||||
String name = c.getString(NAME_COLUMN);
|
||||
format = c.getLong(FORMAT_COLUMN);
|
||||
Log.d(TAG, "rowId: " + rowId + " name: " + name + " format: " + format);
|
||||
}
|
||||
if (format == MtpConstants.FORMAT_ASSOCIATION) {
|
||||
Intent intent = new Intent(this, ObjectBrowser.class);
|
||||
intent.putExtra("device", mDeviceID);
|
||||
intent.putExtra("storage", mStorageID);
|
||||
intent.putExtra("object", rowID);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(this, ObjectViewer.class);
|
||||
intent.putExtra("device", mDeviceID);
|
||||
intent.putExtra("storage", mStorageID);
|
||||
intent.putExtra("object", rowID);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private class ObjectCursorAdapter extends ResourceCursorAdapter {
|
||||
|
||||
public ObjectCursorAdapter(Context context, Cursor c) {
|
||||
super(context, R.layout.object_list, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
ImageView thumbView = (ImageView)view.findViewById(R.id.thumbnail);
|
||||
TextView nameView = (TextView)view.findViewById(R.id.name);
|
||||
|
||||
// get the thumbnail
|
||||
byte[] thumbnail = cursor.getBlob(THUMB_COLUMN);
|
||||
if (thumbnail != null) {
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length);
|
||||
if (bitmap != null) {
|
||||
thumbView.setImageBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
// get the name
|
||||
String name = cursor.getString(NAME_COLUMN);
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
nameView.setText(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* 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.ActivityNotFoundException;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.Ptp;
|
||||
import android.util.Log;
|
||||
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.Date;
|
||||
|
||||
/**
|
||||
* A view to display the properties of an object.
|
||||
*/
|
||||
public class ObjectViewer extends Activity implements View.OnClickListener {
|
||||
|
||||
private static final String TAG = "ObjectViewer";
|
||||
|
||||
private int mDeviceID;
|
||||
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[] { Ptp.Object._ID,
|
||||
Ptp.Object.NAME,
|
||||
Ptp.Object.SIZE,
|
||||
Ptp.Object.THUMB_WIDTH,
|
||||
Ptp.Object.THUMB_HEIGHT,
|
||||
Ptp.Object.THUMB_SIZE,
|
||||
Ptp.Object.IMAGE_WIDTH,
|
||||
Ptp.Object.IMAGE_HEIGHT,
|
||||
Ptp.Object.IMAGE_DEPTH,
|
||||
Ptp.Object.SEQUENCE_NUMBER,
|
||||
Ptp.Object.DATE_CREATED,
|
||||
Ptp.Object.DATE_MODIFIED,
|
||||
Ptp.Object.KEYWORDS,
|
||||
Ptp.Object.THUMB,
|
||||
Ptp.Object.FORMAT,
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
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();
|
||||
|
||||
if (mDeviceID != 0 && mObjectID != 0) {
|
||||
Cursor c = getContentResolver().query(
|
||||
Ptp.Object.getContentUri(mDeviceID, mObjectID),
|
||||
OBJECT_COLUMNS, null, null, null);
|
||||
c.moveToFirst();
|
||||
TextView view = (TextView)findViewById(R.id.name);
|
||||
mFileName = c.getString(1);
|
||||
view.setText(mFileName);
|
||||
view = (TextView)findViewById(R.id.size);
|
||||
view.setText(Long.toString(c.getLong(2)));
|
||||
view = (TextView)findViewById(R.id.thumb_width);
|
||||
view.setText(Long.toString(c.getLong(3)));
|
||||
view = (TextView)findViewById(R.id.thumb_height);
|
||||
view.setText(Long.toString(c.getLong(4)));
|
||||
view = (TextView)findViewById(R.id.thumb_size);
|
||||
view.setText(Long.toString(c.getLong(5)));
|
||||
view = (TextView)findViewById(R.id.width);
|
||||
view.setText(Long.toString(c.getLong(6)));
|
||||
view = (TextView)findViewById(R.id.height);
|
||||
view.setText(Long.toString(c.getLong(7)));
|
||||
view = (TextView)findViewById(R.id.depth);
|
||||
view.setText(Long.toString(c.getLong(8)));
|
||||
view = (TextView)findViewById(R.id.sequence);
|
||||
view.setText(Long.toString(c.getLong(9)));
|
||||
view = (TextView)findViewById(R.id.created);
|
||||
Date date = new Date(c.getLong(10) * 1000);
|
||||
view.setText(date.toString());
|
||||
view = (TextView)findViewById(R.id.modified);
|
||||
date = new Date(c.getLong(11) * 1000);
|
||||
view.setText(date.toString());
|
||||
view = (TextView)findViewById(R.id.keywords);
|
||||
view.setText(c.getString(12));
|
||||
byte[] thumbnail = c.getBlob(13);
|
||||
if (thumbnail != null) {
|
||||
ImageView thumbView = (ImageView)findViewById(R.id.thumbnail);
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length);
|
||||
if (bitmap != null) {
|
||||
thumbView.setImageBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
view = (TextView)findViewById(R.id.format);
|
||||
view.setText(Long.toHexString(c.getLong(14)).toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
unregisterReceiver(mDisconnectedReceiver);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void importObject() {
|
||||
// copy file to /mnt/sdcard/imported/<filename>
|
||||
File dest = Environment.getExternalStorageDirectory();
|
||||
dest = new File(dest, "imported");
|
||||
dest.mkdirs();
|
||||
dest = new File(dest, mFileName);
|
||||
|
||||
Uri requestUri = Ptp.Object.getContentUriForImport(mDeviceID, mObjectID,
|
||||
dest.getAbsolutePath());
|
||||
Uri resultUri = getContentResolver().insert(requestUri, new ContentValues());
|
||||
Log.d(TAG, "save returned " + resultUri);
|
||||
|
||||
if (resultUri != null) {
|
||||
Toast.makeText(this, R.string.object_saved_message, Toast.LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, resultUri);
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(this, R.string.start_activity_failed_message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(this, R.string.save_failed_message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteObject() {
|
||||
Uri uri = Ptp.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();
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
if (v == mImportButton) {
|
||||
importObject();
|
||||
} else if (v == mDeleteButton) {
|
||||
deleteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* 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.ListActivity;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Ptp;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleCursorAdapter;
|
||||
|
||||
/**
|
||||
* A list view displaying all storage units on a device.
|
||||
*/
|
||||
public class StorageBrowser extends ListActivity {
|
||||
|
||||
private static final String TAG = "StorageBrowser";
|
||||
|
||||
private ListAdapter mAdapter;
|
||||
private int mDeviceID;
|
||||
private DeviceDisconnectedReceiver mDisconnectedReceiver;
|
||||
|
||||
private static final String[] STORAGE_COLUMNS =
|
||||
new String[] { Ptp.Storage._ID, Ptp.Storage.DESCRIPTION };
|
||||
|
||||
@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();
|
||||
|
||||
if (mDeviceID != 0) {
|
||||
Cursor c = getContentResolver().query(Ptp.Storage.getContentUri(mDeviceID),
|
||||
STORAGE_COLUMNS, null, null, null);
|
||||
Log.d(TAG, "query returned " + c);
|
||||
startManagingCursor(c);
|
||||
|
||||
// Map Cursor columns to views defined in simple_list_item_1.xml
|
||||
mAdapter = new SimpleCursorAdapter(this,
|
||||
android.R.layout.simple_list_item_1, c,
|
||||
new String[] { Ptp.Storage.DESCRIPTION },
|
||||
new int[] { android.R.id.text1, android.R.id.text2 });
|
||||
setListAdapter(mAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
intent.putExtra("storage", mAdapter.getItemId(position));
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.hardware.UsbManager;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
public class UsbReceiver extends BroadcastReceiver
|
||||
{
|
||||
private static final String TAG = "UsbReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG, "onReceive " + intent);
|
||||
if (UsbManager.ACTION_USB_CAMERA_ATTACHED.equals(intent.getAction())) {
|
||||
Uri uri = intent.getData();
|
||||
intent = new Intent(context, StorageBrowser.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
try {
|
||||
// TODO - add a wrapper to Mtp.Device for this
|
||||
int id = Integer.parseInt(uri.getPathSegments().get(1));
|
||||
intent.putExtra("device", id);
|
||||
context.startActivity(intent);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "bad device Uri " + uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user