diff --git a/app/src/main/java/com/zhongjh/cameraapp/phone/MainActivity.java b/app/src/main/java/com/zhongjh/cameraapp/phone/MainActivity.java index 4726c2c4..b760ed88 100644 --- a/app/src/main/java/com/zhongjh/cameraapp/phone/MainActivity.java +++ b/app/src/main/java/com/zhongjh/cameraapp/phone/MainActivity.java @@ -75,7 +75,6 @@ public static void newInstance(Activity activity) { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); -// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.activity_main); mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main); @@ -91,10 +90,6 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onAddDataSuccess(@NotNull List multiMediaViews) { -// // 如果需要其他参数的话,循环数据初始化相关数值,这个读取时间会较长,建议异步线程执行 -// for (MultiMediaView item : multiMediaViews) { -// item.initDataByPath(); -// } } @Override @@ -368,11 +363,11 @@ private CameraSetting initCameraSetting() { cameraSetting.mimeTypeSet(mimeTypeCameras); } else if (mBinding.cbCameraImage.isChecked()) { mimeTypeCameras = MimeType.ofImage(); - // 支持的类型:图片,视频 + // 支持的类型:图片 cameraSetting.mimeTypeSet(mimeTypeCameras); } else if (mBinding.cbCameraVideo.isChecked()) { mimeTypeCameras = MimeType.ofVideo(); - // 支持的类型:图片,视频 + // 支持的类型:视频 cameraSetting.mimeTypeSet(mimeTypeCameras); } // 最长录制时间 @@ -398,6 +393,12 @@ private CameraSetting initCameraSetting() { // 开启点击即开启录制(失去点击拍照功能) cameraSetting.isClickRecord(mBinding.cbClickRecord.isChecked()); + // 开启高清拍照(失去录像功能) + cameraSetting.enableImageHighDefinition(mBinding.cbPictureHD.isChecked()); + + // 开启高清录像(失去拍照功能) + cameraSetting.enableVideoHighDefinition(mBinding.cbVideoHD.isChecked()); + return cameraSetting; } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 882c20cf..a19c7e0f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -392,8 +392,8 @@ android:layout_height="wrap_content" android:layout_marginTop="10dp" android:checked="true" - android:visibility="gone" - android:text="@string/support_gif" /> + android:text="@string/support_gif" + android:visibility="gone" /> - - - - + + + + + + + + + 开启拍摄功能 开启分段录制功能 开启点击即开启录制(失去点击拍照功能) + 高清拍照(失去录像功能) + 高清录像(失去拍照功能) 最长录制时间 最短录制时间(毫秒) 开启录音功能 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b407805..056ce1a4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -46,6 +46,8 @@ Turn on the shooting function Enable segmented recording Click to start recording (lose the click to take photos function) + Take pictures in HD(Lost video recording function) + Take video in HD(Losing the ability to take pictures) Maximum recording time Minimum recording time (milliseconds) Enable recording diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/CameraLayout.java b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/CameraLayout.java index f6b2d7d7..4c2f9e6c 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/CameraLayout.java +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/CameraLayout.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.res.TypedArray; import android.graphics.Bitmap; +import android.graphics.Picture; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Handler; @@ -72,6 +73,8 @@ import it.sephiroth.android.library.imagezoom.ImageViewTouch; +import static com.otaliastudios.cameraview.controls.Mode.PICTURE; +import static com.otaliastudios.cameraview.controls.Mode.VIDEO; import static com.zhongjh.albumcamerarecorder.camera.constants.FlashModels.TYPE_FLASH_AUTO; import static com.zhongjh.albumcamerarecorder.camera.constants.FlashModels.TYPE_FLASH_OFF; import static com.zhongjh.albumcamerarecorder.camera.constants.FlashModels.TYPE_FLASH_ON; @@ -207,6 +210,10 @@ public void setBreakOff(boolean breakOff) { * 用于延迟显示的事件,如果不用延迟,会有短暂闪屏现象 */ private final Handler mCameraViewVisibleHandler = new Handler(Looper.getMainLooper()); + /** + * 延迟拍摄,用于打开闪光灯再拍摄 + */ + private final Handler mCameraTakePictureHandler = new Handler(Looper.getMainLooper()); private final Runnable mCameraViewGoneRunnable = new Runnable() { @Override public void run() { @@ -220,6 +227,16 @@ public void run() { mViewHolder.cameraView.open(); } }; + private final Runnable mCameraTakePictureRunnable = new Runnable() { + @Override + public void run() { + if (mCameraSpec.enableImageHighDefinition) { + mViewHolder.cameraView.takePicture(); + } else { + mViewHolder.cameraView.takePictureSnapshot(); + } + } + }; // region 回调监听事件 @@ -368,6 +385,15 @@ private void initView() { View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_camera_main_view_zjh, this); mViewHolder = new ViewHolder(view); + // 如果有设置高清模式,则根据相应高清模式更改模式 + if (mCameraSpec.enableImageHighDefinition) { + mViewHolder.cameraView.setMode(PICTURE); + } else if (mCameraSpec.enableVideoHighDefinition) { + mViewHolder.cameraView.setMode(VIDEO); + } else { + mViewHolder.cameraView.setMode(VIDEO); + } + if (mCameraSpec.watermarkResource != -1) { LayoutInflater.from(getContext()).inflate(mCameraSpec.watermarkResource, mViewHolder.cameraView, true); } @@ -547,6 +573,7 @@ protected void onDestroy(boolean isCommit) { } mCameraViewGoneHandler.removeCallbacks(mCameraViewGoneRunnable); mCameraViewVisibleHandler.removeCallbacks(mCameraViewVisibleRunnable); + mCameraTakePictureHandler.removeCallbacks(mCameraTakePictureRunnable); if (mMovePictureFileTask != null) { mMovePictureFileTask.cancel(); } @@ -657,9 +684,9 @@ private void takePhoto() { if (mFlashModel == TYPE_FLASH_AUTO) { mViewHolder.cameraView.setFlash(Flash.TORCH); // 延迟1秒拍照 - new Handler(Looper.getMainLooper()).postDelayed(() -> mViewHolder.cameraView.takePictureSnapshot(), 1000); + mCameraTakePictureHandler.postDelayed(mCameraTakePictureRunnable, 1000); } else { - mViewHolder.cameraView.takePictureSnapshot(); + mCameraTakePictureRunnable.run(); } } else { Toast.makeText(getContext(), getResources().getString(R.string.z_multi_library_the_camera_limit_has_been_reached), Toast.LENGTH_SHORT).show(); @@ -677,7 +704,11 @@ private void recordVideo() { if (mVideoFile == null) { mVideoFile = mVideoMediaStoreCompat.createFile(1, true, "mp4"); } - mViewHolder.cameraView.takeVideoSnapshot(mVideoFile); + if (mCameraSpec.enableVideoHighDefinition) { + mViewHolder.cameraView.takeVideo(mVideoFile); + } else { + mViewHolder.cameraView.takeVideoSnapshot(mVideoFile); + } // 设置录制状态 if (mIsSectionRecord) { mCameraStateManagement.setState(mCameraStateManagement.getVideoMultipleIn()); @@ -802,7 +833,6 @@ private void initCameraViewListener() { @Override public void onPictureTaken(@NonNull PictureResult result) { - // 如果是自动闪光灯模式便关闭闪光灯 if (mFlashModel == TYPE_FLASH_AUTO) { mViewHolder.cameraView.setFlash(Flash.OFF); @@ -1130,6 +1160,7 @@ private void addCaptureData(Bitmap bitmap) { // 初始化数据并且存储进file File file = mPictureMediaStoreCompat.saveFileByBitmap(bitmap, true); Uri uri = mPictureMediaStoreCompat.getUri(file.getPath()); + Log.d(TAG, "file:" + file.getAbsolutePath()); BitmapData bitmapData = new BitmapData(file.getPath(), uri, bitmap.getWidth(), bitmap.getHeight()); // 回收bitmap if (bitmap.isRecycled()) { diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/PreviewVideoActivity.java b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/PreviewVideoActivity.java index b032aba1..56f70802 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/PreviewVideoActivity.java +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/PreviewVideoActivity.java @@ -7,23 +7,23 @@ import android.view.View; import android.widget.ImageView; import android.widget.MediaController; -import android.widget.Toast; import android.widget.VideoView; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; -import com.zhongjh.albumcamerarecorder.MainActivity; import com.zhongjh.albumcamerarecorder.R; import com.zhongjh.albumcamerarecorder.camera.util.FileUtil; import com.zhongjh.albumcamerarecorder.settings.GlobalSpec; import com.zhongjh.albumcamerarecorder.utils.MediaStoreUtils; import com.zhongjh.albumcamerarecorder.widget.progressbutton.CircularProgressButton; import com.zhongjh.common.entity.LocalFile; +import com.zhongjh.common.entity.MediaExtraInfo; import com.zhongjh.common.enums.MimeType; import com.zhongjh.common.listener.VideoEditListener; import com.zhongjh.common.utils.MediaStoreCompat; +import com.zhongjh.common.utils.MediaUtils; import com.zhongjh.common.utils.StatusBarUtils; import com.zhongjh.common.utils.ThreadUtils; @@ -68,7 +68,7 @@ public class PreviewVideoActivity extends AppCompatActivity { /** * 拍摄配置 */ - GlobalSpec mGlobalSpec= GlobalSpec.getInstance(); + GlobalSpec mGlobalSpec = GlobalSpec.getInstance(); /** * 迁移视频的异步线程 */ @@ -175,8 +175,6 @@ private void playVideo(File file) { mVideoViewPreview.setOnPreparedListener(mp -> { // 获取相关参数 mLocalFile.setDuration(mVideoViewPreview.getDuration()); - mLocalFile.setWidth(mVideoViewPreview.getWidth()); - mLocalFile.setHeight(mVideoViewPreview.getHeight()); }); mVideoViewPreview.setOnCompletionListener(mediaPlayer -> { // 循环播放 @@ -284,6 +282,9 @@ public void onFail(Throwable t) { */ private void confirm(File newFile) { Intent intent = new Intent(); + MediaExtraInfo mediaExtraInfo = MediaUtils.getVideoSize(getApplicationContext(), newFile.getPath()); + mLocalFile.setWidth(mediaExtraInfo.getWidth()); + mLocalFile.setHeight(mediaExtraInfo.getHeight()); Uri uri = MediaStoreUtils.displayToGallery(getApplicationContext(), newFile, TYPE_VIDEO, mLocalFile.getDuration(), mLocalFile.getWidth(), mLocalFile.getHeight(), mVideoMediaStoreCompat.getSaveStrategy().getDirectory(), mVideoMediaStoreCompat); diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/CameraSetting.java b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/CameraSetting.java index d6dc4fa7..2cbbb77f 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/CameraSetting.java +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/CameraSetting.java @@ -33,7 +33,31 @@ public void onDestroy() { @Override public CameraSetting mimeTypeSet(@NonNull Set mimeTypes) { - mCameraSpec.mimeTypeSet = mimeTypes; + // 如果设置了高清模式,则优先以高清模式为准 + if (!mCameraSpec.enableImageHighDefinition && !mCameraSpec.enableVideoHighDefinition) { + mCameraSpec.mimeTypeSet = mimeTypes; + } + return this; + } + + @Override + public CameraSetting enableImageHighDefinition(boolean enable) { + mCameraSpec.enableImageHighDefinition = enable; + // 如果启用图片高清,就禁用录制视频 + if (enable) { + mCameraSpec.mimeTypeSet = MimeType.ofImage(); + } + return this; + } + + @Override + public CameraSetting enableVideoHighDefinition(boolean enable) { + mCameraSpec.enableVideoHighDefinition = enable; + // 如果启用视频高清,就禁用拍摄图片,并且单击就能录制 + if (enable) { + mCameraSpec.mimeTypeSet = MimeType.ofVideo(); + mCameraSpec.isClickRecord = true; + } return this; } diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/CameraSpec.java b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/CameraSpec.java index 5c51f8c9..b2f273f2 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/CameraSpec.java +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/CameraSpec.java @@ -63,6 +63,16 @@ private void reset() { * 选择 视频图片 的类型,MimeType.allOf() */ public Set mimeTypeSet; + /** + * 是否开启图片高清拍摄 + * 注意开启该模式后,录制界面不能同时存在拍摄图片功能和录制视频功能 + */ + public boolean enableImageHighDefinition = false; + /** + * 是否开启视频高清录制 + * 注意开启该模式后,录制界面不能同时存在拍摄图片功能和录制视频功能 + */ + public boolean enableVideoHighDefinition = false; /** * 切换前置/后置摄像头图标资源 */ diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/api/CameraSettingApi.java b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/api/CameraSettingApi.java index 6b6b8764..647854c1 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/api/CameraSettingApi.java +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/settings/api/CameraSettingApi.java @@ -35,6 +35,24 @@ public interface CameraSettingApi { */ CameraSetting mimeTypeSet(@NonNull Set mimeTypes); + /** + * 是否开启图片高清拍摄 + * 注意开启该模式后,录制界面不能同时存在拍摄图片功能和录制视频功能 + * + * @param enable whether to enable + * @return {@link CameraSetting} for fluent API. + */ + CameraSetting enableImageHighDefinition(boolean enable); + + /** + * 是否开启视频高清录制 + * 注意开启该模式后,录制界面不能同时存在拍摄图片功能和录制视频功能 + * + * @param enable whether to enable + * @return {@link CameraSetting} for fluent API. + */ + CameraSetting enableVideoHighDefinition(boolean enable); + /** * 最长录制时间,默认10秒 *