Skip to content

Commit

Permalink
更新相机工具类
Browse files Browse the repository at this point in the history
  • Loading branch information
秋逸 committed Jul 9, 2018
1 parent 678842f commit 21c0aaa
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
67 changes: 29 additions & 38 deletions RxCamera/src/main/java/com/vondear/camera/tool/RxCameraTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.util.Log;

import com.vondear.camera.RxCameraView;
import com.vondear.rxtool.RxConstants;
import com.vondear.rxtool.RxExifTool;
import com.vondear.rxtool.RxFileTool;
import com.vondear.rxtool.RxTool;
Expand All @@ -21,7 +22,6 @@
import java.io.OutputStream;

/**
*
* @author Vondear
* @date 2017/9/22
*/
Expand Down Expand Up @@ -71,37 +71,28 @@ public static void closeFlashLight() {
}

public static void takePic(Context mContext, final RxCameraView mCameraView) {
if (RxTool.isFastClick(1000)) {
RxToast.normal("请不要重复点击拍照按钮");
return;
} else {
try {
if (mCameraView.isCameraOpened()) {
RxVibrateTool.vibrateOnce(mContext, 150);
RxToast.normal("正在拍照..");
if (mCameraView != null) {
mCameraView.takePicture();
}
} else {
mCameraView.start();
RxVibrateTool.vibrateOnce(mContext, 150);
RxToast.normal("正在拍照..");
RxTool.delayToDo(500, new OnSimpleListener() {
@Override
public void doSomething() {
try {
if (mCameraView != null) {
mCameraView.takePicture();
}
}catch (Exception e) {
// Logger.d(e);
}
try {
if (mCameraView.isCameraOpened()) {
RxVibrateTool.vibrateOnce(mContext, 150);
RxToast.normal("正在拍照..");
mCameraView.takePicture();
} else {
mCameraView.start();
RxVibrateTool.vibrateOnce(mContext, 150);
RxToast.normal("正在拍照..");
RxTool.delayToDo(500L, new OnSimpleListener() {
@Override
public void doSomething() {
try {
mCameraView.takePicture();
} catch (Exception var2) {
RxToast.normal("你碰到问题咯");
}
});
}
} catch (Exception e) {
// Logger.d(e);
}
});
}
} catch (Exception var3) {
RxToast.normal("你碰到了问题咯");
}
}

Expand All @@ -113,13 +104,13 @@ public static void initCameraEvent(final Context mContext,
final double mLongitude,
final double mLatitude,
final boolean isEconomize,
final OnRxCamera OnRxCamera) {
OnRxCamera.onBefore();
final OnRxCamera onRxCamera) {
onRxCamera.onBefore();
RxTool.getBackgroundHandler().post(new Runnable() {
@Override
public void run() {
File fileParent = new File(fileDir);
File cacheParent = new File(RxFileTool.getCecheFolder(mContext) + File.separator + "cache" + File.separator + "picture");
File cacheParent = new File(RxConstants.PICTURE_CACHE_PATH);
if (!cacheParent.exists()) {
cacheParent.mkdirs();
}
Expand Down Expand Up @@ -147,10 +138,10 @@ public void onStart() {
public void onSuccess(File file) {
if (RxFileTool.copyOrMoveFile(file, compressFile, true)) {
Log.d("图片压缩", "压缩完成");
OnRxCamera.onSuccessCompress(compressFile);
onRxCamera.onSuccessCompress(compressFile);
if (mLongitude != 0 || mLatitude != 0) {
RxExifTool.writeLatLonIntoJpeg(compressFile.getAbsolutePath(), mLatitude, mLongitude);
OnRxCamera.onSuccessExif(compressFile);
onRxCamera.onSuccessExif(compressFile);
RxToast.normal("拍照成功");
} else {
RxToast.error("请先获取定位信息");
Expand All @@ -168,12 +159,12 @@ public void onError(Throwable e) {
} catch (IOException e) {
Log.w("onPictureTaken", "Cannot write to " + compressFile, e);
} finally {
if (isEconomize) {
mCameraView.stop();
}
if (os != null) {
try {
os.close();
if (isEconomize) {
mCameraView.stop();
}
} catch (IOException e) {
// Ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.vondear.rxtool.RxLocationTool;
import com.vondear.rxtool.RxPermissionsTool;
import com.vondear.rxtool.RxTimeTool;
import com.vondear.rxtool.RxTool;
import com.vondear.rxtool.interfaces.OnRxCamera;
import com.vondear.rxtool.view.RxToast;
import com.vondear.rxui.activity.ActivityBaseLocation;
Expand Down Expand Up @@ -143,7 +144,12 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.btn_take_camera:
RxCameraTool.takePic(mContext, mCameraView);
if (RxTool.isFastClick(1000)) {
RxToast.normal("请不要重复点击拍照按钮");
return;
} else {
RxCameraTool.takePic(mContext, mCameraView);
}
break;
case R.id.iv_pic:
if (photo == null) {
Expand Down
3 changes: 3 additions & 0 deletions RxKit/src/main/java/com/vondear/rxtool/RxConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public class RxConstants {
//默认保存下载文件目录
public static final String DOWNLOAD_DIR = RxFileTool.getRootPath() + File.separator + "Download" + File.separator + RxDeviceTool.getAppPackageName() + File.separator;

//图片缓存路径
public static final String PICTURE_CACHE_PATH = RxFileTool.getCacheFolder(RxTool.getContext()) + File.separator + "Picture" + File.separator + "Cache" + File.separator;

//图片原始路径
public static final String PICTURE_ORIGIN_PATH = RxFileTool.getRootPath() + File.separator + RxDeviceTool.getAppPackageName() + File.separator + "Picture" + File.separator+ "Origin" + File.separator;

Expand Down
2 changes: 1 addition & 1 deletion RxKit/src/main/java/com/vondear/rxtool/RxFileTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static File getRootPath() {
*
* @return
*/
public static File getCecheFolder(Context context) {
public static File getCacheFolder(Context context) {
File folder = new File(context.getCacheDir(), "IMAGECACHE");
if (!folder.exists()) {
folder.mkdir();
Expand Down

0 comments on commit 21c0aaa

Please sign in to comment.