diff --git a/.circleci/config.yml b/.circleci/config.yml index e4e7e19..6304f0b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,9 +5,10 @@ orbs: jobs: build: - executor: android/android - + docker: + - image: cimg/android:2023.02 steps: - checkout - run: - command: ./gradlew build \ No newline at end of file + command: ./gradlew build + diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f1b41af..b48f6b0 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -12,9 +12,9 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 1.8 + - name: Set up JDK 11 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - name: Build with Gradle run: ./gradlew build \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index bbcee36..f571dd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ language: android dist: trusty -jdk: oraclejdk8 +jdk: oraclejdk11 sudo: false env: global: - - ANDROID_API_LEVEL=29 - - ANDROID_BUILD_TOOLS_VERSION=29.0.2 + - ANDROID_API_LEVEL=30 + - ANDROID_BUILD_TOOLS_VERSION=30.0.3 - TRAVIS_SECURE_ENV_VARS=true before_install: diff --git a/README.md b/README.md index 86bb8d2..83c3bc1 100644 --- a/README.md +++ b/README.md @@ -16,37 +16,28 @@ ImageViewer for Android 是一个图片查看器,一般用来查看图片详情或查看大图时使用。 ## Gif 展示 -![Image](GIF.gif) +![Image](GIF.gif) ## 引入 ### Gradle: -1. 在Project的 **build.gradle** 里面添加远程仓库 +1. 在Project的 **build.gradle** 或 **setting.gradle** 中添加远程仓库 -```gradle -allprojects { + ```gradle repositories { //... mavenCentral() + maven { url 'https://jitpack.io' } } -} -``` + ``` 2. 在Module的 **build.gradle** 里面添加引入依赖项 -```gradle -implementation 'com.github.jenly1314:imageviewer:1.0.4' -``` - - -以前发布至JCenter的版本 - -```gradle -implementation 'com.king.image:imageviewer:1.0.2' -``` - + ```gradle + implementation 'com.github.jenly1314:imageviewer:1.1.0' + ``` ## 示例 @@ -55,7 +46,7 @@ implementation 'com.king.image:imageviewer:1.0.2' ```Java //图片查看器 - 简单调用 - // data 可以多张图片List或单张图片,支持的类型可以是{@link Uri}, {@code url}, {@code path},{@link File}, {@link DrawableRes resId}…等 +// data 可以多张图片List或单张图片,支持的类型可以是{@link Uri}, {@code url}, {@code path},{@link File}, {@link DrawableRes resId}…等 ImageViewer.load(data)//要加载的图片数据,单张或多张 .imageLoader(new GlideImageLoader())//加载器,imageLoader必须配置,目前内置的有GlideImageLoader或PicassoImageLoader,也可以自己实现 .start(activity,sharedElement);//activity or fragment, 跳转时的共享元素视图 @@ -65,7 +56,7 @@ implementation 'com.king.image:imageviewer:1.0.2' ```Java //图片查看器 - // data 可以多张图片List或单张图片,支持的类型可以是{@link Uri}, {@code url}, {@code path},{@link File}, {@link DrawableRes resId}…等 +// data 可以多张图片List或单张图片,支持的类型可以是{@link Uri}, {@code url}, {@code path},{@link File}, {@link DrawableRes resId}…等 ImageViewer.load(data)//要加载的图片数据,单张或多张 .selection(position)//当前选中位置,默认:0 .indicator(true)//是否显示指示器,默认不显示 @@ -77,49 +68,54 @@ implementation 'com.king.image:imageviewer:1.0.2' ``` ### 相关说明 -> * 使用 **ImageViewer** 时,必须配置一个实现的 **ImageLoader**。 -> * **ImageViewer** 一次可以查看多张图片或单张图片,支持的类型可以是 **Uri**、 **url** 、 **path** 、 **File**、 **Drawable**、 **ImageDataSource** 等 +* 使用 **ImageViewer** 时,必须配置一个实现的 **ImageLoader**。 -> * 目前内置默认实现的 **ImageLoader** 有和 **PicassoImageLoader** ,二者选其一即可,如果二者不满足您的需求,您也可以自己实现一个 **ImageLoader**。 +* **ImageViewer** 一次可以查看多张图片或单张图片,支持的类型可以是 **Uri**、 **url** 、 **path** 、 **File**、 **DrawableRes**、 **ImageDataSource** 等。 -> * 为了保证 **ImageViewer** 体积最小化,和用户更多可能的选择性,并未将 **Glide** 和 **Picasso** 打包进 **aar**。 ->> 当您使用了 **GlideImageLoader** 时,必须依赖[ **Glide** ](https://github.com/bumptech/glide)库。 +* 目前内置默认实现 **ImageLoader** 的有 **GlideImageLoader** 和 **PicassoImageLoader** ,二者选其一即可,如果二者不满足您的需求,您也可以自己实现一个 **ImageLoader**。 ->> 当您使用了 **PicassoImageLoader** 时,必须依赖[ **Picasso** ](https://github.com/square/picasso)库。 +* 为了保证 **ImageViewer** 体积最小化,让用户有更多选择的可能性, **ImageViewer** 仅编译时用到了 **Glide** 和 **Picasso** 。 +> 当你使用了 **GlideImageLoader** 时,则需依赖[ **Glide** ](https://github.com/bumptech/glide)库。 + +> 当你使用了 **PicassoImageLoader** 时,则需依赖[ **Picasso** ](https://github.com/square/picasso)库。 更多使用详情,请查看[app](app)中的源码使用示例 ## 版本记录 +#### v1.1.0:2023-9-16 +* 更新Gradle至v7.3.3 +* 更新compileSdk至30 +* 优化细节 + #### v1.0.4:2022-9-11 -* 优化细节 +* 优化细节 #### v1.0.3:2022-9-10 (从v1.0.3开始发布至 MavenCentral) -* 看大图界面支持自定义扩展 +* 看大图界面支持自定义扩展 #### v1.0.2:2020-12-3 -* 加载的图片数据新增支持ImageDataSource类型,便于扩展 +* 加载的图片数据新增支持ImageDataSource类型,便于扩展 #### v1.0.1:2019-11-15 -* 简化集成步骤 +* 简化集成步骤 #### v1.0.0:2019-11-7 -* ImageViewer初始版本 +* ImageViewer初始版本 ## 赞赏 -如果您喜欢ImageViewer,或感觉ImageViewer帮助到了您,可以点右上角“Star”支持一下,您的支持就是我的动力,谢谢 :smiley:
+ +如果您喜欢ImageViewer,或感觉ImageViewer帮助到了您,可以点右上角“Star”支持一下,您的支持就是我的动力,谢谢 : +smiley:
您也可以扫描下面的二维码,请作者喝杯咖啡 :coffee:
@@ -34,9 +34,11 @@
*
* @author Jenly
*/
+@SuppressWarnings("unused")
public final class ImageViewer {
+ public static final String SHARED_ELEMENT = "shared_element";
- private ViewerSpec mViewerSpec;
+ private final ViewerSpec mViewerSpec;
private ActivityOptionsCompat mOptionsCompat;
@@ -250,6 +252,7 @@ public ImageViewer imageViewerClass(Class> cls) {
/**
* 设置扩展数据 相当于 {@code intent.putExtras(extras)}
+ *
* @param extras
* @return
*/
@@ -290,7 +293,7 @@ public void start(@NonNull Activity activity) {
public void start(@NonNull Activity activity, @Nullable View sharedElement) {
initResource(activity);
Intent intent = new Intent(activity, imageViewerClass);
- if(extrasBundle != null){
+ if (extrasBundle != null) {
intent.putExtras(extrasBundle);
}
activity.startActivity(intent, obtainActivityOptionsCompatBundle(activity, sharedElement));
@@ -314,24 +317,26 @@ public void start(@NonNull Fragment fragment) {
public void start(@NonNull Fragment fragment, @Nullable View sharedElement) {
initResource(fragment.getContext());
Intent intent = new Intent(fragment.getContext(), imageViewerClass);
- if(extrasBundle != null){
+ if (extrasBundle != null) {
intent.putExtras(extrasBundle);
}
+
fragment.startActivity(intent, obtainActivityOptionsCompatBundle(fragment.getActivity(), sharedElement));
}
/**
* 获取 ActivityOptionsCompat 转 Bundle
- * @param activity
- * @param sharedElement
+ *
+ * @param activity {@link Activity}
+ * @param sharedElement 共享元素
* @return
*/
- private Bundle obtainActivityOptionsCompatBundle(Activity activity, @Nullable View sharedElement){
+ private Bundle obtainActivityOptionsCompatBundle(Activity activity, @Nullable View sharedElement) {
if (mOptionsCompat == null) {
if (sharedElement != null) {
- mOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement, ImageViewerActivity.SHARED_ELEMENT);
+ mOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement, SHARED_ELEMENT);
} else {
- mOptionsCompat = ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.iv_anim_in, R.anim.iv_anim_out);
+ mOptionsCompat = ActivityOptionsCompat.makeCustomAnimation(activity, R.anim.image_viewer_anim_in, R.anim.image_viewer_anim_out);
}
}
return mOptionsCompat.toBundle();
diff --git a/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerActivity.java b/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerActivity.java
index 3c05ceb..a1f1fb1 100644
--- a/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerActivity.java
+++ b/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerActivity.java
@@ -1,10 +1,10 @@
package com.king.image.imageviewer;
import android.os.Bundle;
-import android.os.PersistableBundle;
import android.view.View;
import android.widget.TextView;
+import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.ViewCompat;
@@ -15,96 +15,78 @@
*/
public class ImageViewerActivity extends AppCompatActivity {
- static final String SHARED_ELEMENT = "shared_element";
-
private TextView tvIndicator;
ImageViewerAdapter mAdapter;
- ViewerSpec mViewerSpec;
-
private int mSize;
private boolean isShowIndicator;
- @Override
- public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
- super.onCreate(savedInstanceState, persistentState);
- }
-
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mViewerSpec = ViewerSpec.INSTANCE;
- setRequestedOrientation(mViewerSpec.orientation);
- setTheme(mViewerSpec.theme);
+ setRequestedOrientation(ViewerSpec.INSTANCE.orientation);
+ setTheme(ViewerSpec.INSTANCE.theme);
setContentView(getLayoutId());
init();
}
- protected int getLayoutId(){
+ /**
+ * 获取布局
+ *
+ * @return 返回布局ID
+ */
+ @LayoutRes
+ protected int getLayoutId() {
return R.layout.image_viewer_activity;
}
- protected void init(){
+ /**
+ * 初始化
+ */
+ protected void init() {
tvIndicator = findViewById(R.id.tvIndicator);
ViewPager2 viewPager = findViewById(R.id.viewPager);
viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- super.onPageScrolled(position, positionOffset, positionOffsetPixels);
- }
-
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
- if(isShowIndicator){
- updateIndicator(position,mSize);
+ if (isShowIndicator) {
+ updateIndicator(position, mSize);
}
}
-
- @Override
- public void onPageScrollStateChanged(int state) {
- super.onPageScrollStateChanged(state);
- }
});
- ViewCompat.setTransitionName(viewPager,SHARED_ELEMENT);
+ ViewCompat.setTransitionName(viewPager, ImageViewer.SHARED_ELEMENT);
- mAdapter = new ImageViewerAdapter(mViewerSpec.listData);
+ mAdapter = new ImageViewerAdapter(ViewerSpec.INSTANCE.listData);
viewPager.setAdapter(mAdapter);
- mAdapter.setOnItemClickListener(new ImageViewerAdapter.OnItemClickListener() {
- @Override
- public void onClick(View v, int position) {
- onBackPressed();
- }
- });
+ mAdapter.setOnItemClickListener((v, position) -> onBackPressed());
-
- int position = mViewerSpec.position;
+ int position = ViewerSpec.INSTANCE.position;
mSize = mAdapter.getItemCount();
- if(position>=0){
- viewPager.setCurrentItem(position,false);
- updateIndicator(position,mSize);
+ if (position >= 0) {
+ viewPager.setCurrentItem(position, false);
+ updateIndicator(position, mSize);
}
- isShowIndicator = mViewerSpec.isShowIndicator && mSize > 0;
- if(isShowIndicator){
+ isShowIndicator = ViewerSpec.INSTANCE.isShowIndicator && mSize > 0;
+ if (isShowIndicator) {
tvIndicator.setVisibility(View.VISIBLE);
}
}
- private void updateIndicator(int position,int size){
- tvIndicator.setText(String.format("%s/%s",Math.min(position + 1,size),size));
+ /**
+ * 更新指示器
+ *
+ * @param position
+ * @param size
+ */
+ private void updateIndicator(int position, int size) {
+ tvIndicator.setText(String.format("%s/%s", Math.min(position + 1, size), size));
}
- @Override
- protected void onDestroy() {
- if(mViewerSpec != null ){
- mViewerSpec.imageLoader = null;
- }
- super.onDestroy();
- }
}
diff --git a/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerAdapter.java b/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerAdapter.java
index a342efa..7ee6107 100644
--- a/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerAdapter.java
+++ b/imageviewer/src/main/java/com/king/image/imageviewer/ImageViewerAdapter.java
@@ -5,57 +5,63 @@
import android.view.ViewGroup;
import android.widget.ImageView;
-import java.util.ArrayList;
-import java.util.List;
-
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.Adapter;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* @author Jenly
*/
public class ImageViewerAdapter extends Adapter