-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#27 CameraSetting增加了一个setOnCameraViewListenerApi方法,可以在回调中自定义CameraVie…
…w相关设置,具体设置请看它的相关源码网站https://github.com/natario1/CameraView
- Loading branch information
1 parent
727f97c
commit e8e3248
Showing
14 changed files
with
353 additions
and
28 deletions.
There are no files selected for viewing
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
191 changes: 191 additions & 0 deletions
191
app/src/main/java/com/zhongjh/cameraapp/phone/MainCustomCameraViewActivity.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,191 @@ | ||
package com.zhongjh.cameraapp.phone; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.RelativeLayout; | ||
import android.widget.Toast; | ||
|
||
import androidx.databinding.DataBindingUtil; | ||
|
||
import com.otaliastudios.cameraview.CameraView; | ||
import com.zhongjh.albumcamerarecorder.album.filter.BaseFilter; | ||
import com.zhongjh.albumcamerarecorder.camera.listener.OnCameraViewListener; | ||
import com.zhongjh.albumcamerarecorder.settings.AlbumSetting; | ||
import com.zhongjh.albumcamerarecorder.settings.CameraSetting; | ||
import com.zhongjh.albumcamerarecorder.settings.GlobalSetting; | ||
import com.zhongjh.albumcamerarecorder.settings.MultiMediaSetting; | ||
import com.zhongjh.albumcamerarecorder.settings.RecorderSetting; | ||
import com.zhongjh.cameraapp.BaseActivity; | ||
import com.zhongjh.cameraapp.R; | ||
import com.zhongjh.cameraapp.configuration.GifSizeFilter; | ||
import com.zhongjh.cameraapp.configuration.Glide4Engine; | ||
import com.zhongjh.cameraapp.databinding.ActivityMainCustomCameraviewBinding; | ||
import com.zhongjh.cameraapp.databinding.ActivityMainSimpleBinding; | ||
import com.zhongjh.progresslibrary.entity.MultiMediaView; | ||
import com.zhongjh.progresslibrary.listener.MaskProgressLayoutListener; | ||
import com.zhongjh.progresslibrary.widget.MaskProgressLayout; | ||
|
||
import java.util.ArrayList; | ||
|
||
import gaode.zhongjh.com.common.entity.SaveStrategy; | ||
import gaode.zhongjh.com.common.enums.MimeType; | ||
import gaode.zhongjh.com.common.enums.MultimediaTypes; | ||
|
||
/** | ||
* 自定义CameraView | ||
* 如无什么特殊要求,不要自定义该CameraView | ||
* | ||
* @author zhongjh | ||
* @date 2021/8/23 | ||
*/ | ||
public class MainCustomCameraViewActivity extends BaseActivity { | ||
|
||
ActivityMainCustomCameraviewBinding mBinding; | ||
private final String TAG = MainCustomCameraViewActivity.this.getClass().getSimpleName(); | ||
|
||
GlobalSetting mGlobalSetting; | ||
|
||
/** | ||
* @param activity 要跳转的activity | ||
*/ | ||
public static void newInstance(Activity activity) { | ||
activity.startActivity(new Intent(activity, MainCustomCameraViewActivity.class)); | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main_custom_cameraview); | ||
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main_custom_cameraview); | ||
|
||
// 以下为点击事件 | ||
mBinding.mplImageList.setMaskProgressLayoutListener(new MaskProgressLayoutListener() { | ||
|
||
@Override | ||
public void onItemAdd(View view, MultiMediaView multiMediaView, int alreadyImageCount, int alreadyVideoCount, int alreadyAudioCount) { | ||
// 点击添加 | ||
boolean isOk = getPermissions(false); | ||
if (isOk) { | ||
openMain(alreadyImageCount, alreadyVideoCount, alreadyAudioCount); | ||
} | ||
} | ||
|
||
@Override | ||
@SuppressWarnings({"unchecked", "rawtypes"}) | ||
public void onItemImage(View view, MultiMediaView multiMediaView) { | ||
// 点击详情 | ||
if (multiMediaView.getType() == MultimediaTypes.PICTURE) { | ||
// 判断如果是图片类型就预览当前所有图片 | ||
MultiMediaSetting.openPreviewImage(MainCustomCameraViewActivity.this, (ArrayList) mBinding.mplImageList.getImages(), multiMediaView.getPosition()); | ||
} else if (multiMediaView.getType() == MultimediaTypes.VIDEO) { | ||
// 判断如果是视频类型就预览视频 | ||
MultiMediaSetting.openPreviewVideo(MainCustomCameraViewActivity.this, (ArrayList) mBinding.mplImageList.getVideos(), multiMediaView.getPosition()); | ||
} | ||
} | ||
|
||
@Override | ||
public void onItemStartUploading(MultiMediaView multiMediaView) { | ||
// 开始模拟上传 - 指刚添加后的。这里可以使用你自己的上传事件 | ||
MyTask timer = new MyTask(multiMediaView); | ||
timers.put(multiMediaView, timer); | ||
timer.schedule(); | ||
} | ||
|
||
@Override | ||
public void onItemClose(View view, MultiMediaView multiMediaView) { | ||
// 停止上传 | ||
timers.get(multiMediaView).cancel(); | ||
timers.remove(multiMediaView); | ||
} | ||
|
||
@Override | ||
public void onItemAudioStartDownload(View view, String url) { | ||
|
||
} | ||
|
||
@Override | ||
public void onItemVideoStartDownload(String url) { | ||
|
||
} | ||
|
||
}); | ||
|
||
|
||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
if (mGlobalSetting != null) { | ||
mGlobalSetting.onDestroy(); | ||
} | ||
} | ||
|
||
@Override | ||
protected MaskProgressLayout getMaskProgressLayout() { | ||
return mBinding.mplImageList; | ||
} | ||
|
||
@Override | ||
protected void openMain(int alreadyImageCount, int alreadyVideoCount, int alreadyAudioCount) { | ||
// 拍摄有关设置 | ||
CameraSetting cameraSetting = new CameraSetting(); | ||
// 支持的类型:图片,视频 | ||
cameraSetting.mimeTypeSet(MimeType.ofAll()); | ||
// 自定义cameraView的宽高,更多设置参考 https://github.com/natario1/CameraView 源码 | ||
cameraSetting.setOnCameraViewListener(cameraView -> { | ||
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(200, 200); | ||
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT,RelativeLayout.TRUE); | ||
cameraView.setLayoutParams(layoutParams); | ||
}); | ||
|
||
// 相册 | ||
AlbumSetting albumSetting = new AlbumSetting(false) | ||
// 支持的类型:图片,视频 | ||
.mimeTypeSet(MimeType.ofAll()) | ||
// 是否显示多选图片的数字 | ||
.countable(true) | ||
// 自定义过滤器 | ||
.addFilter(new GifSizeFilter(320, 320, 5 * BaseFilter.K * BaseFilter.K)) | ||
// 开启原图 | ||
.originalEnable(true) | ||
// 最大原图size,仅当originalEnable为true的时候才有效 | ||
.maxOriginalSize(10); | ||
|
||
// 录音机 | ||
RecorderSetting recorderSetting = new RecorderSetting(); | ||
|
||
// 全局 | ||
mGlobalSetting = MultiMediaSetting.from(MainCustomCameraViewActivity.this).choose(MimeType.ofAll()); | ||
|
||
// 开启相册功能 | ||
mGlobalSetting.albumSetting(albumSetting); | ||
// 开启拍摄功能 | ||
mGlobalSetting.cameraSetting(cameraSetting); | ||
// 开启录音功能 | ||
mGlobalSetting.recorderSetting(recorderSetting); | ||
|
||
mGlobalSetting | ||
.setOnMainListener(errorMessage -> { | ||
Log.d(TAG, errorMessage); | ||
Toast.makeText(MainCustomCameraViewActivity.this.getApplicationContext(), errorMessage, Toast.LENGTH_LONG).show(); | ||
}) | ||
// 设置路径和7.0保护路径等等 | ||
.allStrategy(new SaveStrategy(true, "com.zhongjh.cameraapp.fileprovider", "aabb")) | ||
// for glide-V4 | ||
.imageEngine(new Glide4Engine()) | ||
// 最大5张图片、最大3个视频、最大1个音频 | ||
.maxSelectablePerMediaType(null, | ||
5, | ||
3, | ||
3, | ||
alreadyImageCount, | ||
alreadyVideoCount, | ||
alreadyAudioCount) | ||
.forResult(REQUEST_CODE_CHOOSE); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
app/src/main/res/layout/activity_main_custom_cameraview.xml
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,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<ScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:text="这是单纯演示如何自定义CameraView的一些参数,当然如果没必要的话,最好是不要自定义" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content"/> | ||
|
||
<com.zhongjh.progresslibrary.widget.MaskProgressLayout | ||
android:id="@+id/mplImageList" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:audioDeleteColor="@color/blue_primary" | ||
app:audioPlayColor="@color/blue_primary" | ||
app:audioProgressColor="@color/blue_primary" | ||
app:authority="com.zhongjh.cameraapp.fileprovider" | ||
app:imageAddDrawable="@drawable/ic_add_gray" | ||
app:imageDeleteDrawable="@drawable/ic_deleted_yellow" | ||
app:imageEngine="com.zhongjh.cameraapp.configuration.Glide4EngineProgress" | ||
app:maskingColor="?attr/colorPrimary" | ||
app:maskingTextColor="@color/black_eighty_percent" | ||
app:maskingTextContent="@string/up_upload_is_customizable" | ||
app:maskingTextSize="12" | ||
app:columnNumber="4" | ||
app:columnSpace="10" | ||
app:maxCount="7" /> | ||
|
||
</LinearLayout> | ||
|
||
|
||
</ScrollView> | ||
|
||
|
||
</layout> |
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
Oops, something went wrong.