├── sample ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── dimens.xml │ │ │ ├── styles.xml │ │ │ └── strings.xml │ │ ├── drawable-nodpi │ │ │ ├── panda.jpg │ │ │ ├── ic_error.png │ │ │ ├── ic_loading.png │ │ │ ├── viewpager_1.jpg │ │ │ ├── viewpager_2.jpg │ │ │ ├── viewpager_3.jpg │ │ │ └── ic_placeholder.jpg │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-anydpi-v26 │ │ │ └── ic_launcher.xml │ │ ├── layout │ │ │ ├── item_photo_view.xml │ │ │ ├── activity_shared_element_launched.xml │ │ │ ├── activity_recycler_view.xml │ │ │ ├── activity_viewpager.xml │ │ │ ├── activity_single.xml │ │ │ └── activity_shared_element.xml │ │ ├── drawable │ │ │ ├── ic_toolbar_back.xml │ │ │ └── ic_launcher_background.xml │ │ ├── menu │ │ │ └── single.xml │ │ └── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ └── me │ │ │ └── relex │ │ │ └── photodraweeview │ │ │ └── sample │ │ │ ├── PhotoApp.java │ │ │ ├── MultiTouchViewPager.java │ │ │ ├── gestures │ │ │ └── ScaleStepDoubleTapListener.java │ │ │ ├── SharedElementLaunchedActivity.java │ │ │ ├── RecyclerViewActivity.java │ │ │ ├── SharedElementActivity.java │ │ │ ├── SingleActivity.java │ │ │ └── ViewPagerActivity.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── photodraweeview ├── .gitignore ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── me │ │ └── relex │ │ └── photodraweeview │ │ ├── OnScaleChangeListener.java │ │ ├── OnViewTapListener.java │ │ ├── OnPhotoTapListener.java │ │ ├── OnScaleDragGestureListener.java │ │ ├── IAttacher.java │ │ ├── DefaultOnDoubleTapListener.java │ │ ├── ScaleDragDetector.java │ │ ├── PhotoDraweeView.java │ │ └── Attacher.java ├── build.gradle ├── proguard-rules.pro └── upload-maven-plugin.gradle ├── settings.gradle ├── screenshot.gif ├── .idea ├── dictionaries │ └── relex.xml ├── encodings.xml ├── vcs.xml ├── assetWizardSettings.xml ├── compiler.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── jarRepositories.xml ├── inspectionProfiles │ └── Project_Default.xml ├── codeStyles │ └── Project.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── PhotoDraweeView.iml ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /photodraweeview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':photodraweeview' 2 | -------------------------------------------------------------------------------- /screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/screenshot.gif -------------------------------------------------------------------------------- /photodraweeview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.idea/dictionaries/relex.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-nodpi/panda.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/drawable-nodpi/panda.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | /.idea/caches 7 | .DS_Store 8 | /build 9 | /captures -------------------------------------------------------------------------------- /sample/src/main/res/drawable-nodpi/ic_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/drawable-nodpi/ic_error.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-nodpi/ic_loading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/drawable-nodpi/ic_loading.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-nodpi/viewpager_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/drawable-nodpi/viewpager_1.jpg -------------------------------------------------------------------------------- /sample/src/main/res/drawable-nodpi/viewpager_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/drawable-nodpi/viewpager_2.jpg -------------------------------------------------------------------------------- /sample/src/main/res/drawable-nodpi/viewpager_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/drawable-nodpi/viewpager_3.jpg -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-nodpi/ic_placeholder.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ongakuer/PhotoDraweeView/HEAD/sample/src/main/res/drawable-nodpi/ic_placeholder.jpg -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jan 04 17:15:19 EET 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/assetWizardSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | -------------------------------------------------------------------------------- /sample/src/main/java/me/relex/photodraweeview/sample/PhotoApp.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview.sample; 2 | 3 | import android.app.Application; 4 | import com.facebook.drawee.backends.pipeline.Fresco; 5 | 6 | public class PhotoApp extends Application { 7 | 8 | @Override public void onCreate() { 9 | super.onCreate(); 10 | Fresco.initialize(getApplicationContext()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PhotoDraweeView 3 | Default Image 4 | Failure Image 5 | ViewPager 6 | RecyclerView 7 | Shared Element 8 | Scale Step 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /photodraweeview/src/main/java/me/relex/photodraweeview/OnScaleChangeListener.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview; 2 | 3 | /** 4 | * Interface definition for callback to be invoked when attached ImageView scale changes 5 | * 6 | * @author Marek Sebera 7 | */ 8 | public interface OnScaleChangeListener { 9 | /** 10 | * Callback for when the scale changes 11 | * 12 | * @param scaleFactor the scale factor 13 | * @param focusX focal point X position 14 | * @param focusY focal point Y position 15 | */ 16 | void onScaleChange(float scaleFactor, float focusX, float focusY); 17 | } 18 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_photo_view.xml: -------------------------------------------------------------------------------- 1 | 13 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/relex/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /photodraweeview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | version = "2.1.0" 4 | int version_code = 210 5 | 6 | android { 7 | compileSdkVersion 30 8 | defaultConfig { 9 | minSdkVersion 14 10 | versionCode version_code 11 | versionName version 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compileOnly 'androidx.annotation:annotation:1.2.0' 23 | compileOnly 'androidx.core:core:1.6.0' 24 | compileOnly 'com.facebook.fresco:fresco:2.5.0' 25 | } 26 | 27 | apply from: "upload-maven-plugin.gradle" -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | -------------------------------------------------------------------------------- /photodraweeview/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/relex/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /photodraweeview/src/main/java/me/relex/photodraweeview/OnViewTapListener.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Interface definition for a callback to be invoked when the ImageView is tapped with a single 7 | * tap. 8 | * 9 | * @author Chris Banes 10 | */ 11 | public interface OnViewTapListener { 12 | /** 13 | * A callback to receive where the user taps on a ImageView. You will receive a callback if 14 | * the user taps anywhere on the view, tapping on 'whitespace' will not be ignored. 15 | * 16 | * @param view - View the user tapped. 17 | * @param x - where the user tapped from the left of the View. 18 | * @param y - where the user tapped from the top of the View. 19 | */ 20 | void onViewTap(View view, float x, float y); 21 | } -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 30 5 | 6 | defaultConfig { 7 | applicationId "me.relex.photodraweeview.sample" 8 | minSdkVersion 14 9 | targetSdkVersion 30 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation 'androidx.appcompat:appcompat:1.3.1' 23 | implementation 'androidx.recyclerview:recyclerview:1.2.0' 24 | implementation 'me.relex:circleindicator:2.1.6' 25 | implementation 'com.facebook.fresco:fresco:2.5.0' 26 | implementation project(':photodraweeview') 27 | } 28 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_shared_element_launched.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 18 | 19 | -------------------------------------------------------------------------------- /photodraweeview/src/main/java/me/relex/photodraweeview/OnPhotoTapListener.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Interface definition for a callback to be invoked when the Photo is tapped with a single 7 | * tap. 8 | * 9 | * @author Chris Banes 10 | */ 11 | public interface OnPhotoTapListener { 12 | 13 | /** 14 | * A callback to receive where the user taps on a photo. You will only receive a callback if 15 | * the user taps on the actual photo, tapping on 'whitespace' will be ignored. 16 | * 17 | * @param view - View the user tapped. 18 | * @param x - where the user tapped from the of the Drawable, as percentage of the 19 | * Drawable width. 20 | * @param y - where the user tapped from the top of the Drawable, as percentage of the 21 | * Drawable height. 22 | */ 23 | void onPhotoTap(View view, float x, float y); 24 | } 25 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | android.enableJetifier=true 20 | android.useAndroidX=true -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_recycler_view.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 13 | 14 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /PhotoDraweeView.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_toolbar_back.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 24 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_viewpager.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 10 | 11 | 20 | 21 | 22 | 28 | 29 | -------------------------------------------------------------------------------- /photodraweeview/src/main/java/me/relex/photodraweeview/OnScaleDragGestureListener.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview; 2 | 3 | /** 4 | * **************************************************************************** 5 | * Copyright 2011, 2012 Chris Banes. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ***************************************************************************** 19 | */ 20 | 21 | public interface OnScaleDragGestureListener { 22 | void onDrag(float dx, float dy); 23 | 24 | void onFling(float startX, float startY, float velocityX, float velocityY); 25 | 26 | void onScale(float scaleFactor, float focusX, float focusY); 27 | 28 | void onScaleEnd(); 29 | } 30 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_single.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 18 | 19 | 27 | 28 | -------------------------------------------------------------------------------- /sample/src/main/java/me/relex/photodraweeview/sample/MultiTouchViewPager.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview.sample; 2 | 3 | import android.content.Context; 4 | import androidx.annotation.NonNull; 5 | import androidx.viewpager.widget.ViewPager; 6 | import android.util.AttributeSet; 7 | import android.view.MotionEvent; 8 | 9 | public class MultiTouchViewPager extends ViewPager { 10 | 11 | public MultiTouchViewPager(Context context) { 12 | super(context); 13 | } 14 | 15 | public MultiTouchViewPager(Context context, AttributeSet attrs) { 16 | super(context, attrs); 17 | } 18 | 19 | private boolean mIsDisallowIntercept = false; 20 | 21 | @Override public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { 22 | mIsDisallowIntercept = disallowIntercept; 23 | super.requestDisallowInterceptTouchEvent(disallowIntercept); 24 | } 25 | 26 | @Override public boolean dispatchTouchEvent(@NonNull MotionEvent ev) { 27 | if (ev.getPointerCount() > 1 && mIsDisallowIntercept) { 28 | requestDisallowInterceptTouchEvent(false); 29 | boolean handled = super.dispatchTouchEvent(ev); 30 | requestDisallowInterceptTouchEvent(true); 31 | return handled; 32 | } else { 33 | return super.dispatchTouchEvent(ev); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_shared_element.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 16 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/single.xml: -------------------------------------------------------------------------------- 1 | 16 | 18 | 19 | 23 | 24 | 28 | 29 | 33 | 34 | 38 | 39 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 | 35 | 36 | 40 | 41 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | **This project is no longer maintained. Recommend using [LargeDraweeView](https://github.com/ongakuer/LargeDraweeView)** 3 | 4 | 5 | # PhotoDraweeView 6 | 7 | [PhotoView](https://github.com/chrisbanes/PhotoView) For [Fresco](https://github.com/facebook/fresco) 8 | 9 | ![Maven Central Version](https://img.shields.io/maven-central/v/me.relex/photodraweeview) 10 | 11 | ![PhotoDraweeView](/screenshot.gif) 12 | 13 | ## Gradle 14 | 15 | ###### AndroidX 16 | ```groovy 17 | dependencies { 18 | implementation 'com.facebook.fresco:fresco:x.x.x' // (latest) 19 | implementation 'me.relex:photodraweeview:2.1.0' 20 | } 21 | ``` 22 | 23 | ###### Android Support Library 24 | ```groovy 25 | dependencies { 26 | implementation 'com.facebook.fresco:fresco:x.x.x' // (latest) 27 | implementation 'me.relex:photodraweeview:1.1.3' 28 | } 29 | ``` 30 | 31 | 32 | 33 | ## Usage 34 | ```java 35 | mPhotoDraweeView.setPhotoUri(Uri.parse("http://your.image.url")); 36 | ``` 37 | 38 | 39 | 40 | ##### Using the ControllerBuilder 41 | ```java 42 | PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder(); 43 | controller.setUri(URI); 44 | controller.setOldController(mPhotoDraweeView.getController()); 45 | controller.setControllerListener(new BaseControllerListener() { 46 | @Override 47 | public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { 48 | super.onFinalImageSet(id, imageInfo, animatable); 49 | if (imageInfo == null || mPhotoDraweeView == null) { 50 | return; 51 | } 52 | mPhotoDraweeView.update(imageInfo.getWidth(), imageInfo.getHeight()); 53 | } 54 | }); 55 | mPhotoDraweeView.setController(controller.build()); 56 | ``` 57 | 58 | 59 | ## [Issues With ViewGroups](https://github.com/chrisbanes/PhotoView#issues-with-viewgroups) 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /sample/src/main/java/me/relex/photodraweeview/sample/gestures/ScaleStepDoubleTapListener.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview.sample.gestures; 2 | 3 | import android.view.MotionEvent; 4 | import me.relex.photodraweeview.Attacher; 5 | import me.relex.photodraweeview.DefaultOnDoubleTapListener; 6 | 7 | public class ScaleStepDoubleTapListener extends DefaultOnDoubleTapListener { 8 | 9 | private static float DEFAULT_SCALE_STEP = 1f; 10 | private float mScaleStep = DEFAULT_SCALE_STEP; 11 | 12 | public ScaleStepDoubleTapListener(Attacher attacher) { 13 | super(attacher); 14 | mAttacher = attacher; 15 | } 16 | 17 | public ScaleStepDoubleTapListener(Attacher attacher, float scaleStep) { 18 | super(attacher); 19 | mAttacher = attacher; 20 | mScaleStep = scaleStep; 21 | } 22 | 23 | public void setScaleStep(float scaleStep) { 24 | mScaleStep = scaleStep; 25 | } 26 | 27 | @Override public boolean onDoubleTap(MotionEvent event) { 28 | if (mAttacher == null) { 29 | return false; 30 | } 31 | 32 | try { 33 | float scale = mAttacher.getScale(); 34 | float x = event.getX(); 35 | float y = event.getY(); 36 | 37 | // min, step, max 38 | float newScale = scale; 39 | if (scale < mAttacher.getMaximumScale()) { 40 | newScale += mScaleStep; 41 | if (newScale > mAttacher.getMaximumScale()) { 42 | newScale = mAttacher.getMaximumScale(); 43 | } 44 | } else { 45 | newScale = mAttacher.getMinimumScale(); 46 | } 47 | 48 | mAttacher.setScale(newScale, x, y, true); 49 | } catch (Exception e) { 50 | // Can sometimes happen when getX() and getY() is called 51 | } 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /photodraweeview/src/main/java/me/relex/photodraweeview/IAttacher.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview; 2 | 3 | import android.view.GestureDetector; 4 | import android.view.View; 5 | 6 | /** 7 | * **************************************************************************** 8 | * Copyright 2011, 2012 Chris Banes. 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * ***************************************************************************** 22 | */ 23 | 24 | public interface IAttacher { 25 | 26 | float DEFAULT_MAX_SCALE = 3.0f; 27 | float DEFAULT_MID_SCALE = 1.75f; 28 | float DEFAULT_MIN_SCALE = 1.0f; 29 | long ZOOM_DURATION = 200L; 30 | 31 | float getMinimumScale(); 32 | 33 | float getMediumScale(); 34 | 35 | float getMaximumScale(); 36 | 37 | void setMaximumScale(float maximumScale); 38 | 39 | void setMediumScale(float mediumScale); 40 | 41 | void setMinimumScale(float minimumScale); 42 | 43 | float getScale(); 44 | 45 | void setScale(float scale); 46 | 47 | void setScale(float scale, boolean animate); 48 | 49 | void setScale(float scale, float focalX, float focalY, boolean animate); 50 | 51 | void setOrientation(@Attacher.OrientationMode int orientation); 52 | 53 | void setZoomTransitionDuration(long duration); 54 | 55 | void setAllowParentInterceptOnEdge(boolean allow); 56 | 57 | void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener listener); 58 | 59 | void setOnScaleChangeListener(OnScaleChangeListener listener); 60 | 61 | void setOnLongClickListener(View.OnLongClickListener listener); 62 | 63 | void setOnPhotoTapListener(OnPhotoTapListener listener); 64 | 65 | void setOnViewTapListener(OnViewTapListener listener); 66 | 67 | OnPhotoTapListener getOnPhotoTapListener(); 68 | 69 | OnViewTapListener getOnViewTapListener(); 70 | 71 | void update(int imageInfoWidth, int imageInfoHeight); 72 | } 73 | -------------------------------------------------------------------------------- /sample/src/main/java/me/relex/photodraweeview/sample/SharedElementLaunchedActivity.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview.sample; 2 | 3 | import android.annotation.TargetApi; 4 | import android.net.Uri; 5 | import android.os.Build; 6 | import android.os.Bundle; 7 | import androidx.core.app.ActivityCompat; 8 | import androidx.core.app.SharedElementCallback; 9 | import androidx.core.view.ViewCompat; 10 | import androidx.appcompat.app.AppCompatActivity; 11 | import android.transition.AutoTransition; 12 | import android.view.View; 13 | import android.view.Window; 14 | import java.util.List; 15 | import me.relex.photodraweeview.OnPhotoTapListener; 16 | import me.relex.photodraweeview.PhotoDraweeView; 17 | 18 | public class SharedElementLaunchedActivity extends AppCompatActivity { 19 | 20 | @Override protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | initWindowTransitions(); 23 | setContentView(R.layout.activity_shared_element_launched); 24 | PhotoDraweeView draweeView = findViewById(R.id.photo_drawee_view); 25 | ViewCompat.setTransitionName(draweeView, SharedElementActivity.SHARED_ELEMENT_NAME); 26 | 27 | draweeView.setPhotoUri(Uri.parse("res:///" + R.drawable.panda)); 28 | draweeView.setOnPhotoTapListener(new OnPhotoTapListener() { 29 | @Override public void onPhotoTap(View view, float x, float y) { 30 | onBackPressed(); 31 | } 32 | }); 33 | } 34 | 35 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void initWindowTransitions() { 36 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 37 | getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS); 38 | AutoTransition transition = new AutoTransition(); 39 | getWindow().setSharedElementEnterTransition(transition); 40 | getWindow().setSharedElementExitTransition(transition); 41 | ActivityCompat.setEnterSharedElementCallback(this, new SharedElementCallback() { 42 | @Override public void onSharedElementEnd(List sharedElementNames, 43 | List sharedElements, List sharedElementSnapshots) { 44 | for (final View view : sharedElements) { 45 | if (view instanceof PhotoDraweeView) { 46 | ((PhotoDraweeView) view).setScale(1f, true); 47 | } 48 | } 49 | } 50 | }); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /photodraweeview/src/main/java/me/relex/photodraweeview/DefaultOnDoubleTapListener.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview; 2 | 3 | import android.graphics.RectF; 4 | import android.view.GestureDetector; 5 | import android.view.MotionEvent; 6 | import com.facebook.drawee.generic.GenericDraweeHierarchy; 7 | import com.facebook.drawee.view.DraweeView; 8 | 9 | public class DefaultOnDoubleTapListener implements GestureDetector.OnDoubleTapListener { 10 | 11 | protected Attacher mAttacher; 12 | 13 | public DefaultOnDoubleTapListener(Attacher attacher) { 14 | setPhotoDraweeViewAttacher(attacher); 15 | } 16 | 17 | @Override public boolean onSingleTapConfirmed(MotionEvent e) { 18 | 19 | if (mAttacher == null) { 20 | return false; 21 | } 22 | DraweeView draweeView = mAttacher.getDraweeView(); 23 | if (draweeView == null) { 24 | return false; 25 | } 26 | 27 | if (mAttacher.getOnPhotoTapListener() != null) { 28 | final RectF displayRect = mAttacher.getDisplayRect(); 29 | 30 | if (null != displayRect) { 31 | final float x = e.getX(), y = e.getY(); 32 | if (displayRect.contains(x, y)) { 33 | float xResult = (x - displayRect.left) / displayRect.width(); 34 | float yResult = (y - displayRect.top) / displayRect.height(); 35 | mAttacher.getOnPhotoTapListener().onPhotoTap(draweeView, xResult, yResult); 36 | return true; 37 | } 38 | } 39 | } 40 | 41 | if (mAttacher.getOnViewTapListener() != null) { 42 | mAttacher.getOnViewTapListener().onViewTap(draweeView, e.getX(), e.getY()); 43 | return true; 44 | } 45 | 46 | return false; 47 | } 48 | 49 | @Override public boolean onDoubleTap(MotionEvent event) { 50 | if (mAttacher == null) { 51 | return false; 52 | } 53 | 54 | try { 55 | float scale = mAttacher.getScale(); 56 | float x = event.getX(); 57 | float y = event.getY(); 58 | 59 | // min, mid, max 60 | if (scale < mAttacher.getMediumScale()) { 61 | mAttacher.setScale(mAttacher.getMediumScale(), x, y, true); 62 | } else if (scale >= mAttacher.getMediumScale() && scale < mAttacher.getMaximumScale()) { 63 | mAttacher.setScale(mAttacher.getMaximumScale(), x, y, true); 64 | } else { 65 | mAttacher.setScale(mAttacher.getMinimumScale(), x, y, true); 66 | } 67 | } catch (Exception e) { 68 | // Can sometimes happen when getX() and getY() is called 69 | } 70 | return true; 71 | } 72 | 73 | @Override public boolean onDoubleTapEvent(MotionEvent event) { 74 | return false; 75 | } 76 | 77 | public void setPhotoDraweeViewAttacher(Attacher attacher) { 78 | mAttacher = attacher; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /sample/src/main/java/me/relex/photodraweeview/sample/RecyclerViewActivity.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview.sample; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | import androidx.appcompat.app.AppCompatActivity; 8 | import androidx.recyclerview.widget.LinearLayoutManager; 9 | import androidx.recyclerview.widget.RecyclerView; 10 | import androidx.appcompat.widget.Toolbar; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import me.relex.photodraweeview.Attacher; 15 | import me.relex.photodraweeview.PhotoDraweeView; 16 | 17 | public class RecyclerViewActivity extends AppCompatActivity { 18 | 19 | public static void startActivity(Context context) { 20 | context.startActivity(new Intent(context, RecyclerViewActivity.class)); 21 | } 22 | 23 | @Override protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_recycler_view); 26 | 27 | ((Toolbar) findViewById(R.id.toolbar)).setNavigationOnClickListener( 28 | new View.OnClickListener() { 29 | @Override public void onClick(View v) { 30 | onBackPressed(); 31 | } 32 | }); 33 | 34 | RecyclerView recyclerView = findViewById(R.id.recycler_view); 35 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 36 | recyclerView.setAdapter(new DraweeAdapter()); 37 | } 38 | 39 | public class DraweeAdapter extends RecyclerView.Adapter { 40 | 41 | private int[] mDrawables = new int[] { 42 | R.drawable.viewpager_1, R.drawable.viewpager_2, R.drawable.viewpager_3, 43 | R.drawable.viewpager_1, R.drawable.viewpager_2, R.drawable.viewpager_3, 44 | }; 45 | 46 | @Override public DraweeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 47 | return DraweeViewHolder.createViewHolder(parent); 48 | } 49 | 50 | @Override public void onBindViewHolder(DraweeViewHolder holder, int position) { 51 | holder.bindView(mDrawables[position]); 52 | } 53 | 54 | @Override public int getItemCount() { 55 | return mDrawables.length; 56 | } 57 | } 58 | 59 | public static class DraweeViewHolder extends RecyclerView.ViewHolder { 60 | 61 | private PhotoDraweeView mPhotoDraweeView; 62 | 63 | public DraweeViewHolder(View itemView) { 64 | super(itemView); 65 | mPhotoDraweeView = itemView.findViewById(R.id.photo_drawee_view); 66 | mPhotoDraweeView.setOrientation(Attacher.VERTICAL); 67 | } 68 | 69 | public static DraweeViewHolder createViewHolder(ViewGroup viewGroup) { 70 | return new DraweeViewHolder(LayoutInflater.from(viewGroup.getContext()) 71 | .inflate(R.layout.item_photo_view, viewGroup, false)); 72 | } 73 | 74 | public void bindView(int resId) { 75 | mPhotoDraweeView.setPhotoUri(Uri.parse("res:///" + resId)); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /sample/src/main/java/me/relex/photodraweeview/sample/SharedElementActivity.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview.sample; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | import androidx.core.app.ActivityCompat; 8 | import androidx.core.app.ActivityOptionsCompat; 9 | import androidx.core.view.ViewCompat; 10 | import androidx.appcompat.app.AppCompatActivity; 11 | import androidx.appcompat.widget.Toolbar; 12 | import android.view.View; 13 | import com.facebook.drawee.view.SimpleDraweeView; 14 | import java.util.List; 15 | 16 | public class SharedElementActivity extends AppCompatActivity { 17 | 18 | public static final String SHARED_ELEMENT_NAME = "SHARED_ELEMENT_NAME"; 19 | 20 | public static void startActivity(Context context) { 21 | context.startActivity(new Intent(context, SharedElementActivity.class)); 22 | } 23 | 24 | @Override protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_shared_element); 27 | 28 | ((Toolbar) findViewById(R.id.toolbar)).setNavigationOnClickListener( 29 | new View.OnClickListener() { 30 | @Override public void onClick(View v) { 31 | onBackPressed(); 32 | } 33 | }); 34 | 35 | final SimpleDraweeView draweeView = findViewById(R.id.photo_drawee_view); 36 | draweeView.setImageURI(Uri.parse("res:///" + R.drawable.panda)); 37 | ViewCompat.setTransitionName(draweeView, SHARED_ELEMENT_NAME); 38 | draweeView.setOnClickListener(new View.OnClickListener() { 39 | @Override public void onClick(View v) { 40 | 41 | ActivityOptionsCompat optionsCompat = 42 | ActivityOptionsCompat.makeSceneTransitionAnimation( 43 | SharedElementActivity.this, draweeView, SHARED_ELEMENT_NAME); 44 | 45 | // FIX BUG https://github.com/facebook/fresco/issues/1445 46 | ActivityCompat.setExitSharedElementCallback(SharedElementActivity.this, 47 | new androidx.core.app.SharedElementCallback() { 48 | @Override 49 | public void onSharedElementEnd(List sharedElementNames, 50 | List sharedElements, List sharedElementSnapshots) { 51 | super.onSharedElementEnd(sharedElementNames, sharedElements, 52 | sharedElementSnapshots); 53 | for (final View view : sharedElements) { 54 | if (view instanceof SimpleDraweeView) { 55 | view.setVisibility(View.VISIBLE); 56 | } 57 | } 58 | } 59 | }); 60 | 61 | ActivityCompat.startActivity(SharedElementActivity.this, 62 | new Intent(SharedElementActivity.this, SharedElementLaunchedActivity.class), 63 | optionsCompat.toBundle()); 64 | } 65 | }); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sample/src/main/java/me/relex/photodraweeview/sample/SingleActivity.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview.sample; 2 | 3 | import android.net.Uri; 4 | import android.os.Bundle; 5 | import androidx.appcompat.app.AppCompatActivity; 6 | import androidx.appcompat.widget.Toolbar; 7 | import android.view.MenuItem; 8 | import android.view.View; 9 | import android.widget.Toast; 10 | import me.relex.photodraweeview.OnPhotoTapListener; 11 | import me.relex.photodraweeview.OnViewTapListener; 12 | import me.relex.photodraweeview.PhotoDraweeView; 13 | import me.relex.photodraweeview.sample.gestures.ScaleStepDoubleTapListener; 14 | 15 | public class SingleActivity extends AppCompatActivity { 16 | 17 | private PhotoDraweeView mPhotoDraweeView; 18 | 19 | @Override protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_single); 22 | 23 | initToolbar(); 24 | mPhotoDraweeView = findViewById(R.id.photo_drawee_view); 25 | mPhotoDraweeView.setPhotoUri(Uri.parse("res:///" + R.drawable.panda)); 26 | mPhotoDraweeView.setOnPhotoTapListener(new OnPhotoTapListener() { 27 | @Override public void onPhotoTap(View view, float x, float y) { 28 | Toast.makeText(view.getContext(), "onPhotoTap : x = " + x + ";" + " y = " + y, 29 | Toast.LENGTH_SHORT).show(); 30 | } 31 | }); 32 | mPhotoDraweeView.setOnViewTapListener(new OnViewTapListener() { 33 | @Override public void onViewTap(View view, float x, float y) { 34 | Toast.makeText(view.getContext(), "onViewTap", Toast.LENGTH_SHORT).show(); 35 | } 36 | }); 37 | 38 | mPhotoDraweeView.setOnLongClickListener(new View.OnLongClickListener() { 39 | @Override public boolean onLongClick(View v) { 40 | Toast.makeText(v.getContext(), "onLongClick", Toast.LENGTH_SHORT).show(); 41 | return true; 42 | } 43 | }); 44 | } 45 | 46 | private void initToolbar() { 47 | Toolbar toolbar = findViewById(R.id.toolbar); 48 | toolbar.inflateMenu(R.menu.single); 49 | toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { 50 | @Override public boolean onMenuItemClick(MenuItem menuItem) { 51 | switch (menuItem.getItemId()) { 52 | case R.id.default_image: 53 | mPhotoDraweeView.setOnDoubleTapListener(null); 54 | mPhotoDraweeView.setPhotoUri(Uri.parse("res:///" + R.drawable.panda)); 55 | break; 56 | case R.id.failure_image: 57 | mPhotoDraweeView.setPhotoUri(Uri.parse("http://google.com/404.jpg")); 58 | break; 59 | case R.id.view_pager: 60 | ViewPagerActivity.startActivity(SingleActivity.this); 61 | break; 62 | case R.id.recycler_view: 63 | RecyclerViewActivity.startActivity(SingleActivity.this); 64 | break; 65 | case R.id.scale_step: 66 | mPhotoDraweeView.setOnDoubleTapListener( 67 | new ScaleStepDoubleTapListener(mPhotoDraweeView.getAttacher(), 68 | 0.25f)); 69 | break; 70 | case R.id.shared_element: 71 | SharedElementActivity.startActivity(SingleActivity.this); 72 | break; 73 | default: 74 | break; 75 | } 76 | 77 | return true; 78 | } 79 | }); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /sample/src/main/java/me/relex/photodraweeview/sample/ViewPagerActivity.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview.sample; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.drawable.Animatable; 6 | import android.net.Uri; 7 | import android.os.Bundle; 8 | import androidx.viewpager.widget.PagerAdapter; 9 | import androidx.appcompat.app.AppCompatActivity; 10 | import androidx.appcompat.widget.Toolbar; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import com.facebook.drawee.backends.pipeline.Fresco; 14 | import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder; 15 | import com.facebook.drawee.controller.BaseControllerListener; 16 | import com.facebook.imagepipeline.image.ImageInfo; 17 | import me.relex.circleindicator.CircleIndicator; 18 | import me.relex.photodraweeview.PhotoDraweeView; 19 | 20 | public class ViewPagerActivity extends AppCompatActivity { 21 | 22 | public static void startActivity(Context context) { 23 | context.startActivity(new Intent(context, ViewPagerActivity.class)); 24 | } 25 | 26 | @Override protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_viewpager); 29 | 30 | ((Toolbar) findViewById(R.id.toolbar)).setNavigationOnClickListener( 31 | new View.OnClickListener() { 32 | @Override public void onClick(View v) { 33 | onBackPressed(); 34 | } 35 | }); 36 | 37 | CircleIndicator indicator = findViewById(R.id.indicator); 38 | MultiTouchViewPager viewPager = findViewById(R.id.view_pager); 39 | viewPager.setAdapter(new DraweePagerAdapter()); 40 | indicator.setViewPager(viewPager); 41 | } 42 | 43 | public class DraweePagerAdapter extends PagerAdapter { 44 | 45 | private int[] mDrawables = new int[] { 46 | R.drawable.viewpager_1, R.drawable.viewpager_2, R.drawable.viewpager_3 47 | }; 48 | 49 | @Override public int getCount() { 50 | return mDrawables.length; 51 | } 52 | 53 | @Override public boolean isViewFromObject(View view, Object object) { 54 | return view == object; 55 | } 56 | 57 | @Override public void destroyItem(ViewGroup container, int position, Object object) { 58 | container.removeView((View) object); 59 | } 60 | 61 | @Override public Object instantiateItem(ViewGroup viewGroup, int position) { 62 | final PhotoDraweeView photoDraweeView = new PhotoDraweeView(viewGroup.getContext()); 63 | PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder(); 64 | controller.setUri(Uri.parse("res:///" + mDrawables[position])); 65 | controller.setOldController(photoDraweeView.getController()); 66 | controller.setControllerListener(new BaseControllerListener() { 67 | @Override 68 | public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { 69 | super.onFinalImageSet(id, imageInfo, animatable); 70 | if (imageInfo == null) { 71 | return; 72 | } 73 | photoDraweeView.update(imageInfo.getWidth(), imageInfo.getHeight()); 74 | } 75 | }); 76 | photoDraweeView.setController(controller.build()); 77 | 78 | try { 79 | viewGroup.addView(photoDraweeView, ViewGroup.LayoutParams.MATCH_PARENT, 80 | ViewGroup.LayoutParams.MATCH_PARENT); 81 | } catch (Exception e) { 82 | e.printStackTrace(); 83 | } 84 | 85 | return photoDraweeView; 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 33 | 34 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 91 | 110 | 111 | 112 | 113 | 114 | 115 | 117 | -------------------------------------------------------------------------------- /photodraweeview/src/main/java/me/relex/photodraweeview/ScaleDragDetector.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview; 2 | 3 | import android.content.Context; 4 | import android.view.MotionEvent; 5 | import android.view.ScaleGestureDetector; 6 | import android.view.VelocityTracker; 7 | import android.view.ViewConfiguration; 8 | 9 | /** 10 | * **************************************************************************** 11 | * Copyright 2011, 2012 Chris Banes. 12 | * 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * ***************************************************************************** 25 | */ 26 | public class ScaleDragDetector implements ScaleGestureDetector.OnScaleGestureListener { 27 | 28 | private static final int INVALID_POINTER_ID = -1; 29 | 30 | private final float mTouchSlop; 31 | private final float mMinimumVelocity; 32 | private final ScaleGestureDetector mScaleDetector; 33 | private final OnScaleDragGestureListener mScaleDragGestureListener; 34 | 35 | private VelocityTracker mVelocityTracker; 36 | private boolean mIsDragging; 37 | float mLastTouchX; 38 | float mLastTouchY; 39 | private int mActivePointerId = INVALID_POINTER_ID; 40 | private int mActivePointerIndex = 0; 41 | 42 | public ScaleDragDetector(Context context, OnScaleDragGestureListener scaleDragGestureListener) { 43 | mScaleDetector = new ScaleGestureDetector(context, this); 44 | mScaleDragGestureListener = scaleDragGestureListener; 45 | 46 | final ViewConfiguration configuration = ViewConfiguration.get(context); 47 | mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); 48 | mTouchSlop = configuration.getScaledTouchSlop(); 49 | } 50 | 51 | @Override public boolean onScale(ScaleGestureDetector detector) { 52 | float scaleFactor = detector.getScaleFactor(); 53 | 54 | if (Float.isNaN(scaleFactor) || Float.isInfinite(scaleFactor)) { 55 | return false; 56 | } 57 | 58 | mScaleDragGestureListener.onScale(scaleFactor, detector.getFocusX(), detector.getFocusY()); 59 | return true; 60 | } 61 | 62 | @Override public boolean onScaleBegin(ScaleGestureDetector detector) { 63 | return true; 64 | } 65 | 66 | @Override public void onScaleEnd(ScaleGestureDetector detector) { 67 | mScaleDragGestureListener.onScaleEnd(); 68 | } 69 | 70 | public boolean isScaling() { 71 | return mScaleDetector.isInProgress(); 72 | } 73 | 74 | public boolean isDragging() { 75 | return mIsDragging; 76 | } 77 | 78 | private float getActiveX(MotionEvent ev) { 79 | try { 80 | return ev.getX(mActivePointerIndex); 81 | } catch (Exception e) { 82 | return ev.getX(); 83 | } 84 | } 85 | 86 | private float getActiveY(MotionEvent ev) { 87 | try { 88 | return ev.getY(mActivePointerIndex); 89 | } catch (Exception e) { 90 | return ev.getY(); 91 | } 92 | } 93 | 94 | public boolean onTouchEvent(MotionEvent ev) { 95 | mScaleDetector.onTouchEvent(ev); 96 | final int action = ev.getActionMasked(); 97 | onTouchActivePointer(action, ev); 98 | onTouchDragEvent(action, ev); 99 | return true; 100 | } 101 | 102 | private void onTouchActivePointer(int action, MotionEvent ev) { 103 | switch (action) { 104 | case MotionEvent.ACTION_DOWN: 105 | mActivePointerId = ev.getPointerId(0); 106 | break; 107 | case MotionEvent.ACTION_CANCEL: 108 | case MotionEvent.ACTION_UP: 109 | mActivePointerId = INVALID_POINTER_ID; 110 | break; 111 | case MotionEvent.ACTION_POINTER_UP: 112 | final int pointerIndex = ev.getActionIndex(); 113 | final int pointerId = ev.getPointerId(pointerIndex); 114 | if (pointerId == mActivePointerId) { 115 | final int newPointerIndex = (pointerIndex == 0) ? 1 : 0; 116 | mActivePointerId = ev.getPointerId(newPointerIndex); 117 | mLastTouchX = ev.getX(newPointerIndex); 118 | mLastTouchY = ev.getY(newPointerIndex); 119 | } 120 | break; 121 | default: 122 | break; 123 | } 124 | 125 | mActivePointerIndex = 126 | ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0); 127 | } 128 | 129 | private void onTouchDragEvent(int action, MotionEvent ev) { 130 | switch (action) { 131 | case MotionEvent.ACTION_DOWN: { 132 | mVelocityTracker = VelocityTracker.obtain(); 133 | if (null != mVelocityTracker) { 134 | mVelocityTracker.addMovement(ev); 135 | } 136 | 137 | mLastTouchX = getActiveX(ev); 138 | mLastTouchY = getActiveY(ev); 139 | mIsDragging = false; 140 | break; 141 | } 142 | 143 | case MotionEvent.ACTION_MOVE: { 144 | final float x = getActiveX(ev); 145 | final float y = getActiveY(ev); 146 | final float dx = x - mLastTouchX, dy = y - mLastTouchY; 147 | 148 | if (!mIsDragging) { 149 | mIsDragging = Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop; 150 | } 151 | 152 | if (mIsDragging) { 153 | mScaleDragGestureListener.onDrag(dx, dy); 154 | mLastTouchX = x; 155 | mLastTouchY = y; 156 | 157 | if (null != mVelocityTracker) { 158 | mVelocityTracker.addMovement(ev); 159 | } 160 | } 161 | break; 162 | } 163 | 164 | case MotionEvent.ACTION_CANCEL: { 165 | if (null != mVelocityTracker) { 166 | mVelocityTracker.recycle(); 167 | mVelocityTracker = null; 168 | } 169 | break; 170 | } 171 | 172 | case MotionEvent.ACTION_UP: { 173 | if (mIsDragging) { 174 | if (null != mVelocityTracker) { 175 | mLastTouchX = getActiveX(ev); 176 | mLastTouchY = getActiveY(ev); 177 | 178 | mVelocityTracker.addMovement(ev); 179 | mVelocityTracker.computeCurrentVelocity(1000); 180 | 181 | final float vX = mVelocityTracker.getXVelocity(), vY = 182 | mVelocityTracker.getYVelocity(); 183 | 184 | if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) { 185 | mScaleDragGestureListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY); 186 | } 187 | } 188 | } 189 | if (null != mVelocityTracker) { 190 | mVelocityTracker.recycle(); 191 | mVelocityTracker = null; 192 | } 193 | break; 194 | } 195 | default: 196 | break; 197 | } 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /photodraweeview/src/main/java/me/relex/photodraweeview/PhotoDraweeView.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.drawable.Animatable; 6 | import android.net.Uri; 7 | import androidx.annotation.NonNull; 8 | import androidx.annotation.Nullable; 9 | import android.util.AttributeSet; 10 | import android.view.GestureDetector; 11 | import android.view.MotionEvent; 12 | import com.facebook.drawee.backends.pipeline.Fresco; 13 | import com.facebook.drawee.controller.BaseControllerListener; 14 | import com.facebook.drawee.generic.GenericDraweeHierarchy; 15 | import com.facebook.drawee.interfaces.DraweeController; 16 | import com.facebook.drawee.view.SimpleDraweeView; 17 | import com.facebook.imagepipeline.image.ImageInfo; 18 | 19 | public class PhotoDraweeView extends SimpleDraweeView implements IAttacher { 20 | 21 | private Attacher mAttacher; 22 | 23 | private boolean mEnableDraweeMatrix = true; 24 | 25 | public PhotoDraweeView(Context context, GenericDraweeHierarchy hierarchy) { 26 | super(context, hierarchy); 27 | init(); 28 | } 29 | 30 | public PhotoDraweeView(Context context) { 31 | super(context); 32 | init(); 33 | } 34 | 35 | public PhotoDraweeView(Context context, AttributeSet attrs) { 36 | super(context, attrs); 37 | init(); 38 | } 39 | 40 | public PhotoDraweeView(Context context, AttributeSet attrs, int defStyle) { 41 | super(context, attrs, defStyle); 42 | init(); 43 | } 44 | 45 | protected void init() { 46 | if (mAttacher == null || mAttacher.getDraweeView() == null) { 47 | mAttacher = new Attacher(this); 48 | } 49 | } 50 | 51 | public Attacher getAttacher() { 52 | return mAttacher; 53 | } 54 | 55 | @Override public boolean onTouchEvent(MotionEvent event) { 56 | return super.onTouchEvent(event); 57 | } 58 | 59 | @Override protected void onDraw(@NonNull Canvas canvas) { 60 | int saveCount = canvas.save(); 61 | if (mEnableDraweeMatrix) { 62 | canvas.concat(mAttacher.getDrawMatrix()); 63 | } 64 | super.onDraw(canvas); 65 | canvas.restoreToCount(saveCount); 66 | } 67 | 68 | @Override protected void onAttachedToWindow() { 69 | init(); 70 | super.onAttachedToWindow(); 71 | } 72 | 73 | @Override protected void onDetachedFromWindow() { 74 | mAttacher.onDetachedFromWindow(); 75 | super.onDetachedFromWindow(); 76 | } 77 | 78 | @Override public float getMinimumScale() { 79 | return mAttacher.getMinimumScale(); 80 | } 81 | 82 | @Override public float getMediumScale() { 83 | return mAttacher.getMediumScale(); 84 | } 85 | 86 | @Override public float getMaximumScale() { 87 | return mAttacher.getMaximumScale(); 88 | } 89 | 90 | @Override public void setMinimumScale(float minimumScale) { 91 | mAttacher.setMinimumScale(minimumScale); 92 | } 93 | 94 | @Override public void setMediumScale(float mediumScale) { 95 | mAttacher.setMediumScale(mediumScale); 96 | } 97 | 98 | @Override public void setMaximumScale(float maximumScale) { 99 | mAttacher.setMaximumScale(maximumScale); 100 | } 101 | 102 | @Override public float getScale() { 103 | return mAttacher.getScale(); 104 | } 105 | 106 | @Override public void setScale(float scale) { 107 | mAttacher.setScale(scale); 108 | } 109 | 110 | @Override public void setScale(float scale, boolean animate) { 111 | mAttacher.setScale(scale, animate); 112 | } 113 | 114 | @Override public void setScale(float scale, float focalX, float focalY, boolean animate) { 115 | mAttacher.setScale(scale, focalX, focalY, animate); 116 | } 117 | 118 | @Override public void setOrientation(@Attacher.OrientationMode int orientation) { 119 | mAttacher.setOrientation(orientation); 120 | } 121 | 122 | @Override public void setZoomTransitionDuration(long duration) { 123 | mAttacher.setZoomTransitionDuration(duration); 124 | } 125 | 126 | @Override public void setAllowParentInterceptOnEdge(boolean allow) { 127 | mAttacher.setAllowParentInterceptOnEdge(allow); 128 | } 129 | 130 | @Override public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener listener) { 131 | mAttacher.setOnDoubleTapListener(listener); 132 | } 133 | 134 | @Override public void setOnScaleChangeListener(OnScaleChangeListener listener) { 135 | mAttacher.setOnScaleChangeListener(listener); 136 | } 137 | 138 | @Override public void setOnLongClickListener(OnLongClickListener listener) { 139 | mAttacher.setOnLongClickListener(listener); 140 | } 141 | 142 | @Override public void setOnPhotoTapListener(OnPhotoTapListener listener) { 143 | mAttacher.setOnPhotoTapListener(listener); 144 | } 145 | 146 | @Override public void setOnViewTapListener(OnViewTapListener listener) { 147 | mAttacher.setOnViewTapListener(listener); 148 | } 149 | 150 | @Override public OnPhotoTapListener getOnPhotoTapListener() { 151 | return mAttacher.getOnPhotoTapListener(); 152 | } 153 | 154 | @Override public OnViewTapListener getOnViewTapListener() { 155 | return mAttacher.getOnViewTapListener(); 156 | } 157 | 158 | @Override public void update(int imageInfoWidth, int imageInfoHeight) { 159 | mAttacher.update(imageInfoWidth, imageInfoHeight); 160 | } 161 | 162 | public boolean isEnableDraweeMatrix() { 163 | return mEnableDraweeMatrix; 164 | } 165 | 166 | public void setEnableDraweeMatrix(boolean enableDraweeMatrix) { 167 | mEnableDraweeMatrix = enableDraweeMatrix; 168 | } 169 | 170 | public void setPhotoUri(Uri uri) { 171 | setPhotoUri(uri, null); 172 | } 173 | 174 | public void setPhotoUri(Uri uri, @Nullable Context context) { 175 | mEnableDraweeMatrix = false; 176 | DraweeController controller = Fresco.newDraweeControllerBuilder() 177 | .setCallerContext(context) 178 | .setUri(uri) 179 | .setOldController(getController()) 180 | .setControllerListener(new BaseControllerListener() { 181 | @Override public void onFailure(String id, Throwable throwable) { 182 | super.onFailure(id, throwable); 183 | mEnableDraweeMatrix = false; 184 | } 185 | 186 | @Override public void onFinalImageSet(String id, ImageInfo imageInfo, 187 | Animatable animatable) { 188 | super.onFinalImageSet(id, imageInfo, animatable); 189 | mEnableDraweeMatrix = true; 190 | if (imageInfo != null) { 191 | update(imageInfo.getWidth(), imageInfo.getHeight()); 192 | } 193 | } 194 | 195 | @Override 196 | public void onIntermediateImageFailed(String id, Throwable throwable) { 197 | super.onIntermediateImageFailed(id, throwable); 198 | mEnableDraweeMatrix = false; 199 | } 200 | 201 | @Override public void onIntermediateImageSet(String id, ImageInfo imageInfo) { 202 | super.onIntermediateImageSet(id, imageInfo); 203 | mEnableDraweeMatrix = true; 204 | if (imageInfo != null) { 205 | update(imageInfo.getWidth(), imageInfo.getHeight()); 206 | } 207 | } 208 | }) 209 | .build(); 210 | setController(controller); 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /photodraweeview/upload-maven-plugin.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'signing' 3 | 4 | ext { 5 | PUBLISH_DEVELOPER = "Relex" 6 | PUBLISH_NAME = "PhotoDraweeView" 7 | PUBLISH_DESCRIPTION = "PhotoView For Fresco" 8 | PUBLISH_URL = "https://github.com/ongakuer/PhotoDraweeView" 9 | PUBLISH_GIT_URL = "https://github.com/ongakuer/PhotoDraweeView.git" 10 | PUBLISH_GROUP_ID = "me.relex" 11 | PUBLISH_ARTIFACT_ID = "photodraweeview" 12 | PUBLISH_VERSION = android.defaultConfig.versionName 13 | } 14 | 15 | task androidJavadocs(type: Javadoc) { 16 | source = android.sourceSets.main.java.srcDirs 17 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 18 | android.libraryVariants.all { variant -> 19 | if (variant.name == 'release') { 20 | if (variant.hasProperty('javaCompileProvider')) { 21 | owner.classpath += variant.javaCompileProvider.get().classpath 22 | } else { 23 | owner.classpath += variant.javaCompiler.classpath 24 | } 25 | } 26 | } 27 | options { 28 | encoding 'utf-8' 29 | charSet 'utf-8' 30 | } 31 | exclude '**/R.html', '**/R.*.html', '**/index.html', '**/*.kt' 32 | } 33 | 34 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 35 | archiveClassifier.set('javadoc') 36 | from androidJavadocs.destinationDir 37 | } 38 | 39 | task androidSourcesJar(type: Jar) { 40 | archiveClassifier.set('sources') 41 | from android.sourceSets.main.java.srcDirs 42 | } 43 | 44 | project.artifacts { 45 | archives androidJavadocsJar, androidSourcesJar 46 | } 47 | 48 | afterEvaluate { 49 | 50 | publishing { 51 | publications { 52 | maven(MavenPublication) { 53 | groupId project.ext.PUBLISH_GROUP_ID 54 | artifactId project.ext.PUBLISH_ARTIFACT_ID 55 | version project.ext.PUBLISH_VERSION 56 | 57 | artifact bundleReleaseAar 58 | artifact androidJavadocsJar 59 | artifact androidSourcesJar 60 | 61 | pom { 62 | name = project.ext.PUBLISH_NAME 63 | description = project.ext.PUBLISH_DESCRIPTION 64 | url = project.ext.PUBLISH_URL 65 | licenses { 66 | license { 67 | name = 'The Apache License, Version 2.0' 68 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 69 | } 70 | } 71 | developers { 72 | developer { 73 | name = project.ext.PUBLISH_DEVELOPER 74 | } 75 | } 76 | scm { 77 | connection = "scm:git:${project.ext.PUBLISH_GIT_URL}" 78 | url = project.ext.PUBLISH_URL 79 | } 80 | 81 | withXml { 82 | def dependenciesNode = asNode().appendNode('dependencies') 83 | 84 | project.configurations.implementation.allDependencies.each { 85 | def dependencyNode = dependenciesNode.appendNode('dependency') 86 | dependencyNode.appendNode('groupId', it.group) 87 | dependencyNode.appendNode('artifactId', it.name) 88 | dependencyNode.appendNode('version', it.version) 89 | } 90 | } 91 | } 92 | 93 | // pom.withXml { 94 | // final dependenciesNode = asNode().appendNode('dependencies') 95 | // // Dependency 96 | // ext.addDependency = { Dependency dep, String scope -> 97 | // if (dep.group == null || 98 | // dep.version == 99 | // null || 100 | // dep.name == 101 | // null || 102 | // dep.name == 103 | // "unspecified") { 104 | // return 105 | // } 106 | // 107 | // final dependencyNode = dependenciesNode.appendNode('dependency') 108 | // dependencyNode.appendNode('artifactId', dep.name) 109 | // 110 | // if (dep.version == 'unspecified') { 111 | // return 112 | // } else { 113 | // dependencyNode.appendNode('groupId', dep.group) 114 | // dependencyNode.appendNode('version', dep.version) 115 | // System.println("${dep.group} ${dep.name} ${dep.version}") 116 | // } 117 | // 118 | // dependencyNode.appendNode('scope', scope) 119 | // def artifactsList = dep.properties['artifacts'] 120 | // if (artifactsList != null && artifactsList.size() > 0) { 121 | // final artifact = artifactsList[0] 122 | // dependencyNode.appendNode('type', artifact.getType()) 123 | // } 124 | // 125 | // if (!dep.transitive) { 126 | // final exclusionNode = dependencyNode. 127 | // appendNode('exclusions'). 128 | // appendNode('exclusion') 129 | // exclusionNode.appendNode('groupId', '*') 130 | // exclusionNode.appendNode('artifactId', '*') 131 | // } else if (!dep.properties.excludeRules.empty) { 132 | // final exclusions = dependencyNode.appendNode('exclusions') 133 | // dep.properties.excludeRules.each { ExcludeRule rule -> 134 | // final exclusionNode = exclusions.appendNode('exclusion') 135 | // exclusionNode.appendNode('groupId', rule.group ?: '*') 136 | // exclusionNode.appendNode('artifactId', rule.module ?: '*') 137 | // } 138 | // } 139 | // } 140 | // configurations. 141 | // api. 142 | // getDependencies(). 143 | // each { dep -> addDependency(dep, "compile") } 144 | // configurations. 145 | // implementation. 146 | // getDependencies(). 147 | // each { dep -> addDependency(dep, "runtime") } 148 | // } 149 | } 150 | } 151 | 152 | repositories { 153 | maven { 154 | url "$sonatypeRepo" 155 | credentials { 156 | username "$sonatypeUsername" 157 | password "$sonatypePassword" 158 | } 159 | } 160 | } 161 | } 162 | 163 | signing { 164 | sign publishing.publications.maven 165 | } 166 | } 167 | 168 | //task cleanBuildPublish(type: GradleBuild) { 169 | // tasks = ['clean', 'build', 'publish'] 170 | //} -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /photodraweeview/src/main/java/me/relex/photodraweeview/Attacher.java: -------------------------------------------------------------------------------- 1 | package me.relex.photodraweeview; 2 | 3 | import android.content.Context; 4 | import android.graphics.Matrix; 5 | import android.graphics.RectF; 6 | import android.os.Build; 7 | import android.view.GestureDetector; 8 | import android.view.MotionEvent; 9 | import android.view.View; 10 | import android.view.ViewParent; 11 | import android.view.animation.AccelerateDecelerateInterpolator; 12 | import android.view.animation.Interpolator; 13 | import android.widget.OverScroller; 14 | import androidx.annotation.IntDef; 15 | import androidx.annotation.Nullable; 16 | import androidx.core.view.GestureDetectorCompat; 17 | import com.facebook.drawee.drawable.ScalingUtils; 18 | import com.facebook.drawee.generic.GenericDraweeHierarchy; 19 | import com.facebook.drawee.view.DraweeView; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.ref.WeakReference; 23 | 24 | public class Attacher implements IAttacher, View.OnTouchListener, OnScaleDragGestureListener { 25 | 26 | private static final int EDGE_NONE = -1; 27 | private static final int EDGE_LEFT = 0, EDGE_TOP = 0; 28 | private static final int EDGE_RIGHT = 1, EDGE_BOTTOM = 1; 29 | private static final int EDGE_BOTH = 2; 30 | 31 | @IntDef({ HORIZONTAL, VERTICAL }) @Retention(RetentionPolicy.SOURCE) 32 | public @interface OrientationMode { 33 | } 34 | 35 | public static final int HORIZONTAL = 0; 36 | public static final int VERTICAL = 1; 37 | 38 | private int mOrientation = HORIZONTAL; 39 | 40 | private final float[] mMatrixValues = new float[9]; 41 | private final RectF mDisplayRect = new RectF(); 42 | private final Interpolator mZoomInterpolator = new AccelerateDecelerateInterpolator(); 43 | 44 | private float mMinScale = IAttacher.DEFAULT_MIN_SCALE; 45 | private float mMidScale = IAttacher.DEFAULT_MID_SCALE; 46 | private float mMaxScale = IAttacher.DEFAULT_MAX_SCALE; 47 | private long mZoomDuration = IAttacher.ZOOM_DURATION; 48 | 49 | private ScaleDragDetector mScaleDragDetector; 50 | private GestureDetectorCompat mGestureDetector; 51 | 52 | private boolean mBlockParentIntercept = false; 53 | private boolean mAllowParentInterceptOnEdge = true; 54 | private int mScrollEdgeX = EDGE_BOTH; 55 | private int mScrollEdgeY = EDGE_BOTH; 56 | 57 | private final Matrix mMatrix = new Matrix(); 58 | private int mImageInfoHeight = -1, mImageInfoWidth = -1; 59 | private FlingRunnable mCurrentFlingRunnable; 60 | private WeakReference> mDraweeView; 61 | 62 | private OnPhotoTapListener mPhotoTapListener; 63 | private OnViewTapListener mViewTapListener; 64 | private View.OnLongClickListener mLongClickListener; 65 | private OnScaleChangeListener mScaleChangeListener; 66 | 67 | public Attacher(DraweeView draweeView) { 68 | mDraweeView = new WeakReference<>(draweeView); 69 | draweeView.getHierarchy().setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER); 70 | draweeView.setOnTouchListener(this); 71 | mScaleDragDetector = new ScaleDragDetector(draweeView.getContext(), this); 72 | mGestureDetector = new GestureDetectorCompat(draweeView.getContext(), 73 | new GestureDetector.SimpleOnGestureListener() { 74 | @Override public void onLongPress(MotionEvent e) { 75 | super.onLongPress(e); 76 | if (null != mLongClickListener) { 77 | mLongClickListener.onLongClick(getDraweeView()); 78 | } 79 | } 80 | }); 81 | mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); 82 | } 83 | 84 | @Override 85 | public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener newOnDoubleTapListener) { 86 | if (newOnDoubleTapListener != null) { 87 | this.mGestureDetector.setOnDoubleTapListener(newOnDoubleTapListener); 88 | } else { 89 | this.mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); 90 | } 91 | } 92 | 93 | @Nullable public DraweeView getDraweeView() { 94 | return mDraweeView.get(); 95 | } 96 | 97 | @Override public float getMinimumScale() { 98 | return mMinScale; 99 | } 100 | 101 | @Override public float getMediumScale() { 102 | return mMidScale; 103 | } 104 | 105 | @Override public float getMaximumScale() { 106 | return mMaxScale; 107 | } 108 | 109 | @Override public void setMaximumScale(float maximumScale) { 110 | checkZoomLevels(mMinScale, mMidScale, maximumScale); 111 | mMaxScale = maximumScale; 112 | } 113 | 114 | @Override public void setMediumScale(float mediumScale) { 115 | checkZoomLevels(mMinScale, mediumScale, mMaxScale); 116 | mMidScale = mediumScale; 117 | } 118 | 119 | @Override public void setMinimumScale(float minimumScale) { 120 | checkZoomLevels(minimumScale, mMidScale, mMaxScale); 121 | mMinScale = minimumScale; 122 | } 123 | 124 | @Override public float getScale() { 125 | return (float) Math.sqrt( 126 | (float) Math.pow(getMatrixValue(mMatrix, Matrix.MSCALE_X), 2) + (float) Math.pow( 127 | getMatrixValue(mMatrix, Matrix.MSKEW_Y), 2)); 128 | } 129 | 130 | @Override public void setScale(float scale) { 131 | setScale(scale, false); 132 | } 133 | 134 | @Override public void setScale(float scale, boolean animate) { 135 | DraweeView draweeView = getDraweeView(); 136 | if (draweeView != null) { 137 | setScale(scale, (draweeView.getRight()) / 2, (draweeView.getBottom()) / 2, animate); 138 | } 139 | } 140 | 141 | @Override public void setScale(float scale, float focalX, float focalY, boolean animate) { 142 | DraweeView draweeView = getDraweeView(); 143 | 144 | if (draweeView == null || scale < mMinScale || scale > mMaxScale) { 145 | return; 146 | } 147 | 148 | if (animate) { 149 | draweeView.post(new AnimatedZoomRunnable(getScale(), scale, focalX, focalY)); 150 | } else { 151 | mMatrix.setScale(scale, scale, focalX, focalY); 152 | checkMatrixAndInvalidate(); 153 | } 154 | } 155 | 156 | @Override public void setOrientation(@OrientationMode int orientation) { 157 | mOrientation = orientation; 158 | } 159 | 160 | @Override public void setZoomTransitionDuration(long duration) { 161 | duration = duration < 0 ? IAttacher.ZOOM_DURATION : duration; 162 | mZoomDuration = duration; 163 | } 164 | 165 | @Override public void setAllowParentInterceptOnEdge(boolean allow) { 166 | mAllowParentInterceptOnEdge = allow; 167 | } 168 | 169 | @Override public void setOnScaleChangeListener(OnScaleChangeListener listener) { 170 | mScaleChangeListener = listener; 171 | } 172 | 173 | @Override public void setOnLongClickListener(View.OnLongClickListener listener) { 174 | mLongClickListener = listener; 175 | } 176 | 177 | @Override public void setOnPhotoTapListener(OnPhotoTapListener listener) { 178 | mPhotoTapListener = listener; 179 | } 180 | 181 | @Override public void setOnViewTapListener(OnViewTapListener listener) { 182 | mViewTapListener = listener; 183 | } 184 | 185 | @Override public OnPhotoTapListener getOnPhotoTapListener() { 186 | return mPhotoTapListener; 187 | } 188 | 189 | @Override public OnViewTapListener getOnViewTapListener() { 190 | return mViewTapListener; 191 | } 192 | 193 | @Override public void update(int imageInfoWidth, int imageInfoHeight) { 194 | mImageInfoWidth = imageInfoWidth; 195 | mImageInfoHeight = imageInfoHeight; 196 | updateBaseMatrix(); 197 | } 198 | 199 | private static void checkZoomLevels(float minZoom, float midZoom, float maxZoom) { 200 | if (minZoom >= midZoom) { 201 | throw new IllegalArgumentException("MinZoom has to be less than MidZoom"); 202 | } else if (midZoom >= maxZoom) { 203 | throw new IllegalArgumentException("MidZoom has to be less than MaxZoom"); 204 | } 205 | } 206 | 207 | private int getViewWidth() { 208 | 209 | DraweeView draweeView = getDraweeView(); 210 | 211 | if (draweeView != null) { 212 | 213 | return draweeView.getWidth() 214 | - draweeView.getPaddingLeft() 215 | - draweeView.getPaddingRight(); 216 | } 217 | 218 | return 0; 219 | } 220 | 221 | private int getViewHeight() { 222 | DraweeView draweeView = getDraweeView(); 223 | if (draweeView != null) { 224 | return draweeView.getHeight() 225 | - draweeView.getPaddingTop() 226 | - draweeView.getPaddingBottom(); 227 | } 228 | return 0; 229 | } 230 | 231 | private float getMatrixValue(Matrix matrix, int whichValue) { 232 | matrix.getValues(mMatrixValues); 233 | return mMatrixValues[whichValue]; 234 | } 235 | 236 | public Matrix getDrawMatrix() { 237 | return mMatrix; 238 | } 239 | 240 | public RectF getDisplayRect() { 241 | checkMatrixBounds(); 242 | return getDisplayRect(getDrawMatrix()); 243 | } 244 | 245 | public void checkMatrixAndInvalidate() { 246 | 247 | DraweeView draweeView = getDraweeView(); 248 | 249 | if (draweeView == null) { 250 | return; 251 | } 252 | 253 | if (checkMatrixBounds()) { 254 | draweeView.invalidate(); 255 | } 256 | } 257 | 258 | public boolean checkMatrixBounds() { 259 | RectF rect = getDisplayRect(getDrawMatrix()); 260 | if (rect == null) { 261 | return false; 262 | } 263 | 264 | float height = rect.height(); 265 | float width = rect.width(); 266 | float deltaX = 0.0F; 267 | float deltaY = 0.0F; 268 | int viewHeight = getViewHeight(); 269 | 270 | if (height <= (float) viewHeight) { 271 | deltaY = (viewHeight - height) / 2 - rect.top; 272 | mScrollEdgeY = EDGE_BOTH; 273 | } else if (rect.top > 0.0F) { 274 | deltaY = -rect.top; 275 | mScrollEdgeY = EDGE_TOP; 276 | } else if (rect.bottom < (float) viewHeight) { 277 | deltaY = viewHeight - rect.bottom; 278 | mScrollEdgeY = EDGE_BOTTOM; 279 | } else { 280 | mScrollEdgeY = EDGE_NONE; 281 | } 282 | int viewWidth = getViewWidth(); 283 | if (width <= viewWidth) { 284 | deltaX = (viewWidth - width) / 2 - rect.left; 285 | mScrollEdgeX = EDGE_BOTH; 286 | } else if (rect.left > 0) { 287 | deltaX = -rect.left; 288 | mScrollEdgeX = EDGE_LEFT; 289 | } else if (rect.right < viewWidth) { 290 | deltaX = viewWidth - rect.right; 291 | mScrollEdgeX = EDGE_RIGHT; 292 | } else { 293 | mScrollEdgeX = EDGE_NONE; 294 | } 295 | 296 | mMatrix.postTranslate(deltaX, deltaY); 297 | return true; 298 | } 299 | 300 | private RectF getDisplayRect(Matrix matrix) { 301 | DraweeView draweeView = getDraweeView(); 302 | if (draweeView == null || (mImageInfoWidth == -1 && mImageInfoHeight == -1)) { 303 | return null; 304 | } 305 | mDisplayRect.set(0.0F, 0.0F, mImageInfoWidth, mImageInfoHeight); 306 | draweeView.getHierarchy().getActualImageBounds(mDisplayRect); 307 | matrix.mapRect(mDisplayRect); 308 | return mDisplayRect; 309 | } 310 | 311 | private void updateBaseMatrix() { 312 | if (mImageInfoWidth == -1 && mImageInfoHeight == -1) { 313 | return; 314 | } 315 | resetMatrix(); 316 | } 317 | 318 | private void resetMatrix() { 319 | mMatrix.reset(); 320 | checkMatrixBounds(); 321 | DraweeView draweeView = getDraweeView(); 322 | if (draweeView != null) { 323 | draweeView.invalidate(); 324 | } 325 | } 326 | 327 | private void checkMinScale() { 328 | DraweeView draweeView = getDraweeView(); 329 | if (draweeView == null) { 330 | return; 331 | } 332 | 333 | if (getScale() < mMinScale) { 334 | RectF rect = getDisplayRect(); 335 | if (null != rect) { 336 | draweeView.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), 337 | rect.centerY())); 338 | } 339 | } 340 | } 341 | 342 | @Override public void onScale(float scaleFactor, float focusX, float focusY) { 343 | if (getScale() < mMaxScale || scaleFactor < 1.0F) { 344 | 345 | if (mScaleChangeListener != null) { 346 | mScaleChangeListener.onScaleChange(scaleFactor, focusX, focusY); 347 | } 348 | 349 | mMatrix.postScale(scaleFactor, scaleFactor, focusX, focusY); 350 | checkMatrixAndInvalidate(); 351 | } 352 | } 353 | 354 | @Override public void onScaleEnd() { 355 | checkMinScale(); 356 | } 357 | 358 | @Override public void onDrag(float dx, float dy) { 359 | 360 | DraweeView draweeView = getDraweeView(); 361 | 362 | if (draweeView != null && !mScaleDragDetector.isScaling()) { 363 | mMatrix.postTranslate(dx, dy); 364 | checkMatrixAndInvalidate(); 365 | 366 | ViewParent parent = draweeView.getParent(); 367 | if (parent == null) { 368 | return; 369 | } 370 | if (mAllowParentInterceptOnEdge 371 | && !mScaleDragDetector.isScaling() 372 | && !mBlockParentIntercept) { 373 | if (mOrientation == HORIZONTAL && (mScrollEdgeX == EDGE_BOTH || (mScrollEdgeX 374 | == EDGE_LEFT && dx >= 1f) || (mScrollEdgeX == EDGE_RIGHT && dx <= -1f))) { 375 | parent.requestDisallowInterceptTouchEvent(false); 376 | } else if (mOrientation == VERTICAL && (mScrollEdgeY == EDGE_BOTH || (mScrollEdgeY 377 | == EDGE_TOP && dy >= 1f) || (mScrollEdgeY == EDGE_BOTTOM && dy <= -1f))) { 378 | parent.requestDisallowInterceptTouchEvent(false); 379 | } 380 | } else { 381 | parent.requestDisallowInterceptTouchEvent(true); 382 | } 383 | } 384 | } 385 | 386 | @Override public void onFling(float startX, float startY, float velocityX, float velocityY) { 387 | DraweeView draweeView = getDraweeView(); 388 | if (draweeView == null) { 389 | return; 390 | } 391 | 392 | mCurrentFlingRunnable = new FlingRunnable(draweeView.getContext()); 393 | mCurrentFlingRunnable.fling(getViewWidth(), getViewHeight(), (int) velocityX, 394 | (int) velocityY); 395 | draweeView.post(mCurrentFlingRunnable); 396 | } 397 | 398 | @Override public boolean onTouch(View v, MotionEvent event) { 399 | 400 | int action = event.getActionMasked(); 401 | switch (action) { 402 | case MotionEvent.ACTION_DOWN: { 403 | ViewParent parent = v.getParent(); 404 | if (parent != null) { 405 | parent.requestDisallowInterceptTouchEvent(true); 406 | } 407 | cancelFling(); 408 | break; 409 | } 410 | case MotionEvent.ACTION_UP: 411 | case MotionEvent.ACTION_CANCEL: { 412 | ViewParent parent = v.getParent(); 413 | if (parent != null) { 414 | parent.requestDisallowInterceptTouchEvent(false); 415 | } 416 | break; 417 | } 418 | default: 419 | break; 420 | } 421 | 422 | boolean wasScaling = mScaleDragDetector.isScaling(); 423 | boolean wasDragging = mScaleDragDetector.isDragging(); 424 | 425 | boolean handled = mScaleDragDetector.onTouchEvent(event); 426 | 427 | boolean noScale = !wasScaling && !mScaleDragDetector.isScaling(); 428 | boolean noDrag = !wasDragging && !mScaleDragDetector.isDragging(); 429 | mBlockParentIntercept = noScale && noDrag; 430 | 431 | if (mGestureDetector.onTouchEvent(event)) { 432 | handled = true; 433 | } 434 | 435 | return handled; 436 | } 437 | 438 | private class AnimatedZoomRunnable implements Runnable { 439 | private final float mFocalX, mFocalY; 440 | private final long mStartTime; 441 | private final float mZoomStart, mZoomEnd; 442 | 443 | public AnimatedZoomRunnable(final float currentZoom, final float targetZoom, 444 | final float focalX, final float focalY) { 445 | mFocalX = focalX; 446 | mFocalY = focalY; 447 | mStartTime = System.currentTimeMillis(); 448 | mZoomStart = currentZoom; 449 | mZoomEnd = targetZoom; 450 | } 451 | 452 | @Override public void run() { 453 | 454 | DraweeView draweeView = getDraweeView(); 455 | if (draweeView == null) { 456 | return; 457 | } 458 | 459 | float t = interpolate(); 460 | float scale = mZoomStart + t * (mZoomEnd - mZoomStart); 461 | float deltaScale = scale / getScale(); 462 | 463 | onScale(deltaScale, mFocalX, mFocalY); 464 | 465 | if (t < 1f) { 466 | postOnAnimation(draweeView, this); 467 | } 468 | } 469 | 470 | private float interpolate() { 471 | float t = 1f * (System.currentTimeMillis() - mStartTime) / mZoomDuration; 472 | t = Math.min(1f, t); 473 | t = mZoomInterpolator.getInterpolation(t); 474 | return t; 475 | } 476 | } 477 | 478 | private class FlingRunnable implements Runnable { 479 | 480 | private final OverScroller mScroller; 481 | private int mCurrentX, mCurrentY; 482 | 483 | public FlingRunnable(Context context) { 484 | mScroller = new OverScroller(context); 485 | } 486 | 487 | public void cancelFling() { 488 | mScroller.abortAnimation(); 489 | } 490 | 491 | public void fling(int viewWidth, int viewHeight, int velocityX, int velocityY) { 492 | final RectF rect = getDisplayRect(); 493 | if (null == rect) { 494 | return; 495 | } 496 | 497 | final int startX = Math.round(-rect.left); 498 | final int minX, maxX, minY, maxY; 499 | 500 | if (viewWidth < rect.width()) { 501 | minX = 0; 502 | maxX = Math.round(rect.width() - viewWidth); 503 | } else { 504 | minX = maxX = startX; 505 | } 506 | 507 | final int startY = Math.round(-rect.top); 508 | if (viewHeight < rect.height()) { 509 | minY = 0; 510 | maxY = Math.round(rect.height() - viewHeight); 511 | } else { 512 | minY = maxY = startY; 513 | } 514 | 515 | mCurrentX = startX; 516 | mCurrentY = startY; 517 | 518 | if (startX != maxX || startY != maxY) { 519 | mScroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY, 0, 0); 520 | } 521 | } 522 | 523 | @Override public void run() { 524 | if (mScroller.isFinished()) { 525 | return; 526 | } 527 | 528 | DraweeView draweeView = getDraweeView(); 529 | 530 | if (draweeView != null && mScroller.computeScrollOffset()) { 531 | final int newX = mScroller.getCurrX(); 532 | final int newY = mScroller.getCurrY(); 533 | mMatrix.postTranslate(mCurrentX - newX, mCurrentY - newY); 534 | draweeView.invalidate(); 535 | mCurrentX = newX; 536 | mCurrentY = newY; 537 | postOnAnimation(draweeView, this); 538 | } 539 | } 540 | } 541 | 542 | private void cancelFling() { 543 | if (mCurrentFlingRunnable != null) { 544 | mCurrentFlingRunnable.cancelFling(); 545 | mCurrentFlingRunnable = null; 546 | } 547 | } 548 | 549 | private void postOnAnimation(View view, Runnable runnable) { 550 | if (Build.VERSION.SDK_INT >= 16) { 551 | view.postOnAnimation(runnable); 552 | } else { 553 | view.postDelayed(runnable, 16L); 554 | } 555 | } 556 | 557 | protected void onDetachedFromWindow() { 558 | cancelFling(); 559 | } 560 | } 561 | --------------------------------------------------------------------------------