diff --git a/app/build.gradle b/app/build.gradle index 3606770..84d63f2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" @@ -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') } diff --git a/build.gradle b/build.gradle index eebc5a9..44c64cf 100644 --- a/build.gradle +++ b/build.gradle @@ -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 } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 122a0dc..9a778d6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/imageselector/build.gradle b/imageselector/build.gradle index 20fb778..c986a01 100644 --- a/imageselector/build.gradle +++ b/imageselector/build.gradle @@ -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 @@ -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 +} \ No newline at end of file diff --git a/imageselector/src/main/java/com/donkingliang/imageselector/adapter/ImagePagerAdapter.java b/imageselector/src/main/java/com/donkingliang/imageselector/adapter/ImagePagerAdapter.java index fc18f6d..8c1df9b 100644 --- a/imageselector/src/main/java/com/donkingliang/imageselector/adapter/ImagePagerAdapter.java +++ b/imageselector/src/main/java/com/donkingliang/imageselector/adapter/ImagePagerAdapter.java @@ -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; @@ -17,30 +18,26 @@ public class ImagePagerAdapter extends PagerAdapter { private Context mContext; - private List viewList = new ArrayList<>(); + private List viewList = new ArrayList<>(4); List mImgList; private OnItemClickListener mListener; public ImagePagerAdapter(Context context, List imgList) { this.mContext = context; - createImageViews(imgList); + createImageViews(); mImgList = imgList; } - private void createImageViews(List 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 @@ -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()))