Skip to content

Commit

Permalink
update android.
Browse files Browse the repository at this point in the history
  • Loading branch information
zero-meta committed Aug 26, 2024
1 parent 625afd4 commit 137cac9
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 113 deletions.
Binary file modified plugins/2020.3620/android/plugin.screenRecorder.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public void setPlayPauseListener(PlayPauseListener listener) {
mListener = listener;
}

@Override
public boolean performClick() {
return super.performClick();
}

@Override
public void pause() {
super.pause();
Expand Down
128 changes: 47 additions & 81 deletions src/android/plugin/src/main/java/plugin/screenRecorder/LuaLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static android.app.Activity.RESULT_OK;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
Expand All @@ -26,10 +27,14 @@
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
Expand Down Expand Up @@ -425,21 +430,6 @@ public void run() {
MediaController mediaController = new MediaController(activity);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
// videoView.(ImageView.ScaleType.FIT_CENTER);

// MediaPlayer mediaPlayer = MediaPlayer.create(activity, videoUri);
// int videoWidth = mediaPlayer.getVideoWidth();
// int videoHeight = mediaPlayer.getVideoHeight();
// float videoAspectRatio = (float) videoWidth / videoHeight;
// ViewGroup.LayoutParams lp = videoView.getLayoutParams();
// lp.height = (int) (lp.width / videoAspectRatio);
// videoView.setLayoutParams(lp);
// 设置视频保持宽高比
// FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
// ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.MATCH_PARENT,
// android.view.Gravity.CENTER);
// videoView.setLayoutParams(params);

final boolean[] firstStart = {false};
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
Expand All @@ -453,8 +443,6 @@ public void onPrepared(MediaPlayer mp) {
}
});

// videoView.start();

ImageButton shareButton = contentView.findViewById(R.id.shareButton);
shareButton.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -463,8 +451,9 @@ public void onClick(View v) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("video/mp4");
shareIntent.putExtra(Intent.EXTRA_STREAM, videoUri);
shareIntent.putExtra(Intent.EXTRA_TITLE, mFilename);
// activity.startActivity(Intent.createChooser(shareIntent, "选择分享方式"));
// shareIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mFilename);
// shareIntent.putExtra(Intent.EXTRA_TITLE, mFilename);
// shareIntent.putExtra(Intent.EXTRA_TITLE, mFilename);
// activity.setRequestedOrientation(originOrientation);
activity.startActivityForResult(
Intent.createChooser(shareIntent, activity.getResources().getText(R.string.share_chooser_title)), fSHARE_REQUEST_CODE);
Expand All @@ -480,31 +469,45 @@ public void onClick(View v) {
});

RelativeLayout titleBar = contentView.findViewById(R.id.titleBar);
videoView.setPlayPauseListener(new CustomVideoView.PlayPauseListener() {
@Override
public void onPlay() {
if (!firstStart[0]) {
titleBar.setVisibility(View.GONE);
} else {
firstStart[0] = false;
}
}
@Override
public void onPause() {
titleBar.setVisibility(View.VISIBLE);
}
});
// videoView.setOnClickListener(new View.OnClickListener() {
// videoView.setPlayPauseListener(new CustomVideoView.PlayPauseListener() {
// @Override
// public void onClick(View view) {
// if (titleBar.getVisibility() == View.VISIBLE) {
// public void onPlay() {
// if (!firstStart[0]) {
// titleBar.setVisibility(View.GONE);
// } else {
// titleBar.setVisibility(View.VISIBLE);
// firstStart[0] = false;
// }
// }
// @Override
// public void onPause() {
// titleBar.setVisibility(View.VISIBLE);
// }
// });

// videoView.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View view, MotionEvent event) {
// if (event.getAction() == MotionEvent.ACTION_DOWN) {
// if (titleBar.getVisibility() == View.VISIBLE) {
// titleBar.setVisibility(View.GONE);
// // mediaController.hide();
// } else {
// titleBar.setVisibility(View.VISIBLE);
// // mediaController.show();
// }
// }
// return false;
// }
// });

videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
titleBar.setVisibility(View.VISIBLE);
videoView.pause();
}
});

popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
Expand All @@ -516,59 +519,22 @@ public void onDismiss() {
TextView title = contentView.findViewById(R.id.previewTitle);
title.setText(R.string.preview_title);

// popupWindow.setAnimationStyle(R.anim.popup_animation);
popupWindow.showAtLocation(activity.getOverlayView(), android.view.Gravity.CENTER, 0, 0);
// popupWindow.setFocusable(false);
popupWindow.setOutsideTouchable(false);
popupWindow.setAnimationStyle(R.style.popwin_anim);
// popupWindow.showAsDropDown(activity.getOverlayView());
popupWindow.showAtLocation(activity.getOverlayView(), Gravity.CENTER, 0, 0);
}
});
}

// private void styleMediaController(View view, CoronaActivity activity) {
// if (view instanceof MediaController) {
// MediaController v = (MediaController) view;
// for (int i = 0; i < v.getChildCount(); i++) {
// styleMediaController(v.getChildAt(i), activity);
// }
// } else if (view instanceof LinearLayout) {
// LinearLayout ll = (LinearLayout) view;
// for (int i = 0; i < ll.getChildCount(); i++) {
// styleMediaController(ll.getChildAt(i), activity);
// }
// } else if (view instanceof SeekBar) {
// ((SeekBar) view)
// .getProgressDrawable()
// .mutate()
// .setColorFilter(
// activity.getResources().getColor(
// R.color.MediaPlayerMeterColor),
// PorterDuff.Mode.SRC_IN);
// Drawable thumb = ((SeekBar) view).getThumb().mutate();
// if (thumb instanceof androidx.appcompat.graphics.drawable.DrawableWrapperCompat) {
// //compat mode, requires support library v4
// ((androidx.appcompat.graphics.drawable.DrawableWrapperCompat) thumb).setTint(activity.getResources()
// .getColor(R.color.MediaPlayerThumbColor));
// } else {
// //lollipop devices
// thumb.setColorFilter(
// activity.getResources().getColor(R.color.MediaPlayerThumbColor),
// PorterDuff.Mode.SRC_IN);
// }
// }
// }

public void calculateView(VideoView videoView, int videoWidth, int videoHeight) {
int videoViewWidth = videoView.getWidth();
int videoViewHeight = videoView.getHeight();

if (videoWidth < videoViewWidth && videoHeight >= videoViewHeight) {
float videoAspectRatio = (float) videoWidth / videoHeight;
float newVideoWidth = videoViewHeight / videoAspectRatio;
reSetVideoViewWidth(videoView, (int) newVideoWidth);
} else if (videoWidth > videoViewWidth && videoHeight >= videoViewHeight) {
float videoAspectRatio = (float) videoHeight / videoWidth;
float newVideoWidth = videoViewHeight / videoAspectRatio;
reSetVideoViewWidth(videoView, (int) newVideoWidth);
}
float videoAspectRatio = (float) videoWidth / videoHeight;
float newVideoWidth = videoViewHeight * videoAspectRatio;
reSetVideoViewWidth(videoView, (int) newVideoWidth);
}

private void reSetVideoViewWidth(VideoView videoView, int newWidth) {
Expand Down
8 changes: 8 additions & 0 deletions src/android/plugin/src/main/res/anim/pop_enter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="500"
android:fromYDelta="-100%p"
android:toYDelta="0" />
</set>
8 changes: 8 additions & 0 deletions src/android/plugin/src/main/res/anim/pop_exit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="1000"
android:fromYDelta="0"
android:toYDelta="-100%p" />
</set>
5 changes: 0 additions & 5 deletions src/android/plugin/src/main/res/anim/popup_animation.xml

This file was deleted.

39 changes: 13 additions & 26 deletions src/android/plugin/src/main/res/layout/video_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:drawable/screen_background_dark_transparent">
<!--android:padding="16dp"-->

<!--<View-->
<!-- android:id="@+id/view"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:background="#FFFFFF" />-->

<!--<View-->
<!-- android:id="@+id/line"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="1dp"-->
<!-- android:background="#323232"-->
<!-- android:layout_below="@id/shareButton" />-->

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!--android:layout_below="@id/line" >-->
<!--android:background="@drawable/framelayout_border">-->
<plugin.screenRecorder.CustomVideoView
android:id="@+id/videoPreview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>

<RelativeLayout
android:id="@+id/titleBar"
Expand Down Expand Up @@ -75,4 +49,17 @@
android:src="@android:drawable/ic_menu_close_clear_cancel" />
</RelativeLayout>

<FrameLayout
android:id="@+id/videoFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/titleBar" >
<plugin.screenRecorder.CustomVideoView
android:id="@+id/videoPreview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>


</RelativeLayout>
3 changes: 2 additions & 1 deletion src/android/plugin/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="share_chooser_title">选择分享内容</string>
<string name="preview_title">预览和分享</string>
<string name="share_chooser_title">选择分享方式</string>
</resources>
1 change: 1 addition & 0 deletions src/android/plugin/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="preview_title">預覽和分享</string>
<string name="share_chooser_title">選擇分享方式</string>
</resources>
7 changes: 7 additions & 0 deletions src/android/plugin/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="popwin_anim" parent="android:Animation">
<item name="android:windowEnterAnimation">@anim/pop_enter</item>
<item name="android:windowExitAnimation">@anim/pop_exit</item>
</style>
</resources>

0 comments on commit 137cac9

Please sign in to comment.