Skip to content

Commit

Permalink
feat: version 7.0.4;支持平板设备横屏展示;修复中文url加载百分比问题;
Browse files Browse the repository at this point in the history
  • Loading branch information
SherlockGougou committed Sep 8, 2022
1 parent 1e9b371 commit fcb5092
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- 支持BMP格式的图片;
- 支持Android 12;
- 支持自定义预览界面;
- 支持平板等横屏设备显示;

# 用法
### 一、添加依赖
Expand All @@ -39,7 +40,7 @@ allprojects {
##### 此处显示的是本框架的最新版本号:
##### ⚠️注意:glide v3版本不再维护,最终版本为v3_4.0.2。建议使用androidx版本。
```
androidx用户 : 使用 androidx-7.0.3
androidx用户 : 使用 androidx-7.0.4
对于glide4.x : 使用 v4_6.1.3
```

Expand All @@ -53,7 +54,7 @@ dependencies {
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.11.0'
// BigImageViewPager https://github.com/SherlockGougou/BigImageViewPager
implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.0.3'
implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.0.4'
================================分割线==================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cc.shinichi.library.glide.progress
import android.text.TextUtils
import cc.shinichi.library.glide.SSLSocketClient
import cc.shinichi.library.glide.progress.ProgressResponseBody.InternalProgressListener
import cc.shinichi.library.tool.common.HttpUtil
import okhttp3.OkHttpClient
import java.util.*
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -63,6 +64,6 @@ object ProgressManager {
private fun getProgressListener(url: String?): OnProgressListener? {
return if (TextUtils.isEmpty(url) || listenersMap.isEmpty()) {
null
} else listenersMap[url]
} else listenersMap[url?.let { HttpUtil.decode(it) }]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.io.*
import java.net.HttpURLConnection
import java.net.MalformedURLException
import java.net.URL
import java.net.URLDecoder

/**
* HttpURLConnection 下载图片
Expand Down Expand Up @@ -58,4 +59,8 @@ object HttpUtil {
}
return null
}

fun decode(text: String): String {
return URLDecoder.decode(text)
}
}
15 changes: 15 additions & 0 deletions library/src/main/java/cc/shinichi/library/tool/image/ImageUtil.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cc.shinichi.library.tool.image

import android.content.Context
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Matrix
Expand Down Expand Up @@ -127,6 +128,20 @@ object ImageUtil {
} else intArrayOf(srcWidth, srcHeight)
}

fun isTablet(context: Context): Boolean {
return context.resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK >= Configuration.SCREENLAYOUT_SIZE_LARGE
}


fun isLandscape(context: Context): Boolean {
val phoneRatio = PhoneUtil.getPhoneRatio(context.applicationContext)
return phoneRatio <= 1f
}

fun isTabletOrLandscape(context: Context): Boolean {
return isTablet(context) or isLandscape(context)
}

fun isLongImage(context: Context, imagePath: String): Boolean {
val wh = getWidthHeight(imagePath)
val w = wh[0].toFloat()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import cc.shinichi.library.glide.ImageLoader.getGlideCacheFile
import cc.shinichi.library.glide.progress.OnProgressListener
import cc.shinichi.library.glide.progress.ProgressManager.addListener
import cc.shinichi.library.tool.common.HandlerHolder
import cc.shinichi.library.tool.common.HttpUtil
import cc.shinichi.library.tool.common.NetworkUtil
import cc.shinichi.library.tool.image.DownloadPictureUtil.downloadPicture
import cc.shinichi.library.tool.ui.ToastUtil
Expand Down Expand Up @@ -321,7 +322,7 @@ class ImagePreviewActivity : AppCompatActivity(), Handler.Callback, View.OnClick
} else if (msg.what == 1) {
// 加载完成
val bundle = msg.obj as Bundle
val url = bundle.getString("url")
val url = HttpUtil.decode(bundle.getString("url", ""))
gone()
if (currentItem == getRealIndexWithPath(url)) {
if (isUserCustomProgressView) {
Expand All @@ -336,7 +337,7 @@ class ImagePreviewActivity : AppCompatActivity(), Handler.Callback, View.OnClick
} else if (msg.what == 2) {
// 加载中
val bundle = msg.obj as Bundle
val url = bundle.getString("url")
val url = HttpUtil.decode(bundle.getString("url", ""))
val progress = bundle.getInt("progress")
if (currentItem == getRealIndexWithPath(url)) {
if (isUserCustomProgressView) {
Expand Down Expand Up @@ -464,8 +465,6 @@ class ImagePreviewActivity : AppCompatActivity(), Handler.Callback, View.OnClick
}

private fun loadOriginImage(path: String?) {
Glide.with(context).downloadOnly().load(path).into(object : FileTarget() {
})
addListener(path, object : OnProgressListener {
override fun onProgress(
url: String?,
Expand Down Expand Up @@ -496,6 +495,8 @@ class ImagePreviewActivity : AppCompatActivity(), Handler.Callback, View.OnClick
}
}
})
Glide.with(context).downloadOnly().load(path).into(object : FileTarget() {
})
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import cc.shinichi.library.tool.image.ImageUtil.isBmpImageWithMime
import cc.shinichi.library.tool.image.ImageUtil.isLongImage
import cc.shinichi.library.tool.image.ImageUtil.isSmallImage
import cc.shinichi.library.tool.image.ImageUtil.isStaticImage
import cc.shinichi.library.tool.image.ImageUtil.isTabletOrLandscape
import cc.shinichi.library.tool.image.ImageUtil.isWideImage
import cc.shinichi.library.tool.ui.PhoneUtil.getPhoneHei
import cc.shinichi.library.tool.ui.ToastUtil
Expand Down Expand Up @@ -372,7 +373,44 @@ class ImagePreviewAdapter(private val activity: AppCompatActivity, imageList: Mu
}

private fun setImageStatic(imagePath: String, imageStatic: SubsamplingScaleImageViewDragClose) {
val tabletOrLandscape = isTabletOrLandscape(activity)
val isLongImage = isLongImage(activity, imagePath)
if (tabletOrLandscape) {
imageStatic.setMinimumScaleType(SubsamplingScaleImageViewDragClose.SCALE_TYPE_CENTER_INSIDE)
imageStatic.minScale = ImagePreview.instance.minScale
imageStatic.maxScale = ImagePreview.instance.maxScale
imageStatic.setDoubleTapZoomScale(ImagePreview.instance.mediumScale)
// if (isLongImage) {
// imageStatic.minScale = getLongImageMinScale(activity, imagePath)
// imageStatic.maxScale = getLongImageMaxScale(activity, imagePath)
// imageStatic.setDoubleTapZoomScale(getLongImageMaxScale(activity, imagePath))
// } else {
// val isWideImage = isWideImage(activity, imagePath)
// val isSmallImage = isSmallImage(activity, imagePath)
// when {
// isWideImage -> {
// imageStatic.minScale = ImagePreview.instance.minScale
// imageStatic.maxScale = ImagePreview.instance.maxScale
// imageStatic.setDoubleTapZoomScale(
// getWideImageDoubleScale(
// activity, imagePath
// )
// )
// }
// isSmallImage -> {
// imageStatic.minScale = getSmallImageMinScale(activity, imagePath)
// imageStatic.maxScale = getSmallImageMaxScale(activity, imagePath)
// imageStatic.setDoubleTapZoomScale(getSmallImageMaxScale(activity, imagePath))
// }
// else -> {
// imageStatic.minScale = ImagePreview.instance.minScale
// imageStatic.maxScale = ImagePreview.instance.maxScale
// imageStatic.setDoubleTapZoomScale(ImagePreview.instance.mediumScale)
// }
// }
// }
return
}
if (isLongImage) {
imageStatic.setMinimumScaleType(SubsamplingScaleImageViewDragClose.SCALE_TYPE_START)
imageStatic.minScale = getLongImageMinScale(activity, imagePath)
Expand Down
6 changes: 3 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "cc.shinichi.bigimageviewpager"
minSdkVersion 14
targetSdkVersion 32
versionCode 703
versionName "androidx-7.0.3"
versionCode 704
versionName "androidx-7.0.4"
}
buildTypes {
release {
Expand Down Expand Up @@ -57,6 +57,6 @@ dependencies {
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.11.0'
// library
// implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.0.3'
// implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-7.0.4'
implementation project(':library')
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public class MainActivity extends AppCompatActivity {
// 大图:5760 * 3840
"http://img6.16fan.com/attachments/wenzhang/201805/18/152660818127263ge.jpeg",
// 长图:2280 * 22116
"http://img6.16fan.com/attachments/wenzhang/201805/18/152660818716180ge.jpeg",
"http://img6.16fan.com/attachments/wenzhang/201805/18/152660818716180ge.jpeg"
// 支持且不限于以下六种格式的图片
"https://aloss.11oi.com/app/img/temp/launch_top.bmp",
"https://aloss.11oi.com/app/img/temp/launch_top.gif",
"https://aloss.11oi.com/app/img/temp/launch_top.jpeg",
"https://aloss.11oi.com/app/img/temp/launch_top.jpg",
"https://aloss.11oi.com/app/img/temp/launch_top.png",
"https://aloss.11oi.com/app/img/temp/launch_top.webp"
// "https://aloss.11oi.com/app/img/temp/launch_top.bmp",
// "https://aloss.11oi.com/app/img/temp/launch_top.gif",
// "https://aloss.11oi.com/app/img/temp/launch_top.jpeg",
// "https://aloss.11oi.com/app/img/temp/launch_top.jpg",
// "https://aloss.11oi.com/app/img/temp/launch_top.png",
// "https://aloss.11oi.com/app/img/temp/launch_top.webp"
};

@Override
Expand Down Expand Up @@ -228,15 +228,20 @@ private void initData() {

// 动图支持:
ImageInfo i = new ImageInfo();
i.setThumbnailUrl("https://qbapk.com/files/2022-05/c2677ee3e2abeefda68b1366448ebccaeeca660d0cc0fe9b9eee39d339a00cd6.webp");
i.setOriginUrl("https://qbapk.com/files/2022-05/f23b21d2b99c2d754d17f0d0d5c3fd9ee91ac0e70d7e6200a0c36342e0237fba.webp");
i.setThumbnailUrl("https://media3.giphy.com/media/l41lXnhesd96Aa9os/giphy_s.gif?cid=790b76119dc3904439a5a6dc0a25713aeb5f65b3133f46d5&rid=giphy_s.gif&ct=g");
i.setOriginUrl("https://i.giphy.com/media/l41lXnhesd96Aa9os/giphy.webp");
imageInfoList.add(i);

i = new ImageInfo();
i.setThumbnailUrl("https://i.imgur.com/NEJHo0e.png");
i.setOriginUrl("https://i0.hdslb.com/bfs/article/4421aaa8a38beeda1b195b656c883c7508f9b13d.gif");
imageInfoList.add(i);

// 中文url的原图加载
i = new ImageInfo();
i.setThumbnailUrl("https://test-houbo-homework.oss-cn-shanghai.aliyuncs.com/fdf556b61ea58156ff30f54502125e20.jpg");
i.setOriginUrl("https://test-houbo-homework.oss-cn-shanghai.aliyuncs.com/第2课测试-画鸡蛋测试-111-1553831-1662516935.jpg");
imageInfoList.add(i);

// 一、最简单的调用:
findViewById(R.id.buttonEasyUse).setOnClickListener(new View.OnClickListener() {
Expand Down
4 changes: 2 additions & 2 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
android:id="@+id/radioDefault"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:checked="true"
android:text="默认普清手动原图(默认模式)"
/>

Expand All @@ -312,7 +312,7 @@
android:id="@+id/radioAuto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:checked="false"
android:text="完全自适应(WiFi原图;流量普清、可查看原图)"
/>
</RadioGroup>
Expand Down

0 comments on commit fcb5092

Please sign in to comment.