Skip to content

Commit

Permalink
1. 增加高清拍摄图片配置
Browse files Browse the repository at this point in the history
2. 增加高清录像配置
3. 修复录像后提供的宽高数值显示有误
  • Loading branch information
aaatttcccc committed Feb 17, 2022
1 parent b89b7a5 commit 70787f9
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 34 deletions.
15 changes: 8 additions & 7 deletions app/src/main/java/com/zhongjh/cameraapp/phone/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -91,10 +90,6 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
public void onAddDataSuccess(@NotNull List<MultiMediaView> multiMediaViews) {
// // 如果需要其他参数的话,循环数据初始化相关数值,这个读取时间会较长,建议异步线程执行
// for (MultiMediaView item : multiMediaViews) {
// item.initDataByPath();
// }
}

@Override
Expand Down Expand Up @@ -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);
}
// 最长录制时间
Expand All @@ -398,6 +393,12 @@ private CameraSetting initCameraSetting() {
// 开启点击即开启录制(失去点击拍照功能)
cameraSetting.isClickRecord(mBinding.cbClickRecord.isChecked());

// 开启高清拍照(失去录像功能)
cameraSetting.enableImageHighDefinition(mBinding.cbPictureHD.isChecked());

// 开启高清录像(失去拍照功能)
cameraSetting.enableVideoHighDefinition(mBinding.cbVideoHD.isChecked());

return cameraSetting;
}

Expand Down
49 changes: 32 additions & 17 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<CheckBox
android:id="@+id/cbAlbumVideo"
Expand Down Expand Up @@ -618,21 +618,6 @@
android:checked="true"
android:text="@string/turn_on_the_shooting_function" />

<CheckBox
android:id="@+id/cb_video_merge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:checked="true"
android:text="@string/enable_segmented_recording" />

<CheckBox
android:id="@+id/cbClickRecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/click_to_start_recording_lose_the_click_to_take_photos_function" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -656,6 +641,36 @@

</LinearLayout>

<CheckBox
android:id="@+id/cb_video_merge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:checked="true"
android:text="@string/enable_segmented_recording" />

<CheckBox
android:id="@+id/cbClickRecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/click_to_start_recording_lose_the_click_to_take_photos_function" />

<CheckBox
android:id="@+id/cbPictureHD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/take_pictures_in_hd" />

<CheckBox
android:id="@+id/cbVideoHD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/take_video_in_hd" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<string name="turn_on_the_shooting_function">开启拍摄功能</string>
<string name="enable_segmented_recording">开启分段录制功能</string>
<string name="click_to_start_recording_lose_the_click_to_take_photos_function">开启点击即开启录制(失去点击拍照功能)</string>
<string name="take_pictures_in_hd">高清拍照(失去录像功能)</string>
<string name="take_video_in_hd">高清录像(失去拍照功能)</string>
<string name="maximum_recording_time">最长录制时间</string>
<string name="minimum_recording_time_milliseconds">最短录制时间(毫秒)</string>
<string name="enable_recording">开启录音功能</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<string name="turn_on_the_shooting_function">Turn on the shooting function</string>
<string name="enable_segmented_recording">Enable segmented recording</string>
<string name="click_to_start_recording_lose_the_click_to_take_photos_function">Click to start recording (lose the click to take photos function)</string>
<string name="take_pictures_in_hd">Take pictures in HD(Lost video recording function)</string>
<string name="take_video_in_hd">Take video in HD(Losing the ability to take pictures)</string>
<string name="maximum_recording_time">Maximum recording time</string>
<string name="minimum_recording_time_milliseconds">Minimum recording time (milliseconds)</string>
<string name="enable_recording">Enable recording</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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 回调监听事件

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -547,6 +573,7 @@ protected void onDestroy(boolean isCommit) {
}
mCameraViewGoneHandler.removeCallbacks(mCameraViewGoneRunnable);
mCameraViewVisibleHandler.removeCallbacks(mCameraViewVisibleRunnable);
mCameraTakePictureHandler.removeCallbacks(mCameraTakePictureRunnable);
if (mMovePictureFileTask != null) {
mMovePictureFileTask.cancel();
}
Expand Down Expand Up @@ -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();
Expand All @@ -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());
Expand Down Expand Up @@ -802,7 +833,6 @@ private void initCameraViewListener() {

@Override
public void onPictureTaken(@NonNull PictureResult result) {

// 如果是自动闪光灯模式便关闭闪光灯
if (mFlashModel == TYPE_FLASH_AUTO) {
mViewHolder.cameraView.setFlash(Flash.OFF);
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -68,7 +68,7 @@ public class PreviewVideoActivity extends AppCompatActivity {
/**
* 拍摄配置
*/
GlobalSpec mGlobalSpec= GlobalSpec.getInstance();
GlobalSpec mGlobalSpec = GlobalSpec.getInstance();
/**
* 迁移视频的异步线程
*/
Expand Down Expand Up @@ -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 -> {
// 循环播放
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,31 @@ public void onDestroy() {

@Override
public CameraSetting mimeTypeSet(@NonNull Set<MimeType> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ private void reset() {
* 选择 视频图片 的类型,MimeType.allOf()
*/
public Set<MimeType> mimeTypeSet;
/**
* 是否开启图片高清拍摄
* 注意开启该模式后,录制界面不能同时存在拍摄图片功能和录制视频功能
*/
public boolean enableImageHighDefinition = false;
/**
* 是否开启视频高清录制
* 注意开启该模式后,录制界面不能同时存在拍摄图片功能和录制视频功能
*/
public boolean enableVideoHighDefinition = false;
/**
* 切换前置/后置摄像头图标资源
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ public interface CameraSettingApi {
*/
CameraSetting mimeTypeSet(@NonNull Set<MimeType> 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秒
*
Expand Down

0 comments on commit 70787f9

Please sign in to comment.