From 031d6e322821d59976e3ee2263f663605c3fc9fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=93=E4=B8=80=E6=96=87?= <35919502@qq.com> Date: Tue, 30 Jan 2018 16:54:15 +0800 Subject: [PATCH] 2.2.9 --- .../easyphotos/models/album/AlbumModel.java | 11 ++-- .../easyphotos/ui/EasyPhotosActivity.java | 31 ++++++----- .../easyphotos/ui/PreviewActivity.java | 1 + .../easyphotos/ui/PuzzleSelectorActivity.java | 5 ++ .../ui/widget/PressedImageView.java | 20 +++---- .../main/res/layout/activity_easy_photos.xml | 52 +++++++++---------- .../layout/activity_preview_easy_photos.xml | 1 - .../activity_puzzle_selector_easy_photos.xml | 5 -- sample/build.gradle | 7 ++- sample/src/main/AndroidManifest.xml | 1 + .../easyphotos/sample/MyApplication.java | 23 ++++++++ 11 files changed, 94 insertions(+), 63 deletions(-) create mode 100644 sample/src/main/java/com/huantansheng/easyphotos/sample/MyApplication.java diff --git a/easyPhotos/src/main/java/com/huantansheng/easyphotos/models/album/AlbumModel.java b/easyPhotos/src/main/java/com/huantansheng/easyphotos/models/album/AlbumModel.java index 7cb58375..1010ada1 100644 --- a/easyPhotos/src/main/java/com/huantansheng/easyphotos/models/album/AlbumModel.java +++ b/easyPhotos/src/main/java/com/huantansheng/easyphotos/models/album/AlbumModel.java @@ -29,17 +29,17 @@ public class AlbumModel { private static final String TAG = "AlbumModel"; public static AlbumModel instance; public Album album; - private CallBack callBack; + /** * AlbumModel构造方法 + * * @param act 调用专辑的活动实体类 * @param callBack 初始化全部专辑后的回调 */ private AlbumModel(final Activity act, AlbumModel.CallBack callBack) { album = new Album(); - this.callBack = callBack; - init(act); + init(act, callBack); } public static AlbumModel getInstance(final Activity act, AlbumModel.CallBack callBack) { @@ -57,12 +57,13 @@ public static void clear() { instance = null; } - private void init(final Activity act) { + private void init(final Activity act, final CallBack callBack) { new Thread(new Runnable() { @Override public void run() { initAlbum(act); - callBack.onAlbumWorkedCallBack(); + if (null != callBack) + callBack.onAlbumWorkedCallBack(); } }).start(); } diff --git a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/EasyPhotosActivity.java b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/EasyPhotosActivity.java index c24f1e4c..f0e3133c 100644 --- a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/EasyPhotosActivity.java +++ b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/EasyPhotosActivity.java @@ -7,7 +7,6 @@ import android.animation.ObjectAnimator; import android.app.Activity; import android.content.Intent; -import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Build; @@ -61,7 +60,7 @@ import java.util.Date; import java.util.Locale; -public class EasyPhotosActivity extends AppCompatActivity implements AlbumModel.CallBack, AlbumItemsAdapter.OnClickListener, PhotosAdapter.OnClickListener, AdListener, View.OnClickListener { +public class EasyPhotosActivity extends AppCompatActivity implements AlbumItemsAdapter.OnClickListener, PhotosAdapter.OnClickListener, AdListener, View.OnClickListener { private boolean isShowCamera, onlyStartCamera; @@ -97,6 +96,8 @@ public class EasyPhotosActivity extends AppCompatActivity implements AlbumModel. private TextView tvPermission; private View mBottomBar; + AlbumModel.CallBack albumModelCallBack; + public static void start(Activity activity, int requestCode) { Intent intent = new Intent(activity, EasyPhotosActivity.class); activity.startActivityForResult(intent, requestCode); @@ -118,7 +119,7 @@ protected void onCreate(Bundle savedInstanceState) { permissionView = (RelativeLayout) findViewById(R.id.rl_permissions_view); tvPermission = (TextView) findViewById(R.id.tv_permission); rootViewAlbumItems = (RelativeLayout) findViewById(R.id.root_view_album_items); - + setClick(R.id.iv_back); if (PermissionUtil.checkAndRequestPermissionsInActivity(this, getNeedPermissions())) { hasPermissions(); } @@ -132,7 +133,18 @@ private void hasPermissions() { } permissionView.setVisibility(View.GONE); AlbumModel.clear(); - albumModel = AlbumModel.getInstance(this, this); + albumModelCallBack = new AlbumModel.CallBack() { + @Override + public void onAlbumWorkedCallBack() { + runOnUiThread(new Runnable() { + @Override + public void run() { + onAlbumWorkedDo(); + } + }); + } + }; + albumModel = AlbumModel.getInstance(this, albumModelCallBack); } protected String[] getNeedPermissions() { @@ -395,15 +407,6 @@ private void onCameraResult() { } - @Override - public void onAlbumWorkedCallBack() { - runOnUiThread(new Runnable() { - @Override - public void run() { - onAlbumWorkedDo(); - } - }); - } private void onAlbumWorkedDo() { initView(); @@ -468,7 +471,7 @@ public int getSpanSize(int position) { initAlbumItems(); shouldShowMenuDone(); - setClick(R.id.tv_album_items, R.id.iv_album_items, R.id.root_view_album_items, R.id.iv_back, R.id.tv_done, R.id.tv_clear, R.id.tv_original, R.id.tv_preview, R.id.fab_camera, R.id.iv_second_menu, R.id.tv_puzzle); + setClick(R.id.tv_album_items, R.id.iv_album_items, R.id.root_view_album_items, R.id.tv_done, R.id.tv_clear, R.id.tv_original, R.id.tv_preview, R.id.fab_camera, R.id.iv_second_menu, R.id.tv_puzzle); } diff --git a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java index 92aa2d4b..1f38e67f 100644 --- a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java +++ b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java @@ -206,6 +206,7 @@ private void doBack() { } private void initView() { + findViewById(R.id.iv_back).setOnClickListener(this); mRootView = (FrameLayout) findViewById(R.id.m_root_view); mToolBar = (FrameLayout) findViewById(R.id.m_top_bar_layout); if (!SystemUtils.getInstance().hasNavigationBar(this)) { diff --git a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PuzzleSelectorActivity.java b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PuzzleSelectorActivity.java index 7198e311..87f122e9 100644 --- a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PuzzleSelectorActivity.java +++ b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PuzzleSelectorActivity.java @@ -76,10 +76,13 @@ protected void onCreate(Bundle savedInstanceState) { } private void initView() { + setClick(R.id.iv_back); tvAlbumItems = (PressedTextView) findViewById(R.id.tv_album_items); tvAlbumItems.setText(albumModel.getAlbumItems().get(0).name); rootSelectorView = (RelativeLayout) findViewById(R.id.m_selector_root); tvDone = (PressedTextView) findViewById(R.id.tv_done); + tvDone.setOnClickListener(this); + tvAlbumItems.setOnClickListener(this); initAlbumItems(); initPhotos(); initPreview(); @@ -109,6 +112,8 @@ private void initPhotos() { private void initAlbumItems() { rootViewAlbumItems = (RelativeLayout) findViewById(R.id.root_view_album_items); + rootViewAlbumItems.setOnClickListener(this); + setClick(R.id.iv_album_items); rvAlbumItems = (RecyclerView) findViewById(R.id.rv_album_items); LinearLayoutManager lm = new LinearLayoutManager(this); ArrayList list = new ArrayList(); diff --git a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/widget/PressedImageView.java b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/widget/PressedImageView.java index 3ae3ea59..e55771cd 100644 --- a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/widget/PressedImageView.java +++ b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/widget/PressedImageView.java @@ -1,8 +1,6 @@ package com.huantansheng.easyphotos.ui.widget; import android.content.Context; -import android.graphics.Color; -import android.graphics.PorterDuff; import android.support.annotation.Nullable; import android.util.AttributeSet; @@ -12,22 +10,22 @@ */ public class PressedImageView extends android.support.v7.widget.AppCompatImageView { - private int filterColor;//按压颜色 + private float scaleSize;//按压颜色 public PressedImageView(Context context) { super(context); - this.filterColor = Color.GRAY; + this.scaleSize = 0.97f; } public PressedImageView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); - this.filterColor = Color.GRAY; + this.scaleSize = 0.97f; } public PressedImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - this.filterColor = Color.GRAY; + this.scaleSize = 0.97f; } @@ -35,13 +33,15 @@ public PressedImageView(Context context, @Nullable AttributeSet attrs, int defSt public void setPressed(boolean pressed) { super.setPressed(pressed); if (isPressed()) { - setColorFilter(filterColor, PorterDuff.Mode.MULTIPLY); + setScaleX(this.scaleSize); + setScaleY(this.scaleSize); } else { - clearColorFilter(); + setScaleX(1.0f); + setScaleY(1.0f); } } - public void setPressedColor(int pressedColor) { - filterColor = pressedColor; + public void setScaleSize(float scaleSize) { + this.scaleSize = scaleSize; } } diff --git a/easyPhotos/src/main/res/layout/activity_easy_photos.xml b/easyPhotos/src/main/res/layout/activity_easy_photos.xml index a07d44ed..871518e7 100644 --- a/easyPhotos/src/main/res/layout/activity_easy_photos.xml +++ b/easyPhotos/src/main/res/layout/activity_easy_photos.xml @@ -27,6 +27,32 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/m_tool_bar_bottom_line" /> + + + + + + - - - - - diff --git a/easyPhotos/src/main/res/layout/activity_puzzle_selector_easy_photos.xml b/easyPhotos/src/main/res/layout/activity_puzzle_selector_easy_photos.xml index 4f251b07..9552b598 100644 --- a/easyPhotos/src/main/res/layout/activity_puzzle_selector_easy_photos.xml +++ b/easyPhotos/src/main/res/layout/activity_puzzle_selector_easy_photos.xml @@ -60,7 +60,6 @@ android:layout_marginRight="8dp" android:background="@drawable/bg_menu_done_easy_photos" android:gravity="center" - android:onClick="onClick" android:padding="6dp" android:textColor="@color/menu_text_easy_photos" android:textSize="12sp" @@ -81,7 +80,6 @@ android:layout_width="0dp" android:layout_height="0dp" android:background="@color/easy_photos_bar_primary_translation" - android:onClick="onClick" android:paddingEnd="8dp" android:paddingLeft="8dp" android:paddingRight="8dp" @@ -109,7 +107,6 @@ android:layout_height="0dp" android:gravity="center" android:minWidth="70dp" - android:onClick="onClick" android:paddingEnd="6dp" android:paddingLeft="16dp" android:paddingRight="6dp" @@ -123,7 +120,6 @@ android:id="@+id/iv_album_items" android:layout_width="wrap_content" android:layout_height="0dp" - android:onClick="onClick" android:paddingTop="8dp" app:layout_constraintBottom_toBottomOf="@+id/tv_album_items" app:layout_constraintLeft_toRightOf="@+id/tv_album_items" @@ -153,7 +149,6 @@ android:id="@+id/iv_back" android:layout_width="42dp" android:layout_height="42dp" - android:onClick="onClick" android:padding="10dp" app:layout_constraintLeft_toLeftOf="@+id/m_tool_bar" app:layout_constraintTop_toTopOf="@+id/m_tool_bar" diff --git a/sample/build.gradle b/sample/build.gradle index b730c9d4..7b85245e 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.huantansheng.easyphotos.sample" minSdkVersion 15 targetSdkVersion 27 - versionCode 1 - versionName "1.0" + versionCode 2 + versionName "1.0.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -37,4 +37,7 @@ dependencies { exclude group: "com.android.support" } annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0' + //检测内存泄漏 + debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4' + releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 59f48629..bfaf4d39 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@