Skip to content

Commit

Permalink
Merge branch 'develop' into androidx
Browse files Browse the repository at this point in the history
  • Loading branch information
aaatttcccc committed Aug 26, 2022
2 parents e400dfa + 208278d commit cfcf0a2
Show file tree
Hide file tree
Showing 58 changed files with 5,402 additions and 2,390 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
<application
android:name=".MyApplication"
android:allowBackup="true"
android:largeHeap="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">


<activity android:name=".phone.MainListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -62,6 +61,7 @@

<activity android:name=".phone.MainSuperSimpleActivity" />
<activity android:name=".phone.ErrorActivity" />
<activity android:name=".phone.customlayout.MainCustomCameraLayoutActivity" />

<provider
android:name="androidx.core.content.FileProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.zhongjh.cameraapp.R;
import com.zhongjh.cameraapp.configuration.Glide4Engine;
import com.zhongjh.cameraapp.databinding.ActivityMainListBinding;
import com.zhongjh.cameraapp.phone.customlayout.MainCustomCameraLayoutActivity;
import com.zhongjh.common.entity.SaveStrategy;
import com.zhongjh.common.enums.MimeType;

Expand Down Expand Up @@ -65,7 +66,8 @@ protected void onCreate(Bundle savedInstanceState) {
// 自定义CameraView
mBinding.btnCustomCameraView.setOnClickListener(v -> MainCustomCameraViewActivity.newInstance(MainListActivity.this));


// 自定义CameraLayout
mBinding.btnCustomCameraLayout.setOnClickListener(v -> MainCustomCameraLayoutActivity.newInstance(MainListActivity.this));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
package com.zhongjh.cameraapp.phone.customlayout;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.zhongjh.albumcamerarecorder.album.filter.BaseFilter;
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.ActivityMainCustomCameralayoutBinding;
import com.zhongjh.cameraapp.phone.customlayout.camera1.CameraFragment1;
import com.zhongjh.cameraapp.phone.customlayout.camera2.CameraFragment2;
import com.zhongjh.common.entity.SaveStrategy;
import com.zhongjh.common.enums.MimeType;
import com.zhongjh.progresslibrary.entity.MultiMediaView;
import com.zhongjh.progresslibrary.listener.MaskProgressLayoutListener;
import com.zhongjh.progresslibrary.widget.MaskProgressLayout;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
* 可以自己完完全全自定义录制的布局、逻辑
* 当然,随着更深入的逻辑修改,需要了解更多的类
* 如果对于该自定义布局有更好的建议、优化请加QQ群讨论915053430
*
* @author zhongjh
* @date 2022/8/24
*/
public class MainCustomCameraLayoutActivity extends BaseActivity {

ActivityMainCustomCameralayoutBinding mBinding;
private final String TAG = MainCustomCameraLayoutActivity.this.getClass().getSimpleName();

GlobalSetting mGlobalSetting;
CameraSetting cameraSetting;

/**
* @param activity 要跳转的activity
*/
public static void newInstance(Activity activity) {
activity.startActivity(new Intent(activity, MainCustomCameraLayoutActivity.class));
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_custom_cameralayout);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main_custom_cameralayout);

// 以下为点击事件
mBinding.mplImageList.setMaskProgressLayoutListener(new MaskProgressLayoutListener() {

@Override
public void onAddDataSuccess(@NotNull List<MultiMediaView> multiMediaViews) {
}

@Override
public void onItemAdd(@NotNull View view, @NotNull MultiMediaView multiMediaView, int alreadyImageCount, int alreadyVideoCount, int alreadyAudioCount) {
// 点击添加
boolean isOk = getPermissions(false);
if (isOk) {
openMain(alreadyImageCount, alreadyVideoCount, alreadyAudioCount);
}
}

@Override
public void onItemClick(@NotNull View view, @NotNull MultiMediaView multiMediaView) {
// 点击详情
if (multiMediaView.isImageOrGif() || multiMediaView.isVideo()) {
mGlobalSetting.openPreviewData(MainCustomCameraLayoutActivity.this, REQUEST_CODE_CHOOSE,
mBinding.mplImageList.getImagesAndVideos(),
mBinding.mplImageList.getImagesAndVideos().indexOf(multiMediaView));
}
}

@Override
public void onItemStartUploading(@NotNull MultiMediaView multiMediaView) {
// 开始模拟上传 - 指刚添加后的。这里可以使用你自己的上传事件
MyTask timer = new MyTask(multiMediaView);
timers.put(multiMediaView, timer);
timer.schedule();
}

@Override
public void onItemClose(@NotNull View view, @NotNull MultiMediaView multiMediaView) {
// 停止上传
timers.get(multiMediaView).cancel();
timers.remove(multiMediaView);
}

@Override
public void onItemAudioStartDownload(@NotNull View view, @NotNull String url) {

}

@Override
public boolean onItemVideoStartDownload(@NotNull View view, @NotNull MultiMediaView multiMediaView) {
return false;
}

});


}

@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 = new CameraSetting();
// 支持的类型:图片,视频
cameraSetting.mimeTypeSet(MimeType.ofAll());

// 每次使用要重新赋值,因为会在每次关闭界面后删除该Fragment
if (mBinding.radioButton1.isChecked()) {
cameraSetting.setBaseCameraFragment(CameraFragment1.newInstance());
} else if(mBinding.radioButton2.isChecked()) {
cameraSetting.setBaseCameraFragment(CameraFragment2.newInstance());
}

// 相册
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(MainCustomCameraLayoutActivity.this).choose(MimeType.ofAll());

// 开启相册功能
mGlobalSetting.albumSetting(albumSetting);
// 开启拍摄功能
mGlobalSetting.cameraSetting(cameraSetting);
// 开启录音功能
mGlobalSetting.recorderSetting(recorderSetting);

mGlobalSetting
// 设置路径和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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.zhongjh.cameraapp.phone.customlayout.camera1;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.otaliastudios.cameraview.CameraView;
import com.zhongjh.albumcamerarecorder.camera.ui.camera.BaseCameraFragment;
import com.zhongjh.albumcamerarecorder.camera.ui.camera.presenter.BaseCameraPicturePresenter;
import com.zhongjh.albumcamerarecorder.camera.ui.camera.presenter.BaseCameraVideoPresenter;
import com.zhongjh.albumcamerarecorder.camera.ui.camera.state.CameraStateManagement;
import com.zhongjh.albumcamerarecorder.camera.widget.PhotoVideoLayout;
import com.zhongjh.albumcamerarecorder.widget.childclickable.IChildClickableLayout;
import com.zhongjh.cameraapp.R;
import com.zhongjh.cameraapp.databinding.FragmentCamera1Binding;

/**
* 继承于BaseCameraFragment
* 1. setContentView 实现自己想要的布局
* 2. 实现相关view
* 3. 使用默认的 BaseCameraPicturePresenter、BaseCameraVideoPresenter、CameraStateManagement
* <p>
* 该Fragment的例子让我们增加几个view,添加我们想要的事件。
* 使用 TODO 关键字可搜索相关自定义代码
*
* @author zhongjh
* @date 2022/8/12
*/
public class CameraFragment1 extends BaseCameraFragment<CameraStateManagement, BaseCameraPicturePresenter, BaseCameraVideoPresenter> {

FragmentCamera1Binding mBinding;
BaseCameraPicturePresenter cameraPicturePresenter = new BaseCameraPicturePresenter(this);
BaseCameraVideoPresenter cameraVideoPresenter = new BaseCameraVideoPresenter(this);
CameraStateManagement cameraStateManagement = new CameraStateManagement(this);

public static CameraFragment1 newInstance() {
return new CameraFragment1();
}

@Override
public View setContentView(LayoutInflater inflater, ViewGroup container) {
mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_camera1,container,false);
return mBinding.getRoot();
}

@Override
public void initView(View view, Bundle savedInstanceState) {
}

/**
* TODO
* 覆写该事件,赋值自定义按钮事件
*/
@Override
protected void initListener() {
super.initListener();
mBinding.btnCustom.setOnClickListener(v -> Toast.makeText(getMyContext(), "我是自定义的", Toast.LENGTH_SHORT).show());
}

@NonNull
@Override
public IChildClickableLayout getChildClickableLayout() {
return mBinding.rlMain;
}

@Nullable
@Override
public View getTopView() {
return mBinding.clMenu;
}

@NonNull
@Override
public CameraView getCameraView() {
return mBinding.cameraView;
}

@Override
public RecyclerView getRecyclerViewPhoto() {
return mBinding.rlPhoto;
}

@Nullable
@Override
public View[] getMultiplePhotoView() {
return new View[]{mBinding.vLine1, mBinding.vLine2};
}

@NonNull
@Override
public PhotoVideoLayout getPhotoVideoLayout() {
return mBinding.pvLayout;
}

@NonNull
@Override
public com.zhongjh.albumcamerarecorder.widget.ImageViewTouch getSinglePhotoView() {
return mBinding.imgPhoto;
}

@Nullable
@Override
public View getCloseView() {
return mBinding.imgClose;
}

@Nullable
@Override
public ImageView getFlashView() {
return mBinding.imgFlash;
}

@Nullable
@Override
public ImageView getSwitchView() {
return mBinding.imgSwitch;
}

@NonNull
@Override
public CameraStateManagement getCameraStateManagement() {
return cameraStateManagement;
}

@NonNull
@Override
public BaseCameraPicturePresenter getCameraPicturePresenter() {
return cameraPicturePresenter;
}

@NonNull
@Override
public BaseCameraVideoPresenter getCameraVideoPresenter() {
return cameraVideoPresenter;
}

}
Loading

0 comments on commit cfcf0a2

Please sign in to comment.