Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
罗孟伟 committed Jun 2, 2022
1 parent 5ab8f4e commit ea452a1
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 123 deletions.
57 changes: 7 additions & 50 deletions app/src/main/java/com/luck/pictureselector/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ public class MainActivity extends AppCompatActivity implements IBridgePictureBeh
private int aspect_ratio_x = -1, aspect_ratio_y = -1;
private CheckBox cb_voice, cb_choose_mode, cb_isCamera, cb_isGif,
cb_preview_img, cb_preview_video, cb_crop, cb_compress,
cb_mode, cb_hide, cb_crop_circular, cb_crop_use_bitmap, cb_styleCrop, cb_showCropGrid,
cb_mode, cb_hide, cb_crop_circular, cb_styleCrop, cb_showCropGrid,
cb_showCropFrame, cb_preview_audio, cb_original, cb_single_back,
cb_custom_camera, cbPage, cbEnabledMask, cbEditor, cb_custom_sandbox, cb_only_dir,
cb_preview_full, cb_preview_scale, cb_inject_layout, cb_time_axis, cb_WithImageVideo,
cb_system_album, cb_fast_select, cb_skip_not_gif, cb_not_gif, cb_attach_camera_mode,
cb_attach_system_mode, cb_camera_zoom, cb_camera_focus, cb_query_sort_order, cb_watermark,
cb_custom_preview, cb_permission_desc,cb_video_thumbnails;
cb_custom_preview, cb_permission_desc,cb_video_thumbnails,cb_auto_video;
private int chooseMode = SelectMimeType.ofAll();
private boolean isHasLiftDelete;
private boolean needScaleBig = true;
Expand Down Expand Up @@ -234,6 +234,7 @@ protected void onCreate(Bundle savedInstanceState) {
cb_custom_preview = findViewById(R.id.cb_custom_preview);
cb_permission_desc = findViewById(R.id.cb_permission_desc);
cb_preview_video = findViewById(R.id.cb_preview_video);
cb_auto_video = findViewById(R.id.cb_auto_video);
cb_time_axis = findViewById(R.id.cb_time_axis);
cb_crop = findViewById(R.id.cb_crop);
cbPage = findViewById(R.id.cbPage);
Expand All @@ -254,7 +255,6 @@ protected void onCreate(Bundle savedInstanceState) {
cb_not_gif = findViewById(R.id.cb_not_gif);
cb_skip_not_gif = findViewById(R.id.cb_skip_not_gif);
cb_crop_circular = findViewById(R.id.cb_crop_circular);
cb_crop_use_bitmap = findViewById(R.id.cb_crop_use_bitmap);
cb_attach_camera_mode = findViewById(R.id.cb_attach_camera_mode);
cb_attach_system_mode = findViewById(R.id.cb_attach_system_mode);
cb_mode.setOnCheckedChangeListener(this);
Expand All @@ -278,7 +278,6 @@ protected void onCreate(Bundle savedInstanceState) {
cb_only_dir.setOnCheckedChangeListener(this);
cb_custom_sandbox.setOnCheckedChangeListener(this);
cb_crop_circular.setOnCheckedChangeListener(this);
cb_crop_use_bitmap.setOnCheckedChangeListener(this);
cb_attach_camera_mode.setOnCheckedChangeListener(this);
cb_attach_system_mode.setOnCheckedChangeListener(this);
cb_system_album.setOnCheckedChangeListener(this);
Expand Down Expand Up @@ -364,6 +363,8 @@ public void onItemClick(View v, int position) {
.setImageEngine(imageEngine)
.setSelectorUIStyle(selectorStyle)
.setLanguage(language)
.isAutoVideoPlay(cb_auto_video.isChecked())
.isLoopAutoVideoPlay(cb_auto_video.isChecked())
.isPreviewFullScreenMode(cb_preview_full.isChecked())
.setExternalPreviewEventListener(new MyExternalPreviewEventListener(mAdapter))
.startActivityPreview(position, true, mAdapter.getData());
Expand Down Expand Up @@ -405,6 +406,8 @@ public void openPicture() {
.setPermissionDeniedListener(getPermissionDeniedListener())
.setAddBitmapWatermarkListener(getAddBitmapWatermarkListener())
.setVideoThumbnailListener(getVideoThumbnailEventListener())
.isAutoVideoPlay(cb_auto_video.isChecked())
.isLoopAutoVideoPlay(cb_auto_video.isChecked())
// .setQueryFilterListener(new OnQueryFilterListener() {
// @Override
// public boolean onFilter(String absolutePath) {
Expand Down Expand Up @@ -1403,28 +1406,6 @@ public void loadImage(Context context, String url, ImageView imageView) {

@Override
public void loadImage(Context context, Uri url, int maxWidth, int maxHeight, OnCallbackListener<Bitmap> call) {
if (!ImageLoaderUtils.assertValidRequest(context)) {
return;
}
Glide.with(context).asBitmap().override(maxWidth, maxHeight).load(url).into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
if (call != null) {
call.onCall(resource);
}
}

@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
if (call != null) {
call.onCall(null);
}
}

@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
});
uCrop.start(fragment.getActivity(), fragment, requestCode);
Expand Down Expand Up @@ -1469,28 +1450,6 @@ public void loadImage(Context context, String url, ImageView imageView) {

@Override
public void loadImage(Context context, Uri url, int maxWidth, int maxHeight, OnCallbackListener<Bitmap> call) {
if (!ImageLoaderUtils.assertValidRequest(context)) {
return;
}
Glide.with(context).asBitmap().override(maxWidth, maxHeight).load(url).into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
if (call != null) {
call.onCall(resource);
}
}

@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
if (call != null) {
call.onCall(null);
}
}

@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
});
uCrop.start(fragment.getActivity(), fragment, requestCode);
Expand Down Expand Up @@ -1532,7 +1491,6 @@ private UCrop.Options buildOptions() {
options.withAspectRatio(aspect_ratio_x, aspect_ratio_y);
options.setCropOutputPathDir(getSandboxPath());
options.isCropDragSmoothToCenter(false);
options.isUseCustomLoaderBitmap(cb_crop_use_bitmap.isChecked());
options.setSkipCropMimeType(getNotSupportCrop());
options.isForbidCropGifWebp(cb_not_gif.isChecked());
options.isForbidSkipMultipleCrop(false);
Expand Down Expand Up @@ -2057,7 +2015,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
rgb_crop.setVisibility(isChecked ? View.VISIBLE : View.GONE);
cb_hide.setVisibility(isChecked ? View.VISIBLE : View.GONE);
cb_crop_circular.setVisibility(isChecked ? View.VISIBLE : View.GONE);
cb_crop_use_bitmap.setVisibility(isChecked ? View.VISIBLE : View.GONE);
cb_styleCrop.setVisibility(isChecked ? View.VISIBLE : View.GONE);
cb_showCropFrame.setVisibility(isChecked ? View.VISIBLE : View.GONE);
cb_showCropGrid.setVisibility(isChecked ? View.VISIBLE : View.GONE);
Expand Down
21 changes: 10 additions & 11 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,16 @@
android:textColor="@color/app_color_53575e"
android:textSize="14sp" />

<CheckBox
android:id="@+id/cb_auto_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:gravity="center_vertical"
android:text="预览视频自动播放"
android:textColor="@color/app_color_53575e"
android:textSize="14sp" />

<CheckBox
android:id="@+id/cb_preview_audio"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -752,17 +762,6 @@

</RadioGroup>

<CheckBox
android:id="@+id/cb_crop_use_bitmap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:gravity="center_vertical"
android:text="自定义Loader Bitmap"
android:textColor="@color/app_color_53575e"
android:textSize="14sp"
android:visibility="gone" />

<CheckBox
android:id="@+id/cb_crop_circular"
android:layout_width="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
8 changes: 4 additions & 4 deletions camerax/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ ext {
apply from: '../publish.gradle'

dependencies {
api "androidx.camera:camera-core:1.1.0-beta02"
api "androidx.camera:camera-camera2:1.1.0-beta02"
implementation "androidx.camera:camera-view:1.1.0-beta02"
implementation "androidx.camera:camera-lifecycle:1.1.0-beta02"
api "androidx.camera:camera-core:1.2.0-alpha01"
api "androidx.camera:camera-camera2:1.2.0-alpha01"
implementation "androidx.camera:camera-view:1.2.0-alpha01"
implementation "androidx.camera:camera-lifecycle:1.2.0-alpha01"
implementation "androidx.transition:transition:1.4.1"
implementation "androidx.concurrent:concurrent-futures:1.1.0"
implementation 'androidx.appcompat:appcompat:1.4.1'
Expand Down
28 changes: 17 additions & 11 deletions camerax/src/main/java/com/luck/lib/camerax/CustomCameraView.java
Original file line number Diff line number Diff line change
Expand Up @@ -832,18 +832,24 @@ public MyImageResultCallback(ImageView imagePreview, CaptureLayout captureLayout

@Override
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
if (outputFileResults.getSavedUri() == null || mCaptureLayoutReference.get() == null ||
mImagePreviewReference.get() == null || mImageCallbackListenerReference.get() == null) {
return;
}
Uri savedUri = outputFileResults.getSavedUri();
Context context = mImagePreviewReference.get().getContext();
SimpleCameraX.putOutputUri(((Activity) context).getIntent(), savedUri);
String outPutCameraPath = FileUtils.isContent(savedUri.toString()) ? savedUri.toString() : savedUri.getPath();
mCaptureLayoutReference.get().setButtonCaptureEnabled(true);
mImageCallbackListenerReference.get().onLoadImage(outPutCameraPath, mImagePreviewReference.get());
mImagePreviewReference.get().setVisibility(View.VISIBLE);
mCaptureLayoutReference.get().startTypeBtnAnimator();
if (savedUri != null) {
Context context = mImagePreviewReference.get().getContext();
SimpleCameraX.putOutputUri(((Activity) context).getIntent(), savedUri);
if (mCaptureLayoutReference.get() != null) {
mCaptureLayoutReference.get().setButtonCaptureEnabled(true);
}
if (mImageCallbackListenerReference.get() != null) {
String outPutCameraPath = FileUtils.isContent(savedUri.toString()) ? savedUri.toString() : savedUri.getPath();
mImageCallbackListenerReference.get().onLoadImage(outPutCameraPath, mImagePreviewReference.get());
}
if (mImagePreviewReference.get() != null) {
mImagePreviewReference.get().setVisibility(View.VISIBLE);
}
if (mCaptureLayoutReference.get() != null) {
mCaptureLayoutReference.get().startTypeBtnAnimator();
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public void run() {
mCameraView.setImageCallbackListener(new ImageCallbackListener() {
@Override
public void onLoadImage(String url, ImageView imageView) {
CustomCameraConfig.imageEngine.loadImage(imageView.getContext(), url, imageView);
if (CustomCameraConfig.imageEngine != null) {
CustomCameraConfig.imageEngine.loadImage(imageView.getContext(), url, imageView);
}
}
});
mCameraView.setCameraListener(new CameraListener() {
Expand Down
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ext {
buildToolsVersion : "29.0.2",
minSdkVersion : 21,
targetSdkVersion : 31,
versionCode : 79,
versionName : "v3.0.9",
versionCode : 80,
versionName : "v3.10.0",

//open version control
androidSupportVersion : "27.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public class PictureSelectorPreviewFragment extends PictureCommonFragment {

protected PreviewGalleryAdapter mGalleryAdapter;

protected List<View> mAnimViews;
protected List<View> mAnimViews = new ArrayList<>();


public static PictureSelectorPreviewFragment newInstance() {
Expand Down Expand Up @@ -258,16 +258,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
bottomNarBar = view.findViewById(R.id.bottom_nar_bar);
magicalView.setMagicalContent(viewPager);
setMagicalViewBackgroundColor();
mAnimViews = new ArrayList<>();
mAnimViews.add(titleBar);
mAnimViews.add(tvSelected);
mAnimViews.add(tvSelectedWord);
mAnimViews.add(selectClickArea);
mAnimViews.add(completeSelectView);
mAnimViews.add(bottomNarBar);
addAminViews(titleBar, tvSelected, tvSelectedWord, selectClickArea, completeSelectView, bottomNarBar);
initTitleBar();
initViewPagerData(mData);
iniMagicalView();
if (isExternalPreview) {
externalPreviewStyle();
} else {
Expand All @@ -276,6 +269,16 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
initPreviewSelectGallery((ViewGroup) view);
initComplete();
}
iniMagicalView();
}

/**
* addAminViews
*
* @param views
*/
private void addAminViews(View... views) {
Collections.addAll(mAnimViews, views);
}

private void setMagicalViewBackgroundColor() {
Expand Down Expand Up @@ -384,8 +387,12 @@ public void onBeginMagicalAnimComplete(MagicalView mojitoView, boolean showImmed
}
if (currentHolder instanceof PreviewVideoHolder) {
PreviewVideoHolder videoHolder = (PreviewVideoHolder) currentHolder;
if (videoHolder.ivPlayButton.getVisibility() == View.GONE) {
videoHolder.ivPlayButton.setVisibility(View.VISIBLE);
if (config.isAutoVideoPlay) {
startAutoVideoPlay(viewPager.getCurrentItem());
} else {
if (videoHolder.ivPlayButton.getVisibility() == View.GONE) {
videoHolder.ivPlayButton.setVisibility(View.VISIBLE);
}
}
}
}
Expand Down Expand Up @@ -794,7 +801,7 @@ public void run() {
} else {
mGalleryRecycle.setVisibility(View.INVISIBLE);
}
mAnimViews.add(mGalleryRecycle);
addAminViews(mGalleryRecycle);
ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
@Override
public boolean isLongPressDragEnabled() {
Expand Down Expand Up @@ -1069,7 +1076,6 @@ private void initViewPagerData(ArrayList<LocalMedia> data) {
viewPageAdapter.setOnPreviewEventListener(new MyOnPreviewEventListener());
viewPager.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL);
viewPager.setAdapter(viewPageAdapter);
viewPager.setCurrentItem(curPosition, false);
SelectedManager.clearPreviewData();
if (data.size() == 0 || curPosition > data.size()) {
onKeyBackFragmentFinish();
Expand All @@ -1081,6 +1087,7 @@ private void initViewPagerData(ArrayList<LocalMedia> data) {
tvSelected.setSelected(SelectedManager.getSelectedResult().contains(data.get(viewPager.getCurrentItem())));
viewPager.registerOnPageChangeCallback(pageChangeCallback);
viewPager.setPageTransformer(new MarginPageTransformer(DensityUtil.dip2px(getContext(), 3)));
viewPager.setCurrentItem(curPosition, false);
sendChangeSubSelectPositionEvent(false);
notifySelectNumberStyle(data.get(curPosition));
}
Expand Down Expand Up @@ -1317,7 +1324,15 @@ public void onPageSelected(int position) {
}
if (config.isPreviewZoomEffect) {
if (isFirstLoaded || isInternalBottomPreview) {
viewPageAdapter.setVideoPlayButtonUI(position);
if (config.isAutoVideoPlay) {
startAutoVideoPlay(position);
} else {
viewPageAdapter.setVideoPlayButtonUI(position);
}
}
} else {
if (config.isAutoVideoPlay) {
startAutoVideoPlay(position);
}
}
notifyGallerySelectMedia(currentMedia);
Expand All @@ -1337,6 +1352,19 @@ public void onPageSelected(int position) {
}
};

/**
* 自动播放视频
*
* @param position
*/
private void startAutoVideoPlay(int position) {
viewPager.post(new Runnable() {
@Override
public void run() {
viewPageAdapter.startAutoVideoPlay(position);
}
});
}

/**
* 更新MagicalView ViewParams 参数
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.luck.picture.lib.adapter;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

Expand Down Expand Up @@ -108,6 +109,19 @@ public void setVideoPlayButtonUI(int position) {
}
}

/**
* 设置自动播放视频
*
* @param position
*/
public void startAutoVideoPlay(int position) {
BasePreviewHolder currentHolder = getCurrentHolder(position);
if (currentHolder instanceof PreviewVideoHolder) {
PreviewVideoHolder videoHolder = (PreviewVideoHolder) currentHolder;
videoHolder.startPlay();
}
}

/**
* 释放当前视频相关
*/
Expand Down
Loading

0 comments on commit ea452a1

Please sign in to comment.