|
@@ -2,13 +2,17 @@ package com.izouma.screen_stream_plugin;
|
|
|
|
|
|
|
|
import android.annotation.TargetApi;
|
|
import android.annotation.TargetApi;
|
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
|
|
|
+import android.app.AlertDialog;
|
|
|
|
|
+import android.app.Dialog;
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.ComponentName;
|
|
import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
import android.content.IntentFilter;
|
|
|
import android.content.ServiceConnection;
|
|
import android.content.ServiceConnection;
|
|
|
import android.content.SharedPreferences;
|
|
import android.content.SharedPreferences;
|
|
|
|
|
+import android.content.pm.ApplicationInfo;
|
|
|
import android.graphics.Color;
|
|
import android.graphics.Color;
|
|
|
import android.graphics.PixelFormat;
|
|
import android.graphics.PixelFormat;
|
|
|
import android.media.projection.MediaProjectionManager;
|
|
import android.media.projection.MediaProjectionManager;
|
|
@@ -16,16 +20,23 @@ import android.net.Uri;
|
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
|
import android.provider.Settings;
|
|
import android.provider.Settings;
|
|
|
|
|
+import android.util.TypedValue;
|
|
|
import android.view.Gravity;
|
|
import android.view.Gravity;
|
|
|
|
|
+import android.view.LayoutInflater;
|
|
|
import android.view.MotionEvent;
|
|
import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.view.WindowManager;
|
|
import android.view.WindowManager;
|
|
|
import android.widget.Button;
|
|
import android.widget.Button;
|
|
|
|
|
+import android.widget.ImageButton;
|
|
|
|
|
+import android.widget.ImageView;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
+import java.util.Timer;
|
|
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
|
|
|
import io.flutter.plugin.common.MethodCall;
|
|
import io.flutter.plugin.common.MethodCall;
|
|
|
import io.flutter.plugin.common.MethodChannel;
|
|
import io.flutter.plugin.common.MethodChannel;
|
|
@@ -47,7 +58,7 @@ public class ScreenStreamPlugin implements MethodChannel.MethodCallHandler, Plug
|
|
|
|
|
|
|
|
private WindowManager windowManager;
|
|
private WindowManager windowManager;
|
|
|
private WindowManager.LayoutParams layoutParams;
|
|
private WindowManager.LayoutParams layoutParams;
|
|
|
- private Button floatButton;
|
|
|
|
|
|
|
+ private ImageButton floatButton;
|
|
|
private int playerInfoId;
|
|
private int playerInfoId;
|
|
|
|
|
|
|
|
private VideoProcessService.VideoProcessBinder videoProcessBinder;
|
|
private VideoProcessService.VideoProcessBinder videoProcessBinder;
|
|
@@ -86,10 +97,12 @@ public class ScreenStreamPlugin implements MethodChannel.MethodCallHandler, Plug
|
|
|
layoutParams.format = PixelFormat.RGBA_8888;
|
|
layoutParams.format = PixelFormat.RGBA_8888;
|
|
|
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
|
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
|
|
layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
|
layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
|
|
- layoutParams.width = 200;
|
|
|
|
|
- layoutParams.height = 100;
|
|
|
|
|
- layoutParams.x = 300;
|
|
|
|
|
- layoutParams.y = 300;
|
|
|
|
|
|
|
+ layoutParams.width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 42, registrar.activity().getResources().getDisplayMetrics());
|
|
|
|
|
+ layoutParams.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, registrar.activity().getResources().getDisplayMetrics());
|
|
|
|
|
+ layoutParams.x = layoutParams.width / 2;
|
|
|
|
|
+ layoutParams.y = layoutParams.height / 2;
|
|
|
|
|
+
|
|
|
|
|
+ // showFloatWindow();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -149,22 +162,27 @@ public class ScreenStreamPlugin implements MethodChannel.MethodCallHandler, Plug
|
|
|
if (floatButton != null) {
|
|
if (floatButton != null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//判断系统版本
|
|
|
|
|
- if (Settings.canDrawOverlays(registrar.context())) {
|
|
|
|
|
- floatButton = new Button(registrar.context().getApplicationContext());
|
|
|
|
|
- floatButton.setText("CLICK ME!");
|
|
|
|
|
- floatButton.setBackgroundColor(Color.LTGRAY);
|
|
|
|
|
- floatButton.setVisibility(View.GONE);
|
|
|
|
|
- windowManager.addView(floatButton, layoutParams);
|
|
|
|
|
- floatButton.setOnTouchListener(new FloatingOnTouchListener());
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- floatButton = new Button(registrar.context().getApplicationContext());
|
|
|
|
|
- floatButton.setText("CLICK ME!");
|
|
|
|
|
- floatButton.setBackgroundColor(Color.LTGRAY);
|
|
|
|
|
|
|
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(registrar.context())) {
|
|
|
|
|
+ floatButton = new ImageButton(registrar.context().getApplicationContext());
|
|
|
|
|
+ floatButton.setAlpha(0.5f);
|
|
|
|
|
+ floatButton.setPadding(0, 0, 0, 0);
|
|
|
|
|
+ floatButton.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
|
|
+ floatButton.setImageResource(R.mipmap.icon_float_button);
|
|
|
|
|
+ floatButton.setBackgroundColor(Color.TRANSPARENT);
|
|
|
floatButton.setVisibility(View.GONE);
|
|
floatButton.setVisibility(View.GONE);
|
|
|
windowManager.addView(floatButton, layoutParams);
|
|
windowManager.addView(floatButton, layoutParams);
|
|
|
floatButton.setOnTouchListener(new FloatingOnTouchListener());
|
|
floatButton.setOnTouchListener(new FloatingOnTouchListener());
|
|
|
|
|
+ floatButton.setOnClickListener(v -> {
|
|
|
|
|
+ floatButton.setEnabled(false);
|
|
|
|
|
+ Timer timer = new Timer();
|
|
|
|
|
+ timer.schedule(new TimerTask() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ registrar.activity().runOnUiThread(() -> floatButton.setEnabled(true));
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 500);
|
|
|
|
|
+ showCustomPopupMenu();
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -240,6 +258,7 @@ public class ScreenStreamPlugin implements MethodChannel.MethodCallHandler, Plug
|
|
|
public boolean onTouch(View view, MotionEvent event) {
|
|
public boolean onTouch(View view, MotionEvent event) {
|
|
|
switch (event.getAction()) {
|
|
switch (event.getAction()) {
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
|
|
+ floatButton.setAlpha(1f);
|
|
|
x = (int) event.getRawX();
|
|
x = (int) event.getRawX();
|
|
|
y = (int) event.getRawY();
|
|
y = (int) event.getRawY();
|
|
|
ts = System.currentTimeMillis();
|
|
ts = System.currentTimeMillis();
|
|
@@ -258,11 +277,7 @@ public class ScreenStreamPlugin implements MethodChannel.MethodCallHandler, Plug
|
|
|
moved = true;
|
|
moved = true;
|
|
|
break;
|
|
break;
|
|
|
case MotionEvent.ACTION_UP:
|
|
case MotionEvent.ACTION_UP:
|
|
|
- if (System.currentTimeMillis() - ts < 300) {
|
|
|
|
|
- Intent intent = new Intent(registrar.context().getApplicationContext(), registrar.activity().getClass());
|
|
|
|
|
- intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
|
|
|
|
- registrar.activity().startActivity(intent);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ makeTranslucent();
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
break;
|
|
@@ -270,4 +285,52 @@ public class ScreenStreamPlugin implements MethodChannel.MethodCallHandler, Plug
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public static String getApplicationName(Context context) {
|
|
|
|
|
+ ApplicationInfo applicationInfo = context.getApplicationInfo();
|
|
|
|
|
+ int stringId = applicationInfo.labelRes;
|
|
|
|
|
+ return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void showCustomPopupMenu() {
|
|
|
|
|
+ LayoutInflater layoutInflater = (LayoutInflater) this.registrar.context().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
|
+ View dialogOverlay = layoutInflater.inflate(R.layout.dialog, null);
|
|
|
|
|
+ dialogOverlay.findViewById(R.id.btn_cancel).setOnClickListener(v -> {
|
|
|
|
|
+ windowManager.removeView(dialogOverlay);
|
|
|
|
|
+ });
|
|
|
|
|
+ dialogOverlay.findViewById(R.id.btn_ok).setOnClickListener(v -> {
|
|
|
|
|
+ windowManager.removeView(dialogOverlay);
|
|
|
|
|
+ Intent intent = new Intent(registrar.context().getApplicationContext(), registrar.activity().getClass());
|
|
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
|
|
|
|
+ registrar.activity().startActivity(intent);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ ((TextView) dialogOverlay.findViewById(R.id.tv_msg)).setText("是否立即返回" + getApplicationName(registrar.context()) + "?");
|
|
|
|
|
+ WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
+ params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ params.type = WindowManager.LayoutParams.TYPE_PHONE;
|
|
|
|
|
+ }
|
|
|
|
|
+ params.format = PixelFormat.RGBA_8888;
|
|
|
|
|
+ params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
|
|
|
|
+ params.gravity = Gravity.CENTER;
|
|
|
|
|
+ windowManager.addView(dialogOverlay, params);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Timer timer;
|
|
|
|
|
+
|
|
|
|
|
+ private void makeTranslucent() {
|
|
|
|
|
+ if (timer != null) {
|
|
|
|
|
+ timer.cancel();
|
|
|
|
|
+ }
|
|
|
|
|
+ timer = new Timer();
|
|
|
|
|
+ timer.schedule(new TimerTask() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ registrar.activity().runOnUiThread(() -> floatButton.setAlpha(0.5f));
|
|
|
|
|
+ timer = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 2000);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|