|
|
|
|
@@ -2,22 +2,19 @@ package cc.winboll.studio.powerbell.dialogs;
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
import cc.winboll.studio.libappbase.LogUtils;
|
|
|
|
|
import cc.winboll.studio.powerbell.MainActivity;
|
|
|
|
|
import cc.winboll.studio.powerbell.R;
|
|
|
|
|
import cc.winboll.studio.powerbell.activities.BackgroundSettingsActivity;
|
|
|
|
|
import cc.winboll.studio.powerbell.utils.BackgroundSourceUtils;
|
|
|
|
|
import cc.winboll.studio.powerbell.utils.FileUtils;
|
|
|
|
|
import cc.winboll.studio.powerbell.utils.UriUtil;
|
|
|
|
|
import cc.winboll.studio.powerbell.views.BackgroundView;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
|
|
|
|
@@ -29,21 +26,25 @@ public class BackgroundPicturePreviewDialog extends Dialog {
|
|
|
|
|
public static final String TAG = "BackgroundPicturePreviewDialog";
|
|
|
|
|
|
|
|
|
|
Context mContext;
|
|
|
|
|
BackgroundSourceUtils mBackgroundPictureUtils;
|
|
|
|
|
//BackgroundSourceUtils mBackgroundPictureUtils;
|
|
|
|
|
Button dialogbackgroundpicturepreviewButton1;
|
|
|
|
|
Button dialogbackgroundpicturepreviewButton2;
|
|
|
|
|
String mszPreReceivedFileName;
|
|
|
|
|
//String mszPreReceivedFileName;
|
|
|
|
|
IOnRecivedPictureListener mIOnRecivedPictureListener;
|
|
|
|
|
Uri mUriRecivedPicture;
|
|
|
|
|
BackgroundView mBackgroundView;
|
|
|
|
|
|
|
|
|
|
public BackgroundPicturePreviewDialog(Context context) {
|
|
|
|
|
public BackgroundPicturePreviewDialog(Context context, IOnRecivedPictureListener iOnRecivedPictureListener) {
|
|
|
|
|
super(context);
|
|
|
|
|
setContentView(R.layout.dialog_backgroundpicturepreview);
|
|
|
|
|
initEnv();
|
|
|
|
|
mIOnRecivedPictureListener = iOnRecivedPictureListener;
|
|
|
|
|
//initEnv();
|
|
|
|
|
|
|
|
|
|
mContext = context;
|
|
|
|
|
mBackgroundPictureUtils = BackgroundSourceUtils.getInstance(mContext);
|
|
|
|
|
//mBackgroundPictureUtils = BackgroundSourceUtils.getInstance(mContext);
|
|
|
|
|
|
|
|
|
|
ImageView imageView = findViewById(R.id.dialogbackgroundpicturepreviewImageView1);
|
|
|
|
|
copyAndViewRecivePicture(imageView);
|
|
|
|
|
mBackgroundView = findViewById(R.id.backgroundview);
|
|
|
|
|
previewRecivedPicture();
|
|
|
|
|
|
|
|
|
|
dialogbackgroundpicturepreviewButton1 = findViewById(R.id.dialogbackgroundpicturepreviewButton1);
|
|
|
|
|
dialogbackgroundpicturepreviewButton1.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@@ -53,6 +54,7 @@ public class BackgroundPicturePreviewDialog extends Dialog {
|
|
|
|
|
// 跳转到主窗口
|
|
|
|
|
Intent i = new Intent(mContext, MainActivity.class);
|
|
|
|
|
mContext.startActivity(i);
|
|
|
|
|
dismiss();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@@ -62,79 +64,77 @@ public class BackgroundPicturePreviewDialog extends Dialog {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
// 使用分享到的图片
|
|
|
|
|
//
|
|
|
|
|
//LogUtils.d(TAG, "mszReceivedFileName : " + mszReceivedFileName);
|
|
|
|
|
((IOnRecivedPictureListener)mContext).onAcceptRecivedPicture(mszPreReceivedFileName);
|
|
|
|
|
mIOnRecivedPictureListener.onAcceptRecivedPicture(mUriRecivedPicture);
|
|
|
|
|
// 关闭对话框
|
|
|
|
|
dismiss();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void initEnv() {
|
|
|
|
|
LogUtils.d(TAG, "initEnv()");
|
|
|
|
|
mszPreReceivedFileName = "PreReceived.data";
|
|
|
|
|
}
|
|
|
|
|
// void initEnv() {
|
|
|
|
|
// LogUtils.d(TAG, "initEnv()");
|
|
|
|
|
// mszPreReceivedFileName = "PreReceived.data";
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
void copyAndViewRecivePicture(ImageView imageView) {
|
|
|
|
|
//AppConfigUtils appConfigUtils = AppConfigUtils.getInstance((GlobalApplication)mContext.getApplicationContext());
|
|
|
|
|
void previewRecivedPicture() {
|
|
|
|
|
BackgroundSettingsActivity activity = ((BackgroundSettingsActivity)mContext);
|
|
|
|
|
|
|
|
|
|
//取出文件uri
|
|
|
|
|
Uri uri = activity.getIntent().getData();
|
|
|
|
|
if (uri == null) {
|
|
|
|
|
uri = activity.getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
|
|
|
|
|
mUriRecivedPicture = activity.getIntent().getData();
|
|
|
|
|
if (mUriRecivedPicture == null) {
|
|
|
|
|
mUriRecivedPicture = activity.getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
|
|
|
|
|
}
|
|
|
|
|
//获取文件真实地址
|
|
|
|
|
String szSrcImage = UriUtil.getFilePathFromUri(mContext, uri);
|
|
|
|
|
String szSrcImage = UriUtil.getFilePathFromUri(mContext, mUriRecivedPicture);
|
|
|
|
|
if (TextUtils.isEmpty(szSrcImage)) {
|
|
|
|
|
Toast.makeText(mContext, "接收到的文件为空。", Toast.LENGTH_SHORT).show();
|
|
|
|
|
dismiss();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File fSrcImage = new File(szSrcImage);
|
|
|
|
|
//mszPreReceivedFileName = DateUtils.getDateNowString() + "-" + fSrcImage.getName();
|
|
|
|
|
File mfPreReceivedPhoto = new File(BackgroundSourceUtils.getInstance(mContext).getBackgroundSourceDirPath(), mszPreReceivedFileName);
|
|
|
|
|
// 复制源图片到剪裁文件
|
|
|
|
|
try {
|
|
|
|
|
FileUtils.copyFileUsingFileChannels(fSrcImage, mfPreReceivedPhoto);
|
|
|
|
|
LogUtils.d(TAG, "copyFileUsingFileChannels");
|
|
|
|
|
Drawable drawable = Drawable.createFromPath(mfPreReceivedPhoto.getPath());
|
|
|
|
|
imageView.setBackground(drawable);
|
|
|
|
|
//LogUtils.d(TAG, "mszPreReceivedFileName : " + mszPreReceivedFileName);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
|
|
|
|
}
|
|
|
|
|
mBackgroundView.loadImage(szSrcImage);
|
|
|
|
|
//
|
|
|
|
|
// File fSrcImage = new File(szSrcImage);
|
|
|
|
|
// //mszPreReceivedFileName = DateUtils.getDateNowString() + "-" + fSrcImage.getName();
|
|
|
|
|
// File mfPreReceivedPhoto = new File(BackgroundSourceUtils.getInstance(mContext).getBackgroundSourceDirPath(), mszPreReceivedFileName);
|
|
|
|
|
// // 复制源图片到剪裁文件
|
|
|
|
|
// try {
|
|
|
|
|
// FileUtils.copyFileUsingFileChannels(fSrcImage, mfPreReceivedPhoto);
|
|
|
|
|
// LogUtils.d(TAG, "copyFileUsingFileChannels");
|
|
|
|
|
// Drawable drawable = Drawable.createFromPath(mfPreReceivedPhoto.getPath());
|
|
|
|
|
// imageView.setBackground(drawable);
|
|
|
|
|
// //LogUtils.d(TAG, "mszPreReceivedFileName : " + mszPreReceivedFileName);
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 创建图片背景图片目录
|
|
|
|
|
//
|
|
|
|
|
boolean createBackgroundFolder2(String szBackgroundFolder) {
|
|
|
|
|
// 文件路径参数为空值或无效值时返回false.
|
|
|
|
|
if (szBackgroundFolder == null | szBackgroundFolder.equals("")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogUtils.d(TAG, "Background Folder Is : " + szBackgroundFolder);
|
|
|
|
|
File f = new File(szBackgroundFolder);
|
|
|
|
|
if (f.exists()) {
|
|
|
|
|
if (f.isDirectory()) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
// 工作路径不是一个目录
|
|
|
|
|
LogUtils.d(TAG, "createImageWorkFolder() error : szImageCacheFolder isDirectory return false. -->" + szBackgroundFolder);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return f.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// boolean createBackgroundFolder2(String szBackgroundFolder) {
|
|
|
|
|
// // 文件路径参数为空值或无效值时返回false.
|
|
|
|
|
// if (szBackgroundFolder == null | szBackgroundFolder.equals("")) {
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// LogUtils.d(TAG, "Background Folder Is : " + szBackgroundFolder);
|
|
|
|
|
// File f = new File(szBackgroundFolder);
|
|
|
|
|
// if (f.exists()) {
|
|
|
|
|
// if (f.isDirectory()) {
|
|
|
|
|
// return true;
|
|
|
|
|
// } else {
|
|
|
|
|
// // 工作路径不是一个目录
|
|
|
|
|
// LogUtils.d(TAG, "createImageWorkFolder() error : szImageCacheFolder isDirectory return false. -->" + szBackgroundFolder);
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// return f.mkdirs();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public interface IOnRecivedPictureListener {
|
|
|
|
|
void onAcceptRecivedPicture(String szBackgroundFileName);
|
|
|
|
|
void onAcceptRecivedPicture(Uri uriRecivedPicture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|