Skip to content

Commit

Permalink
更新V1.1.7
Browse files Browse the repository at this point in the history
- 优化细节部分
- 更优秀的旋转体验
- 更快速的小窗大小适配检测
- 支持被控端跟随主控端
- 修复一些bug
- 加快启动速度
- 巴拉巴拉。。。
  • Loading branch information
mingzhixian committed Nov 21, 2023
1 parent 5f4ee0e commit 4fcb97d
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 95 deletions.
4 changes: 2 additions & 2 deletions easycontrol/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "top.saymzx.easycontrol.app"
minSdk 21
targetSdk 34
versionCode 10106
versionName "1.1.6"
versionCode 10107
versionName "1.1.7"
resConfigs "zh"
resConfigs "xhdpi"
ndk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.Settings;
import android.util.Log;
import android.util.Pair;
import android.view.OrientationEventListener;
import android.widget.Toast;

import java.util.UUID;
Expand Down Expand Up @@ -71,8 +68,6 @@ public void onCreate(Bundle savedInstanceState) {
CenterHelper.checkCenter();
alarmPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_CENTER_SERVICE), PendingIntent.FLAG_IMMUTABLE);
((AlarmManager) getSystemService(Context.ALARM_SERVICE)).setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 1000 * 60 * 10, alarmPendingIntent);
// 注册旋转监听
setRotationListener();
}

@Override
Expand All @@ -87,7 +82,6 @@ protected void onDestroy() {
// 注销广播监听
((AlarmManager) getSystemService(Context.ALARM_SERVICE)).cancel(alarmPendingIntent);
unregisterReceiver(broadcastReceiver);
orientationEventListener.disable();
super.onDestroy();
}

Expand Down Expand Up @@ -117,23 +111,6 @@ private void setButtonListener() {
mainActivity.buttonSet.setOnClickListener(v -> startActivity(new Intent(this, SetActivity.class)));
}

// 设置旋转监听
private OrientationEventListener orientationEventListener;

private void setRotationListener() {
orientationEventListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int i) {
boolean nowRotation = (i <= 45 || i >= 135) && (i <= 225 || i >= 315);
if (AppData.rotationIsPortrait ^ nowRotation) {
AppData.rotationIsPortrait = nowRotation;
for (Client client : Client.allClients) client.clientView.changeRotation();
}
}
};
orientationEventListener.enable();
}

// 广播处理
private static final String ACTION_USB_PERMISSION = "top.saymzx.easycontrol.app.USB_PERMISSION";
private static final String ACTION_CENTER_SERVICE = "top.saymzx.easycontrol.app.CENTER_SERVICE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.SurfaceTexture;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.util.Pair;
import android.view.MotionEvent;
import android.view.Surface;
Expand Down Expand Up @@ -73,16 +74,6 @@ public void changeToMini() {
miniView.show();
}

// 处理主控端旋转
public void changeRotation() {
Pair<Integer, Integer> screenSize = PublicTools.getNowScreenSize();
if (uiMode == UI_MODE_FULL) {
FullActivity.changeRotation();
if (AppData.setting.getAudoRotation()) client.controller.sendRotateEvent(AppData.rotationIsPortrait);
} else if (uiMode == UI_MODE_SMALL) smallView.changeRotation(screenSize);
else if (uiMode == UI_MODE_MINI) miniView.changeRotation(screenSize);
}

public boolean checkIsNeedPlay() {
return uiMode != UI_MODE_MINI;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
Expand Down Expand Up @@ -48,9 +47,15 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
protected void onPause() {
// 旋转时及时删除
if (isChangingConfigurations()) context.fullActivity.textureViewLayout.removeView(clientView.textureView);
// 退出页面时自动变为小窗
// 旋转
if (isChangingConfigurations()) {
if (AppData.setting.getAudoRotation()) {
int rotation = getWindowManager().getDefaultDisplay().getRotation();
controller.sendRotateEvent(rotation == 1 || rotation == 3);
}
context.fullActivity.textureViewLayout.removeView(clientView.textureView);
}
// 非正常退出页面
else if (isShow) clientView.changeToMini();
super.onPause();
}
Expand Down Expand Up @@ -84,10 +89,6 @@ public static void show(ClientView clientView, Controller controller) {
}
}

public static void changeRotation() {
context.setRequestedOrientation(AppData.rotationIsPortrait ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}

public static void hide() {
if (isShow) {
isShow = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.res.ColorStateList;
import android.graphics.PixelFormat;
import android.os.Build;
import android.util.Pair;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
Expand All @@ -28,7 +27,7 @@ public class MiniView {
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
PixelFormat.TRANSLUCENT
);

Expand All @@ -47,7 +46,7 @@ public MiniView(ClientView clientView) {
else if (colorNum == 2) barColor = R.color.bar3;
else if (colorNum == 3) barColor = R.color.bar4;
miniView.bar.setBackgroundTintList(ColorStateList.valueOf(AppData.main.getResources().getColor(barColor)));
miniViewParams.x = -1 * PublicTools.dp2px(10f);
miniViewParams.x = 0;
}

public void show() {
Expand All @@ -61,16 +60,12 @@ public void show() {
if (isStart) {
miniView.getRoot().setVisibility(View.VISIBLE);
AppData.windowManager.addView(miniView.getRoot(), miniViewParams);
calculateSite(PublicTools.getNowScreenSize());
calculateSite();
}
}));
}
}

public void changeRotation(Pair<Integer, Integer> screenSize) {
calculateSite(screenSize);
}

public void hide() {
if (isShow) {
isShow = false;
Expand All @@ -85,10 +80,10 @@ public void hide() {
}

// 计算合适位置
private void calculateSite(Pair<Integer, Integer> screenSize) {
private void calculateSite() {
int startY;
boolean isConflict;
for (startY = screenSize.second / 5; startY < screenSize.second - height; startY += height / 2) {
for (startY = 100; startY < 1000; startY += height / 2) {
isConflict = false;
for (int i = 0; i < num; i++) {
if (site[i] > startY - height || site[i] < startY + height) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import top.saymzx.easycontrol.app.R;
import top.saymzx.easycontrol.app.client.Controller;
Expand All @@ -36,16 +35,28 @@ public class SmallView extends ViewOutlineProvider {
new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
200,
200,
0,
0,
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE,
LayoutParamsFlagFocus,
PixelFormat.TRANSLUCENT
);
private final View backgroundWindow = new View(AppData.main);
private final WindowManager.LayoutParams backgroundWindowParams =
new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
0,
0,
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE,
backgroundWindowFlag,
PixelFormat.TRANSLUCENT
);

private static final int baseLayoutParamsFlag = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
private static final int LayoutParamsFlagFocus = baseLayoutParamsFlag | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
private static final int LayoutParamsFlagNoFocus = baseLayoutParamsFlag | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
private static final int backgroundWindowFlag = baseLayoutParamsFlag | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;

public SmallView(ClientView clientView) {
this.clientView = clientView;
Expand All @@ -57,6 +68,12 @@ public SmallView(ClientView clientView) {
// 设置圆角
smallView.getRoot().setOutlineProvider(this);
smallView.getRoot().setClipToOutline(true);
// 设置背景窗口监听
backgroundWindow.addOnLayoutChangeListener((view, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
Pair<Integer, Integer> screenSize = new Pair<>(backgroundWindow.getMeasuredWidth(), backgroundWindow.getMeasuredHeight());
clientView.updateMaxSize(new Pair<>(screenSize.first * 4 / 5, screenSize.second * 4 / 5));
calculateSite(screenSize);
});
}

public void show(Controller controller) {
Expand All @@ -74,22 +91,15 @@ public void show(Controller controller) {
clientView.viewAnim(smallView.getRoot(), true, 0, PublicTools.dp2px(40f), (isStart -> {
if (isStart) {
smallView.getRoot().setVisibility(View.VISIBLE);
AppData.windowManager.addView(backgroundWindow, backgroundWindowParams);
AppData.windowManager.addView(smallView.getRoot(), smallViewParams);
}
}));
// 更新TextureView
smallView.textureViewLayout.addView(clientView.textureView, 0);
Pair<Integer, Integer> screenSize = PublicTools.getNowScreenSize();
clientView.updateMaxSize(new Pair<>(screenSize.first * 4 / 5, screenSize.second * 4 / 5));
calculateSite(screenSize);
}
}

public void changeRotation(Pair<Integer, Integer> screenSize) {
clientView.updateMaxSize(new Pair<>(screenSize.first * 4 / 5, screenSize.second * 4 / 5));
calculateSite(screenSize);
}

public void hide() {
if (isShow) {
isShow = false;
Expand All @@ -102,6 +112,7 @@ public void hide() {
if (!isStart) {
smallView.getRoot().setVisibility(View.GONE);
AppData.windowManager.removeView(smallView.getRoot());
AppData.windowManager.removeView(backgroundWindow);
}
}));
}
Expand Down Expand Up @@ -143,7 +154,6 @@ private void setBarListener() {
AtomicInteger yy = new AtomicInteger();
AtomicInteger paramsX = new AtomicInteger();
AtomicInteger paramsY = new AtomicInteger();
AtomicReference<Pair<Integer, Integer>> screenSize = new AtomicReference<>(new Pair<>(0, 0));
smallView.bar.setOnTouchListener((v, event) -> {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN: {
Expand All @@ -152,7 +162,6 @@ private void setBarListener() {
paramsX.set(smallViewParams.x);
paramsY.set(smallViewParams.y);
isFilp.set(false);
screenSize.set(PublicTools.getNowScreenSize());
break;
}
case MotionEvent.ACTION_MOVE: {
Expand All @@ -167,7 +176,7 @@ private void setBarListener() {
smallView.bar.setBackgroundTintList(ColorStateList.valueOf(AppData.main.getResources().getColor(R.color.clientBarSecond)));
}
// 拖动限制
if (x < 100 | x > screenSize.get().first - 100 | y < 150 | y > screenSize.get().second - 100) return true;
if (x < 100 | x > backgroundWindow.getMeasuredWidth() - 100 | y < 150 | y > backgroundWindow.getMeasuredHeight() - 100) return true;
// 更新
smallViewParams.x = paramsX.get() + flipX;
smallViewParams.y = paramsY.get() + flipY;
Expand Down Expand Up @@ -252,4 +261,3 @@ public void getOutline(View view, Outline outline) {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class AppData {

// 系统分辨率
public static final DisplayMetrics realScreenSize = new DisplayMetrics();
public static boolean rotationIsPortrait = true;

// 当前版本号
public static String serverName = "easycontrol_server_" + BuildConfig.VERSION_CODE + ".jar";
Expand Down Expand Up @@ -68,7 +67,6 @@ private static void getRealScreenSize(Activity m) {
display.getRealMetrics(realScreenSize);
int rotation = display.getRotation();
if (rotation == 1 || rotation == 3) {
rotationIsPortrait = false;
int tmp = realScreenSize.heightPixels;
realScreenSize.heightPixels = realScreenSize.widthPixels;
realScreenSize.widthPixels = tmp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ public static int dp2px(Float dp) {
return (int) (dp * AppData.realScreenSize.density);
}

// 获取当前界面宽高
public static Pair<Integer, Integer> getNowScreenSize() {
Pair<Integer, Integer> nowScreenSize = new Pair<>(AppData.realScreenSize.widthPixels, AppData.realScreenSize.heightPixels);
if (!AppData.rotationIsPortrait) nowScreenSize = new Pair<>(nowScreenSize.second, nowScreenSize.first);
return nowScreenSize;
}

// 创建弹窗
public static Dialog createDialog(Context context, boolean canCancel, View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
Expand Down
31 changes: 19 additions & 12 deletions easycontrol/app/src/main/res/layout/module_mini_view.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background_cron"
android:backgroundTint="@color/cardContainerBackground">
android:layout_height="wrap_content">

<View
android:id="@+id/bar"
android:layout_width="6dp"
android:layout_height="40dp"
android:layout_marginStart="18dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="10dp"
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="-10dp"
android:background="@drawable/background_cron"
android:backgroundTint="@color/bar1" />
android:backgroundTint="@color/cardContainerBackground">

<View
android:id="@+id/bar"
android:layout_width="6dp"
android:layout_height="40dp"
android:layout_marginStart="18dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="10dp"
android:background="@drawable/background_cron"
android:backgroundTint="@color/bar1" />
</FrameLayout>

</FrameLayout>
8 changes: 4 additions & 4 deletions easycontrol/app/src/main/res/layout/module_small_view.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cardBackground"
android:orientation="vertical">

Expand Down Expand Up @@ -158,4 +158,4 @@
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
2 changes: 1 addition & 1 deletion easycontrol/app/src/main/res/values-night/color.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<!-- 客户端界面色彩 -->
<color name="clientBar">#579CF9</color>
<color name="clientBarSecond">#807e7e7e</color>
<color name="clientBarSecond">#907e7e7e</color>

<!-- 迷你客户端界面色彩 -->
<color name="bar1">#e8b621</color>
Expand Down
Loading

0 comments on commit 4fcb97d

Please sign in to comment.