diff --git a/.gitignore b/.gitignore index 08a8c4d..f1e3e17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,13 @@ *.iml .gradle +/gradle .idea /local.properties .DS_Store /build /captures /screenshots +*.properties +gradlew +gradlew.bat + diff --git a/imagepicker/src/main/java/com/lzy/imagepicker/Utils.java b/imagepicker/src/main/java/com/lzy/imagepicker/Utils.java index 99e109f..530b839 100644 --- a/imagepicker/src/main/java/com/lzy/imagepicker/Utils.java +++ b/imagepicker/src/main/java/com/lzy/imagepicker/Utils.java @@ -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 diff --git a/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImageBaseActivity.java b/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImageBaseActivity.java index f197143..fe98124 100644 --- a/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImageBaseActivity.java +++ b/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImageBaseActivity.java @@ -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); } diff --git a/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImageCropActivity.java b/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImageCropActivity.java index 73ea96a..75811e0 100644 --- a/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImageCropActivity.java +++ b/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImageCropActivity.java @@ -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; diff --git a/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewBaseActivity.java b/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewBaseActivity.java index cde63b0..aacf7d7 100644 --- a/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewBaseActivity.java +++ b/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewBaseActivity.java @@ -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) getIntent().getSerializableExtra(ImagePicker.EXTRA_IMAGE_ITEMS); diff --git a/imagepicker/src/main/java/com/lzy/imagepicker/view/CropImageView.java b/imagepicker/src/main/java/com/lzy/imagepicker/view/CropImageView.java index a5463ba..d553575 100644 --- a/imagepicker/src/main/java/com/lzy/imagepicker/view/CropImageView.java +++ b/imagepicker/src/main/java/com/lzy/imagepicker/view/CropImageView.java @@ -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; @@ -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); @@ -584,26 +585,37 @@ private void saveOutput(Bitmap croppedImage, Bitmap.CompressFormat outputFormat, } private static class InnerHandler extends Handler { - public InnerHandler() { + + private WeakReference cropImageView; + + InnerHandler(CropImageView view) { super(Looper.getMainLooper()); + cropImageView = new WeakReference(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); diff --git a/imagepicker/src/main/res/layout/activity_image_crop.xml b/imagepicker/src/main/res/layout/activity_image_crop.xml index 2a08917..41b8f1e 100644 --- a/imagepicker/src/main/res/layout/activity_image_crop.xml +++ b/imagepicker/src/main/res/layout/activity_image_crop.xml @@ -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"> @@ -15,6 +14,7 @@ diff --git a/imagepicker/src/main/res/layout/activity_image_grid.xml b/imagepicker/src/main/res/layout/activity_image_grid.xml index 4ec4dc6..2866a55 100644 --- a/imagepicker/src/main/res/layout/activity_image_grid.xml +++ b/imagepicker/src/main/res/layout/activity_image_grid.xml @@ -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">