Skip to content

Commit

Permalink
增加国际化
Browse files Browse the repository at this point in the history
  • Loading branch information
lovexyx committed Nov 24, 2020
1 parent b65f613 commit b5e23f8
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 50 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
57 changes: 30 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### BigImage + ImageView + ViewPager = BigImageViewPager

一个图片浏览器,支持超大图、超长图、支持手势放大、支持查看原图、下载、加载百分比进度显示。采用区块复用加载,优化内存占用,有效避免OOM。支持手势下拉退出。
#### 注意:本框架支持网络图片、本地图片、支持gif动图、支持Android Q
#### 注意:本框架支持网络图片、本地图片、支持gif动图、支持Android 11

# 框架特性
- 支持网络图片、本地图片;
Expand All @@ -19,22 +19,26 @@
- 针对保存图片进行优化,文件扩展名使用文件头部Mime信息进行设置,不用担心gif保存成jpeg;
- 支持自定义查看原图时的百分比View;
- 支持BMP格式的图片;
- 支持Android Q
- 支持Android 11

# 截图

# 强烈推荐推荐扫描二维码进行安装体验:
![扫码下载demo](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e50f06781ec248629b72d597183f5d2a~tplv-k3u1fbpfcp-watermark.image)

![扫码下载demo](https://upload-images.jianshu.io/upload_images/1710902-0073c2f34a714fe2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![kpFnSO.gif](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/bfd23ce0042e431bb200d7e5e2fca87d~tplv-k3u1fbpfcp-zoom-1.image)

![kpFnSO.gif](https://s2.ax1x.com/2019/01/17/kpFnSO.gif)
![kpFefK.jpg](https://s2.ax1x.com/2019/01/17/kpFefK.jpg)
| 说明 | 截图 |
| ------------ | ------------ |
|主要功能|![](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a045eaa577834b00a345b409b81826f8~tplv-k3u1fbpfcp-watermark.image)|
|预览界面|![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a0a1125f397b46619c9beea59691eaf5~tplv-k3u1fbpfcp-watermark.image)|
|下拉关闭|![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/414c415380f742c4918c4b705ffc2f4f~tplv-k3u1fbpfcp-watermark.image)|
|查看原图|![](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/ffb4cfcbaecf43488d7ae671c7c02d3d~tplv-k3u1fbpfcp-watermark.image)|

![主要功能概览](https://upload-images.jianshu.io/upload_images/1710902-2c4cae8d0ddaef1f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

# 用法
#### 添加依赖
##### Step 1. 在你project层级的build.gradle中,添加仓库地址:
### 一、添加依赖
#### Step 1. 在你project层级的build.gradle中,添加仓库地址:
```
allprojects {
repositories {
Expand All @@ -43,70 +47,69 @@ allprojects {
}
}
```
##### Step 2. 在你主module的build.gradle中添加依赖:
#### Step 2. 在你主module的build.gradle中添加依赖:

##### 此处显示的是本框架的最新版本号:
##### ⚠️注意:v3版本不再维护,最终版本为v3_4.0.2。建议使用v4、androidx版本。
##### ⚠️注意:glide v3版本不再维护,最终版本为v3_4.0.2。建议使用glide v4、androidx版本。
```
androidx用户 : 使用 androidx-6.1.2
对于glide4.x : 使用 v4_6.1.2
androidx用户 : 使用 androidx-6.1.3
对于glide4.x : 使用 v4_6.1.3
对于glide3.x : 使用 v3_4.0.2
```

```
dependencies {
// 针对androidx用户,需要添加以下依赖:
// 针对androidx用户,需要添加以下依赖:
// glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.11.0'
// 查看大图
implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-6.1.2'
implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-6.1.3'
================================分割线==================================
// 针对glide v4 版本,需要添加以下依赖:
// 针对glide v4 版本,需要添加以下依赖:
// glide
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.9.0'
// 查看大图
implementation 'com.github.SherlockGougou:BigImageViewPager:v4_6.1.2'
implementation 'com.github.SherlockGougou:BigImageViewPager:v4_6.1.3'
================================分割线==================================
// 针对glide v3 版本,需要添加以下依赖:
// 针对glide v3 版本,需要添加以下依赖:
// 查看大图
implementation 'com.github.SherlockGougou:BigImageViewPager:v3_4.0.2'
}
```

##### Step 3. 在您的主module里,添加自定义AppGlideModule
######(注意!!!如果您用的是glide 3.x版本,不需要做这一步的操作,上一步的依赖后就完事儿了;
###### 但如果您用的是glide 4.x版本,并且您的app中已经存在了自定义的GlideModule,您只需要把下面的那一行代码,添加到对应的重载方法中即可。)例如:
#### Step 3. 在您的主module里,添加自定义AppGlideModule
#####(注意!!!如果您用的是glide 3.x版本,不需要做这一步的操作,上一步的依赖后就完事儿了;
##### 如果您用的是androidx版本,或者glide是4.x版本,您需要继承AppGlideModule并添加以下代码到对应的重载方法中。)例如:
```
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide,
@NonNull Registry registry) {
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
super.registerComponents(context, glide, registry);
// 替换底层网络框架为okhttp3,这步很重要!如果不添加会无法显示原图的加载百分比
// 替换底层网络框架为okhttp3,这步很重要!如果不添加会无法正常显示原图的加载百分比,或者卡在1%
// 如果您的app中已经存在了自定义的GlideModule,您只需要把这一行代码,添加到对应的重载方法中即可。
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(ProgressManager.getOkHttpClient()));
}
}
```

##### Step 4. 以上操作完成后,请点击顶部按钮:Build->Rebuild Project,等待重建完成,至此,框架添加完成。如遇到任何问题,请附带截图提issues,我会及时回复,或添加底部QQ群,进行交流。
#### Step 4. 以上操作完成后,请点击顶部按钮:Build->Rebuild Project,等待重建完成,至此,框架添加完成。如遇到任何问题,请附带截图提issues,我会及时回复,或添加底部QQ群,进行交流。

## 调用方式
## 二、调用方式

#### 1:生成图片源:(如果你有缩略图和原图两种路径,请使用下面的方式,进行图片List的生成;如果你是本地图片或者没有原图缩略图之分,可以跳过这一步)
```
Expand Down Expand Up @@ -365,7 +368,7 @@ public class MyAppGlideModule extends AppGlideModule {
详细操作请参考Demo:https://github.com/SherlockGougou/BigImageViewPager/blob/master/sample/src/main/java/cc/shinichi/bigimageviewpager/MainActivity.java#L291

# DEMO体验
![扫码下载demo](https://upload-images.jianshu.io/upload_images/1710902-0073c2f34a714fe2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![扫码下载demo](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0bc6607b402b4d0d9837fa44291cae43~tplv-k3u1fbpfcp-zoom-1.image)

# GitHub源码
https://github.com/SherlockGougou/BigImageViewPager
Expand All @@ -378,7 +381,7 @@ https://github.com/SherlockGougou/BigImageViewPager
# Bug反馈、增加需求,加 QQ 交流群:271127803(大话安卓)
### 欢迎加入“大话安卓”技术交流群,一起分享,共同进步##

![欢迎加入“大话安卓”技术交流群,互相学习提升](https://upload-images.jianshu.io/upload_images/1710902-5cdeb8c1f58dd425.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![欢迎加入“大话安卓”技术交流群,互相学习提升](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/516d83214bcd4db48e9b40798a945758~tplv-k3u1fbpfcp-zoom-1.image)

# LICENSE
```
Expand Down
4 changes: 4 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion '29.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 29
Expand Down Expand Up @@ -35,7 +36,10 @@ dependencies {
exclude module: 'support-v4'
}
// glide
//noinspection GradleDependency
compileOnly 'com.github.bumptech.glide:okhttp3-integration:4.9.0'
//noinspection GradleDependency
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
//noinspection GradleDependency
compileOnly 'com.github.bumptech.glide:glide:4.9.0'
}
3 changes: 1 addition & 2 deletions library/src/main/java/cc/shinichi/library/ImagePreview.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ public void start() {
}
}
if (imageInfoList == null || imageInfoList.size() == 0) {
throw new IllegalArgumentException(
"Do you forget to call 'setImageInfoList(List<ImageInfo> imageInfoList)' ?");
throw new IllegalArgumentException("Do you forget to call 'setImageInfoList(List<ImageInfo> imageInfoList)' ?");
}
if (this.index >= imageInfoList.size()) {
throw new IllegalArgumentException("index out of range!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.OutputStream;

import cc.shinichi.library.ImagePreview;
import cc.shinichi.library.R;
import cc.shinichi.library.glide.FileTarget;
import cc.shinichi.library.tool.file.FileUtil;
import cc.shinichi.library.tool.file.SingleMediaScanner;
Expand All @@ -40,14 +41,14 @@ public static void downloadPicture(final Context context, final String url) {
@Override
public void onLoadStarted(@Nullable Drawable placeholder) {
super.onLoadStarted(placeholder);
ToastUtil.getInstance()._short(context, "开始下载...");
ToastUtil.getInstance()._short(context, context.getString(R.string.toast_start_download));
super.onLoadStarted(placeholder);
}

@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
ToastUtil.getInstance()._short(context, "保存失败");
ToastUtil.getInstance()._short(context, context.getString(R.string.toast_save_failed));
}

@Override
Expand Down Expand Up @@ -88,10 +89,10 @@ public void onResourceReady(@NonNull File resource, @Nullable Transition<? super
}
os.flush();
}
ToastUtil.getInstance()._short(context, "成功保存到 ".concat(Environment.DIRECTORY_PICTURES + "/" + downloadFolderName));
ToastUtil.getInstance()._short(context, context.getString(R.string.toast_save_success, Environment.DIRECTORY_PICTURES + "/" + downloadFolderName));
} catch (IOException e) {
e.printStackTrace();
ToastUtil.getInstance()._short(context, "保存失败");
ToastUtil.getInstance()._short(context, context.getString(R.string.toast_save_failed));
} finally {
try {
if (os != null) {
Expand All @@ -115,15 +116,15 @@ public void onResourceReady(@NonNull File resource, @Nullable Transition<? super
FileUtil.createFileByDeleteOldFile(path + name);
boolean result = FileUtil.copyFile(resource, path, name);
if (result) {
ToastUtil.getInstance()._short(context, "成功保存到 ".concat(path));
ToastUtil.getInstance()._short(context, context.getString(R.string.toast_save_success, path));
new SingleMediaScanner(context, path.concat(name), new SingleMediaScanner.ScanListener() {
@Override
public void onScanFinish() {
// scanning...
}
});
} else {
ToastUtil.getInstance()._short(context, "保存失败");
ToastUtil.getInstance()._short(context, context.getString(R.string.toast_save_failed));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ public class ToastUtil {

private static final Handler HANDLER = new Handler(Looper.getMainLooper());

public ToastUtil() {

}

public static ToastUtil getInstance() {
return InnerClass.instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public boolean handleMessage(Message msg) {
}
}
} else if (msg.what == 3) {// 隐藏查看原图按钮
btn_show_origin.setText("查看原图");
btn_show_origin.setText(R.string.btn_original);
fm_image_show_origin_container.setVisibility(View.GONE);
originalStatus = false;
} else if (msg.what == 4) {// 显示查看原图按钮
Expand Down Expand Up @@ -405,7 +405,7 @@ public void onClick(View v) {
if (ActivityCompat.shouldShowRequestPermissionRationale(ImagePreviewActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// 拒绝权限
ToastUtil.getInstance()._short(context, "您拒绝了存储权限,下载失败!");
ToastUtil.getInstance()._short(context, getString(R.string.toast_deny_permission_save_failed));
} else {
//申请权限
ActivityCompat.requestPermissions(ImagePreviewActivity.this,
Expand All @@ -430,7 +430,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
if (grantResults[i] == PERMISSION_GRANTED) {
downloadCurrentImg();
} else {
ToastUtil.getInstance()._short(context, "您拒绝了存储权限,下载失败!");
ToastUtil.getInstance()._short(context, getString(R.string.toast_deny_permission_save_failed));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private void loadFailed(SubsamplingScaleImageViewDragClose imageView, ImageView
imageView.setImage(ImageSource.resource(ImagePreview.getInstance().getErrorPlaceHolder()));

if (ImagePreview.getInstance().isShowErrorToast()) {
String errorMsg = "加载失败";
String errorMsg = activity.getString(R.string.toast_load_failed);
if (e != null) {
errorMsg = errorMsg.concat(":\n").concat(e.getMessage());
}
Expand Down
5 changes: 3 additions & 2 deletions library/src/main/res/layout/sh_layout_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<Button
android:id="@+id/btn_show_origin"
android:layout_width="100dp"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:background="@drawable/gray_square_circle_bg_white_stroke"
android:gravity="center"
Expand All @@ -48,7 +48,8 @@
android:paddingTop="5dp"
android:paddingRight="10dp"
android:paddingBottom="5dp"
android:text="查看原图"
android:text="@string/btn_original"
android:textAllCaps="false"
android:textColor="#ffffff"
/>
</FrameLayout>
Expand Down
10 changes: 10 additions & 0 deletions library/src/main/res/values-en-rUS/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<resources>
<string name="indicator">%1$s/%2$s</string>
<string name="btn_original">Original image</string>

<string name="toast_start_download">Download start</string>
<string name="toast_load_failed">Load failed</string>
<string name="toast_save_failed">Save failed</string>
<string name="toast_save_success">Saved to:%1$s</string>
<string name="toast_deny_permission_save_failed">You denied the storage permission and the download failed!</string>
</resources>
10 changes: 8 additions & 2 deletions library/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<resources>
<string name="app_name">library</string>
<string name="indicator">%1$s/%2$s</string>
</resources>
<string name="btn_original">查看原图</string>

<string name="toast_start_download">开始下载</string>
<string name="toast_load_failed">加载失败</string>
<string name="toast_save_failed">保存失败</string>
<string name="toast_save_success">成功保存到:%1$s</string>
<string name="toast_deny_permission_save_failed">您拒绝了存储权限,下载失败!</string>
</resources>
6 changes: 3 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "cc.shinichi.bigimageviewpager"
minSdkVersion 14
targetSdkVersion 29
versionCode 612
versionName "v4_6.1.2"
versionCode 613
versionName "v4_6.1.3"
}
buildTypes {
release {
Expand Down Expand Up @@ -55,6 +55,6 @@ dependencies {
//noinspection GradleDependency
implementation 'com.github.bumptech.glide:okhttp3-integration:4.9.0'
// library
// implementation 'com.github.SherlockGougou:BigImageViewPager:v4_6.1.2'
// implementation 'com.github.SherlockGougou:BigImageViewPager:v4_6.1.3'
implementation project(':library')
}

0 comments on commit b5e23f8

Please sign in to comment.