├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── android-artifacts.gradle
├── bintray-publish.gradle
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── yqritc
│ │ └── scalableimageview
│ │ ├── PivotPoint.java
│ │ ├── ScalableImageView.java
│ │ ├── ScalableType.java
│ │ ├── ScaleManager.java
│ │ └── Size.java
│ └── res
│ └── values
│ └── attrs.xml
├── sample
├── build.gradle
├── sample.gif
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── yqritc
│ │ └── scalableimageview
│ │ └── sample
│ │ ├── MainActivity.java
│ │ ├── SampleActivity.java
│ │ └── SampleAdapter.java
│ └── res
│ ├── drawable-xxhdpi
│ ├── landscape_sample.jpg
│ └── portrait_sample.jpg
│ ├── layout
│ ├── activity_main.xml
│ ├── activity_sample.xml
│ └── layout_sample_item.xml
│ ├── menu
│ ├── menu_main.xml
│ └── menu_sample.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── strings.xml
│ └── styles.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | Thumbs.db
3 |
4 | # gradle files
5 | .gradle
6 |
7 | # Intellij project files
8 | .idea
9 | *.iml
10 |
11 | # generated files
12 | bin/
13 | gen/
14 | obj/
15 | apk/
16 | target/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android-ScalableImageView
2 | [](https://www.apache.org/licenses/LICENSE-2.0)
3 | [](https://bintray.com/yqritc/maven/android-scalableimageview/_latestVersion)
4 |
5 | *__If you want to the same scale feature for video. [Check out ScalableVideoVIew](https://github.com/yqritc/Android-ScalableVideoView)__*
6 |
7 | Android ImageView having extra scale types.
8 |
9 | 
10 |
11 | # Sample
12 |
13 |
14 | # Release Note
15 |
16 | [Release Note] (https://github.com/yqritc/Android-ScalableImageView/releases)
17 |
18 | # Gradle
19 | ```
20 | repositories {
21 | jcenter()
22 | }
23 |
24 | dependencies {
25 | compile 'com.yqritc:android-scalableimageview:1.0.0'
26 | }
27 | ```
28 |
29 | # Support Scale Types
30 |
31 | | ScaleType | ImageView | ScalableImageView |
32 | |:------------------|:---------:|:-----------------:|
33 | | fitXY |◯|◯|
34 | | fitStart |◯|◯|
35 | | fitCenter |◯|◯|
36 | | fitEnd |◯|◯|
37 | | leftTop |X|◯|
38 | | leftCenter |X|◯|
39 | | leftBottom |X|◯|
40 | | centerTop |X|◯|
41 | | center |◯|◯|
42 | | centerBottom |X|◯|
43 | | rightTop |X|◯|
44 | | rightCenter |X|◯|
45 | | rightBottom |X|◯|
46 | | leftTopCrop |X|◯|
47 | | leftCenterCrop |X|◯|
48 | | leftBottomCrop |X|◯|
49 | | centerTopCrop |X|◯|
50 | | centerCrop |◯|◯|
51 | | centerBottomCrop |X|◯|
52 | | rightTopCrop |X|◯|
53 | | rightCenterCrop |X|◯|
54 | | rightBottomCrop |X|◯|
55 | | startInside |X|◯|
56 | | centerInside |◯|◯|
57 | | endInside |X|◯|
58 |
59 |
60 | # Usage
61 |
62 | ### Set scale type in layout file
63 | ```
64 |
69 | ```
70 | Please refere the following xml for the list of scalableType you can set.
71 | [attrs.xml](https://github.com/yqritc/Android-ScalableImageView/blob/master/library/src/main/res/values/attrs.xml)
72 |
73 | ### Set scale type in source code
74 | ```
75 | @Override
76 | protected void onCreate(Bundle savedInstanceState) {
77 | super.onCreate(savedInstanceState);
78 | setContentView(R.layout.activity_main);
79 |
80 | mImageView = (ScalableImageView) findViewById(R.id.image_view);
81 | findViewById(R.id.btn_update_scale).setOnClickListener(this);
82 | }
83 |
84 | @Override
85 | public void onClick(View v) {
86 | switch (v.getId()) {
87 | case R.id.btn_update_scale:
88 | mImageView.setScalableType(ScalableType.CENTER_TOP_CROP);
89 | mImageView.requestLayout();
90 | break;
91 | default:
92 | break;
93 | }
94 | }
95 | ```
96 |
97 |
98 | # License
99 | ```
100 | Copyright 2015 yqritc
101 |
102 | Licensed under the Apache License, Version 2.0 (the "License");
103 | you may not use this file except in compliance with the License.
104 | You may obtain a copy of the License at
105 |
106 | http://www.apache.org/licenses/LICENSE-2.0
107 |
108 | Unless required by applicable law or agreed to in writing, software
109 | distributed under the License is distributed on an "AS IS" BASIS,
110 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
111 | See the License for the specific language governing permissions and
112 | limitations under the License.
113 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.2.3'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=1.0.0
2 | VERSION_CODE=1
3 | GROUP=com.yqritc
4 | ARTIFACT_ID=android-scalableimageview
5 |
6 | COMPILE_SDK_VERSION=22
7 | BUILD_TOOLS_VERSION=22
8 | TARGET_SDK_VERSION=22
9 | MIN_SDK_VERSION=9
10 |
11 | POM_DESCRIPTION=Android ImageView having the variety of scale types
12 | POM_URL=https://github.com/yqritc/Android-ScalableImageView
13 | POM_SCM_URL=git@github.com:yqritc/Android-ScalableImageView.git
14 | POM_SCM_CONNECTION=scm:git@github.com:yqritc/Android-ScalableImageView.git
15 | POM_SCM_DEV_CONNECTION=scm:git@github.com:yqritc/Android-ScalableImageView.git
16 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
17 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
18 | POM_LICENCE_DIST=repo
19 | POM_DEVELOPER_ID=yqritc
20 | POM_DEVELOPER_NAME=yqritc
21 | POM_DEVELOPER_EMAIL=yqritc@gmail.com
22 | ISSUE_URL=https://github.com/yqritc/Android-ScalableImageView/issues
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yqritc/Android-ScalableImageView/0c302dcfd7250838a266d1a3753bc8d3da803c12/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/android-artifacts.gradle:
--------------------------------------------------------------------------------
1 | task androidJavadocs(type: Javadoc) {
2 | source = android.sourceSets.main.java.srcDirs
3 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
4 | }
5 |
6 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
7 | classifier = 'javadoc'
8 | from androidJavadocs.destinationDir
9 | }
10 |
11 | task androidSourcesJar(type: Jar) {
12 | classifier = 'sources'
13 | from android.sourceSets.main.java.sourceFiles
14 | }
15 |
16 | task androidJar(type: Jar) {
17 | from 'build/intermediates/classes/release'
18 | }
19 |
20 | artifacts {
21 | archives androidSourcesJar
22 | archives androidJavadocsJar
23 | archives androidJar
24 | }
--------------------------------------------------------------------------------
/library/bintray-publish.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven-publish'
2 | apply plugin: 'com.jfrog.bintray'
3 |
4 | publishing {
5 | publications {
6 | mavenJava(MavenPublication) {
7 | groupId GROUP
8 | version VERSION_NAME
9 | artifactId ARTIFACT_ID
10 | // artifact androidJar
11 | artifact "build/outputs/aar/library-release.aar"
12 | artifact androidJavadocsJar
13 | artifact androidSourcesJar
14 | pom.withXml {
15 | Node root = asNode()
16 | root.appendNode('name', ARTIFACT_ID)
17 | root.appendNode('description', POM_DESCRIPTION)
18 | root.appendNode('url', POM_URL)
19 |
20 | def issues = root.appendNode('issueManagement')
21 | issues.appendNode('system', 'github')
22 | issues.appendNode('url', ISSUE_URL)
23 |
24 | def scm = root.appendNode('scm')
25 | scm.appendNode('url', POM_SCM_URL)
26 | scm.appendNode('connection', POM_SCM_CONNECTION)
27 | scm.appendNode('developerConnection', POM_SCM_DEV_CONNECTION)
28 |
29 | def license = root.appendNode('licenses').appendNode('license')
30 | license.appendNode('name', POM_LICENCE_NAME)
31 | license.appendNode('url', POM_LICENCE_URL)
32 | license.appendNode('distribution', POM_LICENCE_DIST)
33 |
34 | def developer = root.appendNode('developers').appendNode('developer')
35 | developer.appendNode('id', POM_DEVELOPER_ID)
36 | developer.appendNode('name', POM_DEVELOPER_NAME)
37 | developer.appendNode('email', POM_DEVELOPER_EMAIL)
38 | }
39 | }
40 | }
41 | }
42 |
43 | def getBintrayUserProperty() {
44 | return hasProperty('bintrayUser') ? bintrayUser : ""
45 | }
46 |
47 | def getBintrayApiKeyProperty() {
48 | return hasProperty('bintrayApiKey') ? bintrayApiKey : ""
49 | }
50 |
51 | bintray {
52 | user = bintrayUserProperty
53 | key = bintrayApiKeyProperty
54 | publications = ['mavenJava']
55 |
56 | dryRun = false
57 | publish = false
58 | pkg {
59 | repo = 'maven'
60 | name = ARTIFACT_ID
61 | licenses = ['Apache-2.0']
62 | labels = ['android']
63 |
64 | version {
65 | name = VERSION_NAME
66 | vcsTag = VERSION_NAME
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion COMPILE_SDK_VERSION as int
5 | buildToolsVersion BUILD_TOOLS_VERSION
6 |
7 | defaultConfig {
8 | minSdkVersion MIN_SDK_VERSION as int
9 | targetSdkVersion TARGET_SDK_VERSION as int
10 | versionCode VERSION_CODE as int
11 | versionName VERSION_NAME
12 | }
13 | }
14 |
15 | dependencies {
16 | compile fileTree(dir: 'libs', include: ['*.jar'])
17 | compile 'com.android.support:appcompat-v7:22.2.0'
18 | }
19 |
20 | android.libraryVariants.all { variant ->
21 | if (variant.buildType.isDebuggable()) {
22 | return; // Skip debug builds.
23 | }
24 | task("javadoc${variant.name.capitalize()}", type: Javadoc) {
25 | description "Generates Javadoc for $variant.name."
26 | source = variant.javaCompile.source
27 | ext.androidJar = System.getenv("ANDROID_HOME") +
28 | "/platforms/${android.compileSdkVersion}/android.jar"
29 | classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
30 | }
31 |
32 | task("bundleJavadoc${variant.name.capitalize()}", type: Jar) {
33 | description "Bundles Javadoc into zip for $variant.name."
34 | classifier = "javadoc"
35 | from tasks["javadoc${variant.name.capitalize()}"]
36 | }
37 | }
38 |
39 | apply from: 'android-artifacts.gradle'
40 | apply from: 'bintray-publish.gradle'
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/library/src/main/java/com/yqritc/scalableimageview/PivotPoint.java:
--------------------------------------------------------------------------------
1 | package com.yqritc.scalableimageview;
2 |
3 | /**
4 | * Created by yqritc on 2015/06/14.
5 | */
6 | public enum PivotPoint {
7 | LEFT_TOP,
8 | LEFT_CENTER,
9 | LEFT_BOTTOM,
10 | CENTER_TOP,
11 | CENTER,
12 | CENTER_BOTTOM,
13 | RIGHT_TOP,
14 | RIGHT_CENTER,
15 | RIGHT_BOTTOM
16 | }
17 |
--------------------------------------------------------------------------------
/library/src/main/java/com/yqritc/scalableimageview/ScalableImageView.java:
--------------------------------------------------------------------------------
1 | package com.yqritc.scalableimageview;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Matrix;
6 | import android.graphics.drawable.Drawable;
7 | import android.util.AttributeSet;
8 | import android.widget.ImageView;
9 |
10 | /**
11 | * Created by yqritc on 2015/06/18.
12 | */
13 | public class ScalableImageView extends ImageView {
14 |
15 | protected ScalableType mScalableType = ScalableType.NONE;
16 |
17 | public ScalableImageView(Context context) {
18 | this(context, null);
19 | }
20 |
21 | public ScalableImageView(Context context, AttributeSet attrs) {
22 | this(context, attrs, 0);
23 | }
24 |
25 | public ScalableImageView(Context context, AttributeSet attrs, int defStyleAttr) {
26 | super(context, attrs, defStyleAttr);
27 |
28 | if (attrs == null) {
29 | return;
30 | }
31 |
32 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.scaleStyle, 0, 0);
33 | if (a == null) {
34 | return;
35 | }
36 |
37 | int scaleType = a.getInt(R.styleable.scaleStyle_scalableType, ScalableType.NONE.ordinal());
38 | a.recycle();
39 | mScalableType = ScalableType.values()[scaleType];
40 | setScaleType(ScaleType.MATRIX);
41 | }
42 |
43 | @Override
44 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
45 | super.onLayout(changed, left, top, right, bottom);
46 | scaleImageSize();
47 | }
48 |
49 | public void setScalableType(ScalableType scalableType) {
50 | setScaleType(ScaleType.MATRIX);
51 | mScalableType = scalableType;
52 | }
53 |
54 | private void scaleImageSize() {
55 | Drawable drawable = getDrawable();
56 | if (drawable == null) {
57 | return;
58 | }
59 |
60 | int imageWidth = drawable.getIntrinsicWidth();
61 | int imageHeight = drawable.getIntrinsicHeight();
62 | if (imageWidth <= 0 || imageHeight <= 0) {
63 | return;
64 | }
65 |
66 | int viewWidth = getWidth() - getPaddingLeft() - getPaddingRight();
67 | int viewHeight = getHeight() - getPaddingTop() - getPaddingBottom();
68 | if (viewWidth <= 0 || viewHeight <= 0) {
69 | return;
70 | }
71 |
72 | Size viewSize = new Size(viewWidth, viewHeight);
73 | Size imageSize = new Size(imageWidth, imageHeight);
74 |
75 | ScaleManager scaleManager = new ScaleManager(viewSize, imageSize);
76 | Matrix matrix = scaleManager.getScaleMatrix(mScalableType);
77 | if (matrix != null) {
78 | setImageMatrix(matrix);
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/library/src/main/java/com/yqritc/scalableimageview/ScalableType.java:
--------------------------------------------------------------------------------
1 | package com.yqritc.scalableimageview;
2 |
3 | /**
4 | * Created by yqritc on 2015/06/12.
5 | */
6 | public enum ScalableType {
7 | NONE,
8 |
9 | FIT_XY,
10 | FIT_START,
11 | FIT_CENTER,
12 | FIT_END,
13 |
14 | LEFT_TOP,
15 | LEFT_CENTER,
16 | LEFT_BOTTOM,
17 | CENTER_TOP,
18 | CENTER,
19 | CENTER_BOTTOM,
20 | RIGHT_TOP,
21 | RIGHT_CENTER,
22 | RIGHT_BOTTOM,
23 |
24 | LEFT_TOP_CROP,
25 | LEFT_CENTER_CROP,
26 | LEFT_BOTTOM_CROP,
27 | CENTER_TOP_CROP,
28 | CENTER_CROP,
29 | CENTER_BOTTOM_CROP,
30 | RIGHT_TOP_CROP,
31 | RIGHT_CENTER_CROP,
32 | RIGHT_BOTTOM_CROP,
33 |
34 | START_INSIDE,
35 | CENTER_INSIDE,
36 | END_INSIDE
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/com/yqritc/scalableimageview/ScaleManager.java:
--------------------------------------------------------------------------------
1 | package com.yqritc.scalableimageview;
2 |
3 | import android.graphics.Matrix;
4 | import android.support.annotation.NonNull;
5 |
6 | /**
7 | * Created by yqritc on 2015/06/12.
8 | */
9 | public class ScaleManager {
10 |
11 | private Size mViewSize;
12 | private Size mImageSize;
13 |
14 | public ScaleManager(Size viewSize, Size imageSize) {
15 | mViewSize = viewSize;
16 | mImageSize = imageSize;
17 | }
18 |
19 | public Matrix getScaleMatrix(ScalableType scale) {
20 | switch (scale) {
21 | case NONE:
22 | return getNoScale();
23 |
24 | case FIT_XY:
25 | return fitXY();
26 | case FIT_CENTER:
27 | return fitCenter();
28 | case FIT_START:
29 | return fitStart();
30 | case FIT_END:
31 | return fitEnd();
32 |
33 | case LEFT_TOP:
34 | return getOriginalScale(PivotPoint.LEFT_TOP);
35 | case LEFT_CENTER:
36 | return getOriginalScale(PivotPoint.LEFT_CENTER);
37 | case LEFT_BOTTOM:
38 | return getOriginalScale(PivotPoint.LEFT_BOTTOM);
39 | case CENTER_TOP:
40 | return getOriginalScale(PivotPoint.CENTER_TOP);
41 | case CENTER:
42 | return getOriginalScale(PivotPoint.CENTER);
43 | case CENTER_BOTTOM:
44 | return getOriginalScale(PivotPoint.CENTER_BOTTOM);
45 | case RIGHT_TOP:
46 | return getOriginalScale(PivotPoint.RIGHT_TOP);
47 | case RIGHT_CENTER:
48 | return getOriginalScale(PivotPoint.RIGHT_CENTER);
49 | case RIGHT_BOTTOM:
50 | return getOriginalScale(PivotPoint.RIGHT_BOTTOM);
51 |
52 | case LEFT_TOP_CROP:
53 | return getCropScale(PivotPoint.LEFT_TOP);
54 | case LEFT_CENTER_CROP:
55 | return getCropScale(PivotPoint.LEFT_CENTER);
56 | case LEFT_BOTTOM_CROP:
57 | return getCropScale(PivotPoint.LEFT_BOTTOM);
58 | case CENTER_TOP_CROP:
59 | return getCropScale(PivotPoint.CENTER_TOP);
60 | case CENTER_CROP:
61 | return getCropScale(PivotPoint.CENTER);
62 | case CENTER_BOTTOM_CROP:
63 | return getCropScale(PivotPoint.CENTER_BOTTOM);
64 | case RIGHT_TOP_CROP:
65 | return getCropScale(PivotPoint.RIGHT_TOP);
66 | case RIGHT_CENTER_CROP:
67 | return getCropScale(PivotPoint.RIGHT_CENTER);
68 | case RIGHT_BOTTOM_CROP:
69 | return getCropScale(PivotPoint.RIGHT_BOTTOM);
70 |
71 | case START_INSIDE:
72 | return startInside();
73 | case CENTER_INSIDE:
74 | return centerInside();
75 | case END_INSIDE:
76 | return endInside();
77 |
78 | default:
79 | return null;
80 | }
81 | }
82 |
83 | private Matrix getNoScale() {
84 | Matrix matrix = new Matrix();
85 | matrix.postScale(1f, 1f);
86 | return matrix;
87 | }
88 |
89 | private Matrix fitXY() {
90 | Matrix matrix = new Matrix();
91 | float sx = (float) mViewSize.getWidth() / mImageSize.getWidth();
92 | float sy = (float) mViewSize.getHeight() / mImageSize.getHeight();
93 | matrix.postScale(sx, sy);
94 | return matrix;
95 | }
96 |
97 | private Matrix fitStart() {
98 | return getFitScale(PivotPoint.LEFT_TOP);
99 | }
100 |
101 | private Matrix fitCenter() {
102 | return getFitScale(PivotPoint.CENTER);
103 | }
104 |
105 | private Matrix fitEnd() {
106 | return getFitScale(PivotPoint.RIGHT_BOTTOM);
107 | }
108 |
109 | private Matrix getFitScale(PivotPoint pivotPoint) {
110 | Matrix matrix = new Matrix();
111 | float sx = (float) mViewSize.getWidth() / mImageSize.getWidth();
112 | float sy = (float) mViewSize.getHeight() / mImageSize.getHeight();
113 | float minScale = Math.min(sx, sy);
114 | matrix.postScale(minScale, minScale);
115 |
116 | if (sx == minScale) {
117 | postTranslateY(matrix, minScale, pivotPoint);
118 | } else {
119 | postTranslateX(matrix, minScale, pivotPoint);
120 | }
121 | return matrix;
122 | }
123 |
124 | private Matrix getOriginalScale(PivotPoint pivotPoint) {
125 | Matrix matrix = new Matrix();
126 | matrix.postScale(1f, 1f);
127 | postTranslate(matrix, pivotPoint);
128 | return matrix;
129 | }
130 |
131 | private Matrix getCropScale(PivotPoint pivotPoint) {
132 | Matrix matrix = new Matrix();
133 | float sx = (float) mViewSize.getWidth() / mImageSize.getWidth();
134 | float sy = (float) mViewSize.getHeight() / mImageSize.getHeight();
135 | float maxScale = Math.max(sx, sy);
136 |
137 | matrix.postScale(maxScale, maxScale);
138 | if (sx == maxScale) {
139 | postTranslateY(matrix, maxScale, pivotPoint);
140 | } else {
141 | postTranslateX(matrix, maxScale, pivotPoint);
142 | }
143 | return matrix;
144 | }
145 |
146 | private Matrix startInside() {
147 | if (mImageSize.getHeight() <= mViewSize.getWidth()
148 | && mImageSize.getHeight() <= mViewSize.getHeight()) {
149 | // video is smaller than view size
150 | return getOriginalScale(PivotPoint.LEFT_TOP);
151 | } else {
152 | // either of width or height of the video is larger than view size
153 | return fitStart();
154 | }
155 | }
156 |
157 | private Matrix centerInside() {
158 | if (mImageSize.getHeight() <= mViewSize.getWidth()
159 | && mImageSize.getHeight() <= mViewSize.getHeight()) {
160 | // video is smaller than view size
161 | return getOriginalScale(PivotPoint.CENTER);
162 | } else {
163 | // either of width or height of the video is larger than view size
164 | return fitCenter();
165 | }
166 | }
167 |
168 | private Matrix endInside() {
169 | if (mImageSize.getHeight() <= mViewSize.getWidth()
170 | && mImageSize.getHeight() <= mViewSize.getHeight()) {
171 | // video is smaller than view size
172 | return getOriginalScale(PivotPoint.RIGHT_BOTTOM);
173 | } else {
174 | // either of width or height of the video is larger than view size
175 | return fitEnd();
176 | }
177 | }
178 |
179 | private void postTranslate(@NonNull Matrix matrix, PivotPoint pivotPoint) {
180 | float translateX = 0f;
181 | float translateY = 0f;
182 | switch (pivotPoint) {
183 | case LEFT_TOP:
184 | break;
185 | case LEFT_CENTER:
186 | translateY = (mImageSize.getHeight() - mViewSize.getHeight()) / 2f;
187 | break;
188 | case LEFT_BOTTOM:
189 | translateY = mImageSize.getHeight() - mViewSize.getHeight();
190 | break;
191 | case CENTER_TOP:
192 | translateX = (mImageSize.getWidth() - mViewSize.getWidth()) / 2f;
193 | break;
194 | case CENTER:
195 | translateX = (mImageSize.getWidth() - mViewSize.getWidth()) / 2f;
196 | translateY = (mImageSize.getHeight() - mViewSize.getHeight()) / 2f;
197 | break;
198 | case CENTER_BOTTOM:
199 | translateX = (mImageSize.getWidth() - mViewSize.getWidth()) / 2f;
200 | translateY = mImageSize.getHeight() - mViewSize.getHeight();
201 | break;
202 | case RIGHT_TOP:
203 | translateX = mImageSize.getWidth() - mViewSize.getWidth();
204 | break;
205 | case RIGHT_CENTER:
206 | translateX = mImageSize.getWidth() - mViewSize.getWidth();
207 | translateY = (mImageSize.getHeight() - mViewSize.getHeight()) / 2f;
208 | break;
209 | case RIGHT_BOTTOM:
210 | translateX = mImageSize.getWidth() - mViewSize.getWidth();
211 | translateY = mImageSize.getHeight() - mViewSize.getHeight();
212 | break;
213 | }
214 |
215 | matrix.postTranslate(-translateX, -translateY);
216 | }
217 |
218 | private void postTranslateX(Matrix matrix, float scale, PivotPoint pivotPoint) {
219 | float translate;
220 | switch (pivotPoint) {
221 | case CENTER_TOP:
222 | case CENTER:
223 | case CENTER_BOTTOM:
224 | translate = (mImageSize.getWidth() * scale - mViewSize.getWidth()) / 2f;
225 | matrix.postTranslate(-translate, 0);
226 | break;
227 | case RIGHT_TOP:
228 | case RIGHT_CENTER:
229 | case RIGHT_BOTTOM:
230 | translate = mImageSize.getWidth() * scale - mViewSize.getWidth();
231 | matrix.postTranslate(-translate, 0);
232 | break;
233 | case LEFT_TOP:
234 | case LEFT_CENTER:
235 | case LEFT_BOTTOM:
236 | default:
237 | break;
238 | }
239 | }
240 |
241 | private void postTranslateY(Matrix matrix, float scale, PivotPoint pivotPoint) {
242 | float translate;
243 | switch (pivotPoint) {
244 | case LEFT_CENTER:
245 | case CENTER:
246 | case RIGHT_CENTER:
247 | translate = (mImageSize.getHeight() * scale - mViewSize.getHeight()) / 2f;
248 | matrix.postTranslate(0, -translate);
249 | break;
250 | case LEFT_BOTTOM:
251 | case CENTER_BOTTOM:
252 | case RIGHT_BOTTOM:
253 | translate = mImageSize.getHeight() * scale - mViewSize.getHeight();
254 | matrix.postTranslate(0, -translate);
255 | break;
256 | case LEFT_TOP:
257 | case CENTER_TOP:
258 | case RIGHT_TOP:
259 | default:
260 | break;
261 | }
262 | }
263 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/yqritc/scalableimageview/Size.java:
--------------------------------------------------------------------------------
1 | package com.yqritc.scalableimageview;
2 |
3 | /**
4 | * Created by yqritc on 2015/06/12.
5 | */
6 | public class Size {
7 |
8 | private int mWidth;
9 | private int mHeight;
10 |
11 | public Size(int width, int height) {
12 | mWidth = width;
13 | mHeight = height;
14 | }
15 |
16 | public int getWidth() {
17 | return mWidth;
18 | }
19 |
20 | public int getHeight() {
21 | return mHeight;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion COMPILE_SDK_VERSION as int
5 | buildToolsVersion BUILD_TOOLS_VERSION
6 |
7 | defaultConfig {
8 | applicationId "com.yqritc.scalableimageview.sample"
9 | minSdkVersion MIN_SDK_VERSION as int
10 | targetSdkVersion TARGET_SDK_VERSION as int
11 | versionCode VERSION_CODE as int
12 | versionName VERSION_NAME
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile project(':library')
24 | // compile 'com.yqritc:android-scalableimageview:1.0.0'
25 | compile 'com.android.support:appcompat-v7:22.2.0'
26 | compile 'com.android.support:recyclerview-v7:22.2.0'
27 | }
28 |
--------------------------------------------------------------------------------
/sample/sample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yqritc/Android-ScalableImageView/0c302dcfd7250838a266d1a3753bc8d3da803c12/sample/sample.gif
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yqritc/scalableimageview/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.yqritc.scalableimageview.sample;
2 |
3 | import com.yqritc.scalableimageview.ScalableImageView;
4 | import com.yqritc.scalableimageview.ScalableType;
5 |
6 | import android.os.Bundle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.Menu;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 |
12 |
13 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
14 |
15 | private ScalableImageView mImageView;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 |
22 | mImageView = (ScalableImageView) findViewById(R.id.image_view);
23 | findViewById(R.id.btn_next).setOnClickListener(this);
24 | }
25 |
26 | @Override
27 | protected void onDestroy() {
28 | super.onDestroy();
29 | }
30 |
31 | @Override
32 | public boolean onCreateOptionsMenu(Menu menu) {
33 | getMenuInflater().inflate(R.menu.menu_main, menu);
34 | return true;
35 | }
36 |
37 | @Override
38 | public boolean onOptionsItemSelected(MenuItem item) {
39 | ScalableType scalableType;
40 | switch (item.getItemId()) {
41 | case R.id.scale_none:
42 | scalableType = ScalableType.NONE;
43 | break;
44 |
45 | case R.id.scale_fit_xy:
46 | scalableType = ScalableType.FIT_XY;
47 | break;
48 | case R.id.scale_fit_start:
49 | scalableType = ScalableType.FIT_START;
50 | break;
51 | case R.id.scale_fit_center:
52 | scalableType = ScalableType.FIT_CENTER;
53 | break;
54 | case R.id.scale_fit_end:
55 | scalableType = ScalableType.FIT_END;
56 | break;
57 |
58 | case R.id.scale_left_top:
59 | scalableType = ScalableType.LEFT_TOP;
60 | break;
61 | case R.id.scale_left_center:
62 | scalableType = ScalableType.LEFT_CENTER;
63 | break;
64 | case R.id.scale_left_bottom:
65 | scalableType = ScalableType.LEFT_BOTTOM;
66 | break;
67 | case R.id.scale_center_top:
68 | scalableType = ScalableType.CENTER_TOP;
69 | break;
70 | case R.id.scale_center:
71 | scalableType = ScalableType.CENTER;
72 | break;
73 | case R.id.scale_center_bottom:
74 | scalableType = ScalableType.CENTER_BOTTOM;
75 | break;
76 | case R.id.scale_right_top:
77 | scalableType = ScalableType.RIGHT_TOP;
78 | break;
79 | case R.id.scale_right_center:
80 | scalableType = ScalableType.RIGHT_CENTER;
81 | break;
82 | case R.id.scale_right_bottom:
83 | scalableType = ScalableType.RIGHT_BOTTOM;
84 | break;
85 |
86 | case R.id.scale_left_top_crop:
87 | scalableType = ScalableType.LEFT_TOP_CROP;
88 | break;
89 | case R.id.scale_left_center_crop:
90 | scalableType = ScalableType.LEFT_CENTER_CROP;
91 | break;
92 | case R.id.scale_left_bottom_crop:
93 | scalableType = ScalableType.LEFT_BOTTOM_CROP;
94 | break;
95 | case R.id.scale_center_top_crop:
96 | scalableType = ScalableType.CENTER_TOP_CROP;
97 | break;
98 | case R.id.scale_center_crop:
99 | scalableType = ScalableType.CENTER_CROP;
100 | break;
101 | case R.id.scale_center_bottom_crop:
102 | scalableType = ScalableType.CENTER_BOTTOM_CROP;
103 | break;
104 | case R.id.scale_right_top_crop:
105 | scalableType = ScalableType.RIGHT_TOP_CROP;
106 | break;
107 | case R.id.scale_right_center_crop:
108 | scalableType = ScalableType.RIGHT_CENTER_CROP;
109 | break;
110 | case R.id.scale_right_bottom_crop:
111 | scalableType = ScalableType.RIGHT_BOTTOM_CROP;
112 | break;
113 |
114 | case R.id.scale_start_inside:
115 | scalableType = ScalableType.START_INSIDE;
116 | break;
117 | case R.id.scale_center_inside:
118 | scalableType = ScalableType.CENTER_INSIDE;
119 | break;
120 | case R.id.scale_end_inside:
121 | scalableType = ScalableType.END_INSIDE;
122 | break;
123 |
124 | default:
125 | return super.onOptionsItemSelected(item);
126 |
127 | }
128 |
129 | mImageView.setScalableType(scalableType);
130 | mImageView.requestLayout();
131 | return true;
132 | }
133 |
134 | @Override
135 | public void onClick(View v) {
136 | switch (v.getId()) {
137 | case R.id.btn_next:
138 | SampleActivity.startActivity(this);
139 | break;
140 | default:
141 | break;
142 | }
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yqritc/scalableimageview/sample/SampleActivity.java:
--------------------------------------------------------------------------------
1 | package com.yqritc.scalableimageview.sample;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.LinearLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 |
12 | /**
13 | * Created by yqritc on 2015/06/18.
14 | */
15 | public class SampleActivity extends AppCompatActivity {
16 |
17 | private RecyclerView mRecyclerView;
18 | private SampleAdapter mSampleAdapter;
19 |
20 | public static void startActivity(Context context) {
21 | Intent intent = new Intent(context, SampleActivity.class);
22 | context.startActivity(intent);
23 | }
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_sample);
29 |
30 | mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);
31 | mSampleAdapter = new SampleAdapter(this);
32 | mRecyclerView.setAdapter(mSampleAdapter);
33 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
34 | }
35 |
36 | @Override
37 | public boolean onCreateOptionsMenu(Menu menu) {
38 | getMenuInflater().inflate(R.menu.menu_sample, menu);
39 | return true;
40 | }
41 |
42 | @Override
43 | public boolean onOptionsItemSelected(MenuItem item) {
44 | switch (item.getItemId()) {
45 | case R.id.sample_landscape:
46 | mSampleAdapter.setImageResId(R.drawable.landscape_sample);
47 | break;
48 | case R.id.sample_portrait:
49 | mSampleAdapter.setImageResId(R.drawable.portrait_sample);
50 | break;
51 | default:
52 | break;
53 | }
54 | return true;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/yqritc/scalableimageview/sample/SampleAdapter.java:
--------------------------------------------------------------------------------
1 | package com.yqritc.scalableimageview.sample;
2 |
3 | import com.yqritc.scalableimageview.ScalableImageView;
4 | import com.yqritc.scalableimageview.ScalableType;
5 |
6 | import android.content.Context;
7 | import android.support.annotation.DrawableRes;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.TextView;
13 |
14 | /**
15 | * Created by yqritc on 2015/06/14.
16 | */
17 | public class SampleAdapter extends RecyclerView.Adapter {
18 |
19 | @DrawableRes
20 | private int mImageResId;
21 | private LayoutInflater mLayoutInflater;
22 |
23 | public SampleAdapter(Context context) {
24 | super();
25 | mImageResId = R.drawable.landscape_sample;
26 | mLayoutInflater = LayoutInflater.from(context);
27 | }
28 |
29 | @Override
30 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
31 | View view = mLayoutInflater.inflate(R.layout.layout_sample_item, parent, false);
32 | return new ViewHolder(view);
33 | }
34 |
35 | @Override
36 | public void onBindViewHolder(ViewHolder holder, int position) {
37 | Context context = holder.itemView.getContext();
38 |
39 | ScalableType scalableType = ScalableType.values()[position];
40 | holder.mTextView.setText(context.getString(R.string.sample_scale_title, position,
41 | scalableType.toString()));
42 |
43 | holder.mImageView.setImageResource(mImageResId);
44 | holder.mImageView.setScalableType(scalableType);
45 | holder.mImageView.requestLayout();
46 | }
47 |
48 | @Override
49 | public int getItemCount() {
50 | return ScalableType.values().length;
51 | }
52 |
53 | public void setImageResId(@DrawableRes int id) {
54 | mImageResId = id;
55 | notifyDataSetChanged();
56 | }
57 |
58 | static class ViewHolder extends RecyclerView.ViewHolder {
59 |
60 | TextView mTextView;
61 | ScalableImageView mImageView;
62 |
63 | public ViewHolder(View view) {
64 | super(view);
65 | mTextView = (TextView) view.findViewById(R.id.title_text);
66 | mImageView = (ScalableImageView) view.findViewById(R.id.image_view);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/landscape_sample.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yqritc/Android-ScalableImageView/0c302dcfd7250838a266d1a3753bc8d3da803c12/sample/src/main/res/drawable-xxhdpi/landscape_sample.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/portrait_sample.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yqritc/Android-ScalableImageView/0c302dcfd7250838a266d1a3753bc8d3da803c12/sample/src/main/res/drawable-xxhdpi/portrait_sample.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
12 |
19 |
20 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_sample.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/layout_sample_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
22 |
23 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
110 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yqritc/Android-ScalableImageView/0c302dcfd7250838a266d1a3753bc8d3da803c12/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yqritc/Android-ScalableImageView/0c302dcfd7250838a266d1a3753bc8d3da803c12/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yqritc/Android-ScalableImageView/0c302dcfd7250838a266d1a3753bc8d3da803c12/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yqritc/Android-ScalableImageView/0c302dcfd7250838a266d1a3753bc8d3da803c12/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ScalableImageView
3 |
4 | None
5 |
6 | FitXY
7 | FitStart
8 | FitCenter
9 | FitEnd
10 |
11 | LeftTop
12 | LeftCenter
13 | LeftBottom
14 | CenterTop
15 | Center
16 | CenterBottom
17 | RightTop
18 | RightCenter
19 | RightBottom
20 |
21 | LeftTopCrop
22 | LeftCenterCrop
23 | LeftBottomCrop
24 | CenterTopCrop
25 | CenterCrop
26 | CenterBottomCrop
27 | RightTopCrop
28 | RightCenterCrop
29 | RightBottomCrop
30 |
31 | StartInside
32 | CenterInside
33 | EndInside
34 |
35 | View images as list
36 |
37 | Landscape Image
38 | Portrait Image
39 | %1$d: %2$s
40 |
41 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':library'
2 |
--------------------------------------------------------------------------------