Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Baseflow/PhotoView
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: vectorform/PhotoView
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 5 commits
  • 9 files changed
  • 1 contributor

Commits on Jan 3, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d47daac View commit details
  2. Copy the full SHA
    5b35512 View commit details
  3. Copy the full SHA
    9e4d884 View commit details

Commits on Feb 21, 2020

  1. Copy the full SHA
    3383004 View commit details

Commits on Feb 24, 2020

  1. Copy the full SHA
    f57e329 View commit details
89 changes: 86 additions & 3 deletions photoview/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,102 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven-publish'

android {
compileSdkVersion rootProject.ext.sdkVersion

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

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

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.javaCompile.classpath
}
}
exclude '**/R.html', '**/R.*.html', '**/index.html', '**/*.kt'
}

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

task androidSourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier.set('sources')
}

project.afterEvaluate {
publishing {
publications {
aar(MavenPublication) {
groupId 'com.vectorform.vfandroid'
artifactId 'photoview'
version '1.0.5'

artifact bundleReleaseAar
artifact androidJavadocsJar
artifact androidSourcesJar

pom.withXml {
final dependenciesNode = asNode().appendNode('dependencies')

ext.addDependency = { Dependency dep, String scope ->
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
return // ignore invalid dependencies

final dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)
dependencyNode.appendNode('scope', scope)

if (!dep.transitive) {
// If this dependency is transitive, we should force exclude all its dependencies them from the POM
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('groupId', '*')
exclusionNode.appendNode('artifactId', '*')
} else if (!dep.properties.excludeRules.empty) {
// Otherwise add specified exclude rules
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
dep.properties.excludeRules.each { ExcludeRule rule ->
exclusionNode.appendNode('groupId', rule.group ?: '*')
exclusionNode.appendNode('artifactId', rule.module ?: '*')
}
}
}

// List all "compile" dependencies (for old Gradle)
configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }
// List all "api" dependencies (for new Gradle) as "compile" dependencies
configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") }
// List all "implementation" dependencies (for new Gradle) as "runtime" dependencies
configurations.implementation.getDependencies().each { dep -> addDependency(dep, "runtime") }
}
}
}

repositories {
maven {
url "https://core.vectorform.com/repository/maven-releases-vf/"
credentials {
username VF_MAVEN_USERNAME
password VF_MAVEN_PASSWORD
}
}
}
}
}

apply from: 'https://raw.githubusercontent.com/Commit451/gradle-android-javadocs/1.0.0/gradle-android-javadocs.gradle'
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.github.chrisbanes.photoview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

public class CircleTesterView extends View {

private Path path;
private Paint paint;

public RectF boundingRect = new RectF(165f, 627f, 915f, 1377f);

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public CircleTesterView(Context context) {
this(context, null, 0, 0);
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public CircleTesterView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0, 0);
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public CircleTesterView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public CircleTesterView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);

path = new Path();


paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
paint.setStrokeWidth(1f * getResources().getDisplayMetrics().density);
paint.setColor(0xFFFF0000);

}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);

path.addCircle(getWidth() / 2f, getHeight() / 2f, 250 * getResources().getDisplayMetrics().density / 2f, Path.Direction.CW);
path.computeBounds(boundingRect, true);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

canvas.drawPath(path, paint);
}
}
Original file line number Diff line number Diff line change
@@ -134,6 +134,15 @@ protected boolean setFrame(int l, int t, int r, int b) {
return changed;
}

public void constraintToRect(RectF rect) {
attacher.setConstraintRect(rect);
setFlingable(false);
}

public void setFlingable(boolean flingable) {
attacher.setFlingable(flingable);
}

public void setRotationTo(float rotationDegree) {
attacher.setRotationTo(rotationDegree);
}
Original file line number Diff line number Diff line change
@@ -92,9 +92,12 @@ public class PhotoViewAttacher implements View.OnTouchListener,
private int mVerticalScrollEdge = VERTICAL_EDGE_BOTH;
private float mBaseRotation;

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

private RectF constraintRect = null;

private OnGestureListener onGestureListener = new OnGestureListener() {
@Override
public void onDrag(float dx, float dy) {
@@ -136,10 +139,12 @@ public void onDrag(float dx, float dy) {

@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);
if (mFlingEnabled) {
mCurrentFlingRunnable = new FlingRunnable(mImageView.getContext());
mCurrentFlingRunnable.fling(getImageViewWidth(mImageView),
getImageViewHeight(mImageView), (int) velocityX, (int) velocityY);
mImageView.post(mCurrentFlingRunnable);
}
}

@Override
@@ -289,6 +294,14 @@ public void setBaseRotation(final float degrees) {
checkAndDisplayMatrix();
}

public void setConstraintRect(RectF rect) {
constraintRect = rect;
}

public void setFlingable(boolean flingable) {
mFlingEnabled = flingable;
}

public void setRotationTo(float degrees) {
mSuppMatrix.setRotate(degrees % 360);
checkAndDisplayMatrix();
@@ -493,6 +506,30 @@ public void update() {
if (mZoomEnabled) {
// Update the base matrix using the current drawable
updateBaseMatrix(mImageView.getDrawable());

if (constraintRect != null) {
Drawable image = mImageView.getDrawable();
if (image != null) {

float height = image.getIntrinsicHeight();
float width = image.getIntrinsicWidth();
final float scale = Math.max(constraintRect.width() / width, constraintRect.height() / height);

setScaleLevels(scale, scale * 3f, scale * 6f);
mImageView.post(new Runnable() {
@Override
public void run() {
float[] values = new float[9];
mBaseMatrix.getValues(values);
values[Matrix.MSCALE_X] = 1f;
values[Matrix.MSCALE_Y] = 1f;
mBaseMatrix.setValues(values);

setScale(scale, false);
}
});
}
}
} else {
// Reset the Matrix...
resetMatrix();
@@ -653,53 +690,70 @@ private boolean checkMatrixBounds() {
}
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;

if (constraintRect == null) {
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;
}
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;
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;
}
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;
// Finally actually translate the matrix

} else {
mHorizontalScrollEdge = HORIZONTAL_EDGE_NONE;
if (constraintRect.left < rect.left)
deltaX += constraintRect.left - rect.left;

if (constraintRect.right > rect.right)
deltaX += constraintRect.right - rect.right;

if (constraintRect.top < rect.top)
deltaY += constraintRect.top - rect.top;

if (constraintRect.bottom > rect.bottom)
deltaY += constraintRect.bottom - rect.bottom;
}
// Finally actually translate the matrix

mSuppMatrix.postTranslate(deltaX, deltaY);
return true;
}
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ android {

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