From 6ff76cd519446634e23ced26ffd5e4e0d6a43289 Mon Sep 17 00:00:00 2001 From: Jawnnypoo Date: Tue, 2 Aug 2016 17:46:53 -0500 Subject: [PATCH] Create sample activity to test activity transitions --- README.md | 13 ++--- library/build.gradle | 2 +- sample/build.gradle | 6 +- sample/src/main/AndroidManifest.xml | 14 ++++- .../sample/ActivityTransitionActivity.java | 56 +++++++++++++++++++ .../sample/ActivityTransitionToActivity.java | 17 ++++++ .../senab/photoview/sample/ImageAdapter.java | 43 ++++++++++++++ .../photoview/sample/ImageViewHolder.java | 30 ++++++++++ .../photoview/sample/LauncherActivity.java | 9 ++- .../main/res/layout/activity_transition.xml | 5 ++ .../res/layout/activity_transition_to.xml | 8 +++ sample/src/main/res/layout/item_image.xml | 7 +++ sample/src/main/res/values/styles.xml | 5 +- sample/src/main/res/values/transitions.xml | 4 ++ 14 files changed, 201 insertions(+), 18 deletions(-) create mode 100755 sample/src/main/java/uk/co/senab/photoview/sample/ActivityTransitionActivity.java create mode 100644 sample/src/main/java/uk/co/senab/photoview/sample/ActivityTransitionToActivity.java create mode 100644 sample/src/main/java/uk/co/senab/photoview/sample/ImageAdapter.java create mode 100644 sample/src/main/java/uk/co/senab/photoview/sample/ImageViewHolder.java create mode 100755 sample/src/main/res/layout/activity_transition.xml create mode 100755 sample/src/main/res/layout/activity_transition_to.xml create mode 100644 sample/src/main/res/layout/item_image.xml create mode 100644 sample/src/main/res/values/transitions.xml diff --git a/README.md b/README.md index 8da24d5a..e7b0e874 100755 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ # PhotoView PhotoView aims to help produce an easily usable implementation of a zooming Android ImageView. -Branch **Develop**: [![Build Status](https://travis-ci.org/chrisbanes/PhotoView.png?branch=develop)](https://travis-ci.org/chrisbanes/PhotoView) -Branch **Master**: [![Build Status](https://travis-ci.org/chrisbanes/PhotoView.png?branch=master)](https://travis-ci.org/chrisbanes/PhotoView) - ![PhotoView](https://raw.github.com/chrisbanes/PhotoView/master/art/header_graphic.png) ## Features @@ -13,11 +10,6 @@ Branch **Master**: [![Build Status](https://travis-ci.org/chrisbanes/PhotoView.p - Allows the application to be notified when the displayed Matrix has changed. Useful for when you need to update your UI based on the current zoom/scroll position. - Allows the application to be notified when the user taps on the Photo. -## Sample Application -The sample application (the source is in the repository) has been published onto Google Play for easy access: - -[![Get it on Google Play](https://raw.github.com/chrisbanes/PhotoView/master/art/google-play-badge-small.png)](http://play.google.com/store/apps/details?id=uk.co.senab.photoview.sample) - # Gradle Dependency Add this in your root `build.gradle` file (**not** your module `build.gradle` file): @@ -38,6 +30,11 @@ dependencies { } ``` +## Sample Application +The sample application (the source is in the repository) has been published onto Google Play for easy access: + +[![Get it on Google Play](https://raw.github.com/chrisbanes/PhotoView/master/art/google-play-badge-small.png)](http://play.google.com/store/apps/details?id=uk.co.senab.photoview.sample) + ## Sample Usage There is a [sample](https://github.com/chrisbanes/PhotoView/tree/master/sample) provided which shows how to use the library in a more advanced way, but for completeness here is all that is required to get PhotoView working: diff --git a/library/build.gradle b/library/build.gradle index 7bc2d706..a07a10bf 100755 --- a/library/build.gradle +++ b/library/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' android { compileSdkVersion 24 - buildToolsVersion '24.0.0' + buildToolsVersion '24.0.1' defaultConfig { minSdkVersion 4 diff --git a/sample/build.gradle b/sample/build.gradle index d476fa82..18760922 100755 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -2,14 +2,14 @@ apply plugin: 'com.android.application' android { compileSdkVersion 24 - buildToolsVersion '24.0.0' + buildToolsVersion '24.0.1' defaultConfig { applicationId "uk.co.senab.photoview.sample" minSdkVersion 8 targetSdkVersion 24 - versionCode 126 - versionName "1.2.6" + versionCode 100 + versionName "1.0" } lintOptions { abortOnError false diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index fc5bb14b..8de2eccd 100755 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -6,9 +6,11 @@ + android:label="@string/app_name" + android:theme="@style/AppTheme"> + @@ -16,10 +18,18 @@ + + + + + + + + diff --git a/sample/src/main/java/uk/co/senab/photoview/sample/ActivityTransitionActivity.java b/sample/src/main/java/uk/co/senab/photoview/sample/ActivityTransitionActivity.java new file mode 100755 index 00000000..1bc8a853 --- /dev/null +++ b/sample/src/main/java/uk/co/senab/photoview/sample/ActivityTransitionActivity.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright 2011, 2012 Chris Banes. + * + * 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 uk.co.senab.photoview.sample; + +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.support.v4.app.ActivityOptionsCompat; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.Toast; + +public class ActivityTransitionActivity extends AppCompatActivity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_transition); + + RecyclerView list = (RecyclerView) findViewById(R.id.list); + list.setLayoutManager(new GridLayoutManager(this, 2)); + ImageAdapter imageAdapter = new ImageAdapter(new ImageAdapter.Listener() { + @Override + public void onImageClicked(View view) { + transition(view); + } + }); + list.setAdapter(imageAdapter); + } + + private void transition(View view) { + if (Build.VERSION.SDK_INT < 21) { + Toast.makeText(ActivityTransitionActivity.this, "21+ only, keep out", Toast.LENGTH_SHORT).show(); + } else { + Intent intent = new Intent(ActivityTransitionActivity.this, ActivityTransitionToActivity.class); + ActivityOptionsCompat options = ActivityOptionsCompat. + makeSceneTransitionAnimation(ActivityTransitionActivity.this, view, getString(R.string.transition_test)); + startActivity(intent, options.toBundle()); + } + } +} diff --git a/sample/src/main/java/uk/co/senab/photoview/sample/ActivityTransitionToActivity.java b/sample/src/main/java/uk/co/senab/photoview/sample/ActivityTransitionToActivity.java new file mode 100644 index 00000000..22c0dea2 --- /dev/null +++ b/sample/src/main/java/uk/co/senab/photoview/sample/ActivityTransitionToActivity.java @@ -0,0 +1,17 @@ +package uk.co.senab.photoview.sample; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; + +/** + * Activity that gets transitioned to + */ +public class ActivityTransitionToActivity extends AppCompatActivity { + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_transition_to); + } +} diff --git a/sample/src/main/java/uk/co/senab/photoview/sample/ImageAdapter.java b/sample/src/main/java/uk/co/senab/photoview/sample/ImageAdapter.java new file mode 100644 index 00000000..2bf8670b --- /dev/null +++ b/sample/src/main/java/uk/co/senab/photoview/sample/ImageAdapter.java @@ -0,0 +1,43 @@ +package uk.co.senab.photoview.sample; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.view.ViewGroup; + +/** + * Image adapter + */ +public class ImageAdapter extends RecyclerView.Adapter { + + Listener mListener; + + public ImageAdapter(Listener listener) { + mListener = listener; + } + + @Override + public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + ImageViewHolder holder = ImageViewHolder.inflate(parent); + holder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mListener.onImageClicked(view); + } + }); + return holder; + } + + @Override + public void onBindViewHolder(ImageViewHolder holder, int position) { + + } + + @Override + public int getItemCount() { + return 20; + } + + public interface Listener { + void onImageClicked(View view); + } +} diff --git a/sample/src/main/java/uk/co/senab/photoview/sample/ImageViewHolder.java b/sample/src/main/java/uk/co/senab/photoview/sample/ImageViewHolder.java new file mode 100644 index 00000000..8f5038a1 --- /dev/null +++ b/sample/src/main/java/uk/co/senab/photoview/sample/ImageViewHolder.java @@ -0,0 +1,30 @@ +package uk.co.senab.photoview.sample; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +/** + * Image in recyclerview + */ +public class ImageViewHolder extends RecyclerView.ViewHolder { + + public static ImageViewHolder inflate(ViewGroup parent) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.item_image, parent, false); + return new ImageViewHolder(view); + } + + public TextView mTextTitle; + + public ImageViewHolder(View view) { + super(view); + mTextTitle = (TextView) view.findViewById(R.id.title); + } + + private void bind(String title) { + mTextTitle.setText(title); + } +} diff --git a/sample/src/main/java/uk/co/senab/photoview/sample/LauncherActivity.java b/sample/src/main/java/uk/co/senab/photoview/sample/LauncherActivity.java index bbbfe025..9fdedd1c 100755 --- a/sample/src/main/java/uk/co/senab/photoview/sample/LauncherActivity.java +++ b/sample/src/main/java/uk/co/senab/photoview/sample/LauncherActivity.java @@ -28,7 +28,7 @@ public class LauncherActivity extends AppCompatActivity { - public static final String[] options = {"Simple Sample", "ViewPager Sample", "Rotation Sample", "Picasso Sample"}; + public static final String[] options = {"Simple Sample", "ViewPager Sample", "Rotation Sample", "Picasso Sample", "Activity Transition Sample"}; @Override protected void onCreate(Bundle savedInstanceState) { @@ -47,14 +47,14 @@ public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { } @Override - public void onBindViewHolder(final ItemViewHolder holder, final int position) { + public void onBindViewHolder(final ItemViewHolder holder, int position) { holder.bind(options[position]); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Class c; - switch (position) { + switch (holder.getAdapterPosition()) { default: case 0: c = SimpleSampleActivity.class; @@ -68,6 +68,9 @@ public void onClick(View v) { case 3: c = PicassoSampleActivity.class; break; + case 4: + c = ActivityTransitionActivity.class; + break; } Context context = holder.itemView.getContext(); diff --git a/sample/src/main/res/layout/activity_transition.xml b/sample/src/main/res/layout/activity_transition.xml new file mode 100755 index 00000000..86b8422d --- /dev/null +++ b/sample/src/main/res/layout/activity_transition.xml @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_transition_to.xml b/sample/src/main/res/layout/activity_transition_to.xml new file mode 100755 index 00000000..1eabe338 --- /dev/null +++ b/sample/src/main/res/layout/activity_transition_to.xml @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/sample/src/main/res/layout/item_image.xml b/sample/src/main/res/layout/item_image.xml new file mode 100644 index 00000000..c6346a54 --- /dev/null +++ b/sample/src/main/res/layout/item_image.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml index c9ffde0d..da4adbe9 100644 --- a/sample/src/main/res/values/styles.xml +++ b/sample/src/main/res/values/styles.xml @@ -1,10 +1,13 @@ - + \ No newline at end of file diff --git a/sample/src/main/res/values/transitions.xml b/sample/src/main/res/values/transitions.xml new file mode 100644 index 00000000..e0e3c44e --- /dev/null +++ b/sample/src/main/res/values/transitions.xml @@ -0,0 +1,4 @@ + + + test + \ No newline at end of file