|
12 | 12 | import static android.app.Activity.RESULT_OK;
|
13 | 13 |
|
14 | 14 | import android.Manifest;
|
15 |
| -import android.annotation.SuppressLint; |
16 | 15 | import android.content.ContentResolver;
|
17 | 16 | import android.content.ContentValues;
|
18 | 17 | import android.content.Context;
|
19 | 18 | import android.content.Intent;
|
20 |
| -import android.content.pm.ActivityInfo; |
21 | 19 | import android.content.pm.PackageManager;
|
22 |
| -import android.graphics.PorterDuff; |
23 |
| -import android.graphics.drawable.Drawable; |
24 |
| -import android.media.MediaPlayer; |
25 | 20 | import android.media.MediaScannerConnection;
|
26 | 21 | import android.media.projection.MediaProjectionManager;
|
27 | 22 | import android.net.Uri;
|
28 | 23 | import android.os.Build;
|
29 | 24 | import android.os.Environment;
|
30 |
| -import android.os.Handler; |
31 | 25 | import android.provider.MediaStore;
|
32 |
| -import android.transition.Transition; |
33 |
| -import android.transition.TransitionInflater; |
34 | 26 | 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; |
53 | 27 | import android.widget.Toast;
|
54 |
| -import android.widget.VideoView; |
55 | 28 |
|
56 |
| -import androidx.annotation.NonNull; |
57 | 29 | import androidx.core.app.ActivityCompat;
|
58 | 30 | import androidx.core.content.ContextCompat;
|
59 | 31 |
|
|
71 | 43 | import com.hbisoft.hbrecorder.HBRecorderListener;
|
72 | 44 |
|
73 | 45 | import java.io.File;
|
74 |
| -import java.nio.file.Path; |
75 | 46 | import java.sql.Date;
|
76 | 47 | import java.text.SimpleDateFormat;
|
77 | 48 | import java.util.Locale;
|
@@ -387,162 +358,27 @@ private void updateGalleryUri() {
|
387 | 358 | showPopup(activity, true);
|
388 | 359 | }
|
389 | 360 |
|
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 |
| - |
412 | 361 | private void showPopup(CoronaActivity activity, boolean wasUri) {
|
413 |
| - // createShareItent(activity, wasUri); |
414 | 362 | activity.runOnUiThread(new Runnable() {
|
415 | 363 | @Override
|
416 | 364 | 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); |
422 | 365 | Uri videoUri;
|
| 366 | + String filename; |
423 | 367 | if (wasUri) {
|
424 | 368 | videoUri = mUri;
|
425 |
| - videoView.setVideoURI(videoUri); |
| 369 | + filename = mUri.toString(); |
426 | 370 | } else {
|
427 | 371 | videoUri = Uri.fromFile(new File(fRecorder.getFilePath()));
|
428 |
| - videoView.setVideoPath(fRecorder.getFilePath()); |
| 372 | + filename =fRecorder.getFilePath(); |
429 | 373 | }
|
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); |
527 | 378 | }
|
528 | 379 | });
|
529 | 380 | }
|
530 | 381 |
|
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 |
| - |
546 | 382 | /**
|
547 | 383 | * Simple example on how to dispatch events to Lua. Note that events are dispatched with
|
548 | 384 | * 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 {
|
675 | 511 | public String getName() {
|
676 | 512 | return "init";
|
677 | 513 | }
|
678 |
| - |
| 514 | + |
679 | 515 | /**
|
680 | 516 | * This method is called when the Lua function is called.
|
681 | 517 | * <p>
|
|
0 commit comments