This commit is contained in:
parent
f3be12177c
commit
0ecc077bc2
|
|
@ -13,11 +13,13 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
|
@ -29,11 +31,13 @@ import android.widget.TextView;
|
|||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.ifish.basebean.BaseBean;
|
||||
import com.ifish.basebean.EventBean;
|
||||
import com.ifish.basebean.LoadHeadImage;
|
||||
import com.ifish.basebean.User;
|
||||
import com.ifish.baseclass.BaseActivity;
|
||||
import com.ifish.baseclass.UriForFile;
|
||||
import com.ifish.utils.AnimationUtil;
|
||||
import com.ifish.utils.AppUtil;
|
||||
import com.ifish.utils.Commons;
|
||||
import com.ifish.utils.Commons.NetWork;
|
||||
import com.ifish.utils.Commons.Text;
|
||||
|
|
@ -44,7 +48,10 @@ import com.ifish.utils.L;
|
|||
import com.ifish.utils.SPUtil;
|
||||
import com.ifish.utils.ToastUtil;
|
||||
import com.ifish.view.CircleImageView;
|
||||
import com.ifish.view.picture.PictureSelectBean;
|
||||
import com.ifish.view.picture.PictureSelectorUtil;
|
||||
import com.luck.picture.lib.basic.PictureSelector;
|
||||
import com.luck.picture.lib.config.PictureConfig;
|
||||
import com.luck.picture.lib.config.SelectMimeType;
|
||||
import com.luck.picture.lib.config.SelectModeConfig;
|
||||
import com.luck.picture.lib.engine.CropEngine;
|
||||
|
|
@ -60,6 +67,7 @@ import java.io.File;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
|
|
@ -118,11 +126,7 @@ public class MineActivity extends BaseActivity {
|
|||
et_et.setText(Commons.USER.getSignature());
|
||||
et_username.setText(Commons.USER.getNickName());
|
||||
String wximg = sp.getString(Commons.LoginSPKey.WXIMAGE);
|
||||
if (!TextUtils.isEmpty(wximg)) {
|
||||
Picasso.with(MineActivity.this).load(wximg).error(R.drawable.ic_error).into(iv_head);
|
||||
} else {
|
||||
Picasso.with(MineActivity.this).load(HttpManager.HEAD_URL + Commons.USER.getUserImg()).error(R.drawable.ic_error).into(iv_head);
|
||||
}
|
||||
AppUtil.setHeader(this,iv_head,wximg);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -437,6 +441,8 @@ public class MineActivity extends BaseActivity {
|
|||
if (uploadFileResult == NetWork.Success) {
|
||||
Commons.USER.setUserImg(baseBean.data.getUserImg());
|
||||
}
|
||||
|
||||
EventBus.getDefault().post(new EventBean(EventBean.HEADER,mCompressPath));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -507,24 +513,29 @@ public class MineActivity extends BaseActivity {
|
|||
// Intent intent = new Intent(Intent.ACTION_PICK);
|
||||
// intent.setType("image/*");
|
||||
// startActivityForResult(intent, PHOTO_REQUEST_GALLERY);
|
||||
PictureSelector.create(this)
|
||||
.openGallery(SelectMimeType.ofImage())
|
||||
.setImageEngine(GlideEngine.createGlideEngine())
|
||||
.setSelectionMode(SelectModeConfig.SINGLE)
|
||||
|
||||
if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.R){
|
||||
if (!Environment.isExternalStorageManager()){
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
|
||||
intent.setData(Uri.parse("package:"+getPackageName()));
|
||||
startActivityForResult(intent,1024);
|
||||
}else {
|
||||
selectPic();
|
||||
}
|
||||
}else {
|
||||
selectPic();
|
||||
}
|
||||
|
||||
|
||||
.forResult(new OnResultCallbackListener<LocalMedia>() {
|
||||
@Override
|
||||
public void onResult(ArrayList<LocalMedia> result) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
|
||||
}
|
||||
});
|
||||
private void selectPic(){
|
||||
PictureSelectBean bean = new PictureSelectBean();
|
||||
bean.setCircle(true);
|
||||
bean.setWidth(1);
|
||||
bean.setHeigh(1);
|
||||
|
||||
PictureSelectorUtil.selectPic(this,bean);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -539,44 +550,100 @@ public class MineActivity extends BaseActivity {
|
|||
startActivityForResult(intent, PHOTO_REQUEST_CAMERA);
|
||||
}
|
||||
|
||||
private String mCompressPath = null;
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == PHOTO_REQUEST_GALLERY) {
|
||||
if (data != null) {
|
||||
// 得到图片的全路径
|
||||
Uri uri = data.getData();
|
||||
crop(uri);
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
} else if (requestCode == PHOTO_REQUEST_CAMERA) {
|
||||
if (hasSdcard()) {
|
||||
tempFile = new File(Environment.getExternalStorageDirectory(),
|
||||
PHOTO_FILE_NAME);
|
||||
crop(UriForFile.getUriForFile(MineActivity.this, tempFile));
|
||||
} else {
|
||||
ToastUtil.show(MineActivity.this, "未找到存储卡 无法存储照片");
|
||||
}
|
||||
if (resultCode == RESULT_OK){
|
||||
if (requestCode==1024 && Build.VERSION.SDK_INT >=Build.VERSION_CODES.R){
|
||||
selectPic();
|
||||
}else
|
||||
if (requestCode== PictureConfig.CHOOSE_REQUEST){
|
||||
ArrayList<LocalMedia> selectList = PictureSelector.obtainSelectorList(data);
|
||||
if (selectList!=null && selectList.size()>0){
|
||||
LocalMedia localMedia = selectList.get(0);
|
||||
if (localMedia.isCut()){
|
||||
mCompressPath = localMedia.getCutPath();
|
||||
}else
|
||||
{
|
||||
mCompressPath = localMedia.getCompressPath();
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(mCompressPath)){
|
||||
mCompressPath = localMedia.getRealPath();
|
||||
}
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
bitmap = Glide.with(MineActivity.this).asBitmap().load(mCompressPath).submit().get();
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
iv_head.setImageBitmap(bitmap);
|
||||
try {
|
||||
saveFile = saveFile(bitmap, PHOTO_FILE_NAME);//bitmap文件转成file
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (tempFile != null) {
|
||||
boolean delete = tempFile.delete();
|
||||
System.out.println("delete = " + delete);
|
||||
}
|
||||
upload(bitmap);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
} else if (requestCode == PHOTO_REQUEST_CUT) {
|
||||
try {
|
||||
bitmap = data.getParcelableExtra("data");
|
||||
this.iv_head.setImageBitmap(bitmap);
|
||||
if (!hasSdcard()) {//未找到SD卡
|
||||
ToastUtil.show(MineActivity.this, "未找到存储卡 无法存储照片");
|
||||
return;
|
||||
}
|
||||
saveFile = saveFile(bitmap, PHOTO_FILE_NAME);//bitmap文件转成file
|
||||
if (tempFile != null) {
|
||||
boolean delete = tempFile.delete();
|
||||
System.out.println("delete = " + delete);
|
||||
}
|
||||
upload(bitmap);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
ToastUtil.show(MineActivity.this, "未找到图片 请重试");
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
// if (requestCode == PHOTO_REQUEST_GALLERY) {
|
||||
// if (data != null) {
|
||||
// // 得到图片的全路径
|
||||
// Uri uri = data.getData();
|
||||
// crop(uri);
|
||||
// }
|
||||
//
|
||||
// } else if (requestCode == PHOTO_REQUEST_CAMERA) {
|
||||
// if (hasSdcard()) {
|
||||
// tempFile = new File(Environment.getExternalStorageDirectory(),
|
||||
// PHOTO_FILE_NAME);
|
||||
// crop(UriForFile.getUriForFile(MineActivity.this, tempFile));
|
||||
// } else {
|
||||
// ToastUtil.show(MineActivity.this, "未找到存储卡 无法存储照片");
|
||||
// }
|
||||
//
|
||||
// } else if (requestCode == PHOTO_REQUEST_CUT) {
|
||||
// try {
|
||||
// bitmap = data.getParcelableExtra("data");
|
||||
// this.iv_head.setImageBitmap(bitmap);
|
||||
// if (!hasSdcard()) {//未找到SD卡
|
||||
// ToastUtil.show(MineActivity.this, "未找到存储卡 无法存储照片");
|
||||
// return;
|
||||
// }
|
||||
// saveFile = saveFile(bitmap, PHOTO_FILE_NAME);//bitmap文件转成file
|
||||
// if (tempFile != null) {
|
||||
// boolean delete = tempFile.delete();
|
||||
// System.out.println("delete = " + delete);
|
||||
// }
|
||||
// upload(bitmap);
|
||||
// } catch (Exception e) {
|
||||
// System.out.println(e);
|
||||
// ToastUtil.show(MineActivity.this, "未找到图片 请重试");
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ public class EventBean {
|
|||
public static String TAB_INDEX = "tab_index";
|
||||
public static String LINK_FINISH = "link_finish";
|
||||
public static String CHANGE_DEVICE_NAME = "change_device_name";
|
||||
public static String HEADER = "header";
|
||||
|
||||
public EventBean(String name){
|
||||
this.name = name;
|
||||
|
|
|
|||
|
|
@ -942,13 +942,7 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
|||
private void loadHeadImage() {
|
||||
try {
|
||||
String wximg = sp.getString(Commons.LoginSPKey.WXIMAGE);
|
||||
if (!TextUtils.isEmpty(wximg)) {
|
||||
Picasso.with(getActivity()).invalidate(wximg);//清除缓存 重新加载图片
|
||||
Picasso.with(getActivity()).load(wximg).error(R.drawable.ic_error).into(iv_head);
|
||||
} else {
|
||||
Picasso.with(getActivity()).invalidate(HttpManager.HEAD_URL + Commons.USER.getUserImg());//清除缓存 重新加载图片
|
||||
Picasso.with(getActivity()).load(HttpManager.HEAD_URL + Commons.USER.getUserImg()).error(R.drawable.ic_error).into(iv_head);
|
||||
}
|
||||
AppUtil.setHeader(getActivity(),iv_head,wximg);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1945,6 +1939,8 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
|||
}else {
|
||||
oonPause();
|
||||
}
|
||||
}else if (EventBean.HEADER.equals(eventBean.name)){
|
||||
Glide.with(getActivity()).load(eventBean.value).into(iv_head);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.clj.fastble.BleManager;
|
||||
import com.ifish.activity.AboutActivity;
|
||||
import com.ifish.activity.CaptureActivity;
|
||||
import com.ifish.activity.DeviceInstructionActivity;
|
||||
|
|
@ -46,6 +48,7 @@ import com.ifish.activity.MySettingActivity;
|
|||
import com.ifish.activity.R;
|
||||
import com.ifish.activity.TellIfishActivity;
|
||||
import com.ifish.basebean.BaseBean;
|
||||
import com.ifish.basebean.EventBean;
|
||||
import com.ifish.basebean.FinishMainActivity;
|
||||
import com.ifish.basebean.LoadHeadImage;
|
||||
import com.ifish.basebean.MineNewInfo;
|
||||
|
|
@ -54,6 +57,7 @@ import com.ifish.baseclass.BaseV4Fragment;
|
|||
import com.ifish.baseclass.UriForFile;
|
||||
import com.ifish.utils.ActivityManager;
|
||||
import com.ifish.utils.AnimationUtil;
|
||||
import com.ifish.utils.AppUtil;
|
||||
import com.ifish.utils.Commons;
|
||||
import com.ifish.utils.Commons.NetWork;
|
||||
import com.ifish.utils.Commons.Text;
|
||||
|
|
@ -116,13 +120,7 @@ public class MineFragment extends BaseV4Fragment {
|
|||
private void loadHeadImage() {
|
||||
try {
|
||||
String wximg = SPUtil.getInstance(getActivity()).getString(Commons.LoginSPKey.WXIMAGE);
|
||||
if (!TextUtils.isEmpty(wximg)) {
|
||||
Picasso.with(getActivity()).invalidate(wximg);//清除缓存 重新加载图片
|
||||
Picasso.with(getActivity()).load(wximg).error(R.drawable.ic_error).into(iv_head);
|
||||
} else {
|
||||
Picasso.with(getActivity()).invalidate(HttpManager.HEAD_URL + Commons.USER.getUserImg());//清除缓存 重新加载图片
|
||||
Picasso.with(getActivity()).load(HttpManager.HEAD_URL + Commons.USER.getUserImg()).error(R.drawable.ic_error).into(iv_head);
|
||||
}
|
||||
AppUtil.setHeader(getActivity(),iv_head,wximg);
|
||||
L.d("用户头像=" + HttpManager.HEAD_URL + Commons.USER.getUserImg());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
|
@ -618,4 +616,12 @@ public class MineFragment extends BaseV4Fragment {
|
|||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public void onEventMainThread(EventBean eventBean){
|
||||
if (eventBean!= null){
|
||||
if (EventBean.HEADER.equals(eventBean.name)){
|
||||
Glide.with(getActivity()).load(eventBean.value).into(iv_head);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ifish.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothManager;
|
||||
import android.content.ComponentName;
|
||||
|
|
@ -7,11 +8,16 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.activity.ComponentActivity;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.ifish.activity.R;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -206,4 +212,18 @@ public class AppUtil {
|
|||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public static void setHeader(Activity activity,ImageView header,String weixin){
|
||||
String userImg = Commons.USER.getUserImg();
|
||||
if (!TextUtils.isEmpty(userImg)){
|
||||
Picasso.with(activity).invalidate(HttpManager.HEAD_URL + Commons.USER.getUserImg());//清除缓存 重新加载图片
|
||||
Picasso.with(activity).load(HttpManager.HEAD_URL + Commons.USER.getUserImg()).error(R.drawable.ic_error).into(header);
|
||||
}else {
|
||||
if (!TextUtils.isEmpty(weixin)) {
|
||||
Picasso.with(activity).invalidate(weixin);//清除缓存 重新加载图片
|
||||
Picasso.with(activity).load(weixin).error(R.drawable.ic_error).into(header);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,111 @@
|
|||
package com.ifish.view.picture;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.ifish.activity.R;
|
||||
import com.luck.picture.lib.engine.ImageEngine;
|
||||
import com.luck.picture.lib.utils.ActivityCompatHelper;
|
||||
|
||||
/**
|
||||
* @author:luck
|
||||
* @date:2019-11-13 17:02
|
||||
* @describe:Glide加载引擎
|
||||
*/
|
||||
public class GlideEngine implements ImageEngine {
|
||||
|
||||
/**
|
||||
* 加载图片
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 资源url
|
||||
* @param imageView 图片承载控件
|
||||
*/
|
||||
@Override
|
||||
public void loadImage(Context context, String url, ImageView imageView) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadImage(Context context, ImageView imageView, String url, int maxWidth, int maxHeight) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.override(maxWidth, maxHeight)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载相册目录封面
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 图片路径
|
||||
* @param imageView 承载图片ImageView
|
||||
*/
|
||||
@Override
|
||||
public void loadAlbumCover(Context context, String url, ImageView imageView) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.override(180, 180)
|
||||
.sizeMultiplier(0.5f)
|
||||
.transform(new CenterCrop(), new RoundedCorners(8))
|
||||
.placeholder(R.color.color_999999)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加载图片列表图片
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 图片路径
|
||||
* @param imageView 承载图片ImageView
|
||||
*/
|
||||
@Override
|
||||
public void loadGridImage(Context context, String url, ImageView imageView) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.override(200, 200)
|
||||
.centerCrop()
|
||||
.placeholder(R.color.color_999999)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseRequests(Context context) {
|
||||
Glide.with(context).pauseRequests();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeRequests(Context context) {
|
||||
Glide.with(context).resumeRequests();
|
||||
}
|
||||
|
||||
private GlideEngine() {
|
||||
}
|
||||
|
||||
private static final class InstanceHolder {
|
||||
static final GlideEngine instance = new GlideEngine();
|
||||
}
|
||||
|
||||
public static GlideEngine createGlideEngine() {
|
||||
return InstanceHolder.instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.ifish.view.picture;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.luck.picture.lib.engine.CompressFileEngine;
|
||||
import com.luck.picture.lib.interfaces.OnKeyValueResultCallbackListener;
|
||||
import com.luck.picture.lib.utils.DateUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import top.zibin.luban.Luban;
|
||||
import top.zibin.luban.OnNewCompressListener;
|
||||
import top.zibin.luban.OnRenameListener;
|
||||
|
||||
public class ImageFileCompressEngine implements CompressFileEngine {
|
||||
|
||||
@Override
|
||||
public void onStartCompress(Context context, ArrayList<Uri> source, OnKeyValueResultCallbackListener call) {
|
||||
Luban.with(context).load(source).ignoreBy(1000).setRenameListener(new OnRenameListener() {
|
||||
@Override
|
||||
public String rename(String filePath) {
|
||||
int indexOf = filePath.lastIndexOf(".");
|
||||
String postfix = indexOf != -1 ? filePath.substring(indexOf) : ".jpg";
|
||||
return DateUtils.getCreateFileName("CMP_") + postfix;
|
||||
}
|
||||
}).setCompressListener(new OnNewCompressListener() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String source, File compressFile) {
|
||||
if (call != null) {
|
||||
call.onCallback(source, compressFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String source, Throwable e) {
|
||||
if (call != null) {
|
||||
call.onCallback(source, null);
|
||||
}
|
||||
}
|
||||
}).launch();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,177 @@
|
|||
package com.ifish.view.picture;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.ifish.activity.R;
|
||||
import com.luck.picture.lib.config.PictureMimeType;
|
||||
import com.luck.picture.lib.engine.CropFileEngine;
|
||||
import com.luck.picture.lib.style.PictureSelectorStyle;
|
||||
import com.luck.picture.lib.style.SelectMainStyle;
|
||||
import com.luck.picture.lib.style.TitleBarStyle;
|
||||
import com.luck.picture.lib.utils.StyleUtils;
|
||||
import com.yalantis.ucrop.UCrop;
|
||||
import com.yalantis.ucrop.UCropImageEngine;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ImageFileCropEngine implements CropFileEngine {
|
||||
|
||||
private PictureSelectBean bean;
|
||||
private int height = 1, width = 2, maxNum = 9;
|
||||
|
||||
private boolean isCircle = false, freeStyle = false;
|
||||
|
||||
public ImageFileCropEngine() {
|
||||
|
||||
}
|
||||
|
||||
public ImageFileCropEngine(PictureSelectBean bean) {
|
||||
this.bean = bean;
|
||||
if (bean != null) {
|
||||
this.isCircle = bean.isCircle();
|
||||
if (isCircle) {
|
||||
this.height = 1;
|
||||
this.width = 1;
|
||||
} else {
|
||||
this.height = bean.getHeigh();
|
||||
this.width = bean.getWidth();
|
||||
}
|
||||
this.maxNum = bean.getMaxNum();
|
||||
this.freeStyle = bean.isFreeStyle();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartCrop(Fragment fragment, Uri srcUri, Uri destinationUri, ArrayList<String> dataSource, int requestCode) {
|
||||
UCrop.Options options = buildOptions(fragment.getContext());
|
||||
UCrop uCrop = UCrop.of(srcUri, destinationUri, dataSource);
|
||||
uCrop.withOptions(options);
|
||||
uCrop.setImageEngine(new UCropImageEngine() {
|
||||
@Override
|
||||
public void loadImage(Context context, String url, ImageView imageView) {
|
||||
if (!ImageLoaderUtils.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).load(url).override(180, 180).into(imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadImage(Context context, Uri url, int maxWidth, int maxHeight, OnCallbackListener<Bitmap> call) {
|
||||
Glide.with(context).asBitmap().load(url).override(maxWidth, maxHeight).into(new CustomTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
if (call != null) {
|
||||
call.onCall(resource);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
if (call != null) {
|
||||
call.onCall(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
uCrop.start(fragment.requireActivity(), fragment, requestCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 配制UCrop,可根据需求自我扩展
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private PictureSelectorStyle selectorStyle;
|
||||
|
||||
private UCrop.Options buildOptions(Context context) {
|
||||
selectorStyle = new PictureSelectorStyle();
|
||||
UCrop.Options options = new UCrop.Options();
|
||||
//是否显示裁剪菜单
|
||||
options.setHideBottomControls(true);
|
||||
//裁剪框or图片拖动
|
||||
options.setFreeStyleCropEnabled(freeStyle);
|
||||
//是否显示裁剪边框
|
||||
options.setShowCropFrame(true);
|
||||
//是否显示裁剪框网格
|
||||
options.setShowCropGrid(true);
|
||||
// 圆形头像裁剪模式
|
||||
options.setCircleDimmedLayer(isCircle);
|
||||
//裁剪比例
|
||||
if (width != -1) {
|
||||
options.withAspectRatio(width, height);
|
||||
}
|
||||
|
||||
//设置路径
|
||||
options.setCropOutputPathDir(getSandboxPath(context));
|
||||
options.isCropDragSmoothToCenter(false);
|
||||
//是否跳过gif裁剪
|
||||
options.setSkipCropMimeType(getNotSupportCrop(true));
|
||||
//是否禁止裁剪gif
|
||||
options.isForbidCropGifWebp(true);
|
||||
options.isForbidSkipMultipleCrop(false);
|
||||
options.setMaxScaleMultiplier(100);
|
||||
if (selectorStyle != null && selectorStyle.getSelectMainStyle().getStatusBarColor() != 0) {
|
||||
SelectMainStyle mainStyle = selectorStyle.getSelectMainStyle();
|
||||
boolean isDarkStatusBarBlack = mainStyle.isDarkStatusBarBlack();
|
||||
int statusBarColor = mainStyle.getStatusBarColor();
|
||||
options.isDarkStatusBarBlack(isDarkStatusBarBlack);
|
||||
if (StyleUtils.checkStyleValidity(statusBarColor)) {
|
||||
options.setStatusBarColor(statusBarColor);
|
||||
options.setToolbarColor(statusBarColor);
|
||||
} else {
|
||||
options.setStatusBarColor(ContextCompat.getColor(context, R.color.primary));
|
||||
options.setToolbarColor(ContextCompat.getColor(context, R.color.primary));
|
||||
}
|
||||
TitleBarStyle titleBarStyle = selectorStyle.getTitleBarStyle();
|
||||
if (StyleUtils.checkStyleValidity(titleBarStyle.getTitleTextColor())) {
|
||||
options.setToolbarWidgetColor(titleBarStyle.getTitleTextColor());
|
||||
} else {
|
||||
options.setToolbarWidgetColor(ContextCompat.getColor(context, R.color.white));
|
||||
}
|
||||
} else {
|
||||
options.setStatusBarColor(ContextCompat.getColor(context, R.color.primary));
|
||||
options.setToolbarColor(ContextCompat.getColor(context, R.color.primary));
|
||||
options.setToolbarWidgetColor(ContextCompat.getColor(context, R.color.white));
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建自定义输出目录
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getSandboxPath(Context context) {
|
||||
File externalFilesDir = context.getExternalFilesDir("");
|
||||
File customFile = new File(externalFilesDir.getAbsolutePath(), "Sandbox");
|
||||
if (!customFile.exists()) {
|
||||
customFile.mkdirs();
|
||||
}
|
||||
return customFile.getAbsolutePath() + File.separator;
|
||||
}
|
||||
|
||||
private String[] getNotSupportCrop(boolean isJump) {
|
||||
if (isJump) {
|
||||
return new String[]{PictureMimeType.ofGIF(), PictureMimeType.ofWEBP()};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.ifish.view.picture;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
|
||||
/**
|
||||
* @author:luck
|
||||
* @date:2021/7/14 3:15 PM
|
||||
* @describe:ImageLoaderUtils
|
||||
*/
|
||||
public class ImageLoaderUtils {
|
||||
|
||||
public static boolean assertValidRequest(Context context) {
|
||||
if (context instanceof Activity) {
|
||||
Activity activity = (Activity) context;
|
||||
return !isDestroy(activity);
|
||||
} else if (context instanceof ContextWrapper){
|
||||
ContextWrapper contextWrapper = (ContextWrapper) context;
|
||||
if (contextWrapper.getBaseContext() instanceof Activity){
|
||||
Activity activity = (Activity) contextWrapper.getBaseContext();
|
||||
return !isDestroy(activity);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isDestroy(Activity activity) {
|
||||
if (activity == null) {
|
||||
return true;
|
||||
}
|
||||
return activity.isFinishing() || activity.isDestroyed();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.ifish.view.picture
|
||||
|
||||
import com.luck.picture.lib.config.PictureConfig
|
||||
import com.luck.picture.lib.config.SelectMimeType
|
||||
|
||||
class PictureSelectBean {
|
||||
|
||||
var maxNum: Int = 9
|
||||
var width: Int = 3
|
||||
var heigh: Int = 2
|
||||
var type: Int = SelectMimeType.TYPE_IMAGE
|
||||
var isCircle: Boolean = false
|
||||
var isFreeStyle: Boolean = false
|
||||
var isCrop: Boolean = true
|
||||
var isCompress: Boolean = true
|
||||
var isSingle: Boolean = true
|
||||
var code: Int = PictureConfig.CHOOSE_REQUEST
|
||||
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
maxNum: Int = 9,
|
||||
width: Int = 3,
|
||||
heigh: Int = 2,
|
||||
type: Int = SelectMimeType.TYPE_IMAGE,
|
||||
isCircle: Boolean = false,
|
||||
isFreeStyle: Boolean = true,
|
||||
isSingle: Boolean = true,
|
||||
isCrop: Boolean = true,
|
||||
isCompress: Boolean = true,
|
||||
code: Int = PictureConfig.CHOOSE_REQUEST
|
||||
) {
|
||||
this.maxNum = maxNum
|
||||
this.width = width
|
||||
this.type = type
|
||||
this.heigh = heigh
|
||||
this.isCircle = isCircle
|
||||
this.isSingle = isSingle
|
||||
this.isCrop = isCrop
|
||||
this.isCompress = isCompress
|
||||
this.isFreeStyle = isFreeStyle
|
||||
this.code = code
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
package com.ifish.view.picture
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.ifish.activity.R
|
||||
import com.luck.picture.lib.basic.PictureSelector
|
||||
import com.luck.picture.lib.config.SelectModeConfig
|
||||
import com.luck.picture.lib.style.*
|
||||
import com.luck.picture.lib.utils.DensityUtil
|
||||
|
||||
|
||||
class PictureSelectorUtil {
|
||||
|
||||
|
||||
companion object {
|
||||
|
||||
// @JvmStatic
|
||||
// @JvmOverloads
|
||||
// fun selectPic(
|
||||
// context: Activity,
|
||||
// bean: PictureSelectBean
|
||||
// ) {
|
||||
// if (StringUtil.hasPermission(context, Manifest.permission.CAMERA)) {
|
||||
// selectPic2(context, bean)
|
||||
// } else {
|
||||
// EventBus.getDefault().post(bean)
|
||||
// }
|
||||
// }
|
||||
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun selectPic(
|
||||
context: Context,
|
||||
bean: PictureSelectBean
|
||||
) {
|
||||
PictureSelector.create(context)
|
||||
.openGallery(bean.type) //图片
|
||||
.setSelectorUIStyle(getStyle(context))//样式风格
|
||||
.setImageEngine(GlideEngine.createGlideEngine())
|
||||
.setMaxSelectNum(bean.maxNum) // 最大图片选择数量
|
||||
.setMinSelectNum(1) // 最小选择数量
|
||||
.setSelectionMode(if (bean.isSingle) SelectModeConfig.SINGLE else SelectModeConfig.MULTIPLE) // 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
|
||||
// .isPreviewImage(false)// 是否可预览图片 true or false
|
||||
.isDisplayCamera(true) //滑动选择
|
||||
.isFastSlidingSelect(false) //
|
||||
.setCropEngine(if (bean.isCrop) ImageFileCropEngine(bean) else null)
|
||||
.setCompressEngine(if (bean.isCompress) ImageFileCompressEngine() else null)
|
||||
.isGif(false) // 是否显示gif图片 true or false
|
||||
.forResult(bean.code)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getStyle(context: Context): PictureSelectorStyle? {
|
||||
val selectorStyle: PictureSelectorStyle? = PictureSelectorStyle()
|
||||
|
||||
|
||||
// 主体风格
|
||||
val numberSelectMainStyle = SelectMainStyle()
|
||||
numberSelectMainStyle.isSelectNumberStyle = true
|
||||
numberSelectMainStyle.isPreviewSelectNumberStyle = false
|
||||
numberSelectMainStyle.isPreviewDisplaySelectGallery = true
|
||||
// numberSelectMainStyle.selectBackground = R.drawable.ps_default_num_selector
|
||||
// numberSelectMainStyle.previewSelectBackground = R.drawable.ps_preview_checkbox_selector
|
||||
// numberSelectMainStyle.selectNormalBackgroundResources =
|
||||
// R.drawable.ps_select_complete_normal_bg
|
||||
numberSelectMainStyle.selectNormalTextColor =
|
||||
ContextCompat.getColor(context, R.color.ps_color_53575e)
|
||||
numberSelectMainStyle.selectNormalText = context.getString(R.string.ps_send)
|
||||
// numberSelectMainStyle.adapterPreviewGalleryBackgroundResource =
|
||||
// R.drawable.ps_preview_gallery_bg
|
||||
numberSelectMainStyle.adapterPreviewGalleryItemSize =
|
||||
DensityUtil.dip2px(context, 52f)
|
||||
numberSelectMainStyle.previewSelectText = context.getString(R.string.ps_select)
|
||||
numberSelectMainStyle.previewSelectTextSize = 14
|
||||
numberSelectMainStyle.previewSelectTextColor =
|
||||
ContextCompat.getColor(context, R.color.white)
|
||||
numberSelectMainStyle.previewSelectMarginRight =
|
||||
DensityUtil.dip2px(context, 6f)
|
||||
numberSelectMainStyle.selectBackgroundResources = R.drawable.ps_select_complete_bg
|
||||
numberSelectMainStyle.selectText = context.getString(R.string.ps_send_num)
|
||||
numberSelectMainStyle.selectTextColor =
|
||||
ContextCompat.getColor(context, R.color.white)
|
||||
numberSelectMainStyle.mainListBackgroundColor =
|
||||
ContextCompat.getColor(context, R.color.black)
|
||||
numberSelectMainStyle.isCompleteSelectRelativeTop = true
|
||||
numberSelectMainStyle.isPreviewSelectRelativeBottom = true
|
||||
numberSelectMainStyle.isAdapterItemIncludeEdge = false
|
||||
|
||||
// 头部TitleBar 风格
|
||||
|
||||
// 头部TitleBar 风格
|
||||
val numberTitleBarStyle = TitleBarStyle()
|
||||
numberTitleBarStyle.isHideCancelButton = true
|
||||
numberTitleBarStyle.isAlbumTitleRelativeLeft = true
|
||||
// if (cb_only_dir.isChecked()) {
|
||||
// numberTitleBarStyle.titleAlbumBackgroundResource = R.drawable.ps_demo_only_album_bg
|
||||
// } else {
|
||||
// numberTitleBarStyle.titleAlbumBackgroundResource = R.drawable.ps_album_bg
|
||||
// }
|
||||
// numberTitleBarStyle.titleAlbumBackgroundResource = R.drawable.ps_album_bg
|
||||
// numberTitleBarStyle.titleDrawableRightResource = R.drawable.ps_ic_grey_arrow
|
||||
// numberTitleBarStyle.previewTitleLeftBackResource = R.drawable.ps_ic_normal_back
|
||||
|
||||
// 底部NavBar 风格
|
||||
|
||||
// 底部NavBar 风格
|
||||
val numberBottomNavBarStyle = BottomNavBarStyle()
|
||||
numberBottomNavBarStyle.bottomPreviewNarBarBackgroundColor =
|
||||
ContextCompat.getColor(context, R.color.ps_color_half_grey)
|
||||
numberBottomNavBarStyle.bottomPreviewNormalText = context.getString(R.string.ps_preview)
|
||||
numberBottomNavBarStyle.bottomPreviewNormalTextColor =
|
||||
ContextCompat.getColor(context, R.color.ps_color_9b)
|
||||
numberBottomNavBarStyle.bottomPreviewNormalTextSize = 16
|
||||
numberBottomNavBarStyle.isCompleteCountTips = false
|
||||
numberBottomNavBarStyle.bottomPreviewSelectText =
|
||||
context.getString(R.string.ps_preview_num)
|
||||
numberBottomNavBarStyle.bottomPreviewSelectTextColor =
|
||||
ContextCompat.getColor(context, R.color.white)
|
||||
|
||||
|
||||
selectorStyle?.titleBarStyle = numberTitleBarStyle
|
||||
selectorStyle?.bottomBarStyle = numberBottomNavBarStyle
|
||||
selectorStyle?.selectMainStyle = numberSelectMainStyle
|
||||
|
||||
|
||||
val animationStyle = PictureWindowAnimationStyle()
|
||||
animationStyle.setActivityEnterAnimation(R.anim.ps_anim_up_in)
|
||||
animationStyle.setActivityExitAnimation(R.anim.ps_anim_down_out)
|
||||
selectorStyle?.windowAnimationStyle = animationStyle
|
||||
return selectorStyle;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate
|
||||
android:duration="300"
|
||||
android:fromYDelta="0%p"
|
||||
android:interpolator="@android:anim/accelerate_interpolator"
|
||||
android:toYDelta="100%p" />
|
||||
</set>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate
|
||||
android:interpolator="@android:anim/linear_interpolator"
|
||||
android:fromYDelta="100%p"
|
||||
android:toYDelta="0%p"
|
||||
android:duration="300"/>
|
||||
</set>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/primary" />
|
||||
<corners android:radius="5dp" />
|
||||
<padding
|
||||
android:bottom="5dp"
|
||||
android:left="10dp"
|
||||
android:right="10dp"
|
||||
android:top="5dp" />
|
||||
</shape>
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="province_line_border">#C7C7C7</color>
|
||||
<color name="primary">#00b7ee</color>
|
||||
<color name="blue_my">#00b7ee</color>
|
||||
<color name="blue_my_1">#00A0E9</color>
|
||||
<color name="blue_my_4">#00b4ef</color>
|
||||
|
|
@ -465,4 +466,8 @@
|
|||
<color name="color_393b42">#393b42</color>
|
||||
<color name="color_59B29C">#59B29C</color>
|
||||
<color name="color_333333">#333333</color>
|
||||
|
||||
<color name="ps_color_53575e">#53575e</color>
|
||||
<color name="ps_color_half_grey">#E6393a3e</color>
|
||||
<color name="ps_color_9b">#9b9b9b</color>
|
||||
</resources>
|
||||
|
|
@ -75,5 +75,9 @@
|
|||
|
||||
<string name="ap_connect_tip1">1、点击连接设备按钮以后,请耐心等待连接,如提示设备连接失败,请将插座断一次电,然后重新长按复位键13秒左右,再点连接设备</string>
|
||||
<string name="ap_connect_tip2">2、设备连接成功后会进入插座控制界面,过几秒当温度出现时,表示插座联网成功。</string>
|
||||
|
||||
<string name="ps_send_num">完成(%1$d/%2$d)</string>
|
||||
<string name="ps_send">完成</string>
|
||||
<string name="ps_select">选择</string>
|
||||
<string name="ps_preview_num">预览(%1$d)</string>
|
||||
<string name="ps_preview">预览</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Reference in New Issue