Skip to content

Commit

Permalink
Create sample activity to test activity transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jawnnypoo committed Aug 2, 2016
1 parent 7c5b783 commit 6ff76cd
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 18 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand All @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 24
buildToolsVersion '24.0.0'
buildToolsVersion '24.0.1'

defaultConfig {
minSdkVersion 4
Expand Down
6 changes: 3 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,30 @@

<application
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:label="@string/app_name">
android:label="@string/app_name"
android:theme="@style/AppTheme">

<activity android:name=".LauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<activity android:name=".SimpleSampleActivity"/>

<activity android:name=".ViewPagerActivity"/>

<activity android:name=".RotationSampleActivity"/>

<activity android:name=".PicassoSampleActivity"/>

<activity android:name=".ActivityTransitionActivity"/>

<activity android:name=".ActivityTransitionToActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<ImageViewHolder> {

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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions sample/src/main/res/layout/activity_transition.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
8 changes: 8 additions & 0 deletions sample/src/main/res/layout/activity_transition_to.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<uk.co.senab.photoview.PhotoView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/iv_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:transitionName="@string/transition_test"
android:src="@drawable/wallpaper"/>
7 changes: 7 additions & 0 deletions sample/src/main/res/layout/item_image.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/wallpaper"/>
5 changes: 4 additions & 1 deletion sample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/blue</item>
<item name="colorPrimaryDark">@color/blue_dark</item>
<item name="colorAccent">@color/green</item>

<!-- enable window content transitions -->
<item name="android:windowActivityTransitions" tools:targetApi="lollipop">true</item>
</style>
</resources>
4 changes: 4 additions & 0 deletions sample/src/main/res/values/transitions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="transition_test">test</string>
</resources>

0 comments on commit 6ff76cd

Please sign in to comment.