Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PhotoView supports GIF animation #819

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ allprojects {

ext {
sdkVersion = 29
minSdkVersion = 16
minSdkVersion = 17
}
1 change: 1 addition & 0 deletions photoview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ android {

dependencies {
implementation "androidx.appcompat:appcompat:1.1.0"
api "pl.droidsonroids.gif:android-gif-drawable:1.2.24"
}

afterEvaluate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import android.util.AttributeSet;
import android.view.GestureDetector;

import androidx.appcompat.widget.AppCompatImageView;
import pl.droidsonroids.gif.GifImageView;

/**
* A zoomable ImageView. See {@link PhotoViewAttacher} for most of the details on how the zooming
* is accomplished
*/
@SuppressWarnings("unused")
public class PhotoView extends AppCompatImageView {
public class PhotoView extends GifImageView {

private PhotoViewAttacher attacher;
private ScaleType pendingScaleType;
Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<activity android:name=".ActivityTransitionToActivity" />

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

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

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.chrisbanes.photoview.sample;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.github.chrisbanes.photoview.PhotoView;

import pl.droidsonroids.gif.GifDrawable;

public class AnimationSampleActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation_sample);
PhotoView pvGif = findViewById(R.id.pvGif);
findViewById(R.id.btnSwitchPic).setOnClickListener(v -> {
if (pvGif.getTag().equals("pic_dog")) {
pvGif.setImageResource(R.mipmap.pic_cat);
pvGif.setTag("pic_cat");
} else {
pvGif.setImageResource(R.mipmap.pic_dog);
pvGif.setTag("pic_dog");
}
});
findViewById(R.id.btnHalfSpeed).setOnClickListener(v -> ((GifDrawable) pvGif.getDrawable()).setSpeed(0.5f));
findViewById(R.id.btnNormalSpeed).setOnClickListener(v -> ((GifDrawable) pvGif.getDrawable()).setSpeed(1));
findViewById(R.id.btnDoubleSpeed).setOnClickListener(v -> ((GifDrawable) pvGif.getDrawable()).setSpeed(2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class LauncherActivity extends AppCompatActivity {
"Picasso Sample",
"Coil Sample",
"Activity Transition Sample",
"Immersive Sample"
"Immersive Sample",
"Animation Sample"
};

@Override
Expand Down Expand Up @@ -81,6 +82,9 @@ public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
break;
case 6:
clazz = ImmersiveActivity.class;
break;
case 7:
clazz = AnimationSampleActivity.class;
}

Context context = holder.itemView.getContext();
Expand Down
51 changes: 51 additions & 0 deletions sample/src/main/res/layout/activity_animation_sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/pvGif"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="@mipmap/pic_dog"
android:tag="pic_dog" />

<Button
android:id="@+id/btnSwitchPic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Switch Pic"
android:textAllCaps="false" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
android:id="@+id/btnHalfSpeed"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Half Speed"
android:textAllCaps="false" />

<Button
android:id="@+id/btnNormalSpeed"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Normal Speed"
android:textAllCaps="false" />

<Button
android:id="@+id/btnDoubleSpeed"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Double Speed"
android:textAllCaps="false" />
</LinearLayout>
</LinearLayout>
Binary file added sample/src/main/res/mipmap-xxxhdpi/pic_cat.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/src/main/res/mipmap-xxxhdpi/pic_dog.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.