Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

防止过度重绘和内存泄露及整理颜色资源 #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
*.iml
.gradle
/gradle
.idea
/local.properties
.DS_Store
/build
/captures
/screenshots
*.properties
gradlew
gradlew.bat

7 changes: 0 additions & 7 deletions imagepicker/src/main/java/com/lzy/imagepicker/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Environment;
import android.util.DisplayMetrics;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Random;

/**
* ================================================
* 作 者:jeasonlzy(廖子尧 Github地址:https://github.com/jeasonlzy0216
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ImageBaseActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawableResource(R.color.transparent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.lzy.imagepicker.ImagePicker;
import com.lzy.imagepicker.R;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public abstract class ImagePreviewBaseActivity extends ImageBaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_preview);
getWindow().setBackgroundDrawableResource(R.color.transparent);

mCurrentPosition = getIntent().getIntExtra(ImagePicker.EXTRA_SELECTED_IMAGE_POSITION, 0);
mImageItems = (ArrayList<ImageItem>) getIntent().getSerializableExtra(ImagePicker.EXTRA_IMAGE_ITEMS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
Expand Down Expand Up @@ -98,7 +99,7 @@ public enum Style {
private float mMaxScale = MAX_SCALE;//程序根据不同图片的大小,动态得到的最大缩放比
private boolean isInited = false; //是否经过了 onSizeChanged 初始化
private boolean mSaving = false; //是否正在保存
private static Handler mHandler = new InnerHandler();
private Handler mHandler = new InnerHandler(this);

public CropImageView(Context context) {
this(context, null);
Expand Down Expand Up @@ -584,26 +585,37 @@ private void saveOutput(Bitmap croppedImage, Bitmap.CompressFormat outputFormat,
}

private static class InnerHandler extends Handler {
public InnerHandler() {

private WeakReference<CropImageView> cropImageView;

InnerHandler(CropImageView view) {
super(Looper.getMainLooper());
cropImageView = new WeakReference<CropImageView>(view);
}

@Override
public void handleMessage(Message msg) {
File saveFile = (File) msg.obj;
switch (msg.what) {
case SAVE_SUCCESS:
if (mListener != null) mListener.onBitmapSaveSuccess(saveFile);
break;
case SAVE_ERROR:
if (mListener != null) mListener.onBitmapSaveError(saveFile);
break;
CropImageView view = cropImageView.get();
if (view != null){
view.handleMessage(msg);
}
}
}

private void handleMessage(Message msg) {
File saveFile = (File) msg.obj;
switch (msg.what) {
case SAVE_SUCCESS:
if (mListener != null) mListener.onBitmapSaveSuccess(saveFile);
break;
case SAVE_ERROR:
if (mListener != null) mListener.onBitmapSaveError(saveFile);
break;
}
}

/** 图片保存完成的监听 */
private static OnBitmapSaveCompleteListener mListener;
private OnBitmapSaveCompleteListener mListener;

public interface OnBitmapSaveCompleteListener {
void onBitmapSaveSuccess(File file);
Expand Down
2 changes: 1 addition & 1 deletion imagepicker/src/main/res/layout/activity_image_crop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical">

<include layout="@layout/include_top_bar"/>
Expand All @@ -15,6 +14,7 @@

<com.lzy.imagepicker.view.CropImageView
android:id="@+id/cv_crop_image"
android:background="@color/black"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Expand Down
5 changes: 2 additions & 3 deletions imagepicker/src/main/res/layout/activity_image_grid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical">

<include
Expand Down Expand Up @@ -51,7 +50,7 @@
android:singleLine="true"
android:text="全部图片"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textColor="@color/white"
android:textSize="16sp"/>

<Button
Expand All @@ -64,7 +63,7 @@
android:paddingRight="16dp"
android:text="预览(3)"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textColor="@color/white"
android:textSize="16sp"/>

<View
Expand Down
11 changes: 5 additions & 6 deletions imagepicker/src/main/res/layout/activity_image_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
android:id="@+id/content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000">
android:layout_height="match_parent">

<com.lzy.imagepicker.view.ViewPagerFixed
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"/>
android:background="@color/black"/>

<include
android:id="@+id/top_bar"
Expand All @@ -20,7 +19,7 @@
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:background="#cc22292c"
android:background="@color/theme_body"
android:visibility="gone">

<com.lzy.imagepicker.view.SuperCheckBox
Expand All @@ -31,7 +30,7 @@
android:layout_marginLeft="10dp"
android:paddingLeft="8dp"
android:text="原图(3.07M)"
android:textColor="#FFF"/>
android:textColor="@color/white"/>

<com.lzy.imagepicker.view.SuperCheckBox
android:id="@+id/cb_check"
Expand All @@ -45,6 +44,6 @@
android:includeFontPadding="true"
android:paddingLeft="8dp"
android:text="选择"
android:textColor="#ffffff"/>
android:textColor="@color/white"/>
</RelativeLayout>
</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:background="@color/white"
android:gravity="center_vertical"
android:orientation="horizontal">

Expand Down
6 changes: 3 additions & 3 deletions imagepicker/src/main/res/layout/include_top_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#cc22292c"
android:background="@color/theme_body"
android:clickable="true">

<ImageView
Expand Down Expand Up @@ -31,7 +31,7 @@
android:layout_marginLeft="8dp"
android:layout_toRightOf="@id/btn_back"
android:text="选择图片"
android:textColor="#ffffff"
android:textColor="@color/white"
android:textSize="16dp"/>

<Button
Expand All @@ -47,7 +47,7 @@
android:minWidth="50dp"
android:padding="8dp"
android:text="完成(3/9)"
android:textColor="#ffffff"
android:textColor="@color/white"
android:textSize="14dp"/>

<ImageView
Expand Down
2 changes: 1 addition & 1 deletion imagepicker/src/main/res/layout/pop_folder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
android:id="@+id/margin"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#0000"/>
android:background="@color/transparent"/>
</LinearLayout>
3 changes: 2 additions & 1 deletion imagepicker/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="theme_body">#cc22292c</color>
<color name="black">#000000</color>
<color name="white">@android:color/white</color>
<color name="black">@android:color/black</color>
<color name="status_bar">#303135</color>
<color name="top_bar">#9f556061</color>
<color name="transparent">#00000000</color>
Expand Down
8 changes: 4 additions & 4 deletions imagepicker/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<resources>
<string name="all_images">全部图片</string>
<string name="folder_image_count">共%1$d张</string>
<string name="preview_image_count">%1$s/%2$s</string>
<string name="select_limit">最多选择%1$s张图片</string>
<string name="preview_image_count">%1$d/%2$d</string>
<string name="select_limit">最多选择%1$d张图片</string>
<string name="complete">完成</string>
<string name="select_complete">完成(%1$s/%2$s)</string>
<string name="preview_count">预览(%1$s)</string>
<string name="select_complete">完成(%1$d/%2$d)</string>
<string name="preview_count">预览(%1$d)</string>
<string name="photo_crop">图片裁剪</string>
<string name="origin">原图</string>
<string name="origin_size">原图(%1$s)</string>
Expand Down