Commit b86849771513cd183071e5dd5e156a5894be102e
1 parent
9610bf97
处理默认
Showing
5 changed files
with
61 additions
and
10 deletions
app/src/main/java/com/cnlive/strike/debug/MainActivity.java
| ... | ... | @@ -66,8 +66,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe |
| 66 | 66 | case R.id.tv_media: |
| 67 | 67 | //打开相册 |
| 68 | 68 | new ImagePicker.Builder() |
| 69 | - .maxNum(5) | |
| 70 | - .setSelectGif(false) | |
| 69 | + .maxNum(1) | |
| 70 | + .setSelectGif(true) | |
| 71 | 71 | .maxImageSize(25 * 1024 * 1024) |
| 72 | 72 | .maxVideoSize(100*1024*1024) |
| 73 | 73 | .isReturnUri(AndroidQUtil.isAndroidQ()) | ... | ... |
lib_media/src/main/java/com/cnlive/media/frame/view/RecordFragmentView.java
| ... | ... | @@ -59,6 +59,8 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | public void initView() { |
| 62 | + | |
| 63 | + Log.e("启动流程","initView"); | |
| 62 | 64 | if (getActivity().mOptions == null) { |
| 63 | 65 | showMesage("数据异常"); |
| 64 | 66 | mFragment.getActivity().finish(); |
| ... | ... | @@ -110,6 +112,7 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { |
| 110 | 112 | videoCaceDirPath = getActivity().mOptions.getCachePath(); |
| 111 | 113 | } |
| 112 | 114 | } |
| 115 | + Log.e("启动流程","initView2"); | |
| 113 | 116 | getActivity().mOptions.setCachePath(videoCaceDirPath); |
| 114 | 117 | recordSetting.setVideoCacheDir(videoCaceDirPath); |
| 115 | 118 | ... | ... |
lib_media/src/main/java/com/cnlive/media/frame/view/RecordView.java
| ... | ... | @@ -33,6 +33,7 @@ public class RecordView implements MvpView { |
| 33 | 33 | |
| 34 | 34 | RecordActivity mActivity; |
| 35 | 35 | |
| 36 | + | |
| 36 | 37 | public RecordView(RecordActivity mActivity) { |
| 37 | 38 | this.mActivity = mActivity; |
| 38 | 39 | } |
| ... | ... | @@ -68,7 +69,11 @@ public class RecordView implements MvpView { |
| 68 | 69 | hasPermissions = mActivity.getPresenter().checkPermissions(mActivity, mActivity.permissionsRecordNoAudio, mActivity.PERMISISSION_CODE_ASK, true); |
| 69 | 70 | } |
| 70 | 71 | if (hasPermissions) { |
| 71 | - mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.pre_frame, RecordFragment.newInstance()).addToBackStack("").commit(); | |
| 72 | + if ( mActivity.getSupportFragmentManager().getFragments()==null|| mActivity.getSupportFragmentManager().getFragments().size()==0){ | |
| 73 | + mActivity.isInit=true; | |
| 74 | + mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.pre_frame, RecordFragment.newInstance()).addToBackStack("").commit(); | |
| 75 | + | |
| 76 | + } | |
| 72 | 77 | } |
| 73 | 78 | |
| 74 | 79 | } | ... | ... |
lib_media/src/main/java/com/cnlive/media/ui/activity/RecordActivity.java
| ... | ... | @@ -7,6 +7,8 @@ import android.content.Intent; |
| 7 | 7 | import android.graphics.Bitmap; |
| 8 | 8 | import android.graphics.Color; |
| 9 | 9 | import android.os.Bundle; |
| 10 | +import android.os.PersistableBundle; | |
| 11 | +import android.util.Log; | |
| 10 | 12 | |
| 11 | 13 | import androidx.annotation.NonNull; |
| 12 | 14 | import androidx.fragment.app.Fragment; |
| ... | ... | @@ -42,7 +44,7 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent |
| 42 | 44 | |
| 43 | 45 | |
| 44 | 46 | public ImagePickerOptions mOptions; |
| 45 | - | |
| 47 | + public boolean isInit = false; | |
| 46 | 48 | public Bitmap preBitmap; |
| 47 | 49 | public String videoPath; |
| 48 | 50 | public int resultCode; |
| ... | ... | @@ -57,7 +59,7 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent |
| 57 | 59 | // 是否需要录音权限 |
| 58 | 60 | public boolean isNeedAudio = true; |
| 59 | 61 | public static String[] permissionsRecord = {Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}; |
| 60 | - public static String[] permissionsRecordNoAudio = {Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO,Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}; | |
| 62 | + public static String[] permissionsRecordNoAudio = {Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}; | |
| 61 | 63 | |
| 62 | 64 | public static void newInstance(Context context, ImagePickerOptions mOptions) { |
| 63 | 65 | Intent intent = new Intent(); |
| ... | ... | @@ -77,12 +79,21 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent |
| 77 | 79 | this.getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT); |
| 78 | 80 | StatusBarUtil2.setTransparentForWindow(this); |
| 79 | 81 | StatusBarUtil2.addTranslucentView(this, 0); |
| 82 | + Log.e("启动流程:","onCreate"+savedInstanceState); | |
| 80 | 83 | QiniuVideoUtil.chcekInitState(this, isInit -> { |
| 81 | 84 | if (isInit) { |
| 82 | - resultCode = getIntent().getIntExtra(PickerConfig.RESULT_CODE, 0); | |
| 83 | - isJumpCamera = getIntent().getBooleanExtra(PickerConfig.WHERE_JUMP_CAMERA, false); | |
| 84 | - selectMedia = getIntent().getParcelableArrayListExtra(PickerConfig.WHERE_JUMP_CAMERA_SELECTS); | |
| 85 | - mOptions = getIntent().getParcelableExtra(PickerConfig.INTENT_KEY_OPTIONS); | |
| 85 | + | |
| 86 | + if (savedInstanceState != null) { | |
| 87 | + mOptions = savedInstanceState.getParcelable(PickerConfig.INTENT_KEY_OPTIONS); | |
| 88 | + resultCode = savedInstanceState.getInt(PickerConfig.RESULT_CODE, resultCode); | |
| 89 | + isJumpCamera = savedInstanceState.getBoolean(PickerConfig.WHERE_JUMP_CAMERA, isJumpCamera); | |
| 90 | + } else { | |
| 91 | + resultCode = getIntent().getIntExtra(PickerConfig.RESULT_CODE, 0); | |
| 92 | + isJumpCamera = getIntent().getBooleanExtra(PickerConfig.WHERE_JUMP_CAMERA, false); | |
| 93 | + selectMedia = getIntent().getParcelableArrayListExtra(PickerConfig.WHERE_JUMP_CAMERA_SELECTS); | |
| 94 | + mOptions = getIntent().getParcelableExtra(PickerConfig.INTENT_KEY_OPTIONS); | |
| 95 | + } | |
| 96 | + | |
| 86 | 97 | MeidaResultObservable.getInstance().addObserver(this); |
| 87 | 98 | if (mOptions != null) { |
| 88 | 99 | if (mOptions.getJumpCameraMode() == PickerConfig.CAMERA_MODE_PIC) { |
| ... | ... | @@ -103,8 +114,20 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent |
| 103 | 114 | } |
| 104 | 115 | |
| 105 | 116 | }); |
| 117 | + } | |
| 106 | 118 | |
| 107 | 119 | |
| 120 | + @Override | |
| 121 | + public void onSaveInstanceState(@NonNull Bundle outState, @NonNull PersistableBundle outPersistentState) { | |
| 122 | + super.onSaveInstanceState(outState, outPersistentState); | |
| 123 | + if (outState != null) { | |
| 124 | + if (mOptions != null) outState.putParcelable(PickerConfig.INTENT_KEY_OPTIONS, mOptions); | |
| 125 | + outState.putInt(PickerConfig.RESULT_CODE, resultCode); | |
| 126 | + outState.putBoolean(PickerConfig.WHERE_JUMP_CAMERA, isJumpCamera); | |
| 127 | + if (selectMedia != null) | |
| 128 | + outState.putParcelableArrayList(PickerConfig.WHERE_JUMP_CAMERA_SELECTS, selectMedia); | |
| 129 | + } | |
| 130 | + | |
| 108 | 131 | } |
| 109 | 132 | |
| 110 | 133 | public void showPreViewImg(Bitmap plbitMap) { |
| ... | ... | @@ -132,6 +155,7 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent |
| 132 | 155 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, |
| 133 | 156 | @NonNull int[] grantResults) { |
| 134 | 157 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 158 | + Log.e("启动流程:","onRequestPermissionsResult"+isNeverAsk); | |
| 135 | 159 | if (requestCode == PERMISISSION_CODE_ASK) { |
| 136 | 160 | |
| 137 | 161 | boolean[] hasPermissions = getPresenter().onRequestPermissionsResult(this, requestCode, permissions, grantResults); |
| ... | ... | @@ -153,11 +177,21 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent |
| 153 | 177 | |
| 154 | 178 | } |
| 155 | 179 | |
| 180 | + @Override | |
| 181 | + protected void onNewIntent(Intent intent) { | |
| 182 | + super.onNewIntent(intent); | |
| 183 | + Log.e("启动流程:","onNewIntent"+isNeverAsk); | |
| 184 | + } | |
| 156 | 185 | |
| 157 | 186 | @Override |
| 158 | 187 | protected void onResume() { |
| 159 | 188 | super.onResume(); |
| 160 | - | |
| 189 | + Log.e("启动流程:","onResume"+isNeverAsk); | |
| 190 | + if (isNeverAsk) { | |
| 191 | + isNeverAsk = false; | |
| 192 | + //永久拒绝后,返回页面时检测权限并初始化 | |
| 193 | + getMvpView().checkPermisssion(); | |
| 194 | + } | |
| 161 | 195 | } |
| 162 | 196 | |
| 163 | 197 | @Override |
| ... | ... | @@ -168,6 +202,7 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent |
| 168 | 202 | @Override |
| 169 | 203 | protected void onDestroy() { |
| 170 | 204 | super.onDestroy(); |
| 205 | + Log.e("启动流程:","onDestroy"+isNeverAsk); | |
| 171 | 206 | MeidaResultObservable.getInstance().deleteObserver(this); |
| 172 | 207 | if (preBitmap != null) { |
| 173 | 208 | // glide 加载维护了 bitmap 回收 | ... | ... |
lib_media/src/main/java/com/cnlive/media/ui/fragment/RecordFragment.java
| ... | ... | @@ -3,6 +3,7 @@ package com.cnlive.media.ui.fragment; |
| 3 | 3 | import android.graphics.Bitmap; |
| 4 | 4 | import android.os.Bundle; |
| 5 | 5 | import android.text.TextUtils; |
| 6 | +import android.util.Log; | |
| 6 | 7 | import android.view.View; |
| 7 | 8 | |
| 8 | 9 | import androidx.activity.OnBackPressedCallback; |
| ... | ... | @@ -10,6 +11,7 @@ import androidx.annotation.Nullable; |
| 10 | 11 | |
| 11 | 12 | import com.cnlive.libs.base.frame.fragment.MvpBindingFragment; |
| 12 | 13 | import com.cnlive.libs.base.util.DoublePressed; |
| 14 | +import com.cnlive.media.PickerConfig; | |
| 13 | 15 | import com.cnlive.media.R; |
| 14 | 16 | import com.cnlive.media.databinding.FragmentRecordBinding; |
| 15 | 17 | import com.cnlive.media.frame.presenter.RecordFragmentPresenter; |
| ... | ... | @@ -69,14 +71,20 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor |
| 69 | 71 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 70 | 72 | super.onViewCreated(view, savedInstanceState); |
| 71 | 73 | RecordCameraViewObservable.newInstance().addObserver(this); |
| 74 | + Log.e("启动流程:","onViewCreated"+savedInstanceState); | |
| 72 | 75 | if (getMvpView() != null) getMvpView().initView(); |
| 73 | 76 | requireActivity().getOnBackPressedDispatcher().addCallback(this, callback); |
| 74 | 77 | } |
| 75 | 78 | |
| 79 | + @Override | |
| 80 | + public void onSaveInstanceState(Bundle outState) { | |
| 81 | + super.onSaveInstanceState(outState); | |
| 82 | + } | |
| 76 | 83 | |
| 77 | 84 | @Override |
| 78 | 85 | public void onResume() { |
| 79 | 86 | super.onResume(); |
| 87 | + Log.e("启动流程:","FragmentonResume"); | |
| 80 | 88 | if (isFlash && getMvpView() != null) getMvpView().processFlash(isFlash); |
| 81 | 89 | if (plShortVideoRecorder != null) plShortVideoRecorder.resume(); |
| 82 | 90 | plShortVideoRecorder.deleteLastSection(); | ... | ... |