Skip to content

Commit

Permalink
Optimize preview performance,clean file
Browse files Browse the repository at this point in the history
  • Loading branch information
limuyang committed Oct 16, 2018
1 parent 52ac475 commit f0ae2ea
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 110 deletions.
18 changes: 8 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
compileSdkVersion 28
defaultConfig {
applicationId "top.limuyang2.pohotopicker"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

renderscriptTargetApi 27
renderscriptTargetApi 28
renderscriptSupportModeEnabled true
ndk {
abiFilters "x86", "armeabi-v7a"
Expand All @@ -36,21 +36,19 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation 'com.github.bumptech.glide:glide:4.7.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'

implementation 'pub.devrel:easypermissions:1.2.0'
implementation 'pub.devrel:easypermissions:2.0.0'
implementation 'com.github.yalantis:ucrop:2.2.2'

// implementation project(path:':library')
implementation project(path:':photolibrary')

// implementation 'com.zhihu.android:matisse:0.5.1-beta1'
}
7 changes: 3 additions & 4 deletions photolibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 27



defaultConfig {
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0.2"
versionName "1.0.3"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand All @@ -36,6 +34,7 @@ dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:exifinterface:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

testImplementation 'junit:junit:4.12'
Expand All @@ -45,7 +44,7 @@ dependencies {
implementation 'com.github.mmin18:realtimeblurview:1.1.2'
implementation 'com.github.bumptech.glide:glide:4.7.1'
implementation 'org.jetbrains.anko:anko-coroutines:0.10.5'
implementation 'com.github.chrisbanes:PhotoView:2.1.4'
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import top.limuyang2.photolibrary.popwindow.LPhotoFolderPopWin
import top.limuyang2.photolibrary.util.*



/**
*
* Date 2018/7/31
Expand All @@ -38,7 +37,7 @@ import top.limuyang2.photolibrary.util.*
class LPhotoPickerActivity : LBaseActivity() {

companion object {
// private const val EXTRA_CAMERA_FILE_DIR = "EXTRA_CAMERA_FILE_DIR"
// private const val EXTRA_CAMERA_FILE_DIR = "EXTRA_CAMERA_FILE_DIR"
private const val EXTRA_SELECTED_PHOTOS = "EXTRA_SELECTED_PHOTOS"
private const val EXTRA_MAX_CHOOSE_COUNT = "EXTRA_MAX_CHOOSE_COUNT"
private const val EXTRA_PAUSE_ON_SCROLL = "EXTRA_PAUSE_ON_SCROLL"
Expand All @@ -49,18 +48,11 @@ class LPhotoPickerActivity : LBaseActivity() {

private val STATE_SELECTED_PHOTOS = "STATE_SELECTED_PHOTOS"

/**
* 拍照的请求码
*/
private val REQUEST_CODE_TAKE_PHOTO = 1
/**
* 预览照片的请求码
*/
private val RC_PREVIEW_CODE = 2

private val SPAN_COUNT = 3


/**
* 获取已选择的图片集合
*
Expand All @@ -76,13 +68,13 @@ class LPhotoPickerActivity : LBaseActivity() {
class IntentBuilder(context: Context) {
private val mIntent: Intent = Intent(context, LPhotoPickerActivity::class.java)

// /**
// * 拍照后图片保存的目录。如果传 null 表示没有拍照功能,如果不为 null 则具有拍照功能,
// */
// fun cameraFileDir(cameraFileDir: File?): IntentBuilder {
// mIntent.putExtra(EXTRA_CAMERA_FILE_DIR, cameraFileDir)
// return this
// }
// /**
// * 拍照后图片保存的目录。如果传 null 表示没有拍照功能,如果不为 null 则具有拍照功能,
// */
// fun cameraFileDir(cameraFileDir: File?): IntentBuilder {
// mIntent.putExtra(EXTRA_CAMERA_FILE_DIR, cameraFileDir)
// return this
// }

/**
* 需要显示哪种类型的图片(JPG\PNG\GIF\WEBP),默认全部加载
Expand Down Expand Up @@ -159,8 +151,8 @@ class LPhotoPickerActivity : LBaseActivity() {
}
}

// // 获取拍照图片保存目录
// private val cameraFileDir by lazy { intent.getSerializableExtra(EXTRA_CAMERA_FILE_DIR) as File }
// // 获取拍照图片保存目录
// private val cameraFileDir by lazy { intent.getSerializableExtra(EXTRA_CAMERA_FILE_DIR) as File }

// 获取图片选择的最大张数
private val maxChooseCount by lazy { intent.getIntExtra(EXTRA_MAX_CHOOSE_COUNT, 1) }
Expand Down Expand Up @@ -253,7 +245,7 @@ class LPhotoPickerActivity : LBaseActivity() {

val bottomBarEnableTextColor = typedArray.getColor(R.styleable.LPPAttr_l_pp_picker_bottomBar_enabled_text_color, Color.parseColor("#333333"))
val bottomBarUnEnableTextColor = typedArray.getColor(R.styleable.LPPAttr_l_pp_picker_bottomBar_unEnabled_text_color, Color.GRAY)
val colors = intArrayOf(bottomBarEnableTextColor, bottomBarUnEnableTextColor)
val colors = intArrayOf(bottomBarEnableTextColor, bottomBarUnEnableTextColor)
val states = arrayOfNulls<IntArray>(2)
states[0] = intArrayOf(android.R.attr.state_enabled)
states[1] = intArrayOf(android.R.attr.state_window_focused)
Expand Down Expand Up @@ -320,8 +312,10 @@ class LPhotoPickerActivity : LBaseActivity() {

override fun initData() {
async(UI) {
val photoModelList = bg { findPhoto(this@LPhotoPickerActivity, showTypeArray) }.await()
this@LPhotoPickerActivity.photoModelList.addAll(photoModelList)
bg {
val list = findPhoto(this@LPhotoPickerActivity, showTypeArray)
this@LPhotoPickerActivity.photoModelList.addAll(list)
}.await()

reloadPhotos(0)
}
Expand Down Expand Up @@ -390,7 +384,7 @@ class LPhotoPickerActivity : LBaseActivity() {
}
}

Activity.RESULT_OK -> {
Activity.RESULT_OK -> {
data?.let {
returnSelectedPhotos(LPhotoPickerPreviewActivity.getSelectedPhotos(it))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ import top.limuyang2.photolibrary.adapter.LPreviewPagerAdapter
import top.limuyang2.photolibrary.util.dp2px
import top.limuyang2.photolibrary.util.getStatusBarHeight

/**
* 预览界面
* @property nowSelectedPhotos ArrayList<String>
* @property intentMaxChooseCount Int
* @property intentSelectedPhotos (java.util.ArrayList<(kotlin.String..kotlin.String?)>..java.util.ArrayList<(kotlin.String..kotlin.String?)>?)
* @property viewPageAdapter LPreviewPagerAdapter
* @property currentPath String
* @property mIsHidden Boolean
*/
@SuppressLint("SetTextI18n")
class LPhotoPickerPreviewActivity : LBaseActivity() {

Expand All @@ -47,7 +56,7 @@ class LPhotoPickerPreviewActivity : LBaseActivity() {
viewPage.adapter = viewPageAdapter
}

var currentPath = ""
private var currentPath = ""

override fun initListener() {
toolBar.setNavigationOnClickListener { onBackPressed() }
Expand Down Expand Up @@ -126,7 +135,7 @@ class LPhotoPickerPreviewActivity : LBaseActivity() {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = Color.TRANSPARENT
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}

//获取状态栏高度,设置顶部layout高度
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package top.limuyang2.photolibrary.fragment

import android.content.Context
import android.graphics.BitmapFactory
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.davemorrissey.labs.subscaleview.ImageSource
import kotlinx.android.synthetic.main.l_pp_fragment_preview_item.view.*
import top.limuyang2.photolibrary.R
import top.limuyang2.photolibrary.activity.LPhotoPickerPreviewActivity
import top.limuyang2.photolibrary.util.ImageEngineUtils


/**
Expand Down Expand Up @@ -40,36 +39,18 @@ class LPreviewItemFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.photoView.setOnPhotoTapListener { _, _, _ ->
if (System.currentTimeMillis() - mLastShowHiddenTime > 300) {
mLastShowHiddenTime = System.currentTimeMillis()

if (mContext is LPhotoPickerPreviewActivity) {
val activity = mContext as LPhotoPickerPreviewActivity
activity.changeToolBar()
}
view.photoView.setOnClickListener {
if (System.currentTimeMillis() - mLastShowHiddenTime > 500) {
mLastShowHiddenTime = System.currentTimeMillis()

if (mContext is LPhotoPickerPreviewActivity) {
val activity = mContext as LPhotoPickerPreviewActivity
activity.changeToolBar()
}
}
}

load()
}

private fun load() {
view?.let {

val options = BitmapFactory.Options()
/**
* 最关键在此,把options.inJustDecodeBounds = true;
* 这里再decodeFile(),返回的bitmap为空,但此时调用options.outHeight时,已经包含了图片的高了
*/
options.inJustDecodeBounds = true
BitmapFactory.decodeFile(path, options) // 此时返回的bitmap为null
/**
*options.outHeight为原始图片的高
*/
ImageEngineUtils.engine.load(mContext, it.photoView, path, R.drawable.ic_l_pp_ic_holder_light, options.outWidth, options.outHeight)

}
view.photoView.setImage(ImageSource.uri(path ?: ""))
}

companion object {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent">


<com.github.chrisbanes.photoview.PhotoView
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/photoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />




android:layout_height="match_parent"/>

</LinearLayout>
18 changes: 0 additions & 18 deletions photolibrary/src/main/res/layout/l_pp_layout_toolbar.xml

This file was deleted.

4 changes: 0 additions & 4 deletions photolibrary/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
<attr name="l_pp_checkBox_stroke_width" format="dimension"/><!--(预览页面)边框宽度-->
<attr name="l_pp_checkBox_tick_width" format="dimension"/><!--勾勾的线条宽度-->





</declare-styleable>


Expand Down
2 changes: 0 additions & 2 deletions photolibrary/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
<!-- colorPrimary的颜色 -->
<color name="l_pp_colorPrimary">#169ce4</color>


<!-- 文件夹名称颜色 -->
<color name="l_pp_folder_name_textColor">#333333</color>
<!-- 文件夹中照片数量颜色 -->
<color name="l_pp_folder_count_textColor">#585858</color>
<!-- 图片条目背景色 -->
<color name="l_pp_popWindow_bg">#f9f9f9</color>


<color name="l_pp_photo_preview_bg">#000</color>

</resources>
8 changes: 0 additions & 8 deletions photolibrary/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
<resources>

<string name="l_pp_take_picture">拍摄照片</string>
<string name="l_pp_not_support_take_photo">当前设备不支持拍照</string>
<string name="l_pp_not_support_crop">当前设备不支持裁剪图片</string>
<string name="l_pp_toast_photo_picker_max">最多只能选择 %1$d 张图片</string>
<string name="l_pp_all_image">所有图片</string>
<string name="l_pp_preview">预览</string>
<string name="l_pp_apply">使用</string>
<string name="l_pp_view_photo">查看图片</string>
<string name="l_pp_download_img_failure">下载到图片失败</string>
<string name="l_pp_save_img_failure">保存图片失败,再试试?</string>
<string name="l_pp_save_img_success_folder">图片已保存至 %s 文件夹</string>

</resources>
4 changes: 0 additions & 4 deletions photolibrary/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
<item name="android:navigationBarColor" tools:targetApi="lollipop">
@color/l_pp_navigationBarColor
</item>




</style>

<style name="LPPDialog">
Expand Down

0 comments on commit f0ae2ea

Please sign in to comment.