diff options
Diffstat (limited to 'photoviewer')
21 files changed, 341 insertions, 3 deletions
diff --git a/photoviewer/Android.mk b/photoviewer/Android.mk index a97a1ff..54ad563 100644 --- a/photoviewer/Android.mk +++ b/photoviewer/Android.mk @@ -25,3 +25,8 @@ LOCAL_SRC_FILES := \ $(call all-logtags-files-under, src) LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res include $(BUILD_STATIC_JAVA_LIBRARY) + +################################################## +# Build all sub-directories + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/photoviewer/sample/Android.mk b/photoviewer/sample/Android.mk new file mode 100644 index 0000000..8346e7c --- /dev/null +++ b/photoviewer/sample/Android.mk @@ -0,0 +1,47 @@ +# Copyright 2011, 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. + +LOCAL_PATH:= $(call my-dir) + +#Include res dir from photoviewer +photo_dir := ..//res +res_dirs := $(photo_dir) res + +################################################## +# Build APK +include $(CLEAR_VARS) + +src_dirs := src +LOCAL_PACKAGE_NAME := PhotoViewerSample + +LOCAL_STATIC_JAVA_LIBRARIES += android-common-photoviewer +LOCAL_STATIC_JAVA_LIBRARIES += android-common +LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4 +LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13 + +LOCAL_SDK_VERSION := 16 + +LOCAL_SRC_FILES := $(call all-java-files-under, $(src_dirs)) \ + $(call all-logtags-files-under, $(src_dirs)) +LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dirs)) $(LOCAL_PATH)/res +LOCAL_AAPT_FLAGS := --auto-add-overlay +LOCAL_AAPT_FLAGS += --extra-packages com.android.ex.photo + +include $(BUILD_PACKAGE) + + +################################################## +# Build all sub-directories + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/photoviewer/sample/AndroidManifest.xml b/photoviewer/sample/AndroidManifest.xml new file mode 100644 index 0000000..8a75d6a --- /dev/null +++ b/photoviewer/sample/AndroidManifest.xml @@ -0,0 +1,35 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.photoviewersample" + android:versionCode="1" + android:versionName="1.0" > + + <uses-sdk + android:minSdkVersion="14" + android:targetSdkVersion="16" /> + + <application + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" + android:theme="@style/AppTheme" > + <activity + android:name=".MainActivity" + android:label="@string/app_name" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + <activity + android:name="com.android.ex.photo.PhotoViewActivity" + android:label="@string/app_name" + android:theme="@style/PhotoViewTheme" > + </activity> + <provider + android:name=".SampleProvider" + android:exported="false" + android:authorities="com.example.photoviewersample.SampleProvider"> + </provider> + </application> + +</manifest>
\ No newline at end of file diff --git a/photoviewer/sample/assets/blah.png b/photoviewer/sample/assets/blah.png Binary files differnew file mode 100644 index 0000000..f895669 --- /dev/null +++ b/photoviewer/sample/assets/blah.png diff --git a/photoviewer/sample/assets/galaxy.png b/photoviewer/sample/assets/galaxy.png Binary files differnew file mode 100644 index 0000000..3fcfec8 --- /dev/null +++ b/photoviewer/sample/assets/galaxy.png diff --git a/photoviewer/sample/assets/johannson.png b/photoviewer/sample/assets/johannson.png Binary files differnew file mode 100644 index 0000000..0b6be7f --- /dev/null +++ b/photoviewer/sample/assets/johannson.png diff --git a/photoviewer/sample/assets/planets.png b/photoviewer/sample/assets/planets.png Binary files differnew file mode 100644 index 0000000..1644c48 --- /dev/null +++ b/photoviewer/sample/assets/planets.png diff --git a/photoviewer/sample/res/drawable-hdpi/ic_action_search.png b/photoviewer/sample/res/drawable-hdpi/ic_action_search.png Binary files differnew file mode 100644 index 0000000..67de12d --- /dev/null +++ b/photoviewer/sample/res/drawable-hdpi/ic_action_search.png diff --git a/photoviewer/sample/res/drawable-hdpi/ic_launcher.png b/photoviewer/sample/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..fba1ff0 --- /dev/null +++ b/photoviewer/sample/res/drawable-hdpi/ic_launcher.png diff --git a/photoviewer/sample/res/drawable-mdpi/ic_action_search.png b/photoviewer/sample/res/drawable-mdpi/ic_action_search.png Binary files differnew file mode 100644 index 0000000..134d549 --- /dev/null +++ b/photoviewer/sample/res/drawable-mdpi/ic_action_search.png diff --git a/photoviewer/sample/res/drawable-mdpi/ic_launcher.png b/photoviewer/sample/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..72a445d --- /dev/null +++ b/photoviewer/sample/res/drawable-mdpi/ic_launcher.png diff --git a/photoviewer/sample/res/drawable-xhdpi/ic_action_search.png b/photoviewer/sample/res/drawable-xhdpi/ic_action_search.png Binary files differnew file mode 100644 index 0000000..d699c6b --- /dev/null +++ b/photoviewer/sample/res/drawable-xhdpi/ic_action_search.png diff --git a/photoviewer/sample/res/drawable-xhdpi/ic_launcher.png b/photoviewer/sample/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..002e7b0 --- /dev/null +++ b/photoviewer/sample/res/drawable-xhdpi/ic_launcher.png diff --git a/photoviewer/sample/res/layout/activity_main.xml b/photoviewer/sample/res/layout/activity_main.xml new file mode 100644 index 0000000..ae94392 --- /dev/null +++ b/photoviewer/sample/res/layout/activity_main.xml @@ -0,0 +1,16 @@ +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" > + + <Button + android:id="@+id/button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_centerHorizontal="true" + android:layout_centerVertical="true" + android:padding="@dimen/padding_medium" + android:text="@string/launch" + tools:context=".MainActivity" /> + +</RelativeLayout> diff --git a/photoviewer/sample/res/menu/activity_main.xml b/photoviewer/sample/res/menu/activity_main.xml new file mode 100644 index 0000000..cfc10fd --- /dev/null +++ b/photoviewer/sample/res/menu/activity_main.xml @@ -0,0 +1,6 @@ +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:id="@+id/menu_settings" + android:title="@string/menu_settings" + android:orderInCategory="100" + android:showAsAction="never" /> +</menu> diff --git a/photoviewer/sample/res/values/dimens.xml b/photoviewer/sample/res/values/dimens.xml new file mode 100644 index 0000000..ec96646 --- /dev/null +++ b/photoviewer/sample/res/values/dimens.xml @@ -0,0 +1,7 @@ +<resources> + + <dimen name="padding_small">8dp</dimen> + <dimen name="padding_medium">8dp</dimen> + <dimen name="padding_large">16dp</dimen> + +</resources>
\ No newline at end of file diff --git a/photoviewer/sample/res/values/strings.xml b/photoviewer/sample/res/values/strings.xml new file mode 100644 index 0000000..be31909 --- /dev/null +++ b/photoviewer/sample/res/values/strings.xml @@ -0,0 +1,8 @@ +<resources> + + <string name="app_name">PhotoViewerSample</string> + <string name="menu_settings">Settings</string> + <string name="title_activity_main">MainActivity</string> + <string name="launch">Launch Photo Viewer</string> + +</resources>
\ No newline at end of file diff --git a/photoviewer/sample/res/values/styles.xml b/photoviewer/sample/res/values/styles.xml new file mode 100644 index 0000000..1c089a7 --- /dev/null +++ b/photoviewer/sample/res/values/styles.xml @@ -0,0 +1,5 @@ +<resources> + + <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" /> + +</resources>
\ No newline at end of file diff --git a/photoviewer/sample/src/com/example/photoviewersample/MainActivity.java b/photoviewer/sample/src/com/example/photoviewersample/MainActivity.java new file mode 100644 index 0000000..efc2064 --- /dev/null +++ b/photoviewer/sample/src/com/example/photoviewersample/MainActivity.java @@ -0,0 +1,30 @@ +package com.example.photoviewersample; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; + +import com.android.ex.photo.Intents; +import com.android.ex.photo.Intents.PhotoViewIntentBuilder; + +public class MainActivity extends Activity implements OnClickListener { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + View b = findViewById(R.id.button); + b.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + final PhotoViewIntentBuilder builder = + Intents.newPhotoViewActivityIntentBuilder(this); + builder + .setPhotosUri("content://com.example.photoviewersample.SampleProvider/photos"); + + startActivity(builder.build()); + } +} diff --git a/photoviewer/sample/src/com/example/photoviewersample/SampleProvider.java b/photoviewer/sample/src/com/example/photoviewersample/SampleProvider.java new file mode 100644 index 0000000..86ae82b --- /dev/null +++ b/photoviewer/sample/src/com/example/photoviewersample/SampleProvider.java @@ -0,0 +1,179 @@ +package com.example.photoviewersample; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.content.res.AssetFileDescriptor; +import android.database.Cursor; +import android.database.MatrixCursor; +import android.net.Uri; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +public class SampleProvider extends ContentProvider { + private static final int PHOTOS = 1; + private static final int PHOTO_INDIVIDUAL_1 = 2; + private static final int PHOTO_INDIVIDUAL_2 = 3; + private static final int PHOTO_INDIVIDUAL_3 = 4; + private static final int PHOTO_INDIVIDUAL_4 = 5; + + private static final String PROVIDER_URI = "com.example.photoviewersample.SampleProvider"; + + // Creates a UriMatcher object. + private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + + static + { + sUriMatcher.addURI(PROVIDER_URI, "photos", PHOTOS); + sUriMatcher.addURI(PROVIDER_URI, "photos/1", PHOTO_INDIVIDUAL_1); + sUriMatcher.addURI(PROVIDER_URI, "photos/2", PHOTO_INDIVIDUAL_2); + sUriMatcher.addURI(PROVIDER_URI, "photos/3", PHOTO_INDIVIDUAL_3); + sUriMatcher.addURI(PROVIDER_URI, "photos/4", PHOTO_INDIVIDUAL_4); + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getType(Uri uri) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean onCreate() { + // TODO Auto-generated method stub + return false; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, + String sortOrder) { + MatrixCursor matrix = new MatrixCursor(projection); + + /* + * Choose the table to query and a sort order based on the code returned for the incoming + * URI. Here, too, only the statements for table 3 are shown. + */ + switch (sUriMatcher.match(uri)) { + // If the incoming URI was for all of the photos table + case PHOTOS: + addRow(matrix, PHOTO_INDIVIDUAL_1); + addRow(matrix, PHOTO_INDIVIDUAL_2); + addRow(matrix, PHOTO_INDIVIDUAL_3); + addRow(matrix, PHOTO_INDIVIDUAL_4); + break; + + // If the incoming URI was for a single row + case PHOTO_INDIVIDUAL_1: + addRow(matrix, PHOTO_INDIVIDUAL_1); + break; + case PHOTO_INDIVIDUAL_2: + addRow(matrix, PHOTO_INDIVIDUAL_2); + break; + case PHOTO_INDIVIDUAL_3: + addRow(matrix, PHOTO_INDIVIDUAL_3); + break; + case PHOTO_INDIVIDUAL_4: + addRow(matrix, PHOTO_INDIVIDUAL_4); + break; + + default: + // If the URI is not recognized, you should do some error handling here. + } + // call the code to actually do the query + + return matrix; + } + + /** + * Adds a single row to the Cursor. A real implementation should + * check the projection to properly match the columns. + */ + private void addRow(MatrixCursor matrix, int match_id) { + switch (match_id) { + case PHOTO_INDIVIDUAL_1: + matrix.newRow() + .add("content://" + PROVIDER_URI + "/photos/1") // uri + .add("blah.png") // displayName + .add("content://" + PROVIDER_URI + "/photos/1/contentUri") // contentUri + .add("content://" + PROVIDER_URI + "/photos/1/thumbnailUri") // thumbnailUri + .add("image/png"); // contentType + break; + case PHOTO_INDIVIDUAL_2: + matrix.newRow() + .add("content://" + PROVIDER_URI + "/photos/2") // uri + .add("johannson.png") // displayName + .add("content://" + PROVIDER_URI + "/photos/2/contentUri") // contentUri + .add("content://" + PROVIDER_URI + "/photos/2/thumbnailUri") // thumbnailUri + .add("image/png"); // contentType + break; + case PHOTO_INDIVIDUAL_3: + matrix.newRow() + .add("content://" + PROVIDER_URI + "/photos/3") // uri + .add("planets.png") // displayName + .add("content://" + PROVIDER_URI + "/photos/3/contentUri") // contentUri + .add("content://" + PROVIDER_URI + "/photos/3/thumbnailUri") // thumbnailUri + .add("image/png"); // contentType + break; + case PHOTO_INDIVIDUAL_4: + matrix.newRow() + .add("content://" + PROVIDER_URI + "/photos/4") // uri + .add("galaxy.png") // displayName + .add("content://" + PROVIDER_URI + "/photos/4/contentUri") // contentUri + .add("content://" + PROVIDER_URI + "/photos/4/thumbnailUri") // thumbnailUri + .add("image/png"); // contentType + break; + + default: + // If the URI is not recognized, you should do some error handling here. + } + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException { + List<String> pathSegments = uri.getPathSegments(); + final int id = Integer.parseInt(pathSegments.get(1)); + String fileName; + switch (id) { + case 1: + fileName = "blah.png"; + break; + case 2: + fileName = "johannson.png"; + break; + case 3: + fileName = "planets.png"; + break; + case 4: + fileName = "galaxy.png"; + break; + default: + fileName = null; + break; + } + try { + return getContext().getAssets().openFd(fileName); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/photoviewer/src/com/android/ex/photo/provider/PhotoContract.java b/photoviewer/src/com/android/ex/photo/provider/PhotoContract.java index 0a9a43a..439b68b 100644 --- a/photoviewer/src/com/android/ex/photo/provider/PhotoContract.java +++ b/photoviewer/src/com/android/ex/photo/provider/PhotoContract.java @@ -34,14 +34,14 @@ public final class PhotoContract { */ public static final String NAME = OpenableColumns.DISPLAY_NAME; /** - * This column is a {@link Uri} that points to the downloaded local file - * This value is undefined in any other state. + * This column is a {@link Uri} that points to the downloaded local file. + * Can be null. */ public static final String CONTENT_URI = "contentUri"; /** * This column is a {@link Uri} that points to a thumbnail of the image * that ideally is a local file. - * This value is undefined in any other state. + * Can be null. */ public static final String THUMBNAIL_URI = "thumbnailUri"; /** |