Skip to content

Commit 7f26c16

Browse files
committed
update android.
1 parent c051212 commit 7f26c16

File tree

7 files changed

+236
-178
lines changed

7 files changed

+236
-178
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Add following to your *build.settings* to use:
99
["plugin.screenRecorder"] = {
1010
publisherId = "com.labolado",
1111
supportedPlatforms = {
12-
["android"] = {url = "https://github.com/labolado/solar2d-plugin_screen_recorder/releases/download/v6/2020.3620-android.tgz"},
13-
["iphone"] = {url = "https://github.com/labolado/solar2d-plugin_screen_recorder/releases/download/v6/2020.3620-iphone.tgz"},
14-
["iphone-sim"] = {url = "https://github.com/labolado/solar2d-plugin_screen_recorder/releases/download/v6/2020.3620-iphone-sim.tgz"},
12+
["android"] = {url = "https://github.com/labolado/solar2d-plugin_screen_recorder/releases/download/v7/2020.3620-android.tgz"},
13+
["iphone"] = {url = "https://github.com/labolado/solar2d-plugin_screen_recorder/releases/download/v7/2020.3620-iphone.tgz"},
14+
["iphone-sim"] = {url = "https://github.com/labolado/solar2d-plugin_screen_recorder/releases/download/v7/2020.3620-iphone-sim.tgz"},
1515
}
1616
}
1717
},
359 Bytes
Binary file not shown.

src/android/plugin/src/main/AndroidManifest.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools">
4+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
5+
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
6+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
47
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
58
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
69
<uses-permission android:name="android.permission.RECORD_AUDIO" />
710

811
<application
9-
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
1012
tools:targetApi="q">
1113

14+
<activity android:name=".VideoPreviewActivity"
15+
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
16+
android:configChanges="keyboard|keyboardHidden|navigation|screenSize|orientation"
17+
android:screenOrientation="fullSensor"
18+
android:exported="false">
19+
</activity>
20+
1221
<service android:name="com.hbisoft.hbrecorder.ScreenRecordService"
1322
android:foregroundServiceType="mediaProjection|microphone"
1423
tools:targetApi="q" />

src/android/plugin/src/main/java/plugin/screenRecorder/LuaLoader.java

Lines changed: 8 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,20 @@
1212
import static android.app.Activity.RESULT_OK;
1313

1414
import android.Manifest;
15-
import android.annotation.SuppressLint;
1615
import android.content.ContentResolver;
1716
import android.content.ContentValues;
1817
import android.content.Context;
1918
import android.content.Intent;
20-
import android.content.pm.ActivityInfo;
2119
import android.content.pm.PackageManager;
22-
import android.graphics.PorterDuff;
23-
import android.graphics.drawable.Drawable;
24-
import android.media.MediaPlayer;
2520
import android.media.MediaScannerConnection;
2621
import android.media.projection.MediaProjectionManager;
2722
import android.net.Uri;
2823
import android.os.Build;
2924
import android.os.Environment;
30-
import android.os.Handler;
3125
import android.provider.MediaStore;
32-
import android.transition.Transition;
33-
import android.transition.TransitionInflater;
3426
import android.util.Log;
35-
import android.view.Gravity;
36-
import android.view.LayoutInflater;
37-
import android.view.MotionEvent;
38-
import android.view.Surface;
39-
import android.view.SurfaceHolder;
40-
import android.view.SurfaceView;
41-
import android.view.View;
42-
import android.view.ViewGroup;
43-
import android.widget.Button;
44-
import android.widget.FrameLayout;
45-
import android.widget.ImageButton;
46-
import android.widget.ImageView;
47-
import android.widget.LinearLayout;
48-
import android.widget.MediaController;
49-
import android.widget.PopupWindow;
50-
import android.widget.RelativeLayout;
51-
import android.widget.SeekBar;
52-
import android.widget.TextView;
5327
import android.widget.Toast;
54-
import android.widget.VideoView;
5528

56-
import androidx.annotation.NonNull;
5729
import androidx.core.app.ActivityCompat;
5830
import androidx.core.content.ContextCompat;
5931

@@ -71,7 +43,6 @@
7143
import com.hbisoft.hbrecorder.HBRecorderListener;
7244

7345
import java.io.File;
74-
import java.nio.file.Path;
7546
import java.sql.Date;
7647
import java.text.SimpleDateFormat;
7748
import java.util.Locale;
@@ -387,162 +358,27 @@ private void updateGalleryUri() {
387358
showPopup(activity, true);
388359
}
389360

390-
private void createShareItent(CoronaActivity activity, boolean wasUri) {
391-
Uri videoUri;
392-
if (wasUri) {
393-
videoUri = mUri;
394-
} else {
395-
videoUri = Uri.fromFile(new File(fRecorder.getFilePath()));
396-
}
397-
398-
activity.runOnUiThread(new Runnable() {
399-
@Override
400-
public void run() {
401-
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
402-
Intent shareIntent = new Intent(Intent.ACTION_SEND);
403-
shareIntent.setType("video/mp4");
404-
shareIntent.putExtra(Intent.EXTRA_STREAM, videoUri);
405-
// activity.startActivity(Intent.createChooser(shareIntent, "选择分享方式"));
406-
// activity.setRequestedOrientation(originOrientation);
407-
activity.startActivityForResult(Intent.createChooser(shareIntent, "选择分享方式"), fSHARE_REQUEST_CODE);
408-
}
409-
});
410-
}
411-
412361
private void showPopup(CoronaActivity activity, boolean wasUri) {
413-
// createShareItent(activity, wasUri);
414362
activity.runOnUiThread(new Runnable() {
415363
@Override
416364
public void run() {
417-
// activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
418-
419-
View contentView = activity.getLayoutInflater().inflate(R.layout.video_preview, null);
420-
PopupWindow popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
421-
CustomVideoView videoView = contentView.findViewById(R.id.videoPreview);
422365
Uri videoUri;
366+
String filename;
423367
if (wasUri) {
424368
videoUri = mUri;
425-
videoView.setVideoURI(videoUri);
369+
filename = mUri.toString();
426370
} else {
427371
videoUri = Uri.fromFile(new File(fRecorder.getFilePath()));
428-
videoView.setVideoPath(fRecorder.getFilePath());
372+
filename =fRecorder.getFilePath();
429373
}
430-
MediaController mediaController = new MediaController(activity);
431-
mediaController.setAnchorView(videoView);
432-
videoView.setMediaController(mediaController);
433-
434-
final boolean[] firstStart = {false};
435-
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
436-
@Override
437-
public void onPrepared(MediaPlayer mp) {
438-
calculateView(videoView, mp.getVideoWidth(), mp.getVideoHeight());
439-
firstStart[0] = true;
440-
videoView.start();
441-
videoView.pause();
442-
mediaController.show();
443-
}
444-
});
445-
446-
ImageButton shareButton = contentView.findViewById(R.id.shareButton);
447-
shareButton.setOnClickListener(new View.OnClickListener() {
448-
@Override
449-
public void onClick(View v) {
450-
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
451-
Intent shareIntent = new Intent(Intent.ACTION_SEND);
452-
shareIntent.setType("video/mp4");
453-
shareIntent.putExtra(Intent.EXTRA_STREAM, videoUri);
454-
// shareIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mFilename);
455-
// shareIntent.putExtra(Intent.EXTRA_TITLE, mFilename);
456-
// shareIntent.putExtra(Intent.EXTRA_TITLE, mFilename);
457-
// activity.setRequestedOrientation(originOrientation);
458-
activity.startActivityForResult(
459-
Intent.createChooser(shareIntent, activity.getResources().getText(R.string.share_chooser_title)), fSHARE_REQUEST_CODE);
460-
}
461-
});
462-
463-
ImageButton closeButton = contentView.findViewById(R.id.closeButton);
464-
closeButton.setOnClickListener(new View.OnClickListener() {
465-
@Override
466-
public void onClick(View v) {
467-
popupWindow.dismiss();
468-
}
469-
});
470-
471-
RelativeLayout titleBar = contentView.findViewById(R.id.titleBar);
472-
// videoView.setPlayPauseListener(new CustomVideoView.PlayPauseListener() {
473-
// @Override
474-
// public void onPlay() {
475-
// if (!firstStart[0]) {
476-
// titleBar.setVisibility(View.GONE);
477-
// } else {
478-
// firstStart[0] = false;
479-
// }
480-
// }
481-
// @Override
482-
// public void onPause() {
483-
// titleBar.setVisibility(View.VISIBLE);
484-
// }
485-
// });
486-
487-
// videoView.setOnTouchListener(new View.OnTouchListener() {
488-
// @Override
489-
// public boolean onTouch(View view, MotionEvent event) {
490-
// if (event.getAction() == MotionEvent.ACTION_DOWN) {
491-
// if (titleBar.getVisibility() == View.VISIBLE) {
492-
// titleBar.setVisibility(View.GONE);
493-
// // mediaController.hide();
494-
// } else {
495-
// titleBar.setVisibility(View.VISIBLE);
496-
// // mediaController.show();
497-
// }
498-
// }
499-
// return false;
500-
// }
501-
// });
502-
503-
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
504-
@Override
505-
public void onCompletion(MediaPlayer mediaPlayer) {
506-
titleBar.setVisibility(View.VISIBLE);
507-
videoView.pause();
508-
}
509-
});
510-
511-
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
512-
@Override
513-
public void onDismiss() {
514-
videoView.stopPlayback();
515-
activity.setRequestedOrientation(activity.getOrientationFromManifest());
516-
}
517-
});
518-
519-
TextView title = contentView.findViewById(R.id.previewTitle);
520-
title.setText(R.string.preview_title);
521-
522-
// popupWindow.setFocusable(false);
523-
popupWindow.setOutsideTouchable(false);
524-
popupWindow.setAnimationStyle(R.style.popwin_anim);
525-
// popupWindow.showAsDropDown(activity.getOverlayView());
526-
popupWindow.showAtLocation(activity.getOverlayView(), Gravity.CENTER, 0, 0);
374+
Intent intent = new Intent(activity, VideoPreviewActivity.class);
375+
intent.putExtra("videoFile", filename);
376+
intent.putExtra("originOrientation", activity.getOrientationFromManifest());
377+
activity.startActivityForResult(intent, fSHARE_REQUEST_CODE);
527378
}
528379
});
529380
}
530381

531-
public void calculateView(VideoView videoView, int videoWidth, int videoHeight) {
532-
int videoViewWidth = videoView.getWidth();
533-
int videoViewHeight = videoView.getHeight();
534-
535-
float videoAspectRatio = (float) videoWidth / videoHeight;
536-
float newVideoWidth = videoViewHeight * videoAspectRatio;
537-
reSetVideoViewWidth(videoView, (int) newVideoWidth);
538-
}
539-
540-
private void reSetVideoViewWidth(VideoView videoView, int newWidth) {
541-
ViewGroup.LayoutParams lp = videoView.getLayoutParams();
542-
lp.width = newWidth;
543-
videoView.setLayoutParams(lp);
544-
}
545-
546382
/**
547383
* Simple example on how to dispatch events to Lua. Note that events are dispatched with
548384
* Runtime dispatcher. It ensures that Lua is accessed on it's thread to avoid race conditions
@@ -675,7 +511,7 @@ private class InitWrapper implements NamedJavaFunction {
675511
public String getName() {
676512
return "init";
677513
}
678-
514+
679515
/**
680516
* This method is called when the Lua function is called.
681517
* <p>

0 commit comments

Comments
 (0)