Skip to content

Commit

Permalink
1、升级引用依赖。2、优化内存,防止OOM.
Browse files Browse the repository at this point in the history
  • Loading branch information
梁任彦 committed Jun 22, 2017
1 parent 802f847 commit 049da36
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 23 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 25
buildToolsVersion '25.0.0'

defaultConfig {
applicationId "com.donkingliang.imageselectdemo"
Expand All @@ -22,6 +22,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile project(':imageselector')
}
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'

classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
41 changes: 37 additions & 4 deletions imageselector/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
apply plugin: 'com.android.library'

group='com.github.donkingliang' // 指定group,com.github.<用户名>

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 25
buildToolsVersion '25.0.0'

defaultConfig {
minSdkVersion 14
Expand All @@ -21,8 +23,39 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.chrisbanes:PhotoView:2.0.0'
}

//---------------------------------------------

// 指定编码
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

// 打包源码
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}

task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.compile
}

// 制作文档(Javadoc)
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives sourcesJar
archives javadocJar
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

Expand All @@ -17,30 +18,26 @@
public class ImagePagerAdapter extends PagerAdapter {

private Context mContext;
private List<PhotoView> viewList = new ArrayList<>();
private List<PhotoView> viewList = new ArrayList<>(4);
List<Image> mImgList;
private OnItemClickListener mListener;

public ImagePagerAdapter(Context context, List<Image> imgList) {
this.mContext = context;
createImageViews(imgList);
createImageViews();
mImgList = imgList;
}

private void createImageViews(List<Image> imgList) {
viewList.clear();
if (imgList != null && !imgList.isEmpty()) {
int size = imgList.size();
for (int i = 0; i < size; i++) {
PhotoView imageView = new PhotoView(mContext);
viewList.add(imageView);
}
private void createImageViews() {
for (int i = 0; i < 4; i++) {
PhotoView imageView = new PhotoView(mContext);
viewList.add(imageView);
}
}

@Override
public int getCount() {
return viewList == null ? 0 : viewList.size();
return mImgList == null ? 0 : mImgList.size();
}

@Override
Expand All @@ -50,12 +47,17 @@ public boolean isViewFromObject(View view, Object object) {

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(viewList.get(position));
if(object instanceof PhotoView){
PhotoView view = (PhotoView)object;
view.setImageDrawable(null);
viewList.add(view);
container.removeView(view);
}
}

@Override
public Object instantiateItem(ViewGroup container, final int position) {
final PhotoView currentView = viewList.get(position);
final PhotoView currentView = viewList.remove(0);
final Image image = mImgList.get(position);
container.addView(currentView);
Glide.with(mContext).load(new File(image.getPath()))
Expand Down

0 comments on commit 049da36

Please sign in to comment.