Skip to content

Commit

Permalink
1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyJayce committed Dec 8, 2016
1 parent 9566be6 commit ae64d11
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

63 changes: 60 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Android 加载大图 可以高清显示10000*10000像素的图片
普通图片也可以用它展示
#Gradle

compile 'com.shizhefei:LargeImageView:1.0.3'
compile 'com.shizhefei:LargeImageView:1.0.4'

Download Demo [apk](raw/LargeImage.apk)
Download Demo [apk](raw/LargeImage.apk)

#效果

![image](raw/demo.gif)
![image](raw/demo.gif)


#使用方法
Expand All @@ -36,6 +36,63 @@ Download Demo [apk](raw/LargeImage.apk)
largeImageView.setImage(drawable);
largeImageView.setImage(bitmap);

支持的事件

largeImageView.setOnClickListener(onClickListener);
largeImageView.setOnLongClickListener(onLongClickListener);
设置是否可以缩放

largeImageView.setEnabled(true);

Hook临界值(不设置的话会使用默认的计算缩放最小倍数和最大倍数)


/**
* Hook临界值
*/
public interface CriticalScaleValueHook {

/**
* 返回最小的缩放倍数
* scale为1的话表示,显示的图片和View一样宽
*
* @param largeImageView
* @param imageWidth
* @param imageHeight
* @param suggestMinScale 默认建议的最小的缩放倍数
* @return
*/
float getMinScale(LargeImageView largeImageView, int imageWidth, int imageHeight, float suggestMinScale);

/**
* 返回最大的缩放倍数
* scale为1的话表示,显示的图片和View一样宽
*
* @param largeImageView
* @param imageWidth
* @param imageHeight
* @param suggestMaxScale 默认建议的最大的缩放倍数
* @return
*/
float getMaxScale(LargeImageView largeImageView, int imageWidth, int imageHeight, float suggestMaxScale);

}

例如

largeImageView.setCriticalScaleValueHook(new LargeImageView.CriticalScaleValueHook() {
@Override
public float getMinScale(LargeImageView largeImageView, int imageWidth, int imageHeight, float suggestMinScale) {
return 1;
}

@Override
public float getMaxScale(LargeImageView largeImageView, int imageWidth, int imageHeight, float suggestMaxScale) {
return 4;
}
});


加载网络的图片,先下载本地,再通过加载图片的文件
比如glide加载图片,具体代码查看demo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.ToggleButton;

import com.shizhefei.view.largeimage.LargeImageView;
import com.shizhefei.view.largeimage.factory.InputStreamBitmapDecoderFactory;
Expand All @@ -14,13 +18,31 @@

public class SingleDemoActivity extends FragmentActivity {
private LargeImageView largeImageView;
private ToggleButton toggleButton;

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

largeImageView = (LargeImageView) findViewById(imageView);
toggleButton = (ToggleButton) findViewById(R.id.toggleButton);

toggleButton.setOnCheckedChangeListener(onCheckedChangeListener);
largeImageView.setOnClickListener(onClickListener);
largeImageView.setOnLongClickListener(onLongClickListener);
largeImageView.setCriticalScaleValueHook(new LargeImageView.CriticalScaleValueHook() {
@Override
public float getMinScale(LargeImageView largeImageView, int imageWidth, int imageHeight, float suggestMinScale) {
return 1;
}

@Override
public float getMaxScale(LargeImageView largeImageView, int imageWidth, int imageHeight, float suggestMaxScale) {
return 4;
}
});

// largeImageView.setImage(R.drawable.mvc);

try {
Expand All @@ -30,4 +52,41 @@ protected void onCreate(Bundle savedInstanceState) {
e.printStackTrace();
}
}

private View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v == largeImageView) {
Toast.makeText(getApplicationContext(), "点击事件", Toast.LENGTH_SHORT).show();
}
}
};
private View.OnLongClickListener onLongClickListener = new View.OnLongClickListener() {

@Override
public boolean onLongClick(View v) {
if (v == largeImageView) {
Toast.makeText(getApplicationContext(), "长按事件", Toast.LENGTH_SHORT).show();
}
return true;
}
};
private CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
largeImageView.setEnabled(!isChecked);
}
};

private LargeImageView.CriticalScaleValueHook criticalScaleValueHook = new LargeImageView.CriticalScaleValueHook() {
@Override
public float getMinScale(LargeImageView largeImageView, int imageWidth, int imageHeight, float suggestMinScale) {
return 1;
}

@Override
public float getMaxScale(LargeImageView largeImageView, int imageWidth, int imageHeight, float suggestMaxScale) {
return 4;
}
};
}
22 changes: 18 additions & 4 deletions app/src/main/res/layout/activity_singledemo.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<com.shizhefei.view.largeimage.LargeImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageView"
android:scrollbars="vertical|horizontal"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:orientation="vertical">

<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:textOff="当前可 缩放和滑动"
android:textOn="当前不可 缩放和滑动" />

<com.shizhefei.view.largeimage.LargeImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical|horizontal" />
</LinearLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.novoda:bintray-release:0.3.4'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 24
versionCode 3
versionName "1.0.3"
versionCode 5
versionName "1.0.4"
}
buildTypes {
release {
Expand All @@ -33,7 +33,7 @@ publish {
userOrg = 'luckyjayce'//bintray.com用户名
groupId = 'com.shizhefei'//jcenter上的路径
artifactId = 'LargeImageView'//项目名称
publishVersion = '1.0.2'//版本号
publishVersion = '1.0.4'//版本号
desc = 'display large image,can scale and move image'//描述,不重要
website = 'https://github.com/LuckyJayce/LargeImageView'//网站,不重要;尽量模拟github上的地址,例如我这样的;当然你有地址最好了
}
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ private void initFitImageScale(int imageWidth, int imageHeight) {
minScale = a;
}
}
if (criticalScaleValueHook != null) {
minScale = criticalScaleValueHook.getMinScale(this, imageWidth, imageHeight, minScale);
maxScale = criticalScaleValueHook.getMaxScale(this, imageWidth, imageHeight, maxScale);
}
}

private void notifyInvalidate() {
Expand Down Expand Up @@ -565,6 +569,58 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
}
}

private OnClickListener onClickListener;
private OnLongClickListener onLongClickListener;

@Override
public void setOnClickListener(OnClickListener l) {
super.setOnClickListener(l);
this.onClickListener = l;
}

@Override
public void setOnLongClickListener(OnLongClickListener l) {
super.setOnLongClickListener(l);
this.onLongClickListener = l;
}

public void setCriticalScaleValueHook(CriticalScaleValueHook criticalScaleValueHook) {
this.criticalScaleValueHook = criticalScaleValueHook;
}

private CriticalScaleValueHook criticalScaleValueHook;

/**
* Hook临界值
*/
public interface CriticalScaleValueHook {

/**
* 返回最小的缩放倍数
* scale为1的话表示,显示的图片和View一样宽
*
* @param largeImageView
* @param imageWidth
* @param imageHeight
* @param suggestMinScale 默认建议的最小的缩放倍数
* @return
*/
float getMinScale(LargeImageView largeImageView, int imageWidth, int imageHeight, float suggestMinScale);

/**
* 返回最大的缩放倍数
* scale为1的话表示,显示的图片和View一样宽
*
* @param largeImageView
* @param imageWidth
* @param imageHeight
* @param suggestMaxScale 默认建议的最大的缩放倍数
* @return
*/
float getMaxScale(LargeImageView largeImageView, int imageWidth, int imageHeight, float suggestMaxScale);

}

private GestureDetector.SimpleOnGestureListener simpleOnGestureListener = new GestureDetector.SimpleOnGestureListener() {

@Override
Expand All @@ -581,22 +637,34 @@ public void onShowPress(MotionEvent e) {
}

@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
public boolean onSingleTapConfirmed(MotionEvent e) {
if (onClickListener != null && isClickable()) {
onClickListener.onClick(LargeImageView.this);
}
return true;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (!isEnabled()) {
return false;
}
overScrollByCompat((int) distanceX, (int) distanceY, getScrollX(), getScrollY(), getScrollRangeX(), getScrollRangeY(), 0, 0, false);
return true;
}

@Override
public void onLongPress(MotionEvent e) {

if (onLongClickListener != null && isLongClickable()) {
onLongClickListener.onLongClick(LargeImageView.this);
}
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (!isEnabled()) {
return false;
}
fling((int) -velocityX, (int) -velocityY);
return true;
}
Expand Down Expand Up @@ -646,6 +714,9 @@ public void smoothScale(float newScale, int centerX, int centerY) {
private ScaleGestureDetector.OnScaleGestureListener onScaleGestureListener = new ScaleGestureDetector.OnScaleGestureListener() {
@Override
public boolean onScale(ScaleGestureDetector detector) {
if (!isEnabled()) {
return false;
}
if (!hasLoad()) {
return false;
}
Expand Down

0 comments on commit ae64d11

Please sign in to comment.