|
@@ -1,118 +0,0 @@
|
|
|
-package com.quansu.heifengwuliu.utils
|
|
|
-
|
|
|
-import android.R
|
|
|
-import android.app.Activity
|
|
|
-import android.content.Context
|
|
|
-import android.net.Uri
|
|
|
-import android.util.Log
|
|
|
-import android.util.SparseArray
|
|
|
-import android.view.View
|
|
|
-import android.view.ViewGroup
|
|
|
-import android.widget.ImageView
|
|
|
-import androidx.core.view.ViewCompat
|
|
|
-import com.github.ielse.imagewatcher.ImageWatcherHelper
|
|
|
-import java.util.*
|
|
|
-
|
|
|
-/**
|
|
|
- *Created by shihuiyun
|
|
|
- *on 2020/9/18
|
|
|
- */
|
|
|
-object LookImgsUtils {
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @param context
|
|
|
- * @param imageView 当前点击的图片的容器
|
|
|
- * @param i
|
|
|
- * @param list
|
|
|
- * @param imageViewslist
|
|
|
- */
|
|
|
- fun setDataImageWAtcher(context: Context, imageView: ImageView, i: Int, list: List<String>, imageViewslist: List<ImageView?>) {
|
|
|
- //图片
|
|
|
- val urls: MutableList<String> = ArrayList()
|
|
|
- for (ss in list) {
|
|
|
- if (ss.contains("?")) {
|
|
|
- val index = ss.indexOf("?")
|
|
|
- urls.add(ss.substring(0, index))
|
|
|
- Log.e("-shy-", "url=: " + ss.substring(0, index))
|
|
|
- // urls.add(url);
|
|
|
- } else {
|
|
|
- urls.add(ss)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //控件
|
|
|
- val imlist: MutableList<ImageView> = ArrayList()
|
|
|
- if (list.size == 1) {
|
|
|
- imlist.add(imageView)
|
|
|
- } else {
|
|
|
- Log.e("-shy-", "imageViewslist=: " + imageViewslist.size)
|
|
|
- imlist.addAll(imageViewslist)
|
|
|
- }
|
|
|
- setDataImageWAtcher(context, i, urls, imlist)
|
|
|
- }
|
|
|
-
|
|
|
- fun setDataImageWAtcher(context: Context, position: Int, images: List<String>, imageViewslist: List<ImageView>) {
|
|
|
- val mapping = SparseArray<ImageView>() // 这个请自行理解,
|
|
|
- val dataList: MutableList<Uri> = ArrayList()
|
|
|
- var clickedImage: ImageView? = null
|
|
|
- var i = 0
|
|
|
- for (iv in imageViewslist) {
|
|
|
- if (i == position) {
|
|
|
- clickedImage = iv
|
|
|
- }
|
|
|
- mapping.put(i, iv)
|
|
|
- // dataList.add(Uri.parse(images.get(i)));
|
|
|
- val ss = images[i]
|
|
|
- if (ss.contains("?")) {
|
|
|
- val substring = ss.substring(0, ss.indexOf("?"))
|
|
|
- dataList.add(Uri.parse(substring))
|
|
|
- } else {
|
|
|
- dataList.add(Uri.parse(ss))
|
|
|
- }
|
|
|
- i++
|
|
|
- }
|
|
|
- val iwHelper: ImageWatcherHelper = ImageWatcherHelper.with(context as Activity, LoadSimpleLoader()) // SimpleLoader demo中有简单实现
|
|
|
-
|
|
|
- // iwHelper.setTranslucentStatus(45);
|
|
|
- val layDecoration = DecorationLayout(context) // SimpleLoader demo中有简单实现
|
|
|
- iwHelper.setOnStateChangedListener(object : OnStateChangedListener() {
|
|
|
- fun onStateChangeUpdate(imageWatcher: ImageWatcher?, imageView: ImageView?, i: Int, uri: Uri?, v: Float, i1: Int) {}
|
|
|
- fun onStateChanged(imageWatcher: ImageWatcher?, i: Int, uri: Uri?, actionTag: Int) {
|
|
|
- if (actionTag == ImageWatcher.STATE_ENTER_DISPLAYING) {
|
|
|
- App.getInstance().iwHelper = iwHelper
|
|
|
- // layDecoration.setVisibility(VISIBLE);
|
|
|
- } else if (actionTag == ImageWatcher.STATE_EXIT_HIDING) { //退出了查看大图
|
|
|
-// layDecoration.setVisibility(GONE);
|
|
|
- App.getInstance().iwHelper = null
|
|
|
- }
|
|
|
- }
|
|
|
- }).setOtherView(layDecoration)
|
|
|
- .addOnPageChangeListener(layDecoration)
|
|
|
- .setLoadingUIProvider(CustomLoadingUIProvider2())
|
|
|
- App.getInstance().iwHelper = iwHelper
|
|
|
- layDecoration.attachImageWatcher(iwHelper)
|
|
|
- iwHelper.show(clickedImage, mapping, dataList)
|
|
|
- fitsSystemWindow(context, layDecoration)
|
|
|
- }
|
|
|
-
|
|
|
- private fun fitsSystemWindow(activity: Activity, otherView: View) {
|
|
|
- var adjustByRoot = false
|
|
|
- val content = activity.findViewById<View>(R.id.content)
|
|
|
- if (content is ViewGroup) {
|
|
|
- val root = content.getChildAt(0)
|
|
|
- if (root != null) {
|
|
|
- val fitsSystemWindows = ViewCompat.getFitsSystemWindows(root)
|
|
|
- if (fitsSystemWindows) {
|
|
|
- otherView.setPadding(root.paddingLeft, root.paddingTop, root.paddingRight, root.paddingBottom)
|
|
|
- adjustByRoot = true
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!adjustByRoot) {
|
|
|
- ViewCompat.requestApplyInsets(otherView)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|