Skip to content

Commit

Permalink
切换回原来的图片视图控件
Browse files Browse the repository at this point in the history
  • Loading branch information
你需要一台永动机 committed Mar 21, 2019
1 parent ddbad10 commit 84b14af
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 51 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ dependencies {
api 'com.romandanylyk:pageindicatorview:1.0.1@aar'
//nineold 配合下拉图片
api 'com.nineoldandroids:library:2.4.0'
//显示大图
compile 'com.shizhefei:LargeImageView:1.1.0'
}
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class DragViewPager : ViewPager, View.OnClickListener {
currentPageStatus = state
}
})
//默认设置自己为显示视图
setCurrentShowView(this)
}


Expand All @@ -87,6 +85,7 @@ class DragViewPager : ViewPager, View.OnClickListener {
override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
if (adapter !is DragViewAdapter) return super.onInterceptTouchEvent(ev)
val mImage: LargeImageView? = (adapter as DragViewAdapter).getImageView(currentItem) //特殊操作
setCurrentShowView(mImage)
if (mImage == null) return super.onInterceptTouchEvent(ev)
val canPullDown = mImage.canScrollVertically(0)//是否可以下拉
when (ev.action) {
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ allprojects {
jcenter()
google()
maven { url "https://jitpack.io" }
// maven { url "https://dl.bintray.com/yongdongji/android" }
}
//加上这些
tasks.withType(Javadoc) {
Expand Down
4 changes: 2 additions & 2 deletions imagepicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ dependencies {
compile "com.github.caoyanglee:universalui:$rootProject.universal_view"
//裁剪图
compile 'com.isseiaoki:simplecropview:1.1.7@aar'
//图片预览
compile 'com.github.chrisbanes:PhotoView:2.1.3'
//鲁班压缩
compile 'top.zibin:Luban:1.1.3'
//显示大图
compile 'com.shizhefei:LargeImageView:1.1.0'
}
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ internal class ImageSelectorActivity : BaseActivity() {

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
fun startPreviewWithAnim(previewImages: List<LocalMedia>, position: Int, view: View) {
ImagePreviewActivity.startPreview(this, imageAdapter.selectedImages, maxSelectNum, position)
ImagePreviewActivity.startPreviewWithAnim(this, imageAdapter.selectedImages, maxSelectNum, position,view)
}

fun startPreview(previewImages: List<LocalMedia>, position: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.weimu.imagepicker.ui.preview

import android.content.Context
import android.support.v4.view.ViewPager
import android.util.AttributeSet
import android.view.MotionEvent

/**
* Author:你需要一台永动机
* Date:2019/3/21 10:36
* Description:防止图片放大闪退
*/
class HackyViewPager : ViewPager {

constructor(context: Context) : super(context) {}

constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}

override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
try {
return super.onInterceptTouchEvent(ev)
} catch (e: IllegalArgumentException) {
return false
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ internal class ImagePreviewActivity : BaseActivity() {
intent.putExtra(OUTPUT_ISDONE, isDone)
setResult(Activity.RESULT_OK, intent)
super.onBackPressed()
overridePendingTransition(-1, R.anim.fade_out)
//overridePendingTransition(-1, R.anim.fade_out)
}

override fun onBackPressed() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.weimu.imagepicker.ui.preview

import android.graphics.BitmapFactory
import android.os.Bundle
import com.shizhefei.view.largeimage.factory.FileBitmapDecoderFactory
import com.weimu.imagepicker.R
import com.weimu.universalview.core.fragment.BaseFragment
import com.weimu.universalview.ktx.load
import kotlinx.android.synthetic.main.fragment_image_preview.*
import java.io.File


internal class ImagePreviewFragment : BaseFragment() {

private var path = ""

companion object {

val PATH = "path"
Expand All @@ -24,48 +24,18 @@ internal class ImagePreviewFragment : BaseFragment() {
}
}

override fun afterViewAttachBaseViewAction(savedInstanceState: Bundle?) {}

override fun beforeViewAttachBaseViewAction(savedInstanceState: Bundle?) {}

override fun getLayoutResID(): Int = R.layout.fragment_image_preview

override fun beforeViewAttach(savedInstanceState: Bundle?) {
path = "${arguments!!.getString(PATH)}"
}

override fun afterViewAttach(savedInstanceState: Bundle?) {
showImage(File("${arguments!!.getString(PATH)}"))
iv_large.setOnClickListener {
photo_view.load(path)
photo_view.setOnPhotoTapListener { view, x, y ->
val activity = activity as ImagePreviewActivity
activity.isShowBar = !activity.isShowBar
}
}


//显示图片
private fun showImage(file: File) {
if (iv_large == null) return
try {
val options = BitmapFactory.Options()
/**
* 最关键在此,把options.inJustDecodeBounds = true;
* 这里再decodeFile(),返回的bitmap为空,但此时调用options.outHeight时,已经包含了图片的高了
*/
options.inJustDecodeBounds = true

val targetBitmap = BitmapFactory.decodeFile(file.toString())// 此时返回的bitmap为null

val bitmapHeight = targetBitmap.height
val bitmapWidth = targetBitmap.width
if (bitmapHeight >= 4 * bitmapWidth || bitmapWidth >= 4 * bitmapHeight) {
//加载大图
iv_large?.setImage(FileBitmapDecoderFactory(file))
} else {
//加载普通图
iv_large.setImage(targetBitmap)
}
} catch (e: OutOfMemoryError) {
iv_large?.setImage(FileBitmapDecoderFactory(file))
} catch (e: Exception) {
iv_large?.setImage(FileBitmapDecoderFactory(file))
}
}

}
2 changes: 1 addition & 1 deletion imagepicker/src/main/res/layout/activity_image_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:layout_height="match_parent">


<android.support.v4.view.ViewPager
<com.weimu.imagepicker.ui.preview.HackyViewPager
android:id="@+id/drag_viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
9 changes: 5 additions & 4 deletions imagepicker/src/main/res/layout/fragment_image_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
android:layout_height="match_parent"
android:orientation="vertical">

<com.shizhefei.view.largeimage.LargeImageView
android:id="@+id/iv_large"

<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical|horizontal" />
android:layout_height="match_parent"/>

</LinearLayout>
1 change: 1 addition & 0 deletions imagepicker/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">图片选择器</string>
<string name="all_image">所有图片</string>
<string name="take_picture">拍摄照片</string>
<string name="preview_num">预览(%1$s)</string>
Expand Down

0 comments on commit 84b14af

Please sign in to comment.