Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
【头像信息修改完善(相机、选图、动态权限初步完成)】
ui下新建一个camera包(用于处理照片),下新建一个CameraHandler、XiaoYunCamera、RequestCodes、CameraImageBean;(后面移动到core/ui) core下引入uCrop库、权限库PermissionsDispatcher、工具库AndroidUtilCode; Camera包转移到core/ui下(相关文件、依赖库同); Drawable、layout、style、anim文件也移动过去(具体移动的文件目录见项目文档); core/res下,新建,anim下push_bottom_in.xml、push_bottom_out.xml;drawable下新建btn_border.xml、btn_border_nativephoto.xml、btn_border_takephoto.xml;layout下dialog_camera_panel.xml; 更新Configurator、PermissionCheckerDelegate、FileUtil(注释)、style、AndroidManifest(权限声明)、UserProfileClickListener、UserProfileDelegate、PersonalDelegate
- Loading branch information
1 parent
94a3c5e
commit 5ed0d2d
Showing
31 changed files
with
603 additions
and
19 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
xiaoyun_core/src/main/java/com/lwp/xiaoyun_core/ui/camera/CameraHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package com.lwp.xiaoyun_core.ui.camera; | ||
|
||
import android.content.ContentValues; | ||
import android.content.Intent; | ||
import android.graphics.Color; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.provider.MediaStore; | ||
import android.support.v7.app.AlertDialog; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
import android.view.Window; | ||
import android.view.WindowManager; | ||
|
||
import com.blankj.utilcode.util.FileUtils; | ||
import com.lwp.xiaoyun_core.R; | ||
import com.lwp.xiaoyun_core.delegates.PermissionCheckerDelegate; | ||
import com.lwp.xiaoyun_core.util.file.FileUtil; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* <pre> | ||
* author : 李蔚蓬(简书_凌川江雪) | ||
* time : 2020/3/2 5:36 | ||
* desc : 照片处理类 | ||
* </pre> | ||
*/ | ||
public class CameraHandler implements View.OnClickListener { | ||
|
||
private final AlertDialog DIALOG; | ||
private final PermissionCheckerDelegate DELEGATE; | ||
|
||
public CameraHandler(PermissionCheckerDelegate delegate) { | ||
this.DELEGATE = delegate; | ||
DIALOG = new AlertDialog.Builder(delegate.getContext()).create(); | ||
} | ||
|
||
//弹出Dialog弹框 内容:三个按钮,拍照 选图 取消 | ||
final void beginCameraDialog() { | ||
DIALOG.show(); | ||
|
||
final Window window = DIALOG.getWindow(); | ||
if (window != null) { | ||
window.setContentView(R.layout.dialog_camera_panel);//设置弹框布局 | ||
window.setGravity(Gravity.BOTTOM); | ||
window.setWindowAnimations(R.style.anim_panel_up_from_bottom); | ||
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); | ||
|
||
//设置属性 | ||
final WindowManager.LayoutParams params = window.getAttributes(); | ||
params.width = WindowManager.LayoutParams.MATCH_PARENT; | ||
params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND; | ||
params.dimAmount = 0.5f;//设置幕布黑暗程度 | ||
window.setAttributes(params); | ||
|
||
//设置弹框中 组件的监听 | ||
window.findViewById(R.id.photodialog_btn_cancel).setOnClickListener(this);//取消按钮 | ||
window.findViewById(R.id.photodialog_btn_take).setOnClickListener(this);//拍照按钮 | ||
window.findViewById(R.id.photodialog_btn_native).setOnClickListener(this);//本地按钮 | ||
} | ||
} | ||
|
||
private String getPhotoName() { | ||
//获取一个 模板格式化后的 文件名(模板:文件头_当前时间.后缀) | ||
return FileUtil.getFileNameByTime("IMG", "jpg"); | ||
} | ||
//拍照取图 | ||
public void takePhoto() { | ||
final String currentPhotoName = getPhotoName(); | ||
//拍照意图 | ||
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | ||
//File 临时文件句柄 临时文件:这里是系统相册目录下的当前文件名的文件临时句柄 | ||
//CAMERA_PHOTO_DIR 系统相册目录 | ||
final File tempFile = new File(FileUtil.CAMERA_PHOTO_DIR, currentPhotoName); | ||
|
||
//兼容7.0及以上的写法 | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||
final ContentValues contentValues = new ContentValues(1); | ||
contentValues.put(MediaStore.Images.Media.DATA, tempFile.getPath()); | ||
//使用 ContentProvider 的方式 | ||
final Uri uri = DELEGATE.getContext().getContentResolver(). | ||
insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues); | ||
|
||
//需要讲Uri路径转化为实际路径 | ||
final File realFile = | ||
FileUtils.getFileByPath(FileUtil.getRealFilePath(DELEGATE.getContext(), uri)); | ||
|
||
final Uri realUri = Uri.fromFile(realFile); | ||
CameraImageBean.getInstance().setPath(realUri); | ||
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); | ||
} else { | ||
|
||
final Uri fileUri = Uri.fromFile(tempFile); | ||
CameraImageBean.getInstance().setPath(fileUri); | ||
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); | ||
} | ||
|
||
//使用startActivityForResult()的形式 启动Activity | ||
DELEGATE.startActivityForResult(intent, RequestCodes.TAKE_PHOTO); | ||
} | ||
|
||
//本地取图 | ||
private void pickPhoto() { | ||
final Intent intent = new Intent(); | ||
intent.setType("image/*");//所有的Image类型 | ||
intent.setAction(Intent.ACTION_GET_CONTENT);//获取内容 | ||
intent.addCategory(Intent.CATEGORY_OPENABLE); | ||
|
||
//使用startActivityForResult()的形式 启动Activity | ||
// createChooser 创建选择器 | ||
DELEGATE.startActivityForResult | ||
(Intent.createChooser(intent, "选择获取图片的方式"), RequestCodes.PICK_PHOTO); | ||
} | ||
|
||
|
||
@Override | ||
public void onClick(View v) { | ||
int id = v.getId(); | ||
|
||
if (id == R.id.photodialog_btn_cancel) { | ||
DIALOG.cancel(); | ||
} else if (id == R.id.photodialog_btn_take) { | ||
//拍照取图 | ||
takePhoto(); | ||
DIALOG.cancel(); | ||
} else if (id == R.id.photodialog_btn_native) { | ||
//本地取图 | ||
pickPhoto(); | ||
DIALOG.cancel(); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
xiaoyun_core/src/main/java/com/lwp/xiaoyun_core/ui/camera/CameraImageBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.lwp.xiaoyun_core.ui.camera; | ||
|
||
import android.net.Uri; | ||
|
||
/** | ||
* <pre> | ||
* author : 李蔚蓬(简书_凌川江雪) | ||
* time : 2020/3/2 5:39 | ||
* desc : 存储中间值 | ||
* </pre> | ||
*/ | ||
public final class CameraImageBean { | ||
|
||
private Uri mPath = null; | ||
|
||
//单例模式 | ||
private static final CameraImageBean INSTANCE = new CameraImageBean(); | ||
public static CameraImageBean getInstance(){ | ||
return INSTANCE; | ||
} | ||
|
||
public Uri getPath() { | ||
return mPath; | ||
} | ||
|
||
public void setPath(Uri mPath) { | ||
this.mPath = mPath; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
xiaoyun_core/src/main/java/com/lwp/xiaoyun_core/ui/camera/RequestCodes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.lwp.xiaoyun_core.ui.camera; | ||
|
||
|
||
import com.yalantis.ucrop.UCrop; | ||
|
||
/** | ||
* <pre> | ||
* author : 李蔚蓬(简书_凌川江雪) | ||
* time : 2020/3/2 5:38 | ||
* desc : 请求码存储 | ||
* </pre> | ||
*/ | ||
public class RequestCodes { | ||
public static final int TAKE_PHOTO = 4;//拍照 | ||
public static final int PICK_PHOTO = 5;//选择图片 | ||
public static final int CROP_PHOTO = UCrop.REQUEST_CROP;//剪裁 | ||
public static final int CROP_ERROR = UCrop.RESULT_ERROR;//剪裁错误 | ||
public static final int SCAN = 7;//扫描二维码 | ||
} |
26 changes: 26 additions & 0 deletions
26
xiaoyun_core/src/main/java/com/lwp/xiaoyun_core/ui/camera/XiaoYunCamera.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.lwp.xiaoyun_core.ui.camera; | ||
|
||
import android.net.Uri; | ||
|
||
import com.lwp.xiaoyun_core.delegates.PermissionCheckerDelegate; | ||
import com.lwp.xiaoyun_core.util.file.FileUtil; | ||
|
||
/** | ||
* <pre> | ||
* author : 李蔚蓬(简书_凌川江雪) | ||
* time : 2020/3/2 5:37 | ||
* desc : 照相机功能模块函数调用等 | ||
* </pre> | ||
*/ | ||
public class XiaoYunCamera { | ||
|
||
//需要剪裁的文件 | ||
public static Uri createCropFile() { | ||
return Uri.parse(FileUtil.createFile("crop_image", | ||
FileUtil.getFileNameByTime("IMG", "jpg")).getPath()); | ||
} | ||
|
||
public static void start(PermissionCheckerDelegate delegate) { | ||
new CameraHandler(delegate).beginCameraDialog();//弹出Dialog弹框 内容:三个按钮,拍照 选图 取消 | ||
} | ||
} |
Oops, something went wrong.