Full Code of Baseflow/PhotoView for AI

master 565505d5cb84 cached
66 files
123.5 KB
29.6k tokens
206 symbols
2 requests
Download .txt
Repository: Baseflow/PhotoView
Branch: master
Commit: 565505d5cb84
Files: 66
Total size: 123.5 KB

Directory structure:
gitextract_rensreqv/

├── .github/
│   ├── FUNDING.yml
│   ├── ISSUE_TEMPLATE/
│   │   ├── a-regression.md
│   │   ├── b-bug-report.md
│   │   ├── c-feature-request.md
│   │   ├── d-enhancement-proposal.md
│   │   └── e-question.md
│   └── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── build.gradle
├── gradle/
│   └── wrapper/
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── photoview/
│   ├── build.gradle
│   └── src/
│       └── main/
│           ├── AndroidManifest.xml
│           └── java/
│               └── com/
│                   └── github/
│                       └── chrisbanes/
│                           └── photoview/
│                               ├── Compat.java
│                               ├── CustomGestureDetector.java
│                               ├── OnGestureListener.java
│                               ├── OnMatrixChangedListener.java
│                               ├── OnOutsidePhotoTapListener.java
│                               ├── OnPhotoTapListener.java
│                               ├── OnScaleChangedListener.java
│                               ├── OnSingleFlingListener.java
│                               ├── OnViewDragListener.java
│                               ├── OnViewTapListener.java
│                               ├── PhotoView.java
│                               ├── PhotoViewAttacher.java
│                               └── Util.java
├── sample/
│   ├── build.gradle
│   └── src/
│       └── main/
│           ├── AndroidManifest.xml
│           ├── java/
│           │   └── com/
│           │       └── github/
│           │           └── chrisbanes/
│           │               └── photoview/
│           │                   └── sample/
│           │                       ├── ActivityTransitionActivity.java
│           │                       ├── ActivityTransitionToActivity.java
│           │                       ├── CoilSampleActivity.kt
│           │                       ├── HackyDrawerLayout.java
│           │                       ├── HackyViewPager.java
│           │                       ├── ImageAdapter.java
│           │                       ├── ImageViewHolder.java
│           │                       ├── ImmersiveActivity.java
│           │                       ├── LauncherActivity.java
│           │                       ├── PicassoSampleActivity.java
│           │                       ├── RotationSampleActivity.java
│           │                       ├── SimpleSampleActivity.java
│           │                       └── ViewPagerActivity.java
│           └── res/
│               ├── drawable/
│               │   └── ic_arrow_back_white_24dp.xml
│               ├── layout/
│               │   ├── activity_immersive.xml
│               │   ├── activity_launcher.xml
│               │   ├── activity_rotation_sample.xml
│               │   ├── activity_simple.xml
│               │   ├── activity_simple_sample.xml
│               │   ├── activity_transition.xml
│               │   ├── activity_transition_to.xml
│               │   ├── activity_view_pager.xml
│               │   ├── item_image.xml
│               │   └── item_sample.xml
│               ├── menu/
│               │   ├── main_menu.xml
│               │   └── rotation.xml
│               └── values/
│                   ├── colors.xml
│                   ├── strings.xml
│                   ├── styles.xml
│                   └── transitions.xml
└── settings.gradle

================================================
FILE CONTENTS
================================================

================================================
FILE: .github/FUNDING.yml
================================================
github: Baseflow
custom: https://baseflow.com/contact


================================================
FILE: .github/ISSUE_TEMPLATE/a-regression.md
================================================
---

name: 🔙 Regression
about: Report unexpected behavior that worked previously
---

## 🔙 Regression

<!--- Summary description of the regression --->

### Old (and correct) behavior

### Current behavior

### Reproduction steps

### Configuration

**Version:** 1.x

**Platform:** :robot: Android 9.x

================================================
FILE: .github/ISSUE_TEMPLATE/b-bug-report.md
================================================
---

name: 🐛 Bug Report
about: Create a report to help us fix bugs and make improvements
---

## 🐛 Bug Report

<!--- Summary description of the bug --->

### Expected behavior

### Reproduction steps

### Configuration

**Version:** 1.x

**Platform:** :robot: Android 9.x

================================================
FILE: .github/ISSUE_TEMPLATE/c-feature-request.md
================================================
---

name: 🚀 Feature Request
about: Want to see something new included in the Framework? Submit it!
---

## 🚀 Feature Requests

<!--- Summary description of the feature --->

### Contextualize the feature
<!--- Where does it fit in the framework and why it's being included there. --->

### Describe the feature
<!--- Use as much detail as possible here! --->



================================================
FILE: .github/ISSUE_TEMPLATE/d-enhancement-proposal.md
================================================
---

name: 🏗 Enhancement Proposal
about: Proposals for code cleanup, refactor and improvements in general
---

## 🏗 Enhancement Proposal

<!--- A clear and concise description for your idea --->

### Pitch

<!--- How will this refactor improve contributors' lives? Input as many details as possible! --->


================================================
FILE: .github/ISSUE_TEMPLATE/e-question.md
================================================
---

name: 💬 Questions and Help
about: If you have questions, please use this for support
---

## 💬 Questions and Help

For questions or help we recommend checking:

- [Stack Overflow](https://stackoverflow.com/)

================================================
FILE: .github/PULL_REQUEST_TEMPLATE.md
================================================
### :sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)


### :arrow_heading_down: What is the current behavior?


### :new: What is the new behavior (if this is a feature change)?


### :boom: Does this PR introduce a breaking change?


### :bug: Recommendations for testing


### :memo: Links to relevant issues/docs


### :thinking: Checklist before submitting

- [ ] All projects build
- [ ] Follows style guide lines 
- [ ] Relevant documentation was updated
- [ ] Rebased onto current develop


================================================
FILE: .gitignore
================================================
#Android generated
bin
gen

#Eclipse
.project
.classpath
.settings

#IntelliJ IDEA
.idea
*.iml
*.ipr
*.iws
out

#Maven
target
release.properties
pom.xml.*

#Ant
build.xml
local.properties
proguard.cfg

#OSX
.DS_Store

#Gradle
.gradle
build



================================================
FILE: CODE_OF_CONDUCT.md
================================================
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
  address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
  professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [mvvmcross@gmail.com](mailto:mvvmcross@gmail). All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/


================================================
FILE: CONTRIBUTING.md
================================================
# Contributing to PhotoView

## Finding an issue to work on

If you'd like to work on something that isn't in a current issue, especially if it would be a big change, please open a new issue for discussion!


================================================
FILE: LICENSE
================================================

                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright [yyyy] [name of copyright owner]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.


================================================
FILE: README.md
================================================
# PhotoView
PhotoView aims to help produce an easily usable implementation of a zooming Android ImageView.

[![](https://jitpack.io/v/chrisbanes/PhotoView.svg)](https://jitpack.io/#chrisbanes/PhotoView)

[![](https://user-images.githubusercontent.com/12352397/85141529-94648e80-b24f-11ea-9a14-a845fb43b181.gif)

## Dependency

Add this in your root `build.gradle` file (**not** your module `build.gradle` file):

```gradle
allprojects {
    repositories {
        maven { url "https://www.jitpack.io" }
    }
}

buildscript {
    repositories {
        maven { url "https://www.jitpack.io" }
    }	
}
```

Then, add the library to your module `build.gradle`
```gradle
dependencies {
    implementation 'com.github.chrisbanes:PhotoView:latest.release.here'
}
```

## Features
- Out of the box zooming, using multi-touch and double-tap.
- Scrolling, with smooth scrolling fling.
- Works perfectly when used in a scrolling parent (such as ViewPager).
- Allows the application to be notified when the displayed Matrix has changed. Useful for when you need to update your UI based on the current zoom/scroll position.
- Allows the application to be notified when the user taps on the Photo.

## Usage
There is a [sample](https://github.com/chrisbanes/PhotoView/tree/master/sample) provided which shows how to use the library in a more advanced way, but for completeness, here is all that is required to get PhotoView working:
```xml
<com.github.chrisbanes.photoview.PhotoView
    android:id="@+id/photo_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
```
```java
PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
photoView.setImageResource(R.drawable.image);
```
That's it!

## Issues With ViewGroups
There are some ViewGroups (ones that utilize onInterceptTouchEvent) that throw exceptions when a PhotoView is placed within them, most notably [ViewPager](http://developer.android.com/reference/android/support/v4/view/ViewPager.html) and [DrawerLayout](https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html). This is a framework issue that has not been resolved. In order to prevent this exception (which typically occurs when you zoom out), take a look at [HackyDrawerLayout](https://github.com/chrisbanes/PhotoView/blob/master/sample/src/main/java/com/github/chrisbanes/photoview/sample/HackyDrawerLayout.java) and you can see the solution is to simply catch the exception. Any ViewGroup which uses onInterceptTouchEvent will also need to be extended and exceptions caught. Use the [HackyDrawerLayout](https://github.com/chrisbanes/PhotoView/blob/master/sample/src/main/java/com/github/chrisbanes/photoview/sample/HackyDrawerLayout.java) as a template of how to do so. The basic implementation is:
```java
public class HackyProblematicViewGroup extends ProblematicViewGroup {

    public HackyProblematicViewGroup(Context context) {
        super(context);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            return super.onInterceptTouchEvent(ev);
        } catch (IllegalArgumentException e) {
						//uncomment if you really want to see these errors
            //e.printStackTrace();
            return false;
        }
    }
}
```

## Usage with Fresco
Due to the complex nature of Fresco, this library does not currently support Fresco. See [this project](https://github.com/ongakuer/PhotoDraweeView) as an alternative solution.

## Subsampling Support
This library aims to keep the zooming implementation simple. If you are looking for an implementation that supports subsampling, check out [this project](https://github.com/davemorrissey/subsampling-scale-image-view)

License
--------

    Copyright 2018 Chris Banes

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


================================================
FILE: build.gradle
================================================
buildscript {
    ext.kotlin_version = '1.3.72'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.2'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

ext {
    sdkVersion = 29
    minSdkVersion = 16
}


================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists


================================================
FILE: gradle.properties
================================================
android.useAndroidX=true
android.enableJetifier=true

================================================
FILE: gradlew
================================================
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
##  Gradle start up script for UN*X
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '/.*' > /dev/null; then
        PRG="$link"
    else
        PRG=`dirname "$PRG"`"/$link"
    fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn () {
    echo "$*"
}

die () {
    echo
    echo "$*"
    echo
    exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
  CYGWIN* )
    cygwin=true
    ;;
  Darwin* )
    darwin=true
    ;;
  MINGW* )
    msys=true
    ;;
  NONSTOP* )
    nonstop=true
    ;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
        # IBM's JDK on AIX uses strange locations for the executables
        JAVACMD="$JAVA_HOME/jre/sh/java"
    else
        JAVACMD="$JAVA_HOME/bin/java"
    fi
    if [ ! -x "$JAVACMD" ] ; then
        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
    fi
else
    JAVACMD="java"
    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
    MAX_FD_LIMIT=`ulimit -H -n`
    if [ $? -eq 0 ] ; then
        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
            MAX_FD="$MAX_FD_LIMIT"
        fi
        ulimit -n $MAX_FD
        if [ $? -ne 0 ] ; then
            warn "Could not set maximum file descriptor limit: $MAX_FD"
        fi
    else
        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
    fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
    JAVACMD=`cygpath --unix "$JAVACMD"`

    # We build the pattern for arguments to be converted via cygpath
    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
    SEP=""
    for dir in $ROOTDIRSRAW ; do
        ROOTDIRS="$ROOTDIRS$SEP$dir"
        SEP="|"
    done
    OURCYGPATTERN="(^($ROOTDIRS))"
    # Add a user-defined pattern to the cygpath arguments
    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
    fi
    # Now convert the arguments - kludge to limit ourselves to /bin/sh
    i=0
    for arg in "$@" ; do
        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option

        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
        else
            eval `echo args$i`="\"$arg\""
        fi
        i=`expr $i + 1`
    done
    case $i in
        0) set -- ;;
        1) set -- "$args0" ;;
        2) set -- "$args0" "$args1" ;;
        3) set -- "$args0" "$args1" "$args2" ;;
        4) set -- "$args0" "$args1" "$args2" "$args3" ;;
        5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
        6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
        7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
        8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
        9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
    esac
fi

# Escape application args
save () {
    for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
    echo " "
}
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

exec "$JAVACMD" "$@"


================================================
FILE: gradlew.bat
================================================
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem      https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem  Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega


================================================
FILE: photoview/build.gradle
================================================
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

android {
    compileSdkVersion rootProject.ext.sdkVersion

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.sdkVersion
        versionCode 1
        versionName "1.0"
    }
}

dependencies {
    implementation "androidx.appcompat:appcompat:1.1.0"
}

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release

                group = 'com.github.chrisbanes'
                artifactId = 'PhotoView'
                version = '2.3.0'

                // Adds javadocs and sources as separate jars.
                artifact androidJavadocsJar
                artifact(sourceJar)

                pom {
                    name = 'PhotoView'
                    description = 'A simple ImageView that support zooming, both by Multi-touch gestures and double-tap.'
                    url = 'https://github.com/Baseflow/PhotoView'
                    licenses {
                        license {
                            name = 'The Apache License, Version 2.0'
                            url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }
                    developers {
                        developer {
                            id = 'chrisbanes'
                            name = 'Chris Banes'
                        }
                    }
                    scm {
                        connection = 'scm:git@github.com/chrisbanes/PhotoView.git'
                        developerConnection = 'scm:git@github.com/chrisbanes/PhotoView.git'
                        url = 'https://github.com/chrisbanes/PhotoView'
                    }
                }
            }
        }
    }
}

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    android.libraryVariants.all { variant ->
        if (variant.name == 'release') {
            owner.classpath += variant.javaCompileProvider.get().classpath
        }
    }
    exclude '**/R.html', '**/R.*.html', '**/index.html'
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
    archiveClassifier.set('javadoc')
    from androidJavadocs.destinationDir
}

task sourceJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier "sources"
}

================================================
FILE: photoview/src/main/AndroidManifest.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.github.chrisbanes.photoview">

</manifest>


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/Compat.java
================================================
/*
 Copyright 2011, 2012 Chris Banes.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package com.github.chrisbanes.photoview;

import android.annotation.TargetApi;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.view.View;

class Compat {

    private static final int SIXTY_FPS_INTERVAL = 1000 / 60;

    public static void postOnAnimation(View view, Runnable runnable) {
        if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
            postOnAnimationJellyBean(view, runnable);
        } else {
            view.postDelayed(runnable, SIXTY_FPS_INTERVAL);
        }
    }

    @TargetApi(16)
    private static void postOnAnimationJellyBean(View view, Runnable runnable) {
        view.postOnAnimation(runnable);
    }
}


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/CustomGestureDetector.java
================================================
/*
 Copyright 2011, 2012 Chris Banes.
 <p/>
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 <p/>
 http://www.apache.org/licenses/LICENSE-2.0
 <p/>
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package com.github.chrisbanes.photoview;

import android.content.Context;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;

/**
 * Does a whole lot of gesture detecting.
 */
class CustomGestureDetector {

    private static final int INVALID_POINTER_ID = -1;

    private int mActivePointerId = INVALID_POINTER_ID;
    private int mActivePointerIndex = 0;
    private final ScaleGestureDetector mDetector;

    private VelocityTracker mVelocityTracker;
    private boolean mIsDragging;
    private float mLastTouchX;
    private float mLastTouchY;
    private final float mTouchSlop;
    private final float mMinimumVelocity;
    private OnGestureListener mListener;

    CustomGestureDetector(Context context, OnGestureListener listener) {
        final ViewConfiguration configuration = ViewConfiguration
                .get(context);
        mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
        mTouchSlop = configuration.getScaledTouchSlop();

        mListener = listener;
        ScaleGestureDetector.OnScaleGestureListener mScaleListener = new ScaleGestureDetector.OnScaleGestureListener() {
            private float lastFocusX, lastFocusY = 0;

            @Override
            public boolean onScale(ScaleGestureDetector detector) {
                float scaleFactor = detector.getScaleFactor();

                if (Float.isNaN(scaleFactor) || Float.isInfinite(scaleFactor))
                    return false;
             
                if (scaleFactor >= 0) {
                    mListener.onScale(scaleFactor,
                            detector.getFocusX(),
                            detector.getFocusY(),
                            detector.getFocusX() - lastFocusX,
                            detector.getFocusY() - lastFocusY
                    );
                    lastFocusX = detector.getFocusX();
                    lastFocusY = detector.getFocusY();
                }
                return true;
            }

            @Override
            public boolean onScaleBegin(ScaleGestureDetector detector) {
                lastFocusX = detector.getFocusX();
                lastFocusY = detector.getFocusY();
                return true;
            }

            @Override
            public void onScaleEnd(ScaleGestureDetector detector) {
                // NO-OP
            }
        };
        mDetector = new ScaleGestureDetector(context, mScaleListener);
    }

    private float getActiveX(MotionEvent ev) {
        try {
            return ev.getX(mActivePointerIndex);
        } catch (Exception e) {
            return ev.getX();
        }
    }

    private float getActiveY(MotionEvent ev) {
        try {
            return ev.getY(mActivePointerIndex);
        } catch (Exception e) {
            return ev.getY();
        }
    }

    public boolean isScaling() {
        return mDetector.isInProgress();
    }

    public boolean isDragging() {
        return mIsDragging;
    }

    public boolean onTouchEvent(MotionEvent ev) {
        try {
            mDetector.onTouchEvent(ev);
            return processTouchEvent(ev);
        } catch (IllegalArgumentException e) {
            // Fix for support lib bug, happening when onDestroy is called
            return true;
        }
    }

    private boolean processTouchEvent(MotionEvent ev) {
        final int action = ev.getAction();
        switch (action & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                mActivePointerId = ev.getPointerId(0);

                mVelocityTracker = VelocityTracker.obtain();
                if (null != mVelocityTracker) {
                    mVelocityTracker.addMovement(ev);
                }

                mLastTouchX = getActiveX(ev);
                mLastTouchY = getActiveY(ev);
                mIsDragging = false;
                break;
            case MotionEvent.ACTION_MOVE:
                final float x = getActiveX(ev);
                final float y = getActiveY(ev);
                final float dx = x - mLastTouchX, dy = y - mLastTouchY;

                if (!mIsDragging) {
                    // Use Pythagoras to see if drag length is larger than
                    // touch slop
                    mIsDragging = Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop;
                }

                if (mIsDragging) {
                    mListener.onDrag(dx, dy);
                    mLastTouchX = x;
                    mLastTouchY = y;

                    if (null != mVelocityTracker) {
                        mVelocityTracker.addMovement(ev);
                    }
                }
                break;
            case MotionEvent.ACTION_CANCEL:
                mActivePointerId = INVALID_POINTER_ID;
                // Recycle Velocity Tracker
                if (null != mVelocityTracker) {
                    mVelocityTracker.recycle();
                    mVelocityTracker = null;
                }
                break;
            case MotionEvent.ACTION_UP:
                mActivePointerId = INVALID_POINTER_ID;
                if (mIsDragging) {
                    if (null != mVelocityTracker) {
                        mLastTouchX = getActiveX(ev);
                        mLastTouchY = getActiveY(ev);

                        // Compute velocity within the last 1000ms
                        mVelocityTracker.addMovement(ev);
                        mVelocityTracker.computeCurrentVelocity(1000);

                        final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker
                                .getYVelocity();

                        // If the velocity is greater than minVelocity, call
                        // listener
                        if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) {
                            mListener.onFling(mLastTouchX, mLastTouchY, -vX,
                                    -vY);
                        }
                    }
                }

                // Recycle Velocity Tracker
                if (null != mVelocityTracker) {
                    mVelocityTracker.recycle();
                    mVelocityTracker = null;
                }
                break;
            case MotionEvent.ACTION_POINTER_UP:
                final int pointerIndex = Util.getPointerIndex(ev.getAction());
                final int pointerId = ev.getPointerId(pointerIndex);
                if (pointerId == mActivePointerId) {
                    // This was our active pointer going up. Choose a new
                    // active pointer and adjust accordingly.
                    final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                    mActivePointerId = ev.getPointerId(newPointerIndex);
                    mLastTouchX = ev.getX(newPointerIndex);
                    mLastTouchY = ev.getY(newPointerIndex);
                }
                break;
        }

        mActivePointerIndex = ev
                .findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId
                        : 0);
        return true;
    }
}


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnGestureListener.java
================================================
/*
 Copyright 2011, 2012 Chris Banes.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package com.github.chrisbanes.photoview;

interface OnGestureListener {

    void onDrag(float dx, float dy);

    void onFling(float startX, float startY, float velocityX,
                 float velocityY);

    void onScale(float scaleFactor, float focusX, float focusY);

    void onScale(float scaleFactor, float focusX, float focusY, float dx, float dy);
}

================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnMatrixChangedListener.java
================================================
package com.github.chrisbanes.photoview;

import android.graphics.RectF;

/**
 * Interface definition for a callback to be invoked when the internal Matrix has changed for
 * this View.
 */
public interface OnMatrixChangedListener {

    /**
     * Callback for when the Matrix displaying the Drawable has changed. This could be because
     * the View's bounds have changed, or the user has zoomed.
     *
     * @param rect - Rectangle displaying the Drawable's new bounds.
     */
    void onMatrixChanged(RectF rect);
}


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnOutsidePhotoTapListener.java
================================================
package com.github.chrisbanes.photoview;

import android.widget.ImageView;

/**
 * Callback when the user tapped outside of the photo
 */
public interface OnOutsidePhotoTapListener {

    /**
     * The outside of the photo has been tapped
     */
    void onOutsidePhotoTap(ImageView imageView);
}


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnPhotoTapListener.java
================================================
package com.github.chrisbanes.photoview;

import android.widget.ImageView;

/**
 * A callback to be invoked when the Photo is tapped with a single
 * tap.
 */
public interface OnPhotoTapListener {

    /**
     * A callback to receive where the user taps on a photo. You will only receive a callback if
     * the user taps on the actual photo, tapping on 'whitespace' will be ignored.
     *
     * @param view ImageView the user tapped.
     * @param x    where the user tapped from the of the Drawable, as percentage of the
     *             Drawable width.
     * @param y    where the user tapped from the top of the Drawable, as percentage of the
     *             Drawable height.
     */
    void onPhotoTap(ImageView view, float x, float y);
}


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnScaleChangedListener.java
================================================
package com.github.chrisbanes.photoview;


/**
 * Interface definition for callback to be invoked when attached ImageView scale changes
 */
public interface OnScaleChangedListener {

    /**
     * Callback for when the scale changes
     *
     * @param scaleFactor the scale factor (less than 1 for zoom out, greater than 1 for zoom in)
     * @param focusX      focal point X position
     * @param focusY      focal point Y position
     */
    void onScaleChange(float scaleFactor, float focusX, float focusY);
}


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnSingleFlingListener.java
================================================
package com.github.chrisbanes.photoview;

import android.view.MotionEvent;

/**
 * A callback to be invoked when the ImageView is flung with a single
 * touch
 */
public interface OnSingleFlingListener {

    /**
     * A callback to receive where the user flings on a ImageView. You will receive a callback if
     * the user flings anywhere on the view.
     *
     * @param e1        MotionEvent the user first touch.
     * @param e2        MotionEvent the user last touch.
     * @param velocityX distance of user's horizontal fling.
     * @param velocityY distance of user's vertical fling.
     */
    boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY);
}


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnViewDragListener.java
================================================
package com.github.chrisbanes.photoview;

/**
 * Interface definition for a callback to be invoked when the photo is experiencing a drag event
 */
public interface OnViewDragListener {

    /**
     * Callback for when the photo is experiencing a drag event. This cannot be invoked when the
     * user is scaling.
     *
     * @param dx The change of the coordinates in the x-direction
     * @param dy The change of the coordinates in the y-direction
     */
    void onDrag(float dx, float dy);
}


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnViewTapListener.java
================================================
package com.github.chrisbanes.photoview;

import android.view.View;

public interface OnViewTapListener {

    /**
     * A callback to receive where the user taps on a ImageView. You will receive a callback if
     * the user taps anywhere on the view, tapping on 'whitespace' will not be ignored.
     *
     * @param view - View the user tapped.
     * @param x    - where the user tapped from the left of the View.
     * @param y    - where the user tapped from the top of the View.
     */
    void onViewTap(View view, float x, float y);
}


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java
================================================
/*
 Copyright 2011, 2012 Chris Banes.
 <p>
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 <p>
 http://www.apache.org/licenses/LICENSE-2.0
 <p>
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package com.github.chrisbanes.photoview;

import android.content.Context;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.GestureDetector;

import androidx.appcompat.widget.AppCompatImageView;

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

    private PhotoViewAttacher attacher;
    private ScaleType pendingScaleType;

    public PhotoView(Context context) {
        this(context, null);
    }

    public PhotoView(Context context, AttributeSet attr) {
        this(context, attr, 0);
    }

    public PhotoView(Context context, AttributeSet attr, int defStyle) {
        super(context, attr, defStyle);
        init();
    }

    private void init() {
        attacher = new PhotoViewAttacher(this);
        //We always pose as a Matrix scale type, though we can change to another scale type
        //via the attacher
        super.setScaleType(ScaleType.MATRIX);
        //apply the previously applied scale type
        if (pendingScaleType != null) {
            setScaleType(pendingScaleType);
            pendingScaleType = null;
        }
    }

    /**
     * Get the current {@link PhotoViewAttacher} for this view. Be wary of holding on to references
     * to this attacher, as it has a reference to this view, which, if a reference is held in the
     * wrong place, can cause memory leaks.
     *
     * @return the attacher.
     */
    public PhotoViewAttacher getAttacher() {
        return attacher;
    }

    @Override
    public ScaleType getScaleType() {
        return attacher.getScaleType();
    }

    @Override
    public Matrix getImageMatrix() {
        return attacher.getImageMatrix();
    }

    @Override
    public void setOnLongClickListener(OnLongClickListener l) {
        attacher.setOnLongClickListener(l);
    }

    @Override
    public void setOnClickListener(OnClickListener l) {
        attacher.setOnClickListener(l);
    }

    @Override
    public void setScaleType(ScaleType scaleType) {
        if (attacher == null) {
            pendingScaleType = scaleType;
        } else {
            attacher.setScaleType(scaleType);
        }
    }

    @Override
    public void setImageDrawable(Drawable drawable) {
        super.setImageDrawable(drawable);
        // setImageBitmap calls through to this method
        if (attacher != null) {
            attacher.update();
        }
    }

    @Override
    public void setImageResource(int resId) {
        super.setImageResource(resId);
        if (attacher != null) {
            attacher.update();
        }
    }

    @Override
    public void setImageURI(Uri uri) {
        super.setImageURI(uri);
        if (attacher != null) {
            attacher.update();
        }
    }

    @Override
    protected boolean setFrame(int l, int t, int r, int b) {
        boolean changed = super.setFrame(l, t, r, b);
        if (changed) {
            attacher.update();
        }
        return changed;
    }

    public void setRotationTo(float rotationDegree) {
        attacher.setRotationTo(rotationDegree);
    }

    public void setRotationBy(float rotationDegree) {
        attacher.setRotationBy(rotationDegree);
    }

    public boolean isZoomable() {
        return attacher.isZoomable();
    }

    public void setZoomable(boolean zoomable) {
        attacher.setZoomable(zoomable);
    }

    public RectF getDisplayRect() {
        return attacher.getDisplayRect();
    }

    public void getDisplayMatrix(Matrix matrix) {
        attacher.getDisplayMatrix(matrix);
    }

    @SuppressWarnings("UnusedReturnValue") public boolean setDisplayMatrix(Matrix finalRectangle) {
        return attacher.setDisplayMatrix(finalRectangle);
    }

    public void getSuppMatrix(Matrix matrix) {
        attacher.getSuppMatrix(matrix);
    }

    public boolean setSuppMatrix(Matrix matrix) {
        return attacher.setDisplayMatrix(matrix);
    }

    public float getMinimumScale() {
        return attacher.getMinimumScale();
    }

    public float getMediumScale() {
        return attacher.getMediumScale();
    }

    public float getMaximumScale() {
        return attacher.getMaximumScale();
    }

    public float getScale() {
        return attacher.getScale();
    }

    public void setAllowParentInterceptOnEdge(boolean allow) {
        attacher.setAllowParentInterceptOnEdge(allow);
    }

    public void setMinimumScale(float minimumScale) {
        attacher.setMinimumScale(minimumScale);
    }

    public void setMediumScale(float mediumScale) {
        attacher.setMediumScale(mediumScale);
    }

    public void setMaximumScale(float maximumScale) {
        attacher.setMaximumScale(maximumScale);
    }

    public void setScaleLevels(float minimumScale, float mediumScale, float maximumScale) {
        attacher.setScaleLevels(minimumScale, mediumScale, maximumScale);
    }

    public void setOnMatrixChangeListener(OnMatrixChangedListener listener) {
        attacher.setOnMatrixChangeListener(listener);
    }

    public void setOnPhotoTapListener(OnPhotoTapListener listener) {
        attacher.setOnPhotoTapListener(listener);
    }

    public void setOnOutsidePhotoTapListener(OnOutsidePhotoTapListener listener) {
        attacher.setOnOutsidePhotoTapListener(listener);
    }

    public void setOnViewTapListener(OnViewTapListener listener) {
        attacher.setOnViewTapListener(listener);
    }

    public void setOnViewDragListener(OnViewDragListener listener) {
        attacher.setOnViewDragListener(listener);
    }

    public void setScale(float scale) {
        attacher.setScale(scale);
    }

    public void setScale(float scale, boolean animate) {
        attacher.setScale(scale, animate);
    }

    public void setScale(float scale, float focalX, float focalY, boolean animate) {
        attacher.setScale(scale, focalX, focalY, animate);
    }

    public void setZoomTransitionDuration(int milliseconds) {
        attacher.setZoomTransitionDuration(milliseconds);
    }

    public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener onDoubleTapListener) {
        attacher.setOnDoubleTapListener(onDoubleTapListener);
    }

    public void setOnScaleChangeListener(OnScaleChangedListener onScaleChangedListener) {
        attacher.setOnScaleChangeListener(onScaleChangedListener);
    }

    public void setOnSingleFlingListener(OnSingleFlingListener onSingleFlingListener) {
        attacher.setOnSingleFlingListener(onSingleFlingListener);
    }
}


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java
================================================
/*
 Copyright 2011, 2012 Chris Banes.
 <p>
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 <p>
 http://www.apache.org/licenses/LICENSE-2.0
 <p>
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package com.github.chrisbanes.photoview;

import android.content.Context;
import android.graphics.Matrix;
import android.graphics.Matrix.ScaleToFit;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.ViewParent;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.OverScroller;

/**
 * The component of {@link PhotoView} which does the work allowing for zooming, scaling, panning, etc.
 * It is made public in case you need to subclass something other than AppCompatImageView and still
 * gain the functionality that {@link PhotoView} offers
 */
public class PhotoViewAttacher implements View.OnTouchListener,
    View.OnLayoutChangeListener {

    private static float DEFAULT_MAX_SCALE = 3.0f;
    private static float DEFAULT_MID_SCALE = 1.75f;
    private static float DEFAULT_MIN_SCALE = 1.0f;
    private static int DEFAULT_ZOOM_DURATION = 200;

    private static final int HORIZONTAL_EDGE_NONE = -1;
    private static final int HORIZONTAL_EDGE_LEFT = 0;
    private static final int HORIZONTAL_EDGE_RIGHT = 1;
    private static final int HORIZONTAL_EDGE_BOTH = 2;
    private static final int VERTICAL_EDGE_NONE = -1;
    private static final int VERTICAL_EDGE_TOP = 0;
    private static final int VERTICAL_EDGE_BOTTOM = 1;
    private static final int VERTICAL_EDGE_BOTH = 2;
    private static int SINGLE_TOUCH = 1;

    private Interpolator mInterpolator = new AccelerateDecelerateInterpolator();
    private int mZoomDuration = DEFAULT_ZOOM_DURATION;
    private float mMinScale = DEFAULT_MIN_SCALE;
    private float mMidScale = DEFAULT_MID_SCALE;
    private float mMaxScale = DEFAULT_MAX_SCALE;

    private boolean mAllowParentInterceptOnEdge = true;
    private boolean mBlockParentIntercept = false;

    private ImageView mImageView;

    // Gesture Detectors
    private GestureDetector mGestureDetector;
    private CustomGestureDetector mScaleDragDetector;

    // These are set so we don't keep allocating them on the heap
    private final Matrix mBaseMatrix = new Matrix();
    private final Matrix mDrawMatrix = new Matrix();
    private final Matrix mSuppMatrix = new Matrix();
    private final RectF mDisplayRect = new RectF();
    private final float[] mMatrixValues = new float[9];

    // Listeners
    private OnMatrixChangedListener mMatrixChangeListener;
    private OnPhotoTapListener mPhotoTapListener;
    private OnOutsidePhotoTapListener mOutsidePhotoTapListener;
    private OnViewTapListener mViewTapListener;
    private View.OnClickListener mOnClickListener;
    private OnLongClickListener mLongClickListener;
    private OnScaleChangedListener mScaleChangeListener;
    private OnSingleFlingListener mSingleFlingListener;
    private OnViewDragListener mOnViewDragListener;

    private FlingRunnable mCurrentFlingRunnable;
    private int mHorizontalScrollEdge = HORIZONTAL_EDGE_BOTH;
    private int mVerticalScrollEdge = VERTICAL_EDGE_BOTH;
    private float mBaseRotation;

    private boolean mZoomEnabled = true;
    private ScaleType mScaleType = ScaleType.FIT_CENTER;

    private OnGestureListener onGestureListener = new OnGestureListener() {
        @Override
        public void onDrag(float dx, float dy) {
            if (mScaleDragDetector.isScaling()) {
                return; // Do not drag if we are already scaling
            }
            if (mOnViewDragListener != null) {
                mOnViewDragListener.onDrag(dx, dy);
            }
            mSuppMatrix.postTranslate(dx, dy);
            checkAndDisplayMatrix();

            /*
             * Here we decide whether to let the ImageView's parent to start taking
             * over the touch event.
             *
             * First we check whether this function is enabled. We never want the
             * parent to take over if we're scaling. We then check the edge we're
             * on, and the direction of the scroll (i.e. if we're pulling against
             * the edge, aka 'overscrolling', let the parent take over).
             */
            ViewParent parent = mImageView.getParent();
            if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) {
                if (mHorizontalScrollEdge == HORIZONTAL_EDGE_BOTH
                        || (mHorizontalScrollEdge == HORIZONTAL_EDGE_LEFT && dx >= 1f)
                        || (mHorizontalScrollEdge == HORIZONTAL_EDGE_RIGHT && dx <= -1f)
                        || (mVerticalScrollEdge == VERTICAL_EDGE_TOP && dy >= 1f)
                        || (mVerticalScrollEdge == VERTICAL_EDGE_BOTTOM && dy <= -1f)) {
                    if (parent != null) {
                        parent.requestDisallowInterceptTouchEvent(false);
                    }
                }
            } else {
                if (parent != null) {
                    parent.requestDisallowInterceptTouchEvent(true);
                }
            }
        }

        @Override
        public void onFling(float startX, float startY, float velocityX, float velocityY) {
            mCurrentFlingRunnable = new FlingRunnable(mImageView.getContext());
            mCurrentFlingRunnable.fling(getImageViewWidth(mImageView),
                getImageViewHeight(mImageView), (int) velocityX, (int) velocityY);
            mImageView.post(mCurrentFlingRunnable);
        }

        @Override
        public void onScale(float scaleFactor, float focusX, float focusY) {
            onScale(scaleFactor, focusX, focusY, 0, 0);
        }

        @Override
        public void onScale(float scaleFactor, float focusX, float focusY, float dx, float dy) {
            if (getScale() < mMaxScale || scaleFactor < 1f) {
                if (mScaleChangeListener != null) {
                    mScaleChangeListener.onScaleChange(scaleFactor, focusX, focusY);
                }
                mSuppMatrix.postScale(scaleFactor, scaleFactor, focusX, focusY);
                mSuppMatrix.postTranslate(dx, dy);
                checkAndDisplayMatrix();
            }
        }
    };

    public PhotoViewAttacher(ImageView imageView) {
        mImageView = imageView;
        imageView.setOnTouchListener(this);
        imageView.addOnLayoutChangeListener(this);
        if (imageView.isInEditMode()) {
            return;
        }
        mBaseRotation = 0.0f;
        // Create Gesture Detectors...
        mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), onGestureListener);
        mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() {

            // forward long click listener
            @Override
            public void onLongPress(MotionEvent e) {
                if (mLongClickListener != null) {
                    mLongClickListener.onLongClick(mImageView);
                }
            }

            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2,
                float velocityX, float velocityY) {
                if (mSingleFlingListener != null) {
                    if (getScale() > DEFAULT_MIN_SCALE) {
                        return false;
                    }
                    if (e1.getPointerCount() > SINGLE_TOUCH
                        || e2.getPointerCount() > SINGLE_TOUCH) {
                        return false;
                    }
                    return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                }
                return false;
            }
        });
        mGestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                if (mOnClickListener != null) {
                    mOnClickListener.onClick(mImageView);
                }
                final RectF displayRect = getDisplayRect();
                final float x = e.getX(), y = e.getY();
                if (mViewTapListener != null) {
                    mViewTapListener.onViewTap(mImageView, x, y);
                }
                if (displayRect != null) {
                    // Check to see if the user tapped on the photo
                    if (displayRect.contains(x, y)) {
                        float xResult = (x - displayRect.left)
                            / displayRect.width();
                        float yResult = (y - displayRect.top)
                            / displayRect.height();
                        if (mPhotoTapListener != null) {
                            mPhotoTapListener.onPhotoTap(mImageView, xResult, yResult);
                        }
                        return true;
                    } else {
                        if (mOutsidePhotoTapListener != null) {
                            mOutsidePhotoTapListener.onOutsidePhotoTap(mImageView);
                        }
                    }
                }
                return false;
            }

            @Override
            public boolean onDoubleTap(MotionEvent ev) {
                try {
                    float scale = getScale();
                    float x = ev.getX();
                    float y = ev.getY();
                    if (scale < getMediumScale()) {
                        setScale(getMediumScale(), x, y, true);
                    } else if (scale >= getMediumScale() && scale < getMaximumScale()) {
                        setScale(getMaximumScale(), x, y, true);
                    } else {
                        setScale(getMinimumScale(), x, y, true);
                    }
                } catch (ArrayIndexOutOfBoundsException e) {
                    // Can sometimes happen when getX() and getY() is called
                }
                return true;
            }

            @Override
            public boolean onDoubleTapEvent(MotionEvent e) {
                // Wait for the confirmed onDoubleTap() instead
                return false;
            }
        });
    }

    public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener newOnDoubleTapListener) {
        this.mGestureDetector.setOnDoubleTapListener(newOnDoubleTapListener);
    }

    public void setOnScaleChangeListener(OnScaleChangedListener onScaleChangeListener) {
        this.mScaleChangeListener = onScaleChangeListener;
    }

    public void setOnSingleFlingListener(OnSingleFlingListener onSingleFlingListener) {
        this.mSingleFlingListener = onSingleFlingListener;
    }

    @Deprecated
    public boolean isZoomEnabled() {
        return mZoomEnabled;
    }

    public RectF getDisplayRect() {
        checkMatrixBounds();
        return getDisplayRect(getDrawMatrix());
    }

    public boolean setDisplayMatrix(Matrix finalMatrix) {
        if (finalMatrix == null) {
            throw new IllegalArgumentException("Matrix cannot be null");
        }
        if (mImageView.getDrawable() == null) {
            return false;
        }
        mSuppMatrix.set(finalMatrix);
        checkAndDisplayMatrix();
        return true;
    }

    public void setBaseRotation(final float degrees) {
        mBaseRotation = degrees % 360;
        update();
        setRotationBy(mBaseRotation);
        checkAndDisplayMatrix();
    }

    public void setRotationTo(float degrees) {
        mSuppMatrix.setRotate(degrees % 360);
        checkAndDisplayMatrix();
    }

    public void setRotationBy(float degrees) {
        mSuppMatrix.postRotate(degrees % 360);
        checkAndDisplayMatrix();
    }

    public float getMinimumScale() {
        return mMinScale;
    }

    public float getMediumScale() {
        return mMidScale;
    }

    public float getMaximumScale() {
        return mMaxScale;
    }

    public float getScale() {
        return (float) Math.sqrt((float) Math.pow(getValue(mSuppMatrix, Matrix.MSCALE_X), 2) + (float) Math.pow
            (getValue(mSuppMatrix, Matrix.MSKEW_Y), 2));
    }

    public ScaleType getScaleType() {
        return mScaleType;
    }

    @Override
    public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int
        oldRight, int oldBottom) {
        // Update our base matrix, as the bounds have changed
        if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
            updateBaseMatrix(mImageView.getDrawable());
        }
    }

    @Override
    public boolean onTouch(View v, MotionEvent ev) {
        boolean handled = false;
        if (mZoomEnabled && Util.hasDrawable((ImageView) v)) {
            switch (ev.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    ViewParent parent = v.getParent();
                    // First, disable the Parent from intercepting the touch
                    // event
                    if (parent != null) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                    // If we're flinging, and the user presses down, cancel
                    // fling
                    cancelFling();
                    break;
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_UP:
                    // If the user has zoomed less than min scale, zoom back
                    // to min scale
                    if (getScale() < mMinScale) {
                        RectF rect = getDisplayRect();
                        if (rect != null) {
                            v.post(new AnimatedZoomRunnable(getScale(), mMinScale,
                                rect.centerX(), rect.centerY()));
                            handled = true;
                        }
                    } else if (getScale() > mMaxScale) {
                        RectF rect = getDisplayRect();
                        if (rect != null) {
                            v.post(new AnimatedZoomRunnable(getScale(), mMaxScale,
                                rect.centerX(), rect.centerY()));
                            handled = true;
                        }
                    }
                    break;
            }
            // Try the Scale/Drag detector
            if (mScaleDragDetector != null) {
                boolean wasScaling = mScaleDragDetector.isScaling();
                boolean wasDragging = mScaleDragDetector.isDragging();
                handled = mScaleDragDetector.onTouchEvent(ev);
                boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
                boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();
                mBlockParentIntercept = didntScale && didntDrag;
            }
            // Check to see if the user double tapped
            if (mGestureDetector != null && mGestureDetector.onTouchEvent(ev)) {
                handled = true;
            }

        }
        return handled;
    }

    public void setAllowParentInterceptOnEdge(boolean allow) {
        mAllowParentInterceptOnEdge = allow;
    }

    public void setMinimumScale(float minimumScale) {
        Util.checkZoomLevels(minimumScale, mMidScale, mMaxScale);
        mMinScale = minimumScale;
    }

    public void setMediumScale(float mediumScale) {
        Util.checkZoomLevels(mMinScale, mediumScale, mMaxScale);
        mMidScale = mediumScale;
    }

    public void setMaximumScale(float maximumScale) {
        Util.checkZoomLevels(mMinScale, mMidScale, maximumScale);
        mMaxScale = maximumScale;
    }

    public void setScaleLevels(float minimumScale, float mediumScale, float maximumScale) {
        Util.checkZoomLevels(minimumScale, mediumScale, maximumScale);
        mMinScale = minimumScale;
        mMidScale = mediumScale;
        mMaxScale = maximumScale;
    }

    public void setOnLongClickListener(OnLongClickListener listener) {
        mLongClickListener = listener;
    }

    public void setOnClickListener(View.OnClickListener listener) {
        mOnClickListener = listener;
    }

    public void setOnMatrixChangeListener(OnMatrixChangedListener listener) {
        mMatrixChangeListener = listener;
    }

    public void setOnPhotoTapListener(OnPhotoTapListener listener) {
        mPhotoTapListener = listener;
    }

    public void setOnOutsidePhotoTapListener(OnOutsidePhotoTapListener mOutsidePhotoTapListener) {
        this.mOutsidePhotoTapListener = mOutsidePhotoTapListener;
    }

    public void setOnViewTapListener(OnViewTapListener listener) {
        mViewTapListener = listener;
    }

    public void setOnViewDragListener(OnViewDragListener listener) {
        mOnViewDragListener = listener;
    }

    public void setScale(float scale) {
        setScale(scale, false);
    }

    public void setScale(float scale, boolean animate) {
        setScale(scale,
            (mImageView.getRight()) / 2,
            (mImageView.getBottom()) / 2,
            animate);
    }

    public void setScale(float scale, float focalX, float focalY,
        boolean animate) {
        // Check to see if the scale is within bounds
        if (scale < mMinScale || scale > mMaxScale) {
            throw new IllegalArgumentException("Scale must be within the range of minScale and maxScale");
        }
        if (animate) {
            mImageView.post(new AnimatedZoomRunnable(getScale(), scale,
                focalX, focalY));
        } else {
            mSuppMatrix.setScale(scale, scale, focalX, focalY);
            checkAndDisplayMatrix();
        }
    }

    /**
     * Set the zoom interpolator
     *
     * @param interpolator the zoom interpolator
     */
    public void setZoomInterpolator(Interpolator interpolator) {
        mInterpolator = interpolator;
    }

    public void setScaleType(ScaleType scaleType) {
        if (Util.isSupportedScaleType(scaleType) && scaleType != mScaleType) {
            mScaleType = scaleType;
            update();
        }
    }

    public boolean isZoomable() {
        return mZoomEnabled;
    }

    public void setZoomable(boolean zoomable) {
        mZoomEnabled = zoomable;
        update();
    }

    public void update() {
        if (mZoomEnabled) {
            // Update the base matrix using the current drawable
            updateBaseMatrix(mImageView.getDrawable());
        } else {
            // Reset the Matrix...
            resetMatrix();
        }
    }

    /**
     * Get the display matrix
     *
     * @param matrix target matrix to copy to
     */
    public void getDisplayMatrix(Matrix matrix) {
        matrix.set(getDrawMatrix());
    }

    /**
     * Get the current support matrix
     */
    public void getSuppMatrix(Matrix matrix) {
        matrix.set(mSuppMatrix);
    }

    private Matrix getDrawMatrix() {
        mDrawMatrix.set(mBaseMatrix);
        mDrawMatrix.postConcat(mSuppMatrix);
        return mDrawMatrix;
    }

    public Matrix getImageMatrix() {
        return mDrawMatrix;
    }

    public void setZoomTransitionDuration(int milliseconds) {
        this.mZoomDuration = milliseconds;
    }

    /**
     * Helper method that 'unpacks' a Matrix and returns the required value
     *
     * @param matrix     Matrix to unpack
     * @param whichValue Which value from Matrix.M* to return
     * @return returned value
     */
    private float getValue(Matrix matrix, int whichValue) {
        matrix.getValues(mMatrixValues);
        return mMatrixValues[whichValue];
    }

    /**
     * Resets the Matrix back to FIT_CENTER, and then displays its contents
     */
    private void resetMatrix() {
        mSuppMatrix.reset();
        setRotationBy(mBaseRotation);
        setImageViewMatrix(getDrawMatrix());
        checkMatrixBounds();
    }

    private void setImageViewMatrix(Matrix matrix) {
        mImageView.setImageMatrix(matrix);
        // Call MatrixChangedListener if needed
        if (mMatrixChangeListener != null) {
            RectF displayRect = getDisplayRect(matrix);
            if (displayRect != null) {
                mMatrixChangeListener.onMatrixChanged(displayRect);
            }
        }
    }

    /**
     * Helper method that simply checks the Matrix, and then displays the result
     */
    private void checkAndDisplayMatrix() {
        if (checkMatrixBounds()) {
            setImageViewMatrix(getDrawMatrix());
        }
    }

    /**
     * Helper method that maps the supplied Matrix to the current Drawable
     *
     * @param matrix - Matrix to map Drawable against
     * @return RectF - Displayed Rectangle
     */
    private RectF getDisplayRect(Matrix matrix) {
        Drawable d = mImageView.getDrawable();
        if (d != null) {
            mDisplayRect.set(0, 0, d.getIntrinsicWidth(),
                d.getIntrinsicHeight());
            matrix.mapRect(mDisplayRect);
            return mDisplayRect;
        }
        return null;
    }

    /**
     * Calculate Matrix for FIT_CENTER
     *
     * @param drawable - Drawable being displayed
     */
    private void updateBaseMatrix(Drawable drawable) {
        if (drawable == null) {
            return;
        }
        final float viewWidth = getImageViewWidth(mImageView);
        final float viewHeight = getImageViewHeight(mImageView);
        final int drawableWidth = drawable.getIntrinsicWidth();
        final int drawableHeight = drawable.getIntrinsicHeight();
        mBaseMatrix.reset();
        final float widthScale = viewWidth / drawableWidth;
        final float heightScale = viewHeight / drawableHeight;
        if (mScaleType == ScaleType.CENTER) {
            mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F,
                (viewHeight - drawableHeight) / 2F);

        } else if (mScaleType == ScaleType.CENTER_CROP) {
            float scale = Math.max(widthScale, heightScale);
            mBaseMatrix.postScale(scale, scale);
            mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

        } else if (mScaleType == ScaleType.CENTER_INSIDE) {
            float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
            mBaseMatrix.postScale(scale, scale);
            mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

        } else {
            RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
            RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);
            if ((int) mBaseRotation % 180 != 0) {
                mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
            }
            switch (mScaleType) {
                case FIT_CENTER:
                    mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
                    break;
                case FIT_START:
                    mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
                    break;
                case FIT_END:
                    mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
                    break;
                case FIT_XY:
                    mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
                    break;
                default:
                    break;
            }
        }
        resetMatrix();
    }

    private boolean checkMatrixBounds() {
        final RectF rect = getDisplayRect(getDrawMatrix());
        if (rect == null) {
            return false;
        }
        final float height = rect.height(), width = rect.width();
        float deltaX = 0, deltaY = 0;
        final int viewHeight = getImageViewHeight(mImageView);
        if (height <= viewHeight) {
            switch (mScaleType) {
                case FIT_START:
                    deltaY = -rect.top;
                    break;
                case FIT_END:
                    deltaY = viewHeight - height - rect.top;
                    break;
                default:
                    deltaY = (viewHeight - height) / 2 - rect.top;
                    break;
            }
            mVerticalScrollEdge = VERTICAL_EDGE_BOTH;
        } else if (rect.top > 0) {
            mVerticalScrollEdge = VERTICAL_EDGE_TOP;
            deltaY = -rect.top;
        } else if (rect.bottom < viewHeight) {
            mVerticalScrollEdge = VERTICAL_EDGE_BOTTOM;
            deltaY = viewHeight - rect.bottom;
        } else {
            mVerticalScrollEdge = VERTICAL_EDGE_NONE;
        }
        final int viewWidth = getImageViewWidth(mImageView);
        if (width <= viewWidth) {
            switch (mScaleType) {
                case FIT_START:
                    deltaX = -rect.left;
                    break;
                case FIT_END:
                    deltaX = viewWidth - width - rect.left;
                    break;
                default:
                    deltaX = (viewWidth - width) / 2 - rect.left;
                    break;
            }
            mHorizontalScrollEdge = HORIZONTAL_EDGE_BOTH;
        } else if (rect.left > 0) {
            mHorizontalScrollEdge = HORIZONTAL_EDGE_LEFT;
            deltaX = -rect.left;
        } else if (rect.right < viewWidth) {
            deltaX = viewWidth - rect.right;
            mHorizontalScrollEdge = HORIZONTAL_EDGE_RIGHT;
        } else {
            mHorizontalScrollEdge = HORIZONTAL_EDGE_NONE;
        }
        // Finally actually translate the matrix
        mSuppMatrix.postTranslate(deltaX, deltaY);
        return true;
    }

    private int getImageViewWidth(ImageView imageView) {
        return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
    }

    private int getImageViewHeight(ImageView imageView) {
        return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
    }

    private void cancelFling() {
        if (mCurrentFlingRunnable != null) {
            mCurrentFlingRunnable.cancelFling();
            mCurrentFlingRunnable = null;
        }
    }

    private class AnimatedZoomRunnable implements Runnable {

        private final float mFocalX, mFocalY;
        private final long mStartTime;
        private final float mZoomStart, mZoomEnd;

        public AnimatedZoomRunnable(final float currentZoom, final float targetZoom,
            final float focalX, final float focalY) {
            mFocalX = focalX;
            mFocalY = focalY;
            mStartTime = System.currentTimeMillis();
            mZoomStart = currentZoom;
            mZoomEnd = targetZoom;
        }

        @Override
        public void run() {
            float t = interpolate();
            float scale = mZoomStart + t * (mZoomEnd - mZoomStart);
            float deltaScale = scale / getScale();
            onGestureListener.onScale(deltaScale, mFocalX, mFocalY);
            // We haven't hit our target scale yet, so post ourselves again
            if (t < 1f) {
                Compat.postOnAnimation(mImageView, this);
            }
        }

        private float interpolate() {
            float t = 1f * (System.currentTimeMillis() - mStartTime) / mZoomDuration;
            t = Math.min(1f, t);
            t = mInterpolator.getInterpolation(t);
            return t;
        }
    }

    private class FlingRunnable implements Runnable {

        private final OverScroller mScroller;
        private int mCurrentX, mCurrentY;

        public FlingRunnable(Context context) {
            mScroller = new OverScroller(context);
        }

        public void cancelFling() {
            mScroller.forceFinished(true);
        }

        public void fling(int viewWidth, int viewHeight, int velocityX,
            int velocityY) {
            final RectF rect = getDisplayRect();
            if (rect == null) {
                return;
            }
            final int startX = Math.round(-rect.left);
            final int minX, maxX, minY, maxY;
            if (viewWidth < rect.width()) {
                minX = 0;
                maxX = Math.round(rect.width() - viewWidth);
            } else {
                minX = maxX = startX;
            }
            final int startY = Math.round(-rect.top);
            if (viewHeight < rect.height()) {
                minY = 0;
                maxY = Math.round(rect.height() - viewHeight);
            } else {
                minY = maxY = startY;
            }
            mCurrentX = startX;
            mCurrentY = startY;
            // If we actually can move, fling the scroller
            if (startX != maxX || startY != maxY) {
                mScroller.fling(startX, startY, velocityX, velocityY, minX,
                    maxX, minY, maxY, 0, 0);
            }
        }

        @Override
        public void run() {
            if (mScroller.isFinished()) {
                return; // remaining post that should not be handled
            }
            if (mScroller.computeScrollOffset()) {
                final int newX = mScroller.getCurrX();
                final int newY = mScroller.getCurrY();
                mSuppMatrix.postTranslate(mCurrentX - newX, mCurrentY - newY);
                checkAndDisplayMatrix();
                mCurrentX = newX;
                mCurrentY = newY;
                // Post On animation
                Compat.postOnAnimation(mImageView, this);
            }
        }
    }
}


================================================
FILE: photoview/src/main/java/com/github/chrisbanes/photoview/Util.java
================================================
package com.github.chrisbanes.photoview;

import android.view.MotionEvent;
import android.widget.ImageView;

class Util {

    static void checkZoomLevels(float minZoom, float midZoom,
                                float maxZoom) {
        if (minZoom >= midZoom) {
            throw new IllegalArgumentException(
                    "Minimum zoom has to be less than Medium zoom. Call setMinimumZoom() with a more appropriate value");
        } else if (midZoom >= maxZoom) {
            throw new IllegalArgumentException(
                    "Medium zoom has to be less than Maximum zoom. Call setMaximumZoom() with a more appropriate value");
        }
    }

    static boolean hasDrawable(ImageView imageView) {
        return imageView.getDrawable() != null;
    }

    static boolean isSupportedScaleType(final ImageView.ScaleType scaleType) {
        if (scaleType == null) {
            return false;
        }
        switch (scaleType) {
            case MATRIX:
                throw new IllegalStateException("Matrix scale type is not supported");
        }
        return true;
    }

    static int getPointerIndex(int action) {
        return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    }
}


================================================
FILE: sample/build.gradle
================================================
apply plugin: "com.android.application"

apply plugin: "kotlin-android"

android {
    compileSdkVersion rootProject.ext.sdkVersion

    defaultConfig {
        applicationId "uk.co.senab.photoview.sample"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.sdkVersion
        versionCode 100
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions {
        abortOnError false
    }
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "androidx.appcompat:appcompat:1.1.0"
    implementation "androidx.recyclerview:recyclerview:1.1.0"

    implementation "com.google.android.material:material:1.1.0"

    implementation "com.squareup.picasso:picasso:2.5.2"
    implementation("io.coil-kt:coil:0.9.1")

    implementation project(":photoview")
}


================================================
FILE: sample/src/main/AndroidManifest.xml
================================================
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.github.chrisbanes.photoview.sample">

    <uses-permission android:name="android.permission.INTERNET" />

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

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

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

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

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

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

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

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

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

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

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

</manifest>


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ActivityTransitionActivity.java
================================================
/*
 Copyright 2011, 2012 Chris Banes.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package com.github.chrisbanes.photoview.sample;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityOptionsCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class ActivityTransitionActivity extends AppCompatActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transition);

        RecyclerView list = findViewById(R.id.list);
        list.setLayoutManager(new GridLayoutManager(this, 2));
        ImageAdapter imageAdapter = new ImageAdapter(new ImageAdapter.Listener() {
            @Override
            public void onImageClicked(View view) {
                transition(view);
            }
        });
        list.setAdapter(imageAdapter);
    }

    private void transition(View view) {
        if (Build.VERSION.SDK_INT < 21) {
            Toast.makeText(ActivityTransitionActivity.this, "21+ only, keep out", Toast.LENGTH_SHORT).show();
        } else {
            Intent intent = new Intent(ActivityTransitionActivity.this, ActivityTransitionToActivity.class);
            ActivityOptionsCompat options = ActivityOptionsCompat.
                    makeSceneTransitionAnimation(ActivityTransitionActivity.this, view, getString(R.string.transition_test));
            startActivity(intent, options.toBundle());
        }
    }
}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ActivityTransitionToActivity.java
================================================
package com.github.chrisbanes.photoview.sample;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * Activity that gets transitioned to
 */
public class ActivityTransitionToActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transition_to);
    }
}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/CoilSampleActivity.kt
================================================
package com.github.chrisbanes.photoview.sample

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import coil.api.load
import com.github.chrisbanes.photoview.PhotoView

class CoilSampleActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_simple)

        val photoView = findViewById<PhotoView>(R.id.iv_photo)
        photoView.load("https://images.unsplash.com/photo-1577643816920-65b43ba99fba?ixlib=rb-1.2.1&auto=format&fit=crop&w=3300&q=80") {
            crossfade(true)
        }
    }
}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/HackyDrawerLayout.java
================================================
package com.github.chrisbanes.photoview.sample;

import android.content.Context;
import android.view.MotionEvent;

import androidx.drawerlayout.widget.DrawerLayout;

/**
 * Hacky fix for Issue #4 and
 * http://code.google.com/p/android/issues/detail?id=18990
 * <p/>
 * ScaleGestureDetector seems to mess up the touch events, which means that
 * ViewGroups which make use of onInterceptTouchEvent throw a lot of
 * IllegalArgumentException: pointerIndex out of range.
 * <p/>
 * There's not much I can do in my code for now, but we can mask the result by
 * just catching the problem and ignoring it.
 */
public class HackyDrawerLayout extends DrawerLayout {

    public HackyDrawerLayout(Context context) {
        super(context);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            return super.onInterceptTouchEvent(ev);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            return false;
        }
    }
}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/HackyViewPager.java
================================================
package com.github.chrisbanes.photoview.sample;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.viewpager.widget.ViewPager;

/**
 * Hacky fix for Issue #4 and
 * http://code.google.com/p/android/issues/detail?id=18990
 * <p/>
 * ScaleGestureDetector seems to mess up the touch events, which means that
 * ViewGroups which make use of onInterceptTouchEvent throw a lot of
 * IllegalArgumentException: pointerIndex out of range.
 * <p/>
 * There's not much I can do in my code for now, but we can mask the result by
 * just catching the problem and ignoring it.
 *
 * @author Chris Banes
 */
public class HackyViewPager extends ViewPager {
	
    public HackyViewPager(Context context) {
        super(context);
    }

    public HackyViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
		try {
			return super.onInterceptTouchEvent(ev);
		} catch (IllegalArgumentException e) {
			return false;
		}
    }
}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ImageAdapter.java
================================================
package com.github.chrisbanes.photoview.sample;

import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

/**
 * Image adapter
 */
public class ImageAdapter extends RecyclerView.Adapter<ImageViewHolder> {

    Listener mListener;

    public ImageAdapter(Listener listener) {
        mListener = listener;
    }

    @Override
    public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ImageViewHolder holder = ImageViewHolder.inflate(parent);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.onImageClicked(view);
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(ImageViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return 20;
    }

    public interface Listener {
        void onImageClicked(View view);
    }
}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ImageViewHolder.java
================================================
package com.github.chrisbanes.photoview.sample;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

/**
 * Image in recyclerview
 */
public class ImageViewHolder extends RecyclerView.ViewHolder {

    public static ImageViewHolder inflate(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_image, parent, false);
        return new ImageViewHolder(view);
    }

    public TextView mTextTitle;

    public ImageViewHolder(View view) {
        super(view);
        mTextTitle = view.findViewById(R.id.title);
    }

    private void bind(String title) {
        mTextTitle.setText(title);
    }
}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ImmersiveActivity.java
================================================
package com.github.chrisbanes.photoview.sample;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.github.chrisbanes.photoview.OnPhotoTapListener;
import com.github.chrisbanes.photoview.PhotoView;
import com.squareup.picasso.Picasso;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import static android.R.attr.uiOptions;

/**
 * Shows immersive image viewer
 */
public class ImmersiveActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_immersive);

        PhotoView photoView = findViewById(R.id.photo_view);
        Picasso.with(this)
                .load("http://pbs.twimg.com/media/Bist9mvIYAAeAyQ.jpg")
                .into(photoView);
        photoView.setOnPhotoTapListener(new OnPhotoTapListener() {
            @Override
            public void onPhotoTap(ImageView view, float x, float y) {
                //fullScreen();
            }
        });
        fullScreen();
    }

    public void fullScreen() {

        // BEGIN_INCLUDE (get_current_ui_flags)
        // The UI options currently enabled are represented by a bitfield.
        // getSystemUiVisibility() gives us that bitfield.
        int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
        int newUiOptions = uiOptions;
        // END_INCLUDE (get_current_ui_flags)
        // BEGIN_INCLUDE (toggle_ui_flags)
        boolean isImmersiveModeEnabled = isImmersiveModeEnabled();
        if (isImmersiveModeEnabled) {
            Log.i("TEST", "Turning immersive mode mode off. ");
        } else {
            Log.i("TEST", "Turning immersive mode mode on.");
        }

        // Navigation bar hiding:  Backwards compatible to ICS.
        if (Build.VERSION.SDK_INT >= 14) {
            newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        }

        // Status bar hiding: Backwards compatible to Jellybean
        if (Build.VERSION.SDK_INT >= 16) {
            newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
        }

        // Immersive mode: Backward compatible to KitKat.
        // Note that this flag doesn't do anything by itself, it only augments the behavior
        // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample
        // all three flags are being toggled together.
        // Note that there are two immersive mode UI flags, one of which is referred to as "sticky".
        // Sticky immersive mode differs in that it makes the navigation and status bars
        // semi-transparent, and the UI flag does not get cleared when the user interacts with
        // the screen.
        if (Build.VERSION.SDK_INT >= 18) {
            newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        }

        getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
        //END_INCLUDE (set_ui_flags)
    }

    private boolean isImmersiveModeEnabled() {
        return ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
    }

}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/LauncherActivity.java
================================================
/*
 Copyright 2011, 2012 Chris Banes.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package com.github.chrisbanes.photoview.sample;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class LauncherActivity extends AppCompatActivity {

    public static final String[] options = {
            "Simple Sample",
            "ViewPager Sample",
            "Rotation Sample",
            "Picasso Sample",
            "Coil Sample",
            "Activity Transition Sample",
            "Immersive Sample"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launcher);
        Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.setTitle(R.string.app_name);
        RecyclerView recyclerView = findViewById(R.id.list);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(new ItemAdapter());
    }


    private static class ItemAdapter extends RecyclerView.Adapter<ItemViewHolder> {
        @Override
        public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            final ItemViewHolder holder = ItemViewHolder.newInstance(parent);
            holder.itemView.setOnClickListener(v -> {
                Class clazz;

                switch (holder.getAdapterPosition()) {
                    default:
                    case 0:
                        clazz = SimpleSampleActivity.class;
                        break;
                    case 1:
                        clazz = ViewPagerActivity.class;
                        break;
                    case 2:
                        clazz = RotationSampleActivity.class;
                        break;
                    case 3:
                        clazz = PicassoSampleActivity.class;
                        break;
                    case 4:
                        clazz = CoilSampleActivity.class;
                        break;
                    case 5:
                        clazz = ActivityTransitionActivity.class;
                        break;
                    case 6:
                        clazz = ImmersiveActivity.class;
                }

                Context context = holder.itemView.getContext();
                context.startActivity(new Intent(context, clazz));
            });
            return holder;
        }

        @Override
        public void onBindViewHolder(final ItemViewHolder holder, int position) {
            holder.bind(options[position]);
        }

        @Override
        public int getItemCount() {
            return options.length;
        }
    }

    private static class ItemViewHolder extends RecyclerView.ViewHolder {

        public static ItemViewHolder newInstance(ViewGroup parent) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.item_sample, parent, false);
            return new ItemViewHolder(view);
        }

        public TextView mTextTitle;

        public ItemViewHolder(View view) {
            super(view);
            mTextTitle = view.findViewById(R.id.title);
        }

        private void bind(String title) {
            mTextTitle.setText(title);
        }
    }
}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/PicassoSampleActivity.java
================================================
package com.github.chrisbanes.photoview.sample;

import android.os.Bundle;

import com.github.chrisbanes.photoview.PhotoView;
import com.squareup.picasso.Picasso;

import androidx.appcompat.app.AppCompatActivity;

public class PicassoSampleActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple);

        final PhotoView photoView = findViewById(R.id.iv_photo);

        Picasso.with(this)
                .load("https://images.unsplash.com/photo-1577643816920-65b43ba99fba?ixlib=rb-1.2.1&auto=format&fit=crop&w=3300&q=80")
                .into(photoView);
    }
}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/RotationSampleActivity.java
================================================
/*
 Copyright 2011, 2012 Chris Banes.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package com.github.chrisbanes.photoview.sample;

import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;

import com.github.chrisbanes.photoview.PhotoView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class RotationSampleActivity extends AppCompatActivity {

    private PhotoView photo;
    private final Handler handler = new Handler();
    private boolean rotating = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rotation_sample);
        Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.inflateMenu(R.menu.rotation);
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.action_rotate_10_right:
                        photo.setRotationBy(10);
                        return true;
                    case R.id.action_rotate_10_left:
                        photo.setRotationBy(-10);
                        return true;
                    case R.id.action_toggle_automatic_rotation:
                        toggleRotation();
                        return true;
                    case R.id.action_reset_to_0:
                        photo.setRotationTo(0);
                        return true;
                    case R.id.action_reset_to_90:
                        photo.setRotationTo(90);
                        return true;
                    case R.id.action_reset_to_180:
                        photo.setRotationTo(180);
                        return true;
                    case R.id.action_reset_to_270:
                        photo.setRotationTo(270);
                        return true;
                }
                return false;
            }
        });
        photo = findViewById(R.id.iv_photo);
        photo.setImageResource(R.drawable.wallpaper);
    }

    @Override
    protected void onPause() {
        super.onPause();
        handler.removeCallbacksAndMessages(null);
    }

    private void toggleRotation() {
        if (rotating) {
            handler.removeCallbacksAndMessages(null);
        } else {
            rotateLoop();
        }
        rotating = !rotating;
    }

    private void rotateLoop() {
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                photo.setRotationBy(1);
                rotateLoop();
            }
        }, 15);
    }
}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/SimpleSampleActivity.java
================================================
/*
 Copyright 2011, 2012 Chris Banes.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package com.github.chrisbanes.photoview.sample;

import android.graphics.Matrix;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.github.chrisbanes.photoview.OnMatrixChangedListener;
import com.github.chrisbanes.photoview.OnPhotoTapListener;
import com.github.chrisbanes.photoview.OnSingleFlingListener;
import com.github.chrisbanes.photoview.PhotoView;

import java.util.Random;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;

public class SimpleSampleActivity extends AppCompatActivity {

    static final String PHOTO_TAP_TOAST_STRING = "Photo Tap! X: %.2f %% Y:%.2f %% ID: %d";
    static final String SCALE_TOAST_STRING = "Scaled to: %.2ff";
    static final String FLING_LOG_STRING = "Fling velocityX: %.2f, velocityY: %.2f";

    private PhotoView mPhotoView;
    private TextView mCurrMatrixTv;

    private Toast mCurrentToast;

    private Matrix mCurrentDisplayMatrix = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_sample);

        Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.setTitle("Simple Sample");
        toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        toolbar.inflateMenu(R.menu.main_menu);
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.menu_zoom_toggle:
                        mPhotoView.setZoomable(!mPhotoView.isZoomable());
                        item.setTitle(mPhotoView.isZoomable() ? R.string.menu_zoom_disable : R.string.menu_zoom_enable);
                        return true;

                    case R.id.menu_scale_fit_center:
                        mPhotoView.setScaleType(ImageView.ScaleType.CENTER);
                        return true;

                    case R.id.menu_scale_fit_start:
                        mPhotoView.setScaleType(ImageView.ScaleType.FIT_START);
                        return true;

                    case R.id.menu_scale_fit_end:
                        mPhotoView.setScaleType(ImageView.ScaleType.FIT_END);
                        return true;

                    case R.id.menu_scale_fit_xy:
                        mPhotoView.setScaleType(ImageView.ScaleType.FIT_XY);
                        return true;

                    case R.id.menu_scale_scale_center:
                        mPhotoView.setScaleType(ImageView.ScaleType.CENTER);
                        return true;

                    case R.id.menu_scale_scale_center_crop:
                        mPhotoView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                        return true;

                    case R.id.menu_scale_scale_center_inside:
                        mPhotoView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                        return true;

                    case R.id.menu_scale_random_animate:
                    case R.id.menu_scale_random:
                        Random r = new Random();

                        float minScale = mPhotoView.getMinimumScale();
                        float maxScale = mPhotoView.getMaximumScale();
                        float randomScale = minScale + (r.nextFloat() * (maxScale - minScale));
                        mPhotoView.setScale(randomScale, item.getItemId() == R.id.menu_scale_random_animate);

                        showToast(String.format(SCALE_TOAST_STRING, randomScale));

                        return true;
                    case R.id.menu_matrix_restore:
                        if (mCurrentDisplayMatrix == null)
                            showToast("You need to capture display matrix first");
                        else
                            mPhotoView.setDisplayMatrix(mCurrentDisplayMatrix);
                        return true;
                    case R.id.menu_matrix_capture:
                        mCurrentDisplayMatrix = new Matrix();
                        mPhotoView.getDisplayMatrix(mCurrentDisplayMatrix);
                        return true;
                }
                return false;
            }
        });
        mPhotoView = findViewById(R.id.iv_photo);
        mCurrMatrixTv = findViewById(R.id.tv_current_matrix);

        Drawable bitmap = ContextCompat.getDrawable(this, R.drawable.wallpaper);
        mPhotoView.setImageDrawable(bitmap);

        // Lets attach some listeners, not required though!
        mPhotoView.setOnMatrixChangeListener(new MatrixChangeListener());
        mPhotoView.setOnPhotoTapListener(new PhotoTapListener());
        mPhotoView.setOnSingleFlingListener(new SingleFlingListener());
    }

    private class PhotoTapListener implements OnPhotoTapListener {

        @Override
        public void onPhotoTap(ImageView view, float x, float y) {
            float xPercentage = x * 100f;
            float yPercentage = y * 100f;

            showToast(String.format(PHOTO_TAP_TOAST_STRING, xPercentage, yPercentage, view == null ? 0 : view.getId()));
        }
    }

    private void showToast(CharSequence text) {
        if (mCurrentToast != null) {
            mCurrentToast.cancel();
        }

        mCurrentToast = Toast.makeText(SimpleSampleActivity.this, text, Toast.LENGTH_SHORT);
        mCurrentToast.show();
    }

    private class MatrixChangeListener implements OnMatrixChangedListener {

        @Override
        public void onMatrixChanged(RectF rect) {
            mCurrMatrixTv.setText(rect.toString());
        }
    }

    private class SingleFlingListener implements OnSingleFlingListener {

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            Log.d("PhotoView", String.format(FLING_LOG_STRING, velocityX, velocityY));
            return true;
        }
    }
}


================================================
FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ViewPagerActivity.java
================================================
/*
 Copyright 2011, 2012 Chris Banes.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package com.github.chrisbanes.photoview.sample;

import android.os.Bundle;

import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;

import com.github.chrisbanes.photoview.PhotoView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

public class ViewPagerActivity extends AppCompatActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_pager);
        ViewPager viewPager = findViewById(R.id.view_pager);
        viewPager.setAdapter(new SamplePagerAdapter());
    }

    static class SamplePagerAdapter extends PagerAdapter {

        private static final int[] sDrawables = {R.drawable.wallpaper, R.drawable.wallpaper, R.drawable.wallpaper,
            R.drawable.wallpaper, R.drawable.wallpaper, R.drawable.wallpaper};

        @Override
        public int getCount() {
            return sDrawables.length;
        }

        @Override
        public View instantiateItem(ViewGroup container, int position) {
            PhotoView photoView = new PhotoView(container.getContext());
            photoView.setImageResource(sDrawables[position]);
            // Now just add PhotoView to ViewPager and return it
            container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            return photoView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

    }
}


================================================
FILE: sample/src/main/res/drawable/ic_arrow_back_white_24dp.xml
================================================
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
</vector>


================================================
FILE: sample/src/main/res/layout/activity_immersive.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.github.chrisbanes.photoview.PhotoView
        android:id="@+id/photo_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

================================================
FILE: sample/src/main/res/layout/activity_launcher.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

================================================
FILE: sample/src/main/res/layout/activity_rotation_sample.xml
================================================
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"/>

    </com.google.android.material.appbar.AppBarLayout>

    <com.github.chrisbanes.photoview.PhotoView
        android:id="@+id/iv_photo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/wallpaper"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

================================================
FILE: sample/src/main/res/layout/activity_simple.xml
================================================
<com.github.chrisbanes.photoview.PhotoView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/iv_photo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

================================================
FILE: sample/src/main/res/layout/activity_simple_sample.xml
================================================
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"/>

    </com.google.android.material.appbar.AppBarLayout>

    <com.github.chrisbanes.photoview.PhotoView
        android:id="@+id/iv_photo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <TextView
        android:id="@+id/tv_current_matrix"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:background="#60000000"
        android:gravity="center"
        android:textColor="@android:color/white"/>

</FrameLayout>

================================================
FILE: sample/src/main/res/layout/activity_transition.xml
================================================
<androidx.recyclerview.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

================================================
FILE: sample/src/main/res/layout/activity_transition_to.xml
================================================
<com.github.chrisbanes.photoview.PhotoView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/iv_photo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:src="@drawable/wallpaper"
    android:transitionName="@string/transition_test" />

================================================
FILE: sample/src/main/res/layout/activity_view_pager.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<com.github.chrisbanes.photoview.sample.HackyViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

================================================
FILE: sample/src/main/res/layout/item_image.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"
    android:src="@drawable/wallpaper"/>

================================================
FILE: sample/src/main/res/layout/item_sample.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/listPreferredItemHeight"
    android:background="?attr/selectableItemBackground">

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/white"/>

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:textSize="20sp"
        android:layout_margin="16dp"
        tools:text="Hello there"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_gravity="bottom"
        android:background="@android:color/white"/>

</FrameLayout>

================================================
FILE: sample/src/main/res/menu/main_menu.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      tools:ignore="UnusedAttribute">

    <item
        android:id="@+id/menu_zoom_toggle"
        android:title="@string/menu_zoom_disable"/>
    <item
        android:id="@+id/menu_scale_fit_center"
        android:title="@string/menu_scale_fit_center"/>
    <item
        android:id="@+id/menu_scale_fit_start"
        android:title="@string/menu_scale_fit_start"/>
    <item
        android:id="@+id/menu_scale_fit_end"
        android:title="@string/menu_scale_fit_end"/>
    <item
        android:id="@+id/menu_scale_fit_xy"
        android:title="@string/menu_scale_fit_xy"/>
    <item
        android:id="@+id/menu_scale_scale_center"
        android:title="@string/menu_scale_center"/>
    <item
        android:id="@+id/menu_scale_scale_center_crop"
        android:title="@string/menu_scale_center_crop"/>
    <item
        android:id="@+id/menu_scale_scale_center_inside"
        android:title="@string/menu_scale_center_inside"/>
    <item
        android:id="@+id/menu_scale_random_animate"
        android:title="@string/menu_zoom_random_animate"/>
    <item
        android:id="@+id/menu_scale_random"
        android:title="@string/menu_zoom_random"/>
    <item
        android:id="@+id/menu_matrix_restore"
        android:title="@string/menu_matrix_restore"/>
    <item
        android:id="@+id/menu_matrix_capture"
        android:title="@string/menu_matrix_capture"/>

</menu>

================================================
FILE: sample/src/main/res/menu/rotation.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/action_rotate_10_right"
        android:title="Rotate 10° Right"/>

    <item
        android:id="@+id/action_rotate_10_left"
        android:title="Rotate 10° Left"/>

    <item
        android:id="@+id/action_toggle_automatic_rotation"
        android:title="Toggle Automatic Rotation"/>

    <item
        android:id="@+id/action_reset_to_0"
        android:title="Reset to 0"/>

    <item
        android:id="@+id/action_reset_to_90"
        android:title="Reset to 90"/>

    <item
        android:id="@+id/action_reset_to_180"
        android:title="Reset to 180"/>

    <item
        android:id="@+id/action_reset_to_270"
        android:title="Reset to 270"/>
</menu>

================================================
FILE: sample/src/main/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="green">#AACE30</color>
    <color name="blue">#142D3E</color>
    <color name="blue_dark">#001425</color>
</resources>

================================================
FILE: sample/src/main/res/values/strings.xml
================================================
<resources>

    <string name="app_name">PhotoView Sample</string>
    <string name="menu_zoom_enable">Enable Zoom</string>
    <string name="menu_zoom_disable">Disable Zoom</string>
    <string name="menu_scale_fit_center">Change to FIT_CENTER</string>
    <string name="menu_scale_fit_start">Change to FIT_START</string>
    <string name="menu_scale_fit_end">Change to FIT_END</string>
    <string name="menu_scale_fit_xy">Change to FIT_XY</string>
    <string name="menu_scale_center">Change to CENTER</string>
    <string name="menu_scale_center_inside">Change to CENTER_INSIDE</string>
    <string name="menu_scale_center_crop">Change to CENTER_CROP</string>
    <string name="menu_zoom_random_animate">Animate scale to random value</string>
    <string name="menu_zoom_random">Set scale to random value</string>
    <string name="menu_matrix_restore">Restore Display Matrix</string>
    <string name="menu_matrix_capture">Capture Display Matrix</string>
    <string name="extract_visible_bitmap">Extract visible bitmap</string>

</resources>


================================================
FILE: sample/src/main/res/values/styles.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/blue</item>
        <item name="colorPrimaryDark">@color/blue_dark</item>
        <item name="colorAccent">@color/green</item>

        <!-- enable window content transitions -->
        <item name="android:windowActivityTransitions" tools:targetApi="lollipop">true</item>
    </style>
</resources>

================================================
FILE: sample/src/main/res/values/transitions.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="transition_test">test</string>
</resources>

================================================
FILE: settings.gradle
================================================
include 'photoview'
include 'sample'
Download .txt
gitextract_rensreqv/

├── .github/
│   ├── FUNDING.yml
│   ├── ISSUE_TEMPLATE/
│   │   ├── a-regression.md
│   │   ├── b-bug-report.md
│   │   ├── c-feature-request.md
│   │   ├── d-enhancement-proposal.md
│   │   └── e-question.md
│   └── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── build.gradle
├── gradle/
│   └── wrapper/
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── photoview/
│   ├── build.gradle
│   └── src/
│       └── main/
│           ├── AndroidManifest.xml
│           └── java/
│               └── com/
│                   └── github/
│                       └── chrisbanes/
│                           └── photoview/
│                               ├── Compat.java
│                               ├── CustomGestureDetector.java
│                               ├── OnGestureListener.java
│                               ├── OnMatrixChangedListener.java
│                               ├── OnOutsidePhotoTapListener.java
│                               ├── OnPhotoTapListener.java
│                               ├── OnScaleChangedListener.java
│                               ├── OnSingleFlingListener.java
│                               ├── OnViewDragListener.java
│                               ├── OnViewTapListener.java
│                               ├── PhotoView.java
│                               ├── PhotoViewAttacher.java
│                               └── Util.java
├── sample/
│   ├── build.gradle
│   └── src/
│       └── main/
│           ├── AndroidManifest.xml
│           ├── java/
│           │   └── com/
│           │       └── github/
│           │           └── chrisbanes/
│           │               └── photoview/
│           │                   └── sample/
│           │                       ├── ActivityTransitionActivity.java
│           │                       ├── ActivityTransitionToActivity.java
│           │                       ├── CoilSampleActivity.kt
│           │                       ├── HackyDrawerLayout.java
│           │                       ├── HackyViewPager.java
│           │                       ├── ImageAdapter.java
│           │                       ├── ImageViewHolder.java
│           │                       ├── ImmersiveActivity.java
│           │                       ├── LauncherActivity.java
│           │                       ├── PicassoSampleActivity.java
│           │                       ├── RotationSampleActivity.java
│           │                       ├── SimpleSampleActivity.java
│           │                       └── ViewPagerActivity.java
│           └── res/
│               ├── drawable/
│               │   └── ic_arrow_back_white_24dp.xml
│               ├── layout/
│               │   ├── activity_immersive.xml
│               │   ├── activity_launcher.xml
│               │   ├── activity_rotation_sample.xml
│               │   ├── activity_simple.xml
│               │   ├── activity_simple_sample.xml
│               │   ├── activity_transition.xml
│               │   ├── activity_transition_to.xml
│               │   ├── activity_view_pager.xml
│               │   ├── item_image.xml
│               │   └── item_sample.xml
│               ├── menu/
│               │   ├── main_menu.xml
│               │   └── rotation.xml
│               └── values/
│                   ├── colors.xml
│                   ├── strings.xml
│                   ├── styles.xml
│                   └── transitions.xml
└── settings.gradle
Download .txt
SYMBOL INDEX (206 symbols across 25 files)

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/Compat.java
  class Compat (line 23) | class Compat {
    method postOnAnimation (line 27) | public static void postOnAnimation(View view, Runnable runnable) {
    method postOnAnimationJellyBean (line 35) | @TargetApi(16)

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/CustomGestureDetector.java
  class CustomGestureDetector (line 27) | class CustomGestureDetector {
    method CustomGestureDetector (line 43) | CustomGestureDetector(Context context, OnGestureListener listener) {
    method getActiveX (line 88) | private float getActiveX(MotionEvent ev) {
    method getActiveY (line 96) | private float getActiveY(MotionEvent ev) {
    method isScaling (line 104) | public boolean isScaling() {
    method isDragging (line 108) | public boolean isDragging() {
    method onTouchEvent (line 112) | public boolean onTouchEvent(MotionEvent ev) {
    method processTouchEvent (line 122) | private boolean processTouchEvent(MotionEvent ev) {

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnGestureListener.java
  type OnGestureListener (line 18) | interface OnGestureListener {
    method onDrag (line 20) | void onDrag(float dx, float dy);
    method onFling (line 22) | void onFling(float startX, float startY, float velocityX,
    method onScale (line 25) | void onScale(float scaleFactor, float focusX, float focusY);
    method onScale (line 27) | void onScale(float scaleFactor, float focusX, float focusY, float dx, ...

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnMatrixChangedListener.java
  type OnMatrixChangedListener (line 9) | public interface OnMatrixChangedListener {
    method onMatrixChanged (line 17) | void onMatrixChanged(RectF rect);

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnOutsidePhotoTapListener.java
  type OnOutsidePhotoTapListener (line 8) | public interface OnOutsidePhotoTapListener {
    method onOutsidePhotoTap (line 13) | void onOutsidePhotoTap(ImageView imageView);

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnPhotoTapListener.java
  type OnPhotoTapListener (line 9) | public interface OnPhotoTapListener {
    method onPhotoTap (line 21) | void onPhotoTap(ImageView view, float x, float y);

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnScaleChangedListener.java
  type OnScaleChangedListener (line 7) | public interface OnScaleChangedListener {
    method onScaleChange (line 16) | void onScaleChange(float scaleFactor, float focusX, float focusY);

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnSingleFlingListener.java
  type OnSingleFlingListener (line 9) | public interface OnSingleFlingListener {
    method onFling (line 20) | boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float...

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnViewDragListener.java
  type OnViewDragListener (line 6) | public interface OnViewDragListener {
    method onDrag (line 15) | void onDrag(float dx, float dy);

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/OnViewTapListener.java
  type OnViewTapListener (line 5) | public interface OnViewTapListener {
    method onViewTap (line 15) | void onViewTap(View view, float x, float y);

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java
  class PhotoView (line 32) | @SuppressWarnings("unused")
    method PhotoView (line 38) | public PhotoView(Context context) {
    method PhotoView (line 42) | public PhotoView(Context context, AttributeSet attr) {
    method PhotoView (line 46) | public PhotoView(Context context, AttributeSet attr, int defStyle) {
    method init (line 51) | private void init() {
    method getAttacher (line 70) | public PhotoViewAttacher getAttacher() {
    method getScaleType (line 74) | @Override
    method getImageMatrix (line 79) | @Override
    method setOnLongClickListener (line 84) | @Override
    method setOnClickListener (line 89) | @Override
    method setScaleType (line 94) | @Override
    method setImageDrawable (line 103) | @Override
    method setImageResource (line 112) | @Override
    method setImageURI (line 120) | @Override
    method setFrame (line 128) | @Override
    method setRotationTo (line 137) | public void setRotationTo(float rotationDegree) {
    method setRotationBy (line 141) | public void setRotationBy(float rotationDegree) {
    method isZoomable (line 145) | public boolean isZoomable() {
    method setZoomable (line 149) | public void setZoomable(boolean zoomable) {
    method getDisplayRect (line 153) | public RectF getDisplayRect() {
    method getDisplayMatrix (line 157) | public void getDisplayMatrix(Matrix matrix) {
    method setDisplayMatrix (line 161) | @SuppressWarnings("UnusedReturnValue") public boolean setDisplayMatrix...
    method getSuppMatrix (line 165) | public void getSuppMatrix(Matrix matrix) {
    method setSuppMatrix (line 169) | public boolean setSuppMatrix(Matrix matrix) {
    method getMinimumScale (line 173) | public float getMinimumScale() {
    method getMediumScale (line 177) | public float getMediumScale() {
    method getMaximumScale (line 181) | public float getMaximumScale() {
    method getScale (line 185) | public float getScale() {
    method setAllowParentInterceptOnEdge (line 189) | public void setAllowParentInterceptOnEdge(boolean allow) {
    method setMinimumScale (line 193) | public void setMinimumScale(float minimumScale) {
    method setMediumScale (line 197) | public void setMediumScale(float mediumScale) {
    method setMaximumScale (line 201) | public void setMaximumScale(float maximumScale) {
    method setScaleLevels (line 205) | public void setScaleLevels(float minimumScale, float mediumScale, floa...
    method setOnMatrixChangeListener (line 209) | public void setOnMatrixChangeListener(OnMatrixChangedListener listener) {
    method setOnPhotoTapListener (line 213) | public void setOnPhotoTapListener(OnPhotoTapListener listener) {
    method setOnOutsidePhotoTapListener (line 217) | public void setOnOutsidePhotoTapListener(OnOutsidePhotoTapListener lis...
    method setOnViewTapListener (line 221) | public void setOnViewTapListener(OnViewTapListener listener) {
    method setOnViewDragListener (line 225) | public void setOnViewDragListener(OnViewDragListener listener) {
    method setScale (line 229) | public void setScale(float scale) {
    method setScale (line 233) | public void setScale(float scale, boolean animate) {
    method setScale (line 237) | public void setScale(float scale, float focalX, float focalY, boolean ...
    method setZoomTransitionDuration (line 241) | public void setZoomTransitionDuration(int milliseconds) {
    method setOnDoubleTapListener (line 245) | public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener...
    method setOnScaleChangeListener (line 249) | public void setOnScaleChangeListener(OnScaleChangedListener onScaleCha...
    method setOnSingleFlingListener (line 253) | public void setOnSingleFlingListener(OnSingleFlingListener onSingleFli...

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java
  class PhotoViewAttacher (line 39) | public class PhotoViewAttacher implements View.OnTouchListener,
    method onDrag (line 99) | @Override
    method onFling (line 137) | @Override
    method onScale (line 145) | @Override
    method onScale (line 150) | @Override
    method PhotoViewAttacher (line 163) | public PhotoViewAttacher(ImageView imageView) {
    method setOnDoubleTapListener (line 257) | public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener...
    method setOnScaleChangeListener (line 261) | public void setOnScaleChangeListener(OnScaleChangedListener onScaleCha...
    method setOnSingleFlingListener (line 265) | public void setOnSingleFlingListener(OnSingleFlingListener onSingleFli...
    method isZoomEnabled (line 269) | @Deprecated
    method getDisplayRect (line 274) | public RectF getDisplayRect() {
    method setDisplayMatrix (line 279) | public boolean setDisplayMatrix(Matrix finalMatrix) {
    method setBaseRotation (line 291) | public void setBaseRotation(final float degrees) {
    method setRotationTo (line 298) | public void setRotationTo(float degrees) {
    method setRotationBy (line 303) | public void setRotationBy(float degrees) {
    method getMinimumScale (line 308) | public float getMinimumScale() {
    method getMediumScale (line 312) | public float getMediumScale() {
    method getMaximumScale (line 316) | public float getMaximumScale() {
    method getScale (line 320) | public float getScale() {
    method getScaleType (line 325) | public ScaleType getScaleType() {
    method onLayoutChange (line 329) | @Override
    method onTouch (line 338) | @Override
    method setAllowParentInterceptOnEdge (line 393) | public void setAllowParentInterceptOnEdge(boolean allow) {
    method setMinimumScale (line 397) | public void setMinimumScale(float minimumScale) {
    method setMediumScale (line 402) | public void setMediumScale(float mediumScale) {
    method setMaximumScale (line 407) | public void setMaximumScale(float maximumScale) {
    method setScaleLevels (line 412) | public void setScaleLevels(float minimumScale, float mediumScale, floa...
    method setOnLongClickListener (line 419) | public void setOnLongClickListener(OnLongClickListener listener) {
    method setOnClickListener (line 423) | public void setOnClickListener(View.OnClickListener listener) {
    method setOnMatrixChangeListener (line 427) | public void setOnMatrixChangeListener(OnMatrixChangedListener listener) {
    method setOnPhotoTapListener (line 431) | public void setOnPhotoTapListener(OnPhotoTapListener listener) {
    method setOnOutsidePhotoTapListener (line 435) | public void setOnOutsidePhotoTapListener(OnOutsidePhotoTapListener mOu...
    method setOnViewTapListener (line 439) | public void setOnViewTapListener(OnViewTapListener listener) {
    method setOnViewDragListener (line 443) | public void setOnViewDragListener(OnViewDragListener listener) {
    method setScale (line 447) | public void setScale(float scale) {
    method setScale (line 451) | public void setScale(float scale, boolean animate) {
    method setScale (line 458) | public void setScale(float scale, float focalX, float focalY,
    method setZoomInterpolator (line 478) | public void setZoomInterpolator(Interpolator interpolator) {
    method setScaleType (line 482) | public void setScaleType(ScaleType scaleType) {
    method isZoomable (line 489) | public boolean isZoomable() {
    method setZoomable (line 493) | public void setZoomable(boolean zoomable) {
    method update (line 498) | public void update() {
    method getDisplayMatrix (line 513) | public void getDisplayMatrix(Matrix matrix) {
    method getSuppMatrix (line 520) | public void getSuppMatrix(Matrix matrix) {
    method getDrawMatrix (line 524) | private Matrix getDrawMatrix() {
    method getImageMatrix (line 530) | public Matrix getImageMatrix() {
    method setZoomTransitionDuration (line 534) | public void setZoomTransitionDuration(int milliseconds) {
    method getValue (line 545) | private float getValue(Matrix matrix, int whichValue) {
    method resetMatrix (line 553) | private void resetMatrix() {
    method setImageViewMatrix (line 560) | private void setImageViewMatrix(Matrix matrix) {
    method checkAndDisplayMatrix (line 574) | private void checkAndDisplayMatrix() {
    method getDisplayRect (line 586) | private RectF getDisplayRect(Matrix matrix) {
    method updateBaseMatrix (line 602) | private void updateBaseMatrix(Drawable drawable) {
    method checkMatrixBounds (line 655) | private boolean checkMatrixBounds() {
    method getImageViewWidth (line 713) | private int getImageViewWidth(ImageView imageView) {
    method getImageViewHeight (line 717) | private int getImageViewHeight(ImageView imageView) {
    method cancelFling (line 721) | private void cancelFling() {
    class AnimatedZoomRunnable (line 728) | private class AnimatedZoomRunnable implements Runnable {
      method AnimatedZoomRunnable (line 734) | public AnimatedZoomRunnable(final float currentZoom, final float tar...
      method run (line 743) | @Override
      method interpolate (line 755) | private float interpolate() {
    class FlingRunnable (line 763) | private class FlingRunnable implements Runnable {
      method FlingRunnable (line 768) | public FlingRunnable(Context context) {
      method cancelFling (line 772) | public void cancelFling() {
      method fling (line 776) | public void fling(int viewWidth, int viewHeight, int velocityX,
      method run (line 806) | @Override

FILE: photoview/src/main/java/com/github/chrisbanes/photoview/Util.java
  class Util (line 6) | class Util {
    method checkZoomLevels (line 8) | static void checkZoomLevels(float minZoom, float midZoom,
    method hasDrawable (line 19) | static boolean hasDrawable(ImageView imageView) {
    method isSupportedScaleType (line 23) | static boolean isSupportedScaleType(final ImageView.ScaleType scaleTyp...
    method getPointerIndex (line 34) | static int getPointerIndex(int action) {

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ActivityTransitionActivity.java
  class ActivityTransitionActivity (line 29) | public class ActivityTransitionActivity extends AppCompatActivity {
    method onCreate (line 31) | @Override
    method transition (line 47) | private void transition(View view) {

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ActivityTransitionToActivity.java
  class ActivityTransitionToActivity (line 11) | public class ActivityTransitionToActivity extends AppCompatActivity {
    method onCreate (line 13) | @Override

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/HackyDrawerLayout.java
  class HackyDrawerLayout (line 19) | public class HackyDrawerLayout extends DrawerLayout {
    method HackyDrawerLayout (line 21) | public HackyDrawerLayout(Context context) {
    method onInterceptTouchEvent (line 25) | @Override

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/HackyViewPager.java
  class HackyViewPager (line 22) | public class HackyViewPager extends ViewPager {
    method HackyViewPager (line 24) | public HackyViewPager(Context context) {
    method HackyViewPager (line 28) | public HackyViewPager(Context context, AttributeSet attrs) {
    method onInterceptTouchEvent (line 32) | @Override

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ImageAdapter.java
  class ImageAdapter (line 11) | public class ImageAdapter extends RecyclerView.Adapter<ImageViewHolder> {
    method ImageAdapter (line 15) | public ImageAdapter(Listener listener) {
    method onCreateViewHolder (line 19) | @Override
    method onBindViewHolder (line 31) | @Override
    method getItemCount (line 36) | @Override
    type Listener (line 41) | public interface Listener {
      method onImageClicked (line 42) | void onImageClicked(View view);

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ImageViewHolder.java
  class ImageViewHolder (line 13) | public class ImageViewHolder extends RecyclerView.ViewHolder {
    method inflate (line 15) | public static ImageViewHolder inflate(ViewGroup parent) {
    method ImageViewHolder (line 23) | public ImageViewHolder(View view) {
    method bind (line 28) | private void bind(String title) {

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ImmersiveActivity.java
  class ImmersiveActivity (line 21) | public class ImmersiveActivity extends AppCompatActivity {
    method onCreate (line 23) | @Override
    method fullScreen (line 41) | public void fullScreen() {
    method isImmersiveModeEnabled (line 83) | private boolean isImmersiveModeEnabled() {

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/LauncherActivity.java
  class LauncherActivity (line 31) | public class LauncherActivity extends AppCompatActivity {
    method onCreate (line 43) | @Override
    class ItemAdapter (line 55) | private static class ItemAdapter extends RecyclerView.Adapter<ItemView...
      method onCreateViewHolder (line 56) | @Override
      method onBindViewHolder (line 92) | @Override
      method getItemCount (line 97) | @Override
    class ItemViewHolder (line 103) | private static class ItemViewHolder extends RecyclerView.ViewHolder {
      method newInstance (line 105) | public static ItemViewHolder newInstance(ViewGroup parent) {
      method ItemViewHolder (line 113) | public ItemViewHolder(View view) {
      method bind (line 118) | private void bind(String title) {

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/PicassoSampleActivity.java
  class PicassoSampleActivity (line 10) | public class PicassoSampleActivity extends AppCompatActivity {
    method onCreate (line 12) | @Override

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/RotationSampleActivity.java
  class RotationSampleActivity (line 27) | public class RotationSampleActivity extends AppCompatActivity {
    method onCreate (line 33) | @Override
    method onPause (line 72) | @Override
    method toggleRotation (line 78) | private void toggleRotation() {
    method rotateLoop (line 87) | private void rotateLoop() {

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/SimpleSampleActivity.java
  class SimpleSampleActivity (line 41) | public class SimpleSampleActivity extends AppCompatActivity {
    method onCreate (line 54) | @Override
    class PhotoTapListener (line 144) | private class PhotoTapListener implements OnPhotoTapListener {
      method onPhotoTap (line 146) | @Override
    method showToast (line 155) | private void showToast(CharSequence text) {
    class MatrixChangeListener (line 164) | private class MatrixChangeListener implements OnMatrixChangedListener {
      method onMatrixChanged (line 166) | @Override
    class SingleFlingListener (line 172) | private class SingleFlingListener implements OnSingleFlingListener {
      method onFling (line 174) | @Override

FILE: sample/src/main/java/com/github/chrisbanes/photoview/sample/ViewPagerActivity.java
  class ViewPagerActivity (line 30) | public class ViewPagerActivity extends AppCompatActivity {
    method onCreate (line 32) | @Override
    class SamplePagerAdapter (line 40) | static class SamplePagerAdapter extends PagerAdapter {
      method getCount (line 45) | @Override
      method instantiateItem (line 50) | @Override
      method destroyItem (line 59) | @Override
      method isViewFromObject (line 64) | @Override
Condensed preview — 66 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (136K chars).
[
  {
    "path": ".github/FUNDING.yml",
    "chars": 54,
    "preview": "github: Baseflow\ncustom: https://baseflow.com/contact\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/a-regression.md",
    "chars": 301,
    "preview": "---\n\nname: 🔙 Regression\nabout: Report unexpected behavior that worked previously\n---\n\n## 🔙 Regression\n\n<!--- Summary des"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/b-bug-report.md",
    "chars": 271,
    "preview": "---\n\nname: 🐛 Bug Report\nabout: Create a report to help us fix bugs and make improvements\n---\n\n## 🐛 Bug Report\n\n<!--- Sum"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/c-feature-request.md",
    "chars": 361,
    "preview": "---\n\nname: 🚀 Feature Request\nabout: Want to see something new included in the Framework? Submit it!\n---\n\n## 🚀 Feature Re"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/d-enhancement-proposal.md",
    "chars": 305,
    "preview": "---\n\nname: 🏗 Enhancement Proposal\nabout: Proposals for code cleanup, refactor and improvements in general\n---\n\n## 🏗 Enha"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/e-question.md",
    "chars": 212,
    "preview": "---\n\nname: 💬 Questions and Help\nabout: If you have questions, please use this for support\n---\n\n## 💬 Questions and Help\n\n"
  },
  {
    "path": ".github/PULL_REQUEST_TEMPLATE.md",
    "chars": 537,
    "preview": "### :sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)\n\n\n### :arrow_heading_down:"
  },
  {
    "path": ".gitignore",
    "chars": 241,
    "preview": "#Android generated\nbin\ngen\n\n#Eclipse\n.project\n.classpath\n.settings\n\n#IntelliJ IDEA\n.idea\n*.iml\n*.ipr\n*.iws\nout\n\n#Maven\nt"
  },
  {
    "path": "CODE_OF_CONDUCT.md",
    "chars": 3253,
    "preview": "# Contributor Covenant Code of Conduct\n\n## Our Pledge\n\nIn the interest of fostering an open and welcoming environment, w"
  },
  {
    "path": "CONTRIBUTING.md",
    "chars": 207,
    "preview": "# Contributing to PhotoView\n\n## Finding an issue to work on\n\nIf you'd like to work on something that isn't in a current "
  },
  {
    "path": "LICENSE",
    "chars": 11358,
    "preview": "\n                                 Apache License\n                           Version 2.0, January 2004\n                  "
  },
  {
    "path": "README.md",
    "chars": 4324,
    "preview": "# PhotoView\nPhotoView aims to help produce an easily usable implementation of a zooming Android ImageView.\n\n[![](https:/"
  },
  {
    "path": "build.gradle",
    "chars": 473,
    "preview": "buildscript {\n    ext.kotlin_version = '1.3.72'\n    repositories {\n        google()\n        jcenter()\n    }\n\n    depende"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "chars": 200,
    "preview": "distributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributi"
  },
  {
    "path": "gradle.properties",
    "chars": 52,
    "preview": "android.useAndroidX=true\nandroid.enableJetifier=true"
  },
  {
    "path": "gradlew",
    "chars": 5764,
    "preview": "#!/usr/bin/env sh\n\n#\n# Copyright 2015 the original author or authors.\n#\n# Licensed under the Apache License, Version 2.0"
  },
  {
    "path": "gradlew.bat",
    "chars": 3056,
    "preview": "@rem\r\n@rem Copyright 2015 the original author or authors.\r\n@rem\r\n@rem Licensed under the Apache License, Version 2.0 (th"
  },
  {
    "path": "photoview/build.gradle",
    "chars": 2512,
    "preview": "apply plugin: 'com.android.library'\napply plugin: 'maven-publish'\n\nandroid {\n    compileSdkVersion rootProject.ext.sdkVe"
  },
  {
    "path": "photoview/src/main/AndroidManifest.xml",
    "chars": 105,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest package=\"com.github.chrisbanes.photoview\">\n\n</manifest>\n"
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/Compat.java",
    "chars": 1254,
    "preview": "/*\n Copyright 2011, 2012 Chris Banes.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use"
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/CustomGestureDetector.java",
    "chars": 7784,
    "preview": "/*\n Copyright 2011, 2012 Chris Banes.\n <p/>\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may no"
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/OnGestureListener.java",
    "chars": 933,
    "preview": "/*\n Copyright 2011, 2012 Chris Banes.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use"
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/OnMatrixChangedListener.java",
    "chars": 524,
    "preview": "package com.github.chrisbanes.photoview;\n\nimport android.graphics.RectF;\n\n/**\n * Interface definition for a callback to "
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/OnOutsidePhotoTapListener.java",
    "chars": 299,
    "preview": "package com.github.chrisbanes.photoview;\n\nimport android.widget.ImageView;\n\n/**\n * Callback when the user tapped outside"
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/OnPhotoTapListener.java",
    "chars": 755,
    "preview": "package com.github.chrisbanes.photoview;\n\nimport android.widget.ImageView;\n\n/**\n * A callback to be invoked when the Pho"
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/OnScaleChangedListener.java",
    "chars": 518,
    "preview": "package com.github.chrisbanes.photoview;\n\n\n/**\n * Interface definition for callback to be invoked when attached ImageVie"
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/OnSingleFlingListener.java",
    "chars": 695,
    "preview": "package com.github.chrisbanes.photoview;\n\nimport android.view.MotionEvent;\n\n/**\n * A callback to be invoked when the Ima"
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/OnViewDragListener.java",
    "chars": 501,
    "preview": "package com.github.chrisbanes.photoview;\n\n/**\n * Interface definition for a callback to be invoked when the photo is exp"
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/OnViewTapListener.java",
    "chars": 547,
    "preview": "package com.github.chrisbanes.photoview;\n\nimport android.view.View;\n\npublic interface OnViewTapListener {\n\n    /**\n     "
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java",
    "chars": 7303,
    "preview": "/*\n Copyright 2011, 2012 Chris Banes.\n <p>\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not"
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java",
    "chars": 30148,
    "preview": "/*\n Copyright 2011, 2012 Chris Banes.\n <p>\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not"
  },
  {
    "path": "photoview/src/main/java/com/github/chrisbanes/photoview/Util.java",
    "chars": 1262,
    "preview": "package com.github.chrisbanes.photoview;\n\nimport android.view.MotionEvent;\nimport android.widget.ImageView;\n\nclass Util "
  },
  {
    "path": "sample/build.gradle",
    "chars": 1098,
    "preview": "apply plugin: \"com.android.application\"\n\napply plugin: \"kotlin-android\"\n\nandroid {\n    compileSdkVersion rootProject.ext"
  },
  {
    "path": "sample/src/main/AndroidManifest.xml",
    "chars": 1299,
    "preview": "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n"
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/ActivityTransitionActivity.java",
    "chars": 2162,
    "preview": "/*\n Copyright 2011, 2012 Chris Banes.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use"
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/ActivityTransitionToActivity.java",
    "chars": 470,
    "preview": "package com.github.chrisbanes.photoview.sample;\n\nimport android.os.Bundle;\n\nimport androidx.annotation.Nullable;\nimport "
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/CoilSampleActivity.kt",
    "chars": 638,
    "preview": "package com.github.chrisbanes.photoview.sample\n\nimport android.os.Bundle\nimport androidx.appcompat.app.AppCompatActivity"
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/HackyDrawerLayout.java",
    "chars": 1002,
    "preview": "package com.github.chrisbanes.photoview.sample;\n\nimport android.content.Context;\nimport android.view.MotionEvent;\n\nimpor"
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/HackyViewPager.java",
    "chars": 1082,
    "preview": "package com.github.chrisbanes.photoview.sample;\n\nimport android.content.Context;\nimport android.util.AttributeSet;\nimpor"
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/ImageAdapter.java",
    "chars": 1015,
    "preview": "package com.github.chrisbanes.photoview.sample;\n\nimport android.view.View;\nimport android.view.ViewGroup;\n\nimport androi"
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/ImageViewHolder.java",
    "chars": 791,
    "preview": "package com.github.chrisbanes.photoview.sample;\n\nimport android.view.LayoutInflater;\nimport android.view.View;\nimport an"
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/ImmersiveActivity.java",
    "chars": 3188,
    "preview": "package com.github.chrisbanes.photoview.sample;\n\nimport android.os.Build;\nimport android.os.Bundle;\nimport android.util."
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/LauncherActivity.java",
    "chars": 4128,
    "preview": "/*\n Copyright 2011, 2012 Chris Banes.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use"
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/PicassoSampleActivity.java",
    "chars": 713,
    "preview": "package com.github.chrisbanes.photoview.sample;\n\nimport android.os.Bundle;\n\nimport com.github.chrisbanes.photoview.Photo"
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/RotationSampleActivity.java",
    "chars": 3231,
    "preview": "/*\n Copyright 2011, 2012 Chris Banes.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use"
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/SimpleSampleActivity.java",
    "chars": 7052,
    "preview": "/*\n Copyright 2011, 2012 Chris Banes.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use"
  },
  {
    "path": "sample/src/main/java/com/github/chrisbanes/photoview/sample/ViewPagerActivity.java",
    "chars": 2376,
    "preview": "/*\n Copyright 2011, 2012 Chris Banes.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use"
  },
  {
    "path": "sample/src/main/res/drawable/ic_arrow_back_white_24dp.xml",
    "chars": 352,
    "preview": "<vector xmlns:android=\"http://schemas.android.com/apk/res/android\"\n        android:width=\"24dp\"\n        android:height=\""
  },
  {
    "path": "sample/src/main/res/layout/activity_immersive.xml",
    "chars": 412,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    andro"
  },
  {
    "path": "sample/src/main/res/layout/activity_launcher.xml",
    "chars": 637,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    andr"
  },
  {
    "path": "sample/src/main/res/layout/activity_rotation_sample.xml",
    "chars": 942,
    "preview": "<androidx.coordinatorlayout.widget.CoordinatorLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    "
  },
  {
    "path": "sample/src/main/res/layout/activity_simple.xml",
    "chars": 219,
    "preview": "<com.github.chrisbanes.photoview.PhotoView\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:id"
  },
  {
    "path": "sample/src/main/res/layout/activity_simple_sample.xml",
    "chars": 1149,
    "preview": "<FrameLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:layout_width=\"match_parent\"\n    "
  },
  {
    "path": "sample/src/main/res/layout/activity_transition.xml",
    "chars": 215,
    "preview": "<androidx.recyclerview.widget.RecyclerView\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:id"
  },
  {
    "path": "sample/src/main/res/layout/activity_transition_to.xml",
    "chars": 343,
    "preview": "<com.github.chrisbanes.photoview.PhotoView xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:id=\"@+"
  },
  {
    "path": "sample/src/main/res/layout/activity_view_pager.xml",
    "chars": 273,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<com.github.chrisbanes.photoview.sample.HackyViewPager\n    xmlns:android=\"http://"
  },
  {
    "path": "sample/src/main/res/layout/item_image.xml",
    "chars": 268,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ImageView\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    and"
  },
  {
    "path": "sample/src/main/res/layout/item_sample.xml",
    "chars": 988,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<FrameLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    x"
  },
  {
    "path": "sample/src/main/res/menu/main_menu.xml",
    "chars": 1555,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<menu xmlns:android=\"http://schemas.android.com/apk/res/android\"\n      xmlns:tool"
  },
  {
    "path": "sample/src/main/res/menu/rotation.xml",
    "chars": 816,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<menu xmlns:android=\"http://schemas.android.com/apk/res/android\">\n\n    <item\n    "
  },
  {
    "path": "sample/src/main/res/values/colors.xml",
    "chars": 186,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <color name=\"green\">#AACE30</color>\n    <color name=\"blue\">#142D3"
  },
  {
    "path": "sample/src/main/res/values/strings.xml",
    "chars": 1048,
    "preview": "<resources>\n\n    <string name=\"app_name\">PhotoView Sample</string>\n    <string name=\"menu_zoom_enable\">Enable Zoom</stri"
  },
  {
    "path": "sample/src/main/res/values/styles.xml",
    "chars": 583,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources xmlns:tools=\"http://schemas.android.com/tools\">\n    <!-- Base applicat"
  },
  {
    "path": "sample/src/main/res/values/transitions.xml",
    "chars": 112,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <string name=\"transition_test\">test</string>\n</resources>"
  },
  {
    "path": "settings.gradle",
    "chars": 37,
    "preview": "include 'photoview'\ninclude 'sample'\n"
  }
]

// ... and 1 more files (download for full content)

About this extraction

This page contains the full source code of the Baseflow/PhotoView GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 66 files (123.5 KB), approximately 29.6k tokens, and a symbol index with 206 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!