diff options
| author | Mike Lockwood <lockwood@android.com> | 2010-06-10 10:13:22 -0400 |
|---|---|---|
| committer | Mike Lockwood <lockwood@android.com> | 2010-06-10 14:08:35 -0400 |
| commit | 0809c0e4c61fb1f64925081c811df86c73f7070f (patch) | |
| tree | c5b5c1231874cb9b17bb7e4e01fa26f86fc82221 /media/tests | |
| parent | f724eed5669762fdb0071e11ab3b38de77dd5c33 (diff) | |
| download | frameworks_base-0809c0e4c61fb1f64925081c811df86c73f7070f.zip frameworks_base-0809c0e4c61fb1f64925081c811df86c73f7070f.tar.gz frameworks_base-0809c0e4c61fb1f64925081c811df86c73f7070f.tar.bz2 | |
CameraBrowser: New test app for the MTP content provider.
Change-Id: I8423d728b13ed8ac87bd2792eefddce3287598bb
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'media/tests')
9 files changed, 599 insertions, 0 deletions
diff --git a/media/tests/CameraBrowser/Android.mk b/media/tests/CameraBrowser/Android.mk new file mode 100644 index 0000000..1d81129 --- /dev/null +++ b/media/tests/CameraBrowser/Android.mk @@ -0,0 +1,10 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := CameraBrowser + +include $(BUILD_PACKAGE) diff --git a/media/tests/CameraBrowser/AndroidManifest.xml b/media/tests/CameraBrowser/AndroidManifest.xml new file mode 100644 index 0000000..dbbd62a --- /dev/null +++ b/media/tests/CameraBrowser/AndroidManifest.xml @@ -0,0 +1,18 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.camerabrowser"> + + <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" /> + </application> + + +</manifest> diff --git a/media/tests/CameraBrowser/res/layout/object_info.xml b/media/tests/CameraBrowser/res/layout/object_info.xml new file mode 100644 index 0000000..f67397f --- /dev/null +++ b/media/tests/CameraBrowser/res/layout/object_info.xml @@ -0,0 +1,144 @@ +<?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/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> +</TableLayout> + diff --git a/media/tests/CameraBrowser/res/values/strings.xml b/media/tests/CameraBrowser/res/values/strings.xml new file mode 100644 index 0000000..c8563b2 --- /dev/null +++ b/media/tests/CameraBrowser/res/values/strings.xml @@ -0,0 +1,31 @@ +<?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> + <string name="name_label">Name: </string> + <string name="size_label">Size: </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> +</resources> diff --git a/media/tests/CameraBrowser/res/values/styles.xml b/media/tests/CameraBrowser/res/values/styles.xml new file mode 100644 index 0000000..c869985 --- /dev/null +++ b/media/tests/CameraBrowser/res/values/styles.xml @@ -0,0 +1,34 @@ +<?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> + diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/CameraBrowser.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/CameraBrowser.java new file mode 100644 index 0000000..118692e --- /dev/null +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/CameraBrowser.java @@ -0,0 +1,71 @@ +/* + * 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.Mtp; +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 static final String[] DEVICE_COLUMNS = + new String[] { Mtp.Device._ID, Mtp.Device.MANUFACTURER, Mtp.Device.MODEL }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + protected void onResume() { + super.onResume(); + + Cursor c = getContentResolver().query(Mtp.Device.CONTENT_URI, + DEVICE_COLUMNS, null, null, null); + Log.d(TAG, "query returned " + c); + startManagingCursor(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[] { Mtp.Device.MANUFACTURER, Mtp.Device.MODEL }, + new int[] { android.R.id.text1, android.R.id.text2 }); + setListAdapter(mAdapter); + } + + @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); + } +} diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java new file mode 100644 index 0000000..da29be8 --- /dev/null +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java @@ -0,0 +1,110 @@ +/* + * 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.Mtp; +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 objects within a container (folder or storage unit). + */ +public class ObjectBrowser extends ListActivity { + + private static final String TAG = "ObjectBrowser"; + + private ListAdapter mAdapter; + private int mDeviceID; + private int mStorageID; + private int mObjectID; + + private static final String[] OBJECT_COLUMNS = + new String[] { Mtp.Object._ID, Mtp.Object.NAME, Mtp.Object.FORMAT }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + protected void onResume() { + super.onResume(); + + mDeviceID = getIntent().getIntExtra("device", 0); + mStorageID = getIntent().getIntExtra("storage", 0); + mObjectID = getIntent().getIntExtra("object", 0); + if (mDeviceID != 0 && mStorageID != 0) { + Cursor c; + if (mObjectID == 0) { + c = getContentResolver().query( + Mtp.Object.getContentUriForStorageChildren(mDeviceID, mStorageID), + OBJECT_COLUMNS, null, null, null); + } else { + c = getContentResolver().query( + Mtp.Object.getContentUriForObjectChildren(mDeviceID, mObjectID), + OBJECT_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[] { Mtp.Object.NAME }, + new int[] { android.R.id.text1, android.R.id.text2 }); + setListAdapter(mAdapter); + } + } + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + int rowID = (int)mAdapter.getItemId(position); + Cursor c = getContentResolver().query( + Mtp.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(0); + String name = c.getString(1); + format = c.getLong(2); + Log.d(TAG, "rowId: " + rowId + " name: " + name + " format: " + format); + } + if (format == Mtp.Object.FORMAT_JFIF) { + Intent intent = new Intent(this, ObjectViewer.class); + intent.putExtra("device", mDeviceID); + intent.putExtra("storage", mStorageID); + intent.putExtra("object",rowID); + startActivity(intent); + } else { + Intent intent = new Intent(this, ObjectBrowser.class); + intent.putExtra("device", mDeviceID); + intent.putExtra("storage", mStorageID); + intent.putExtra("object", rowID); + startActivity(intent); + } + } +} diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java new file mode 100644 index 0000000..7055fc5 --- /dev/null +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java @@ -0,0 +1,105 @@ +/* + * 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.Intent; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; +import android.provider.Mtp; +import android.util.Log; +import android.view.View; +import android.widget.TextView; + +import java.util.Date; + +/** + * A view to display the properties of an object. + */ +public class ObjectViewer extends Activity { + + private static final String TAG = "ObjectViewer"; + + private int mDeviceID; + private int mStorageID; + private int mObjectID; + + private static final String[] OBJECT_COLUMNS = + new String[] { Mtp.Object._ID, + Mtp.Object.NAME, + Mtp.Object.SIZE, + Mtp.Object.THUMB_WIDTH, + Mtp.Object.THUMB_HEIGHT, + Mtp.Object.THUMB_SIZE, + Mtp.Object.IMAGE_WIDTH, + Mtp.Object.IMAGE_HEIGHT, + Mtp.Object.IMAGE_DEPTH, + Mtp.Object.SEQUENCE_NUMBER, + Mtp.Object.DATE_CREATED, + Mtp.Object.DATE_MODIFIED, + Mtp.Object.KEYWORDS, + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.object_info); + } + + @Override + protected void onResume() { + super.onResume(); + + mDeviceID = getIntent().getIntExtra("device", 0); + mStorageID = getIntent().getIntExtra("storage", 0); + mObjectID = getIntent().getIntExtra("object", 0); + + if (mDeviceID != 0 && mObjectID != 0) { + Cursor c = getContentResolver().query( + Mtp.Object.getContentUri(mDeviceID, mObjectID), + OBJECT_COLUMNS, null, null, null); + c.moveToFirst(); + TextView view = (TextView)findViewById(R.id.name); + view.setText(c.getString(1)); + 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)); + } + } +} diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java new file mode 100644 index 0000000..6ddf4e7 --- /dev/null +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java @@ -0,0 +1,76 @@ +/* + * 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.Mtp; +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 static final String[] STORAGE_COLUMNS = + new String[] { Mtp.Storage._ID, Mtp.Storage.DESCRIPTION }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @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); + 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[] { Mtp.Storage.DESCRIPTION }, + new int[] { android.R.id.text1, android.R.id.text2 }); + setListAdapter(mAdapter); + } + } + + @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", (int)mAdapter.getItemId(position)); + startActivity(intent); + } +} |
