模拟蓝牙手柄.
This commit is contained in:
parent
ff16bd4f99
commit
c3bbf70d0d
|
|
@ -1,20 +1,19 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.FLASHLIGHT" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
|
|
@ -53,6 +52,12 @@
|
|||
android:exported="false"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@style/NormalTheme" />
|
||||
<activity
|
||||
android:name=".HandleActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|keyboard|navigation"
|
||||
android:exported="false"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@style/NormalTheme" />
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
<meta-data
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
package co.steamcloud.game;
|
||||
|
||||
import android.bluetooth.BluetoothHidDevice;
|
||||
|
||||
import co.steamcloud.game.utils.GamePara;
|
||||
|
||||
public class Config {
|
||||
public static String url = "https://api.onelight.vip/";//接口域名
|
||||
public static String BsUrl = "https://os.zhijierongxing.com/";//游戏域名
|
||||
|
||||
public static BluetoothHidDevice mBtHidDevice;
|
||||
|
||||
public static String channel_id = "d612a79436ef9ceeee4d6847d854b2e1";
|
||||
public static String sign_key = "";//加密key
|
||||
public static String userToken = "";//用户token
|
||||
|
|
|
|||
478
android/app/src/main/java/co/steamcloud/game/HandleActivity.java
Normal file
478
android/app/src/main/java/co/steamcloud/game/HandleActivity.java
Normal file
|
|
@ -0,0 +1,478 @@
|
|||
package co.steamcloud.game;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import org.simple.eventbus.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import co.steamcloud.game.customize.JoystickView2;
|
||||
import co.steamcloud.game.customize.MoveButton;
|
||||
import co.steamcloud.game.utils.AppConfigFileImpl;
|
||||
import co.steamcloud.game.utils.EventBusParams;
|
||||
import co.steamcloud.game.utils.GamePad;
|
||||
import co.steamcloud.game.utils.GamepadAction;
|
||||
import co.steamcloud.game.utils.GamepadButton;
|
||||
import co.steamcloud.game.utils.GsonJsonUtil;
|
||||
|
||||
public class HandleActivity extends Activity implements GamepadAction {
|
||||
|
||||
private final String TAG = "MainActivity";
|
||||
private int SCREEN_WIDTH = 1920;
|
||||
private int SCREEN_HEIGHT = 1080;
|
||||
|
||||
private boolean isShock = false;// 震动
|
||||
private FrameLayout visualAngle;
|
||||
private MoveButton yaogan_left, direction_key, yaogan_right, Move_a, Move_b, Move_x, Move_y, Move_rs, Move_rt,
|
||||
Move_rb, Move_lt, Move_lb, Move_ls, Move_back, Move_start;
|
||||
ImageView dpad_up, dpad_right, dpad_up_left, dpad_left, dpad_down;
|
||||
Map CustomButtonMap = new HashMap<>();
|
||||
|
||||
private float downJoystickX = 0, downJoystickY = 0, moveJoystickX, moveJoystickY;
|
||||
|
||||
private Vibrator vibrator;
|
||||
|
||||
private final ArrayList<BluetoothDevice> mDevices = new ArrayList<>();
|
||||
|
||||
public GamePad gamepad = new GamePad(this);
|
||||
private TextView button_a, button_b, button_x, button_y, button_rs, button_rt, button_rb, button_lt, button_lb, button_ls, button_back, button_start;
|
||||
private TextView tvExitHandle;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
setContentView(R.layout.activity_handle);
|
||||
|
||||
hideBottomUIMenu();
|
||||
initUI();
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private void initUI() {
|
||||
// 判断屏幕大小
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(dm);// display =
|
||||
// getWindowManager().getDefaultDisplay();display.getMetrics(dm)(把屏幕尺寸信息赋值给DisplayMetrics
|
||||
// dm);
|
||||
if (dm.widthPixels > dm.heightPixels) {
|
||||
SCREEN_WIDTH = dm.widthPixels/*- getNavigationHeight(PlayGameActivity.this)*/;
|
||||
SCREEN_HEIGHT = dm.heightPixels;
|
||||
} else {
|
||||
SCREEN_WIDTH = dm.heightPixels/*- getNavigationHeight(PlayGameActivity.this)*/;
|
||||
SCREEN_HEIGHT = dm.widthPixels;
|
||||
}
|
||||
Globe.landscapeScaleWidht = ((float) SCREEN_WIDTH / Globe.landscapeSW);
|
||||
Globe.landscapeScaleHeight = ((float) SCREEN_HEIGHT / Globe.landscapeSH);
|
||||
|
||||
visualAngle = findViewById(R.id.visual_angle);
|
||||
|
||||
String CustomButton = AppConfigFileImpl.getStringParams(getApplicationContext(), "CustomButton");
|
||||
if (!TextUtils.isEmpty(CustomButton)) {
|
||||
Log.d("TAG", "CustomButton " + CustomButton);
|
||||
CustomButtonMap = GsonJsonUtil.stringToMap(CustomButton);
|
||||
} else {
|
||||
initDefault();// 默认配置
|
||||
}
|
||||
|
||||
tvExitHandle = findViewById(R.id.tv_exit_handle);
|
||||
|
||||
tvExitHandle.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showDialog("退出手柄", "确定退出手柄吗?", "退出", "取消", new IDialogTwoView() {
|
||||
@Override
|
||||
public void cancel() {
|
||||
hideBottomUIMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSure() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnApp() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
yaogan_left = findViewById(R.id.yaogan_left);
|
||||
direction_key = findViewById(R.id.direction_key);
|
||||
yaogan_right = findViewById(R.id.yaogan_right);
|
||||
Move_a = findViewById(R.id.Move_a);
|
||||
Move_b = findViewById(R.id.Move_b);
|
||||
Move_x = findViewById(R.id.Move_x);
|
||||
Move_y = findViewById(R.id.Move_y);
|
||||
Move_rs = findViewById(R.id.Move_rs);
|
||||
Move_rt = findViewById(R.id.Move_rt);
|
||||
Move_rb = findViewById(R.id.Move_rb);
|
||||
Move_lt = findViewById(R.id.Move_lt);
|
||||
Move_lb = findViewById(R.id.Move_lb);
|
||||
Move_ls = findViewById(R.id.Move_ls);
|
||||
Move_back = findViewById(R.id.Move_back);
|
||||
Move_start = findViewById(R.id.Move_start);
|
||||
|
||||
|
||||
button_a = findViewById(R.id.button_a);
|
||||
button_b = findViewById(R.id.button_b);
|
||||
button_x = findViewById(R.id.button_x);
|
||||
button_y = findViewById(R.id.button_y);
|
||||
button_rs = findViewById(R.id.button_rs);
|
||||
button_rt = findViewById(R.id.button_rt);
|
||||
button_rb = findViewById(R.id.button_rb);
|
||||
button_lt = findViewById(R.id.button_lt);
|
||||
button_lb = findViewById(R.id.button_lb);
|
||||
button_ls = findViewById(R.id.button_ls);
|
||||
button_back = findViewById(R.id.button_back);
|
||||
button_start = findViewById(R.id.button_start);
|
||||
|
||||
|
||||
initButtonPosition();
|
||||
dpad_up = findViewById(R.id.dpad_up);
|
||||
dpad_left = findViewById(R.id.dpad_left);
|
||||
dpad_down = findViewById(R.id.dpad_down);
|
||||
dpad_right = findViewById(R.id.dpad_right);
|
||||
dpad_up_left = findViewById(R.id.dpad_up_left);
|
||||
dpad_up.setClickable(true);
|
||||
dpad_left.setClickable(true);
|
||||
dpad_down.setClickable(true);
|
||||
dpad_right.setClickable(true);
|
||||
dpad_up_left.setClickable(true);
|
||||
|
||||
JoystickView2 joystickLeft = findViewById(R.id.joystick_left);
|
||||
JoystickView2 joystickRight = findViewById(R.id.joystick_right);
|
||||
joystickLeft.setOnJoystickListener(new JoystickView2.OnJoystickListener() {
|
||||
@SuppressLint("MissingPermission")
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
@Override
|
||||
public void onPosition(float x, float y) {
|
||||
// Config.keyEvent_time = 0;
|
||||
Log.w("TAG", "stick x=" + x + " y=" + y);
|
||||
gamepad.SetLeftRemoteSensing(x, y);
|
||||
// System.out.println("player1 setXY x="+x+"y="+y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVibrator() {
|
||||
// joystickLeft.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
|
||||
// HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
if (isShock) {
|
||||
joystickLeft.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
|
||||
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
}
|
||||
}
|
||||
});
|
||||
joystickRight.setOnJoystickListener(new JoystickView2.OnJoystickListener() {
|
||||
@SuppressLint("MissingPermission")
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
@Override
|
||||
public void onPosition(float x, float y) {
|
||||
// Config.keyEvent_time = 0;
|
||||
Log.w("TAG", "stick x=" + x + " y=" + y);
|
||||
gamepad.SetRightRemoteSensing(x, y);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVibrator() {
|
||||
// joystickLeft.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
|
||||
// HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
if (isShock) {
|
||||
joystickLeft.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
|
||||
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setBtnKey(button_a, gamepad.BUTTON_A);
|
||||
setBtnKey(button_b, gamepad.BUTTON_B);
|
||||
setBtnKey(button_x, gamepad.BUTTON_X);
|
||||
setBtnKey(button_y, gamepad.BUTTON_Y);
|
||||
setBtnKey(button_lb, gamepad.BUTTON_L1);
|
||||
setBtnKey(button_rb, gamepad.BUTTON_R1);
|
||||
setBtnKey(button_lt, gamepad.BUTTON_L2);
|
||||
setBtnKey(button_rt, gamepad.BUTTON_R2);
|
||||
setBtnKey(button_start, gamepad.BUTTON_START);
|
||||
setBtnKey(button_back, gamepad.BUTTON_SELECT);
|
||||
setBtnKey(button_ls, gamepad.BUTTON_L3);
|
||||
setBtnKey(button_rs, gamepad.BUTTON_R3);
|
||||
setBtnKey(dpad_up, gamepad.BUTTON_DPAD_UP);
|
||||
setBtnKey(dpad_right, gamepad.BUTTON_DPAD_RIGHT);
|
||||
setBtnKey(dpad_down, gamepad.BUTTON_DPAD_DOWN);
|
||||
setBtnKey(dpad_left, gamepad.BUTTON_DPAD_LEFT);
|
||||
|
||||
setBtnKey(dpad_up_left, gamepad.BUTTON_DPAD_UP, gamepad.BUTTON_DPAD_LEFT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
showDialog("退出手柄", "确定退出手柄吗?", "退出", "取消", new IDialogTwoView() {
|
||||
@Override
|
||||
public void cancel() {
|
||||
hideBottomUIMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSure() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnApp() {
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
|
||||
}
|
||||
|
||||
public void showDialog(String title, String content, String cancelStr, String sureStr, final IDialogTwoView iDialogView) {
|
||||
BaseAlertDialog baseAlertDialog = new BaseAlertDialog.Builder(this).show(title, content, cancelStr, sureStr, iDialogView).create();
|
||||
try {
|
||||
baseAlertDialog.show();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void setBtnKey(TextView btn, GamepadButton gamepadButton) {
|
||||
btn.setOnTouchListener(createButtonTouchListener(gamepadButton));
|
||||
}
|
||||
|
||||
public void setBtnKey(ImageView btn, GamepadButton gamepadButton) {
|
||||
btn.setOnTouchListener(createButtonTouchListener(gamepadButton));
|
||||
}
|
||||
|
||||
public void setBtnKey(ImageView btn, GamepadButton gamepadButton, GamepadButton gamepadButton2) {
|
||||
btn.setOnTouchListener(createButtonTouchListener(gamepadButton, gamepadButton2));
|
||||
}
|
||||
|
||||
private byte testKeyCode = (byte) 0x01;
|
||||
|
||||
public void initDefault() {
|
||||
try {
|
||||
CustomButtonMap.put("yaogan_left", 106 * Globe.landscapeScaleWidht + "@" + 653.5 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("direction_key", 565 * Globe.landscapeScaleWidht + "@" + 730.0 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("yaogan_right", 1248 * Globe.landscapeScaleWidht + "@" + 770 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_a", 1645 * Globe.landscapeScaleWidht + "@" + 799 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_b", 1774 * Globe.landscapeScaleWidht + "@" + 680 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_x", 1521 * Globe.landscapeScaleWidht + "@" + 680 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_y", 1645 * Globe.landscapeScaleWidht + "@" + 562 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_rs", 1547 * Globe.landscapeScaleWidht + "@" + 300 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_rt", 1698 * Globe.landscapeScaleWidht + "@" + 343 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_rb", 1452 * Globe.landscapeScaleWidht + "@" + 453 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_ls", 134 * Globe.landscapeScaleWidht + "@" + 303 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_lt", 44 * Globe.landscapeScaleWidht + "@" + 480 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_lb", 261 * Globe.landscapeScaleWidht + "@" + 404 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_back", 1774 * Globe.landscapeScaleWidht + "@" + 30 * Globe.landscapeScaleHeight);
|
||||
CustomButtonMap.put("Move_start", 1774 * Globe.landscapeScaleWidht + "@" + 149 * Globe.landscapeScaleHeight);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 调用前必须先初始化按钮
|
||||
public void initButtonPosition() {
|
||||
try {
|
||||
if (CustomButtonMap.get("yaogan_left") != null
|
||||
&& !TextUtils.isEmpty(CustomButtonMap.get("yaogan_left").toString())) {
|
||||
String[] split = CustomButtonMap.get("yaogan_left").toString().split("@");
|
||||
yaogan_left.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("direction_key") != null
|
||||
&& !TextUtils.isEmpty(CustomButtonMap.get("direction_key").toString())) {
|
||||
String[] split = CustomButtonMap.get("direction_key").toString().split("@");
|
||||
direction_key.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("yaogan_right") != null
|
||||
&& !TextUtils.isEmpty(CustomButtonMap.get("yaogan_right").toString())) {
|
||||
String[] split = CustomButtonMap.get("yaogan_right").toString().split("@");
|
||||
yaogan_right.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_a") != null && !TextUtils.isEmpty(CustomButtonMap.get("Move_a").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_a").toString().split("@");
|
||||
// Log.d(TAG, "initButtonPosition: aaaaaaaaaaaaaaaaaaaaaaaa");
|
||||
Move_a.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_b") != null && !TextUtils.isEmpty(CustomButtonMap.get("Move_b").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_b").toString().split("@");
|
||||
Move_b.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_x") != null && !TextUtils.isEmpty(CustomButtonMap.get("Move_x").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_x").toString().split("@");
|
||||
Move_x.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_y") != null && !TextUtils.isEmpty(CustomButtonMap.get("Move_y").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_y").toString().split("@");
|
||||
Move_y.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_rs") != null
|
||||
&& !TextUtils.isEmpty(CustomButtonMap.get("Move_rs").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_rs").toString().split("@");
|
||||
Move_rs.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_rt") != null
|
||||
&& !TextUtils.isEmpty(CustomButtonMap.get("Move_rt").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_rt").toString().split("@");
|
||||
Move_rt.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_rb") != null
|
||||
&& !TextUtils.isEmpty(CustomButtonMap.get("Move_rb").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_rb").toString().split("@");
|
||||
Move_rb.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_lt") != null
|
||||
&& !TextUtils.isEmpty(CustomButtonMap.get("Move_lt").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_lt").toString().split("@");
|
||||
Move_lt.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_lb") != null
|
||||
&& !TextUtils.isEmpty(CustomButtonMap.get("Move_lb").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_lb").toString().split("@");
|
||||
Move_lb.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_ls") != null
|
||||
&& !TextUtils.isEmpty(CustomButtonMap.get("Move_ls").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_ls").toString().split("@");
|
||||
Move_ls.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_back") != null
|
||||
&& !TextUtils.isEmpty(CustomButtonMap.get("Move_back").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_back").toString().split("@");
|
||||
Move_back.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
if (CustomButtonMap.get("Move_start") != null
|
||||
&& !TextUtils.isEmpty(CustomButtonMap.get("Move_start").toString())) {
|
||||
String[] split = CustomButtonMap.get("Move_start").toString().split("@");
|
||||
Move_start.setPosition(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void hideBottomUIMenu() {
|
||||
// 隐藏虚拟按键,并且全屏
|
||||
if (Build.VERSION.SDK_INT <= 11 && Build.VERSION.SDK_INT < 19) { // lower api
|
||||
View v = this.getWindow().getDecorView();
|
||||
v.setSystemUiVisibility(View.GONE);
|
||||
} else if (Build.VERSION.SDK_INT > 19) {
|
||||
// for new api versions.
|
||||
View decorView = getWindow().getDecorView();
|
||||
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
|
||||
decorView.setSystemUiVisibility(uiOptions);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private View.OnTouchListener createButtonTouchListener(GamepadButton gamepadButton) {
|
||||
return new View.OnTouchListener() {
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
Log.d(TAG, "Button event: " + event.getAction() + ",key=");
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
gamepad.KeyDown(gamepadButton);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
gamepad.KeyUp(gamepadButton);
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private View.OnTouchListener createButtonTouchListener(GamepadButton gamepadButton, GamepadButton gamepadButton2) {
|
||||
return new View.OnTouchListener() {
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
Log.d(TAG, "Button event:2 " + event.getAction() + ",key=");
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
gamepad.KeyDown(gamepadButton);
|
||||
gamepad.KeyDown(gamepadButton2);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
gamepad.KeyUp(gamepadButton);
|
||||
gamepad.KeyUp(gamepadButton2);
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送手柄数据
|
||||
*
|
||||
* @param params 字节
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
@Override
|
||||
public void SendRequest(byte[] params) {
|
||||
|
||||
// HashMap<String, Object> TagMap = new HashMap<>();
|
||||
// TagMap.put("tag", "SendRequest");
|
||||
// TagMap.put("params", params);
|
||||
// EventBus.getDefault().post(TagMap, EventBusParams.MAIN);
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "clickKey: =====>>>>" + Config.mBtHidDevice.getConnectedDevices().size());
|
||||
for (BluetoothDevice btDev : Config.mBtHidDevice.getConnectedDevices()) {
|
||||
// 发送 HID 报文
|
||||
Config.mBtHidDevice.sendReport(btDev, 1, params);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,29 @@
|
|||
package co.steamcloud.game;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothHidDevice;
|
||||
import android.bluetooth.BluetoothHidDeviceAppQosSettings;
|
||||
import android.bluetooth.BluetoothHidDeviceAppSdpSettings;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.PersistableBundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import com.alipay.sdk.app.PayTask;
|
||||
import com.tencent.mm.opensdk.modelpay.PayReq;
|
||||
|
|
@ -25,11 +36,16 @@ import org.json.JSONObject;
|
|||
import org.simple.eventbus.EventBus;
|
||||
import org.simple.eventbus.Subscriber;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import co.steamcloud.game.pay.PayResult;
|
||||
import co.steamcloud.game.utils.AppUtil;
|
||||
import co.steamcloud.game.utils.EventBusParams;
|
||||
import io.flutter.embedding.android.FlutterActivity;
|
||||
import io.flutter.embedding.engine.FlutterEngine;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
|
|
@ -39,40 +55,83 @@ import io.flutter.plugin.common.StandardMethodCodec;
|
|||
public class MainActivity extends FlutterActivity {
|
||||
private static final String TAG = "MainActivity";
|
||||
private static final String CHANNEL = "samples.flutter.dev/battery";
|
||||
|
||||
private MethodChannel nativeChannel;
|
||||
|
||||
private final int SDK_PAY_FLAG = 1;
|
||||
|
||||
private boolean setBtState = false;
|
||||
|
||||
private static final int REQUEST_ENABLE_BT = 99;
|
||||
|
||||
private final BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
|
||||
|
||||
private BluetoothHidDeviceAppQosSettings mBluetoothHidDeviceAppQosSettings;
|
||||
|
||||
private BluetoothDevice mBtDevice;
|
||||
|
||||
private final ArrayList<BluetoothDevice> mDevices = new ArrayList<>();//蓝牙设备列表
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EventBus.getDefault().register(this);
|
||||
WhaleCloud.getInstance().isShowLog(true);
|
||||
|
||||
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
registerReceiver(mBluetoothReceiver, filter);
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean dispatchGenericMotionEvent(MotionEvent ev) {
|
||||
// return super.dispatchGenericMotionEvent(ev);
|
||||
//
|
||||
// }
|
||||
// BroadcastReceiver实现
|
||||
private final BroadcastReceiver mBluetoothReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
|
||||
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
|
||||
switch (state) {
|
||||
case BluetoothAdapter.STATE_OFF:
|
||||
// 蓝牙已关闭
|
||||
Log.d(TAG, "onReceive: 蓝牙已关闭");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("isBtOpen", false);
|
||||
nativeChannel.invokeMethod("isBtOpen", map);
|
||||
break;
|
||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
||||
// 蓝牙正在关闭
|
||||
Log.d(TAG, "onReceive: 蓝牙正在关闭");
|
||||
|
||||
// @Override
|
||||
// public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
// //Log.d(TAG, "dispatchKeyEvent1: event==" + event);
|
||||
// if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
// // 处理按键按下事件
|
||||
// int keyCode = event.getKeyCode();
|
||||
// // 根据keyCode进行相应处理
|
||||
// Log.d(TAG, "dispatchKeyEvent: keyCode==" + keyCode);
|
||||
// }
|
||||
// return super.dispatchKeyEvent(event);
|
||||
// }
|
||||
break;
|
||||
case BluetoothAdapter.STATE_ON:
|
||||
// 蓝牙已打开
|
||||
Log.d(TAG, "onReceive: 蓝牙已打开");
|
||||
Map<String, Object> BtMap = new HashMap<>();
|
||||
BtMap.put("isBtOpen", true);
|
||||
nativeChannel.invokeMethod("isBtOpen", BtMap);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
btListDevices();
|
||||
}
|
||||
break;
|
||||
case BluetoothAdapter.STATE_TURNING_ON:
|
||||
// 蓝牙正在打开
|
||||
Log.d(TAG, "onReceive: 蓝牙正在打开");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
EventBus.getDefault().unregister(this);
|
||||
if (Config.mBtHidDevice != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
btConnect(null); // disconnect
|
||||
}
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
|
@ -87,6 +146,8 @@ public class MainActivity extends FlutterActivity {
|
|||
exitGameMap.put("exitGame", "exitGame");
|
||||
nativeChannel.invokeMethod("exitGame", exitGameMap);
|
||||
break;
|
||||
|
||||
//微信支付回调
|
||||
case "wxPaySuccess":
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("wxPaySuccess", "wxPaySuccess");
|
||||
|
|
@ -98,11 +159,22 @@ public class MainActivity extends FlutterActivity {
|
|||
mapError.put("payError", "payError");
|
||||
nativeChannel.invokeMethod("payError", mapError);
|
||||
break;
|
||||
|
||||
case "SendRequest":
|
||||
byte[] params = TagMap.get("params").getBytes();
|
||||
Log.d(TAG, "Ev: SendRequest");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* flutter to 原生 传递数据
|
||||
*
|
||||
* @param flutterEngine The Flutter engine.
|
||||
*/
|
||||
@Override
|
||||
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine);
|
||||
|
|
@ -112,7 +184,7 @@ public class MainActivity extends FlutterActivity {
|
|||
@Override
|
||||
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
|
||||
switch (call.method) {
|
||||
case "initData":
|
||||
case "initData": //初始化数据
|
||||
Log.d(TAG, "onMethodCall: initData");
|
||||
String gameToken = call.argument("gameToken");
|
||||
Config.BsUrl = call.argument("BsUrl");
|
||||
|
|
@ -124,67 +196,266 @@ public class MainActivity extends FlutterActivity {
|
|||
Config.url = call.argument("Url");
|
||||
|
||||
initSdk(Config.BsUrl, Config.client_sid, gameToken, Config.sn);
|
||||
Log.d(TAG, "onMethodCall: initData");
|
||||
Log.d(TAG, "onMethodCall: gameToken==" + gameToken);
|
||||
Log.d(TAG, "onMethodCall: Config.client_sid==" + Config.client_sid);
|
||||
Log.d(TAG, "onMethodCall: Config.BsUrl==" + Config.BsUrl);
|
||||
break;
|
||||
|
||||
case "playGame":
|
||||
|
||||
case "setBt"://开启/关闭蓝牙
|
||||
setBtState = Boolean.TRUE.equals(call.argument("setBtState"));
|
||||
Log.d(TAG, "onMethodCall: setBtState==" + setBtState);
|
||||
if (setBtState) {
|
||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
||||
} else {
|
||||
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
||||
return;
|
||||
}
|
||||
mBtAdapter.disable();
|
||||
}
|
||||
break;
|
||||
|
||||
case "playGame": //开始游戏
|
||||
Log.d("TAG", "onMethodCall: 66666666666");
|
||||
Config.gameId = call.argument("gameId");
|
||||
String playGameData = call.argument("playGameData");
|
||||
String isReconPlay = call.argument("isReconPlay");
|
||||
|
||||
Log.d("TAG", "onMethodCall: gameId==" + Config.gameId);
|
||||
Log.d("TAG", "onMethodCall: playGameData==" + playGameData);
|
||||
Log.d("TAG", "onMethodCall: isReconPlay==" + isReconPlay);
|
||||
// Config.gamePara.game_key = gameId;
|
||||
// Config.gamePara.record_game_time = 5;
|
||||
// Config.gamePara.start_resolution = "720p";
|
||||
|
||||
// initToken();
|
||||
startGame(playGameData, isReconPlay);
|
||||
break;
|
||||
|
||||
|
||||
case "getInfo":
|
||||
case "getInfo": //获取设备信息
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
Config.sn = AppUtil.getDeviceId(App.getInstance());
|
||||
Config.Language = AppUtil.getSystemLanguage();
|
||||
map.put("deviceID", Config.sn);
|
||||
map.put("Language", Config.Language);
|
||||
result.success(map);
|
||||
|
||||
Log.d(TAG, "onMethodCall: getInfo");
|
||||
//蓝牙是否开启
|
||||
if (mBtAdapter.isEnabled()) {
|
||||
map.put("isBtOpen", true);
|
||||
} else {
|
||||
map.put("isBtOpen", false);
|
||||
}
|
||||
result.success(map);
|
||||
break;
|
||||
|
||||
case "WxPay"://微信支付
|
||||
String orderInfoWx = call.argument("orderInfoWx");
|
||||
Log.d("TAG", "onMethodCall: orderInfoWx===" + orderInfoWx);
|
||||
|
||||
WxPay(orderInfoWx);
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case "Alipay"://支付宝支付
|
||||
|
||||
Log.d("TAG", "onMethodCall: Alipay");
|
||||
|
||||
String orderInfoZfb = call.argument("orderInfoZfb");
|
||||
Alipay(orderInfoZfb);
|
||||
|
||||
break;
|
||||
|
||||
case "test1":
|
||||
Log.d("TAG1", "onMethodCall: 66666666666");
|
||||
case "getBtListDevices"://获取蓝牙设备
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
btListDevices();
|
||||
}
|
||||
break;
|
||||
|
||||
case "connectedDevice"://连接设备
|
||||
int deviceIndex = call.argument("deviceIndex");
|
||||
BluetoothDevice dev = mDevices.get(deviceIndex);
|
||||
Log.d(TAG, "onItemSelected(): " + dev + " " + deviceIndex + " ");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
btConnect(dev);
|
||||
}
|
||||
break;
|
||||
|
||||
case "enterGamePad"://进入蓝牙手柄界面
|
||||
Intent intent = new Intent(MainActivity.this, HandleActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//设置蓝牙从设备
|
||||
public void getProxy() {
|
||||
mBtAdapter.getProfileProxy(App.getInstance(), new BluetoothProfile.ServiceListener() {
|
||||
@Override
|
||||
@SuppressLint({"NewApi", "MissingPermission"})
|
||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||
if (profile == BluetoothProfile.HID_DEVICE) {
|
||||
Log.d(TAG, "Got HID device");
|
||||
Config.mBtHidDevice = (BluetoothHidDevice) proxy;
|
||||
mBluetoothHidDeviceAppQosSettings = new BluetoothHidDeviceAppQosSettings(1, 800, 9, 0, 11250, -1);
|
||||
BluetoothHidDeviceAppSdpSettings sdp = new BluetoothHidDeviceAppSdpSettings(
|
||||
"虚拟蓝牙手柄",
|
||||
"Android BLE HID Keyboard",
|
||||
"Android",
|
||||
(byte) 0x00,
|
||||
AppUtil.gamePadDescriptor);
|
||||
Config.mBtHidDevice.registerApp(sdp, null, mBluetoothHidDeviceAppQosSettings,
|
||||
Executors.newSingleThreadExecutor(), new BluetoothHidDevice.Callback() {
|
||||
@Override
|
||||
public void onGetReport(BluetoothDevice device, byte type, byte id, int bufferSize) {
|
||||
Log.v(TAG, "onGetReport: device=" + device + " type=" + type
|
||||
+ " id=" + id + " bufferSize=" + bufferSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetReport(BluetoothDevice device, byte type, byte id, byte[] data) {
|
||||
// Log.v(TAG, "onSetReport: device=" + device + " type=" + type
|
||||
// + " id=" + id + " data=" + data);
|
||||
// 解析输出报告数据
|
||||
if (data.length >= 2) {
|
||||
int leftMotorStrength = data[0] & 0xFF;
|
||||
int rightMotorStrength = data[1] & 0xFF;
|
||||
// handleVibration(leftMotorStrength, rightMotorStrength);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionStateChanged(BluetoothDevice device, final int state) {
|
||||
Log.v(TAG, "onConnectionStateChanged: device=" + device + " state=" + state);
|
||||
if (device.equals(mBtDevice)) {
|
||||
Log.d(TAG, "onConnectionStateChanged: state==" + state);
|
||||
// 0 断开的
|
||||
// 1 连接中
|
||||
// 2 已连接
|
||||
// 3 正在断开连接…
|
||||
//发送连接状态
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("connectionStatus", state);
|
||||
nativeChannel.invokeMethod("connectionStatus", map);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
if (state == 2) {
|
||||
Log.d(TAG, "onConnectionStateChanged:32132132132132===》 重新new对象");
|
||||
// gamepad.setCallback((b) -> {
|
||||
// Log.d(TAG, "onConnectionStateChanged:32132132132132===》 " + b[0]);
|
||||
// });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(int profile) {
|
||||
if (profile == BluetoothProfile.HID_DEVICE) {
|
||||
Log.d(TAG, "Lost HID device");
|
||||
}
|
||||
}
|
||||
}, BluetoothProfile.HID_DEVICE);
|
||||
}
|
||||
|
||||
//获取蓝牙设备
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void btListDevices() {
|
||||
getProxy(); // 需要先启用蓝牙
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
||||
return;
|
||||
}
|
||||
Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();
|
||||
|
||||
// 将设备添加到适配器
|
||||
List<String> names = new ArrayList<>();
|
||||
|
||||
for (BluetoothDevice btDev : pairedDevices) {
|
||||
names.add(btDev.getName());
|
||||
mDevices.add(btDev);
|
||||
Log.d(TAG, "btListDevices: btDev==" + btDev.getName());
|
||||
Log.d(TAG, "btListDevices: btDev==" + btDev.getAddress());
|
||||
Log.d(TAG, "btListDevices: btDev,getUuids==" + btDev.getUuids());
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("btDevices", names);
|
||||
nativeChannel.invokeMethod("btDevices", map);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//连接蓝牙设备
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void btConnect(BluetoothDevice device) {
|
||||
Log.i(TAG, "btConnect: device=" + device);
|
||||
Log.i(TAG, "btConnect: mBtHidDevice=" + Config.mBtHidDevice);
|
||||
// disconnect from everything else
|
||||
if (Config.mBtHidDevice != null) {
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
||||
return;
|
||||
}
|
||||
for (BluetoothDevice btDev : Config.mBtHidDevice.getDevicesMatchingConnectionStates(new int[]{
|
||||
// BluetoothProfile.STATE_CONNECTING,
|
||||
BluetoothProfile.STATE_CONNECTED,
|
||||
})) {
|
||||
Config.mBtHidDevice.disconnect(btDev);
|
||||
Log.i(TAG, "btConnect: disconnect");
|
||||
}
|
||||
}
|
||||
|
||||
if (device != null) {
|
||||
mBtDevice = device;
|
||||
Config.mBtHidDevice.connect(device);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化游戏SDK
|
||||
*
|
||||
* @param bsUrl bsUrl
|
||||
* @param channelId channelId
|
||||
* @param token token
|
||||
* @param sn 设备号
|
||||
*/
|
||||
void initSdk(final String bsUrl, final String channelId, final String token, final String sn) {
|
||||
WhaleCloud.getInstance().sdkLoading(getApplication(), channelId, bsUrl, token, sn, new WhaleCloud.OnSdkListener() {
|
||||
@Override
|
||||
public void onSdkFail(final int errCode, final String msg) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.w(TAG, "鲸云 SDK 初始化失败|" + errCode + "|" + msg);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("SDKSuccess", false);
|
||||
nativeChannel.invokeMethod("SDKSuccess", map);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSdkSucc() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.w(TAG, "鲸云 SDK 初始化成功");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("SDKSuccess", true);
|
||||
nativeChannel.invokeMethod("SDKSuccess", map);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动游戏
|
||||
*
|
||||
* @param gameData 游戏启动数据
|
||||
* @param isReconPlay 是否是重连
|
||||
*/
|
||||
public void startGame(String gameData, String isReconPlay) {
|
||||
String GameType = "";
|
||||
getIntent().putExtra("GameType", "");
|
||||
Config.is_Playing = true;
|
||||
Intent intent = new Intent(this, PlayGameActivity.class);
|
||||
intent.putExtra("GameData", gameData);
|
||||
intent.putExtra("isReconPlay", isReconPlay);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝 支付结果回调
|
||||
|
|
@ -226,55 +497,6 @@ public class MainActivity extends FlutterActivity {
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* 初始化游戏SDK
|
||||
*
|
||||
* @param bsUrl bsUrl
|
||||
* @param channelId channelId
|
||||
* @param token token
|
||||
* @param sn 设备号
|
||||
*/
|
||||
void initSdk(final String bsUrl, final String channelId, final String token, final String sn) {
|
||||
WhaleCloud.getInstance().sdkLoading(getApplication(), channelId, bsUrl, token, sn, new WhaleCloud.OnSdkListener() {
|
||||
@Override
|
||||
public void onSdkFail(final int errCode, final String msg) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.w(TAG, "鲸云 SDK 初始化失败|" + errCode + "|" + msg);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("SDKSuccess", false);
|
||||
nativeChannel.invokeMethod("SDKSuccess", map);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSdkSucc() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.w(TAG, "鲸云 SDK 初始化成功");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("SDKSuccess", true);
|
||||
nativeChannel.invokeMethod("SDKSuccess", map);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void startGame(String gameData, String isReconPlay) {
|
||||
String GameType = "";
|
||||
getIntent().putExtra("GameType", "");
|
||||
Config.is_Playing = true;
|
||||
Intent intent = new Intent(this, PlayGameActivity.class);
|
||||
intent.putExtra("GameData", gameData);
|
||||
intent.putExtra("isReconPlay", isReconPlay);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微信支付
|
||||
*
|
||||
|
|
@ -325,7 +547,6 @@ public class MainActivity extends FlutterActivity {
|
|||
msg.obj = result;
|
||||
mHandler.sendMessage(msg);
|
||||
};
|
||||
|
||||
// 必须异步调用
|
||||
Thread payThread = new Thread(payRunnable);
|
||||
payThread.start();
|
||||
|
|
|
|||
|
|
@ -73,11 +73,23 @@ import java.util.Timer;
|
|||
import java.util.TimerTask;
|
||||
|
||||
import co.steamcloud.game.HttpUtils.OpenApiRequest;
|
||||
import co.steamcloud.game.customize.GameFrameLayOut;
|
||||
import co.steamcloud.game.customize.JoystickView2;
|
||||
import co.steamcloud.game.customize.KeyButton;
|
||||
import co.steamcloud.game.customize.KeyboardUtil;
|
||||
import co.steamcloud.game.customize.MoveButton;
|
||||
import co.steamcloud.game.customize.MyButton;
|
||||
import co.steamcloud.game.entity.VirtualKeyListBean;
|
||||
import co.steamcloud.game.glide.GlideImageLoader;
|
||||
import co.steamcloud.game.time.SubscribeTimeManage;
|
||||
import co.steamcloud.game.utils.ActivityCollector;
|
||||
import co.steamcloud.game.utils.AppConfigFileImpl;
|
||||
import co.steamcloud.game.utils.AppUtil;
|
||||
import co.steamcloud.game.utils.CountDownTimerUtil;
|
||||
import co.steamcloud.game.utils.EventBusParams;
|
||||
import co.steamcloud.game.utils.GsonJsonUtil;
|
||||
import co.steamcloud.game.utils.PeterTimeCountRefresh;
|
||||
import co.steamcloud.game.utils.RoundCalculator;
|
||||
|
||||
public class PlayGameActivity extends Activity {
|
||||
public static final String TAG = "PlayGameActivity";
|
||||
|
|
|
|||
|
|
@ -1,33 +1,34 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.customize;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
|
||||
public class GameFrameLayOut extends FrameLayout {
|
||||
public class GameFrameLayOut extends FrameLayout {
|
||||
private String TAG = "GameFrameLayOut";
|
||||
int MAX_WIDTH = 1;
|
||||
int MAX_HEIGHT = 1;
|
||||
int SCREEN_WIDTH = 1920;
|
||||
int SCREEN_HEIGHT = 1080;
|
||||
|
||||
public void setScreenSize(int width,int height){
|
||||
public void setScreenSize(int width, int height) {
|
||||
SCREEN_WIDTH = width;
|
||||
SCREEN_HEIGHT = height;
|
||||
}
|
||||
|
||||
public GameFrameLayOut(Context context) {
|
||||
super((Context)context);
|
||||
super((Context) context);
|
||||
|
||||
}
|
||||
|
||||
public GameFrameLayOut(Context context, AttributeSet attrs) {
|
||||
super((Context)context, attrs);
|
||||
super((Context) context, attrs);
|
||||
|
||||
}
|
||||
|
||||
public GameFrameLayOut(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super((Context)context, attrs, defStyleAttr);
|
||||
super((Context) context, attrs, defStyleAttr);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -37,6 +38,7 @@ public class GameFrameLayOut extends FrameLayout {
|
|||
super.onLayout(changed, left, top, right, bottom);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.customize;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
|
@ -13,13 +13,17 @@ import android.view.View;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import co.steamcloud.game.Config;
|
||||
import co.steamcloud.game.R;
|
||||
import co.steamcloud.game.utils.RoundCalculator;
|
||||
|
||||
public class JoystickView2 extends View {
|
||||
public float currentX ;
|
||||
public float currentY ;
|
||||
public float initX ;
|
||||
public float initY ;
|
||||
public float currentX2 ;
|
||||
public float currentY2 ;
|
||||
public float currentX;
|
||||
public float currentY;
|
||||
public float initX;
|
||||
public float initY;
|
||||
public float currentX2;
|
||||
public float currentY2;
|
||||
float lastX;
|
||||
float lastY;
|
||||
float lastVibX;
|
||||
|
|
@ -29,13 +33,14 @@ public class JoystickView2 extends View {
|
|||
private float viewSizeH;
|
||||
private float vibratorRanger;
|
||||
public int pointSize;
|
||||
private float maxRanger=150;
|
||||
private float maxRanger = 150;
|
||||
public float maxRanger2 = 150;
|
||||
public Context context;
|
||||
public Bitmap map;
|
||||
private Bitmap mDirectionBmp;
|
||||
public static Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
public OnJoystickListener mListener;
|
||||
|
||||
public JoystickView2(Context context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
|
|
@ -50,11 +55,12 @@ public class JoystickView2 extends View {
|
|||
super(context, attrs, defStyleAttr);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Bitmap zoomImg(Bitmap bm, int newWidth, int newHeight) {
|
||||
int width = bm.getWidth();
|
||||
int height = bm.getHeight();
|
||||
float scaleWidth = (float)newWidth / (float)width;
|
||||
float scaleHeight = (float)newHeight / (float)height;
|
||||
float scaleWidth = (float) newWidth / (float) width;
|
||||
float scaleHeight = (float) newHeight / (float) height;
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(scaleWidth, scaleHeight);
|
||||
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
|
||||
|
|
@ -67,23 +73,22 @@ public class JoystickView2 extends View {
|
|||
this.viewSize = this.getMeasuredWidth();
|
||||
int var10000 = this.viewSize;
|
||||
this.pointSize = var10000 / 3;
|
||||
viewSizeW=this.getMeasuredWidth();
|
||||
viewSizeH=this.getMeasuredHeight();
|
||||
vibratorRanger=viewSizeH/6;
|
||||
if (maxRanger>viewSizeH/4)
|
||||
{
|
||||
maxRanger=viewSizeH/4;
|
||||
viewSizeW = this.getMeasuredWidth();
|
||||
viewSizeH = this.getMeasuredHeight();
|
||||
vibratorRanger = viewSizeH / 6;
|
||||
if (maxRanger > viewSizeH / 4) {
|
||||
maxRanger = viewSizeH / 4;
|
||||
}
|
||||
if (maxRanger2>viewSizeH/3)
|
||||
{
|
||||
maxRanger2=viewSizeH/3;
|
||||
if (maxRanger2 > viewSizeH / 3) {
|
||||
maxRanger2 = viewSizeH / 3;
|
||||
}
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
currentX = currentX2=initX=lastX=viewSizeW/2;
|
||||
currentY= currentY2 =initY=lastY=viewSizeH/2;
|
||||
currentX = currentX2 = initX = lastX = viewSizeW / 2;
|
||||
currentY = currentY2 = initY = lastY = viewSizeH / 2;
|
||||
int var1 = this.pointSize;
|
||||
Bitmap var10000 = BitmapFactory.decodeResource(this.context.getResources(), R.mipmap.joystick_round);
|
||||
Bitmap mDirectionBmp1 = BitmapFactory.decodeResource(this.context.getResources(), R.mipmap.joystick_down);
|
||||
|
|
@ -93,7 +98,7 @@ public class JoystickView2 extends View {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas){
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
paint.setDither(true);
|
||||
canvas.drawBitmap(this.map, currentX2 - this.pointSize / 2, currentY2 - this.pointSize / 2, paint);
|
||||
|
|
@ -106,7 +111,7 @@ public class JoystickView2 extends View {
|
|||
int offsetY = mDirectionBmp.getHeight() / 2;
|
||||
matrix.postTranslate(-offsetX, -offsetY);
|
||||
matrix.postRotate(270 - rotationDegree);
|
||||
matrix.postTranslate(initX - mDirectionBmp.getWidth()/2 + offsetX, initY - mDirectionBmp.getHeight()/2 + offsetY);
|
||||
matrix.postTranslate(initX - mDirectionBmp.getWidth() / 2 + offsetX, initY - mDirectionBmp.getHeight() / 2 + offsetY);
|
||||
canvas.drawBitmap(mDirectionBmp, matrix, null);
|
||||
}
|
||||
|
||||
|
|
@ -115,12 +120,13 @@ public class JoystickView2 extends View {
|
|||
public void setOnJoystickListener(OnJoystickListener listener) {
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if(Config.s_keyboard){
|
||||
if (Config.s_keyboard) {
|
||||
return false;
|
||||
}
|
||||
if (event.getAction()==MotionEvent.ACTION_DOWN||event.getAction()==MotionEvent.ACTION_MOVE){
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
|
||||
/*if (event.getAction()==MotionEvent.ACTION_DOWN) {
|
||||
initX2 = event.getX();
|
||||
|
|
@ -133,19 +139,17 @@ public class JoystickView2 extends View {
|
|||
this.currentY2 = event.getY();
|
||||
|
||||
float tr = (float) RoundCalculator.calTwoPointDistant(initX, initY, event.getX(), event.getY());
|
||||
if (tr>maxRanger)
|
||||
{
|
||||
if (tr > maxRanger) {
|
||||
float dotCenterOnShow[] = RoundCalculator.calPointLocationByAngle(
|
||||
initX, initY, event.getX(), event.getY(), maxRanger);
|
||||
this.currentX = dotCenterOnShow[0];
|
||||
this.currentY = dotCenterOnShow[1];
|
||||
Log.e("currentXY1","...x="+currentX2+",y="+currentY2+",maxRanger2="+maxRanger2);
|
||||
Log.e("currentXY1", "...x=" + currentX2 + ",y=" + currentY2 + ",maxRanger2=" + maxRanger2);
|
||||
}
|
||||
|
||||
|
||||
float tr2 = (float) RoundCalculator.calTwoPointDistant(initX, initY, event.getX(), event.getY());
|
||||
if (tr2>maxRanger2)
|
||||
{
|
||||
if (tr2 > maxRanger2) {
|
||||
float dotCenterOnShow[] = RoundCalculator.calPointLocationByAngle(
|
||||
initX, initY, event.getX(), event.getY(), maxRanger2);
|
||||
this.currentX2 = dotCenterOnShow[0];
|
||||
|
|
@ -153,28 +157,27 @@ public class JoystickView2 extends View {
|
|||
|
||||
}
|
||||
|
||||
}else {
|
||||
this.currentX =initX;
|
||||
this.currentY =initY;
|
||||
} else {
|
||||
this.currentX = initX;
|
||||
this.currentY = initY;
|
||||
|
||||
this.currentX2 = initX;
|
||||
this.currentY2 = initY;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (mListener!=null){
|
||||
if (mListener != null) {
|
||||
//if (Math.abs(currentX-lastX)>3||Math.abs(currentY-lastY)>3){
|
||||
|
||||
mListener.onPosition((currentX-initX)/(float)maxRanger,(currentY-initY)/(float)maxRanger);
|
||||
mListener.onPosition((currentX - initX) / (float) maxRanger, (currentY - initY) / (float) maxRanger);
|
||||
|
||||
lastX=currentX;
|
||||
lastY=currentY;
|
||||
lastX = currentX;
|
||||
lastY = currentY;
|
||||
// }
|
||||
if (Math.abs(currentX-lastVibX)>vibratorRanger||Math.abs(currentY-lastVibY)>vibratorRanger){//用来震动
|
||||
if (Math.abs(currentX - lastVibX) > vibratorRanger || Math.abs(currentY - lastVibY) > vibratorRanger) {//用来震动
|
||||
this.mListener.onVibrator();
|
||||
lastVibX=currentX;
|
||||
lastVibY=currentY;
|
||||
lastVibX = currentX;
|
||||
lastVibY = currentY;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.customize;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
|
@ -8,6 +8,8 @@ import android.view.View;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import co.steamcloud.game.Config;
|
||||
|
||||
public class KeyButton extends androidx.appcompat.widget.AppCompatTextView {
|
||||
|
||||
|
||||
|
|
@ -59,9 +61,10 @@ public class KeyButton extends androidx.appcompat.widget.AppCompatTextView {
|
|||
public float touchInitX;
|
||||
public float touchInitY;
|
||||
boolean isMove = false;
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
Config.keyEvent_time=0;
|
||||
Config.keyEvent_time = 0;
|
||||
/* if(!Config.s_keyboard){
|
||||
return super.onTouchEvent(event);
|
||||
}*/
|
||||
|
|
@ -77,24 +80,22 @@ public class KeyButton extends androidx.appcompat.widget.AppCompatTextView {
|
|||
isMove = false;
|
||||
|
||||
|
||||
if (mListener!=null){
|
||||
if (mListener != null) {
|
||||
mListener.onActionDown(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if(Config.s_keyboard){
|
||||
if (Config.s_keyboard) {
|
||||
if (Math.abs(event.getX() - touchInitX) > 10 || Math.abs(event.getY() - touchInitY) > 10) {
|
||||
isMove = true;
|
||||
setX(mOriginalX + event.getRawX() - mOriginalRawX);
|
||||
setY(mOriginalY + event.getRawY() - mOriginalRawY);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
if (Math.abs(event.getX() - touchInitX) > 10 || Math.abs(event.getY() - touchInitY) > 10) {
|
||||
if (mListener!=null){
|
||||
if (mListener != null) {
|
||||
mListener.onActionMove(event);
|
||||
}
|
||||
/* setX(mOriginalX + event.getRawX() - mOriginalRawX);
|
||||
|
|
@ -105,7 +106,7 @@ public class KeyButton extends androidx.appcompat.widget.AppCompatTextView {
|
|||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (!isMove) {
|
||||
if (mListener!=null){
|
||||
if (mListener != null) {
|
||||
mListener.onActionUp();
|
||||
}
|
||||
}
|
||||
|
|
@ -116,39 +117,46 @@ public class KeyButton extends androidx.appcompat.widget.AppCompatTextView {
|
|||
|
||||
return true;
|
||||
}
|
||||
public void setOnClickCallBackListener(OnClickCallBackListener listener){
|
||||
this.mListener=listener;
|
||||
|
||||
public void setOnClickCallBackListener(OnClickCallBackListener listener) {
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
public void keyBoardDelectListener(ViewChangMsgListener viewChangMsgListener){
|
||||
this.viewChangMsgListener =viewChangMsgListener;
|
||||
public void keyBoardDelectListener(ViewChangMsgListener viewChangMsgListener) {
|
||||
this.viewChangMsgListener = viewChangMsgListener;
|
||||
}
|
||||
|
||||
|
||||
public interface OnClickCallBackListener{
|
||||
public interface OnClickCallBackListener {
|
||||
void onActionDown(MotionEvent event);
|
||||
|
||||
void onActionUp();
|
||||
|
||||
void onActionMove(MotionEvent event);
|
||||
}
|
||||
|
||||
public void setPosition(float x,float y) {
|
||||
public void setPosition(float x, float y) {
|
||||
this.setX(x);
|
||||
this.setY(y);
|
||||
}
|
||||
|
||||
public interface ViewChangMsgListener{
|
||||
public interface ViewChangMsgListener {
|
||||
void changTexture(String path);
|
||||
|
||||
void showDeletPopup(KeyButton view);
|
||||
|
||||
void showDeletPopup(String index);
|
||||
|
||||
void showFloatPopup();
|
||||
}
|
||||
|
||||
public interface virtualHandleChangeListener{
|
||||
public interface virtualHandleChangeListener {
|
||||
void layerBtnSetVisible(int tag);
|
||||
}
|
||||
public interface virtualKeyboardChangeListener
|
||||
{
|
||||
|
||||
public interface virtualKeyboardChangeListener {
|
||||
void removeChild(View child);
|
||||
|
||||
void hideDirection();
|
||||
}
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.customize;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
|
@ -15,6 +15,8 @@ import com.zjrx.jyengine.WhaleCloud;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import co.steamcloud.game.R;
|
||||
|
||||
public class KeyboardUtil {
|
||||
private Context ctx;
|
||||
private Activity act;
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.customize;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import co.steamcloud.game.Config;
|
||||
|
||||
public class MoveButton extends RelativeLayout {
|
||||
|
||||
|
||||
|
|
@ -58,7 +60,7 @@ public class MoveButton extends RelativeLayout {
|
|||
setX(moveX);
|
||||
moveY = mOriginalY + event.getRawY() - mOriginalRawY;
|
||||
setY(mOriginalY + event.getRawY() - mOriginalRawY);
|
||||
if (mListener != null){
|
||||
if (mListener != null) {
|
||||
mListener.onActionMove(moveX, moveY);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.customize;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
|
@ -23,6 +23,7 @@ public class MyButton extends androidx.appcompat.widget.AppCompatTextView {
|
|||
public MyButton(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
private OnClickCallBackListener mListener;
|
||||
private ViewChangMsgListener viewChangMsgListener;
|
||||
|
||||
|
|
@ -43,6 +44,7 @@ public class MyButton extends androidx.appcompat.widget.AppCompatTextView {
|
|||
public float touchInitX;
|
||||
public float touchInitY;
|
||||
boolean isMove = false;
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
|
||||
|
|
@ -68,7 +70,7 @@ public class MyButton extends androidx.appcompat.widget.AppCompatTextView {
|
|||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (!isMove) {
|
||||
if (mListener!=null){
|
||||
if (mListener != null) {
|
||||
mListener.onActionDown();
|
||||
}
|
||||
}
|
||||
|
|
@ -79,37 +81,44 @@ public class MyButton extends androidx.appcompat.widget.AppCompatTextView {
|
|||
|
||||
return true;
|
||||
}
|
||||
public void setOnClickCallBackListener(OnClickCallBackListener listener){
|
||||
this.mListener=listener;
|
||||
|
||||
public void setOnClickCallBackListener(OnClickCallBackListener listener) {
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
public void keyBoardDelectListener(ViewChangMsgListener viewChangMsgListener){
|
||||
this.viewChangMsgListener =viewChangMsgListener;
|
||||
public void keyBoardDelectListener(ViewChangMsgListener viewChangMsgListener) {
|
||||
this.viewChangMsgListener = viewChangMsgListener;
|
||||
}
|
||||
|
||||
|
||||
public interface OnClickCallBackListener{
|
||||
public interface OnClickCallBackListener {
|
||||
void onActionDown();
|
||||
void onActionMove(float x,float y);
|
||||
|
||||
void onActionMove(float x, float y);
|
||||
}
|
||||
|
||||
public void setPosition(float x,float y) {
|
||||
public void setPosition(float x, float y) {
|
||||
this.setX(x);
|
||||
this.setY(y);
|
||||
}
|
||||
|
||||
public interface ViewChangMsgListener{
|
||||
public interface ViewChangMsgListener {
|
||||
void changTexture(String path);
|
||||
|
||||
void showDeletPopup(MyButton view);
|
||||
|
||||
void showDeletPopup(String index);
|
||||
|
||||
void showFloatPopup();
|
||||
}
|
||||
public interface virtualHandleChangeListener{
|
||||
|
||||
public interface virtualHandleChangeListener {
|
||||
void layerBtnSetVisible(int tag);
|
||||
}
|
||||
public interface virtualKeyboardChangeListener
|
||||
{
|
||||
|
||||
public interface virtualKeyboardChangeListener {
|
||||
void removeChild(View child);
|
||||
|
||||
void hideDirection();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
|
|
@ -64,8 +64,75 @@ import co.steamcloud.game.App;
|
|||
*/
|
||||
public class AppUtil {
|
||||
|
||||
public static final byte[] gamePadDescriptor = new byte[]{
|
||||
// 游戏手柄的 HID 描述符
|
||||
0x05, 0x01, // USAGE_PAGE (Game Controls) - 游戏控制设备
|
||||
0x09, 0x05, // USAGE (Gamepad) - 游戏手柄
|
||||
(byte) 0xA1, 0x01, // COLLECTION (Application) - 应用集合
|
||||
(byte) 0xA1, 0x00, // COLLECTION (Physical) - 物理集合
|
||||
|
||||
// 按钮部分
|
||||
0x05, 0x09, // USAGE_PAGE (Button) - 按钮输入
|
||||
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
||||
0x29, 0x10, // USAGE_MAXIMUM (Button 16)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0) - 按钮的逻辑最小值
|
||||
0x25, 0x01, // LOGICAL_MAXIMUM (1) - 按钮的逻辑最大值
|
||||
0x75, 0x01, // REPORT_SIZE (1) - 每个按钮占用 1 位
|
||||
(byte) 0x95, 0x10, // REPORT_COUNT (16) - 总共有 16 个按钮
|
||||
(byte) 0x81, 0x02, // INPUT (Data, Var, Abs) - 按钮输入,数据类型、变量、绝对值
|
||||
|
||||
// 左摇杆
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x30, // USAGE (X) - 左摇杆水平轴
|
||||
0x09, 0x31, // USAGE (Y) - 左摇杆垂直轴
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0) - 摇杆的逻辑最小值
|
||||
0x25, (byte) 0xFF, // LOGICAL_MAXIMUM (255) - 摇杆的逻辑最大值
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
(byte) 0x95, 0x02, // REPORT_COUNT (2)
|
||||
(byte) 0x81, 0x02, // INPUT (Data, Var, Abs)
|
||||
|
||||
// // 右摇杆
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
// 0x09, 0x33, // USAGE (Rx) - 右摇杆水平轴
|
||||
// 0x09, 0x34, // USAGE (Ry) - 右摇杆垂直轴
|
||||
0x09, 0x32, // USAGE (Z) - 右摇杆水平轴
|
||||
0x09, 0x35, // USAGE (Rz) - 右摇杆垂直轴
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0) - 摇杆的逻辑最小值
|
||||
0x25, (byte) 0xFF, // LOGICAL_MAXIMUM (255) - 摇杆的逻辑最大值
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
(byte) 0x95, 0x02, // REPORT_COUNT (2)
|
||||
(byte) 0x81, 0x02, // INPUT (Data, Var, Abs)
|
||||
|
||||
// 方向键(HAT switch)
|
||||
0x09, 0x39, // USAGE (Hat switch)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x25, 0x07, // LOGICAL_MAXIMUM (7)
|
||||
0x35, 0x00, // PHYSICAL_MINIMUM (0)
|
||||
0x46, 0x3B, 0x01, // PHYSICAL_MAXIMUM (315)
|
||||
0x65, 0x14, // UNIT (Eng Rot: Angular Pos)
|
||||
0x75, 0x04, // REPORT_SIZE (4)
|
||||
(byte) 0x95, 0x01, // REPORT_COUNT (1)
|
||||
(byte) 0x81, 0x42, // INPUT (Data, Var, Abs, Null)
|
||||
|
||||
// 触发器(L2 和 R2)
|
||||
0x75, 0x04, // REPORT_SIZE (4) - 触发器占用 4 位
|
||||
(byte) 0x95, 0x01, // REPORT_COUNT (1) - 只有 1 个触发器
|
||||
(byte) 0x81, 0x01, // INPUT (Cnst, Ary, Abs) - 触发器输入,常量、数组、绝对值
|
||||
|
||||
// 震动输出报告
|
||||
0x09, 0x70, // USAGE (Vibration) - 震动
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0) - 震动强度的逻辑最小值
|
||||
0x26, (byte) 0xFF, 0x00, // LOGICAL_MAXIMUM (255) - 震动强度的逻辑最大值
|
||||
0x75, 0x08, // REPORT_SIZE (8) - 每个震动强度占用 8 位
|
||||
(byte) 0x95, 0x02, // REPORT_COUNT (2) - 左、右震动马达各 1 个字节
|
||||
(byte) 0x91, 0x02, // OUTPUT (Data, Var, Abs) - 震动输出,数据类型、变量、绝对值
|
||||
|
||||
// 结束集合
|
||||
(byte) 0xC0, // END_COLLECTION (Physical) - 结束物理集合
|
||||
(byte) 0xC0 // END_COLLECTION (Application) - 结束应用集合
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param content 字符串内容
|
||||
* @param width 二维码宽度
|
||||
* @param height 二维码高度
|
||||
|
|
@ -79,8 +146,8 @@ public class AppUtil {
|
|||
* @return
|
||||
*/
|
||||
public static Bitmap createQRCodeBitmap(String content, int width, int height, String character_set,
|
||||
String error_correction_level,String margin, int color_black,
|
||||
int color_white,Bitmap logoBitmap, float logoPercent) {
|
||||
String error_correction_level, String margin, int color_black,
|
||||
int color_white, Bitmap logoBitmap, float logoPercent) {
|
||||
// 字符串内容判空
|
||||
if (TextUtils.isEmpty(content)) {
|
||||
return null;
|
||||
|
|
@ -125,7 +192,7 @@ public class AppUtil {
|
|||
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
|
||||
|
||||
/** 5.为二维码添加logo图标 */
|
||||
if(logoBitmap != null){
|
||||
if (logoBitmap != null) {
|
||||
return addLogo(bitmap, logoBitmap, logoPercent);
|
||||
}
|
||||
return bitmap;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.utils;
|
||||
|
||||
import android.os.CountDownTimer;
|
||||
import android.view.View;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.utils;
|
||||
|
||||
/**
|
||||
*
|
||||
245
android/app/src/main/java/co/steamcloud/game/utils/GamePad.java
Normal file
245
android/app/src/main/java/co/steamcloud/game/utils/GamePad.java
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
package co.steamcloud.game.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class GamePad {
|
||||
|
||||
private GamepadAction gamepadAction;
|
||||
|
||||
public GamePad(GamepadAction action) {
|
||||
this.gamepadAction = action;
|
||||
}
|
||||
|
||||
public void setCallback(GamepadAction callback) {
|
||||
this.gamepadAction = callback;
|
||||
}
|
||||
|
||||
private final String TAG = "Gamepad";
|
||||
/**
|
||||
* 按钮A
|
||||
*/
|
||||
public GamepadButton BUTTON_A = new GamepadButton("BUTTON_A");
|
||||
|
||||
/**
|
||||
* 按钮B
|
||||
*/
|
||||
public GamepadButton BUTTON_B = new GamepadButton("BUTTON_B");
|
||||
|
||||
/**
|
||||
* 按钮X
|
||||
*/
|
||||
public GamepadButton BUTTON_X = new GamepadButton("BUTTON_X");
|
||||
|
||||
/**
|
||||
* 按钮Y
|
||||
*/
|
||||
public GamepadButton BUTTON_Y = new GamepadButton("BUTTON_Y");
|
||||
|
||||
/**
|
||||
* 按钮L1
|
||||
*/
|
||||
public GamepadButton BUTTON_L1 = new GamepadButton("BUTTON_L1");
|
||||
|
||||
/**
|
||||
* 按钮R1
|
||||
*/
|
||||
public GamepadButton BUTTON_R1 = new GamepadButton("BUTTON_R1");
|
||||
|
||||
/**
|
||||
* 按钮L2
|
||||
*/
|
||||
public GamepadButton BUTTON_L2 = new GamepadButton("BUTTON_L2");
|
||||
|
||||
/**
|
||||
* 按钮R2
|
||||
*/
|
||||
public GamepadButton BUTTON_R2 = new GamepadButton("BUTTON_R2");
|
||||
|
||||
/**
|
||||
* 按钮Start
|
||||
*/
|
||||
public GamepadButton BUTTON_START = new GamepadButton("BUTTON_START");
|
||||
|
||||
/**
|
||||
* 按钮Select
|
||||
*/
|
||||
public GamepadButton BUTTON_SELECT = new GamepadButton("BUTTON_SELECT");
|
||||
|
||||
/**
|
||||
* 按钮L3
|
||||
*/
|
||||
public GamepadButton BUTTON_L3 = new GamepadButton("BUTTON_L3");
|
||||
|
||||
/**
|
||||
* 按钮R3
|
||||
*/
|
||||
public GamepadButton BUTTON_R3 = new GamepadButton("BUTTON_R3");
|
||||
|
||||
/**
|
||||
* 按钮DPad Up
|
||||
*/
|
||||
public GamepadButton BUTTON_DPAD_UP = new GamepadButton("BUTTON_DPAD_UP");
|
||||
|
||||
/**
|
||||
* 按钮DPad Down
|
||||
*/
|
||||
public GamepadButton BUTTON_DPAD_DOWN = new GamepadButton("BUTTON_DPAD_DOWN");
|
||||
|
||||
/**
|
||||
* 按钮DPad Left
|
||||
*/
|
||||
public GamepadButton BUTTON_DPAD_LEFT = new GamepadButton("BUTTON_DPAD_LEFT");
|
||||
|
||||
/**
|
||||
* 按钮DPad Right
|
||||
*/
|
||||
public GamepadButton BUTTON_DPAD_RIGHT = new GamepadButton("BUTTON_DPAD_RIGHT");
|
||||
|
||||
public GamepadButton Placeholder = new GamepadButton("");
|
||||
|
||||
/**
|
||||
* 第一位请求数据
|
||||
*/
|
||||
|
||||
public boolean KeyDown(GamepadButton btn) {
|
||||
Log.d(TAG, "KeyDown——old: " + btn.Name + "===<>>>" + btn.getStatus());
|
||||
btn.setStatus(true);
|
||||
Log.d(TAG, "KeyDown: " + btn.Name + "===<>>>" + btn.getStatus());
|
||||
GenerateParams();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean KeyUp(GamepadButton btn) {
|
||||
Log.d(TAG, "KeyDown——-up-old: " + btn.Name + "===<>>>" + btn.getStatus());
|
||||
btn.setStatus(false);
|
||||
Log.d(TAG, "KeyDown——-up: " + btn.Name + "===<>>>" + btn.getStatus());
|
||||
GenerateParams();
|
||||
return true;
|
||||
}
|
||||
|
||||
private byte report3 = 0x00;
|
||||
private byte report4 = 0x00;
|
||||
|
||||
private byte report5 = 0x00;
|
||||
private byte report6 = 0x00;
|
||||
|
||||
/**
|
||||
* 设置坐标
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
public void SetLeftRemoteSensing(float x, float y) {
|
||||
report3 = (byte) mapToJoystick(x);
|
||||
report4 = (byte) mapToJoystick(y);
|
||||
// Log.d(TAG, "SetLeftRemoteSensing: report3===>"+report3+"====>report4"+report4);
|
||||
GenerateParams();
|
||||
}
|
||||
|
||||
public void SetRightRemoteSensing(float x, float y) {
|
||||
report5 = (byte) mapToJoystick(x);
|
||||
report6 = (byte) mapToJoystick(y);
|
||||
Log.d(TAG, "SetLeftRemoteSensing: report5===>" + report5 + "====>report6" + report6);
|
||||
GenerateParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数组转换为二进制字符串
|
||||
*
|
||||
* @param boolArray
|
||||
* @return
|
||||
*/
|
||||
public String booleanArrayToBinaryString(GamepadButton[] boolArray) {
|
||||
if (boolArray == null || boolArray.length != 8) {
|
||||
throw new IllegalArgumentException("数组必须是8位长度的boolean数组");
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (GamepadButton b : boolArray) {
|
||||
// sb.append(b.getStatus() ? "1" : "0");
|
||||
sb.insert(0, b.getStatus() ? "1" : "0");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public GamepadButton[] report1GamepadButton = {BUTTON_A, BUTTON_B, Placeholder, BUTTON_X, BUTTON_Y, Placeholder, BUTTON_L1, BUTTON_R1};
|
||||
public GamepadButton[] report2GamepadButton = {BUTTON_L2, BUTTON_R2, BUTTON_SELECT, BUTTON_START, Placeholder, BUTTON_L3, BUTTON_R3, Placeholder};
|
||||
|
||||
/**
|
||||
* 生产请求字节
|
||||
*
|
||||
* @param boolArray
|
||||
* @return
|
||||
*/
|
||||
public byte GetGenerateParams(GamepadButton[] boolArray) {
|
||||
String binaryString = booleanArrayToBinaryString(boolArray);
|
||||
// 将二进制字符串转换为整数
|
||||
int intValue = Integer.parseInt(binaryString, 2); // 第二个参数是基数(2表示二进制)
|
||||
// 将整数转换为byte
|
||||
byte byteValue = (byte) intValue;
|
||||
return byteValue;
|
||||
}
|
||||
|
||||
public int mapToJoystick(float value) {
|
||||
// 保证值在 [-1, 1] 范围内
|
||||
value = Math.max(-1, Math.min(1, value));
|
||||
return (int) ((value + 1) * 127.5);
|
||||
}
|
||||
|
||||
private byte dpadState = 0x08; // 默认中立状态
|
||||
|
||||
public void SetDpadState() {
|
||||
if (BUTTON_DPAD_UP.getStatus()) {
|
||||
if (BUTTON_DPAD_LEFT.getStatus()) {
|
||||
dpadState = 0x07; // 左上
|
||||
} else if (BUTTON_DPAD_RIGHT.getStatus()) {
|
||||
dpadState = 0x01; // 右上
|
||||
} else {
|
||||
dpadState = 0x00; // 上
|
||||
}
|
||||
} else if (BUTTON_DPAD_DOWN.getStatus()) {
|
||||
if (BUTTON_DPAD_LEFT.getStatus()) {
|
||||
dpadState = 0x05; // 左下
|
||||
} else if (BUTTON_DPAD_RIGHT.getStatus()) {
|
||||
dpadState = 0x03; // 右下
|
||||
} else {
|
||||
dpadState = 0x04; // 下
|
||||
}
|
||||
} else if (BUTTON_DPAD_LEFT.getStatus()) {
|
||||
dpadState = 0x06; // 左
|
||||
} else if (BUTTON_DPAD_RIGHT.getStatus()) {
|
||||
dpadState = 0x02; // 右
|
||||
} else {
|
||||
dpadState = 0x08; // 中立
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateParams() {
|
||||
SetDpadState();
|
||||
//按钮1
|
||||
byte report1 = GetGenerateParams(report1GamepadButton);
|
||||
byte report2 = GetGenerateParams(report2GamepadButton);
|
||||
byte[] report = new byte[8];
|
||||
// 设置按钮 A 按下(假设 A 是第一个按钮)
|
||||
report[0] = report1; // 0x01 表示 A 按下,0x00 表示释放
|
||||
report[1] = report2;//; // 其他按钮未按下
|
||||
// 设置摇杆为中立值
|
||||
report[2] = report3; // 左摇杆水平中立位置
|
||||
report[3] = report4; // 左摇杆垂直中立位置
|
||||
report[4] = report5; // 右摇杆水平中立位置
|
||||
report[5] = report6; // 右摇杆垂直中立位置
|
||||
// Log.d(TAG, "GenerateParams: report3==>"+report3+"===>report4===>"+report3);
|
||||
// 设置触发器未按下
|
||||
report[6] = dpadState; // 左右触发器未按下
|
||||
// 保留字节
|
||||
report[7] = 0x00; // 保留字段
|
||||
Log.d(TAG, "SetLeftRemoteSensing: report7" + dpadState);
|
||||
gamepadAction.SendRequest(report);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.utils;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
public class GamePara {
|
||||
String game_key;
|
||||
int display_grade;
|
||||
int queue_grade;
|
||||
int able_queue;
|
||||
int display_grade;
|
||||
int queue_grade;
|
||||
int able_queue;
|
||||
String gs_name;
|
||||
String save_time;
|
||||
String room_name;
|
||||
String start_resolution;
|
||||
int record_game_time;
|
||||
int record_game_time;
|
||||
String model_name;
|
||||
String sc_id;
|
||||
String hangup_time;
|
||||
|
|
@ -23,7 +23,7 @@ public class GamePara {
|
|||
int enable_restart;//是否支持重新启动游戏,可选, 1为支持,0为不支持,默认为0
|
||||
String room_key; //设置字符串房间随机密码,只有使用相同密码的操控设备权限变更才能判定有效
|
||||
|
||||
public GamePara(){
|
||||
public GamePara() {
|
||||
game_key = "";
|
||||
display_grade = 1;
|
||||
queue_grade = 1;
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package co.steamcloud.game.utils;
|
||||
|
||||
/**
|
||||
* 手柄请求方法
|
||||
*/
|
||||
|
||||
@FunctionalInterface
|
||||
public interface GamepadAction {
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void SendRequest(byte[] params);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package co.steamcloud.game.utils;
|
||||
|
||||
public class GamepadButton {
|
||||
|
||||
public GamepadButton(String name) {
|
||||
this.Name = name;
|
||||
this.Status = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按钮名称
|
||||
*/
|
||||
public String Name;
|
||||
/**
|
||||
* 按钮状态
|
||||
*/
|
||||
public Boolean Status;
|
||||
|
||||
|
||||
public Boolean getStatus() {
|
||||
return Status;
|
||||
}
|
||||
|
||||
public void setStatus(boolean value) {
|
||||
this.Status = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
|
@ -54,7 +54,7 @@ public class GsonJsonUtil {
|
|||
* 转成list
|
||||
*
|
||||
* @param string 字符串
|
||||
* @param cls 类
|
||||
* @param cls 类
|
||||
* @return list
|
||||
*/
|
||||
public static <T> List<T> stringToList(String string, Class<T> cls) {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.utils;
|
||||
|
||||
import android.os.CountDownTimer;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package co.steamcloud.game;
|
||||
package co.steamcloud.game.utils;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -17,7 +17,7 @@ import org.simple.eventbus.EventBus;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import co.steamcloud.game.EventBusParams;
|
||||
import co.steamcloud.game.utils.EventBusParams;
|
||||
import co.steamcloud.game.MainActivity;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:background="#000000">
|
||||
|
||||
<co.steamcloud.game.GameFrameLayOut
|
||||
<co.steamcloud.game.customize.GameFrameLayOut
|
||||
android:id="@+id/video_renderer_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
android:layout_gravity="center"
|
||||
android:visibility="visible"
|
||||
tools:visibility="visible" />
|
||||
</co.steamcloud.game.GameFrameLayOut>
|
||||
</co.steamcloud.game.customize.GameFrameLayOut>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/qosLayout"
|
||||
|
|
@ -75,7 +75,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<co.steamcloud.game.MyButton
|
||||
<co.steamcloud.game.customize.MyButton
|
||||
android:id="@+id/imageCursor"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
|
|
@ -155,7 +155,7 @@
|
|||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<co.steamcloud.game.MyButton
|
||||
<co.steamcloud.game.customize.MyButton
|
||||
android:id="@+id/menu_set"
|
||||
android:layout_width="33dp"
|
||||
android:layout_height="33dp"
|
||||
|
|
@ -165,7 +165,7 @@
|
|||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<co.steamcloud.game.MyButton
|
||||
<co.steamcloud.game.customize.MyButton
|
||||
android:id="@+id/Move_show_hide"
|
||||
android:layout_width="33dp"
|
||||
android:layout_height="33dp"
|
||||
|
|
|
|||
386
android/app/src/main/res/layout/activity_handle.xml
Normal file
386
android/app/src/main/res/layout/activity_handle.xml
Normal file
|
|
@ -0,0 +1,386 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#FF1A1B20"
|
||||
tools:context=".HandleActivity">
|
||||
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/HandleCL"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/visual_angle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="1.0" />
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/yaogan_left"
|
||||
android:layout_width="135dp"
|
||||
android:layout_height="135dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="5dp"
|
||||
android:src="@mipmap/joystick" />
|
||||
|
||||
<co.steamcloud.game.customize.JoystickView2
|
||||
android:id="@+id/joystick_left"
|
||||
android:layout_width="135dp"
|
||||
android:layout_height="135dp"
|
||||
android:layout_centerInParent="true" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/direction_key"
|
||||
android:layout_width="95dp"
|
||||
android:layout_height="95dp"
|
||||
android:background="@mipmap/direction_bg"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dpad_up"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:clickable="true"
|
||||
android:src="@drawable/button_up" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dpad_left"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:src="@drawable/button_left" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dpad_right"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:src="@drawable/button_right" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dpad_down"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:src="@drawable/button_down" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dpad_up_left"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_above="@+id/dpad_left"
|
||||
android:layout_toStartOf="@+id/dpad_up" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dpad_up_right"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_above="@+id/dpad_right"
|
||||
android:layout_toEndOf="@+id/dpad_up" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dpad_down_left"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_below="@+id/dpad_left"
|
||||
android:layout_toStartOf="@+id/dpad_down" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dpad_down_right"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_below="@+id/dpad_right"
|
||||
android:layout_toEndOf="@+id/dpad_down" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/yaogan_right"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="5dp"
|
||||
android:src="@mipmap/joystick" />
|
||||
|
||||
<co.steamcloud.game.customize.JoystickView2
|
||||
android:id="@+id/joystick_right"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_centerInParent="true" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_a"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_a"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
android:background="@drawable/handle_button_ls"
|
||||
android:clickable="true"
|
||||
android:gravity="center"
|
||||
android:text="A"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="20sp" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_b"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_b"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
android:background="@drawable/handle_button_ls"
|
||||
android:clickable="true"
|
||||
android:gravity="center"
|
||||
android:text="B"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="20sp" />
|
||||
|
||||
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_x"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_x"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:background="@drawable/handle_button_ls"
|
||||
android:clickable="true"
|
||||
android:gravity="center"
|
||||
android:text="X"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="20sp" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_y"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_y"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:background="@drawable/handle_button_ls"
|
||||
android:clickable="true"
|
||||
android:gravity="center"
|
||||
android:text="Y"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="20sp" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_rs"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_rs"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:background="@drawable/handle_button_ls"
|
||||
android:clickable="true"
|
||||
android:gravity="center"
|
||||
android:text="RS"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="12sp" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_rt"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_rt"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
android:background="@drawable/handle_button_ls"
|
||||
android:clickable="true"
|
||||
android:gravity="center"
|
||||
android:text="RT"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="20sp" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_rb"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_rb"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
android:background="@drawable/handle_button_ls"
|
||||
android:clickable="true"
|
||||
android:gravity="center"
|
||||
android:text="RB"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="16sp" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_lt"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_lt"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
android:background="@drawable/handle_button_ls"
|
||||
android:clickable="true"
|
||||
android:gravity="center"
|
||||
android:text="LT"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="16sp" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_lb"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_lb"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
android:background="@drawable/handle_button_ls"
|
||||
android:clickable="true"
|
||||
android:gravity="center"
|
||||
android:text="LB"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="16sp" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_ls"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_ls"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:background="@drawable/handle_button_ls"
|
||||
android:clickable="true"
|
||||
android:gravity="center"
|
||||
android:text="LS"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="12sp" />
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_back"
|
||||
android:layout_width="33dp"
|
||||
android:layout_height="33dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_back"
|
||||
android:layout_width="33dp"
|
||||
android:layout_height="33dp"
|
||||
android:background="@drawable/button_back"
|
||||
android:clickable="true"
|
||||
android:gravity="center_vertical" />
|
||||
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_start"
|
||||
android:layout_width="33dp"
|
||||
android:layout_height="33dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_start"
|
||||
android:layout_width="33dp"
|
||||
android:layout_height="33dp"
|
||||
android:background="@drawable/button_play_start"
|
||||
android:clickable="true"
|
||||
android:gravity="center_vertical" />
|
||||
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_exit_handle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:background="@drawable/shap_exit_game_cancel"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:text="退出"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="1.0" />
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/yaogan_left"
|
||||
android:layout_width="135dp"
|
||||
android:layout_height="135dp"
|
||||
|
|
@ -48,14 +48,14 @@
|
|||
android:padding="5dp"
|
||||
android:src="@mipmap/joystick" />
|
||||
|
||||
<co.steamcloud.game.JoystickView2
|
||||
<co.steamcloud.game.customize.JoystickView2
|
||||
android:id="@+id/joystick_left"
|
||||
android:layout_width="135dp"
|
||||
android:layout_height="135dp"
|
||||
android:layout_centerInParent="true" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/direction_key"
|
||||
android:layout_width="95dp"
|
||||
android:layout_height="95dp"
|
||||
|
|
@ -120,9 +120,9 @@
|
|||
android:layout_height="35dp"
|
||||
android:layout_below="@+id/dpad_right"
|
||||
android:layout_toEndOf="@+id/dpad_down" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/yaogan_right"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
|
|
@ -135,14 +135,14 @@
|
|||
android:padding="5dp"
|
||||
android:src="@mipmap/joystick" />
|
||||
|
||||
<co.steamcloud.game.JoystickView2
|
||||
<co.steamcloud.game.customize.JoystickView2
|
||||
android:id="@+id/joystick_right"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_centerInParent="true" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_a"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
|
|
@ -158,9 +158,9 @@
|
|||
android:text="A"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="20sp" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_b"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
|
|
@ -178,10 +178,10 @@
|
|||
android:textSize="20sp" />
|
||||
|
||||
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_x"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
|
|
@ -197,10 +197,10 @@
|
|||
android:text="X"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="20sp" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_y"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
|
|
@ -217,10 +217,10 @@
|
|||
android:text="Y"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="20sp" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_rs"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
|
|
@ -236,10 +236,10 @@
|
|||
android:text="RS"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="12sp" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_rt"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
|
|
@ -255,9 +255,9 @@
|
|||
android:text="RT"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="20sp" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_rb"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
|
|
@ -273,9 +273,9 @@
|
|||
android:text="RB"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="16sp" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_lt"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
|
|
@ -291,9 +291,9 @@
|
|||
android:text="LT"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="16sp" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_lb"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
|
|
@ -309,9 +309,9 @@
|
|||
android:text="LB"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="16sp" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_ls"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
|
|
@ -327,9 +327,9 @@
|
|||
android:text="LS"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="12sp" />
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_back"
|
||||
android:layout_width="33dp"
|
||||
android:layout_height="33dp"
|
||||
|
|
@ -343,9 +343,9 @@
|
|||
android:background="@drawable/button_back"
|
||||
android:gravity="center_vertical" />
|
||||
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
<co.steamcloud.game.MoveButton
|
||||
<co.steamcloud.game.customize.MoveButton
|
||||
android:id="@+id/Move_start"
|
||||
android:layout_width="33dp"
|
||||
android:layout_height="33dp"
|
||||
|
|
@ -359,7 +359,7 @@
|
|||
android:background="@drawable/button_play_start"
|
||||
android:gravity="center_vertical" />
|
||||
|
||||
</co.steamcloud.game.MoveButton>
|
||||
</co.steamcloud.game.customize.MoveButton>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
|
|
|||
BIN
assets/images/ic_bt_device.png
Normal file
BIN
assets/images/ic_bt_device.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
BIN
assets/images/ic_bt_off.png
Normal file
BIN
assets/images/ic_bt_off.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
BIN
assets/images/ic_bt_on.png
Normal file
BIN
assets/images/ic_bt_on.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
BIN
assets/images/ic_bt_refresh.png
Normal file
BIN
assets/images/ic_bt_refresh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
BIN
assets/images/ic_describe.png
Normal file
BIN
assets/images/ic_describe.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
|
|
@ -54,3 +54,8 @@ class TabSwitch extends Event {
|
|||
|
||||
TabSwitch(this.index);
|
||||
}
|
||||
|
||||
//刷新蓝牙状态
|
||||
class RefreshBtState extends Event {
|
||||
RefreshBtState();
|
||||
}
|
||||
|
|
|
|||
50
lib/dialog/bt_description_dialog.dart
Normal file
50
lib/dialog/bt_description_dialog.dart
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class BtDescriptionDialog extends StatefulWidget {
|
||||
BtDescriptionDialog();
|
||||
|
||||
@override
|
||||
State<BtDescriptionDialog> createState() => _BtDescriptionDialogState();
|
||||
}
|
||||
|
||||
class _BtDescriptionDialogState extends State<BtDescriptionDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final size = MediaQuery.of(context).size;
|
||||
final l14 = size.width / 25.71428571428571;
|
||||
final t20 = size.width / 18;
|
||||
final s13 = size.width / 27.692307692307;
|
||||
|
||||
return Material(
|
||||
type: MaterialType.transparency, //透明类型
|
||||
color: Color(0x1A000000),
|
||||
child: Center(
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(right: l14, left: l14),
|
||||
decoration: BoxDecoration(color: Color(0xFF202530), borderRadius: BorderRadius.all(Radius.circular(7))),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
margin: EdgeInsets.only(top: t20, left: l14),
|
||||
child: Text(
|
||||
"使用说明:",
|
||||
style: TextStyle(fontSize: s13, color: Color(0xFF9D9D9D)),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
margin: EdgeInsets.only(top: t20, left: l14, right: l14, bottom: t20),
|
||||
child: Text(
|
||||
"1. 本功能适用于蒸汽云游车机版,TV版,帮助用户在无实体手柄的情 况下尽可能还原手柄游戏体验。\n\n 2. 使用本功能前,请打开当前设备,游戏端设备的蓝牙开关。在搜索 列表中找到游戏端设备,点击连接,连接成功后即可正常游戏。",
|
||||
style: TextStyle(fontSize: s13, color: Color(0xFF9D9D9D)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import 'package:game/tools/home/my_home_page.dart';
|
|||
import 'package:game/tools/home/search_page.dart';
|
||||
import 'package:game/tools/home_page.dart';
|
||||
import 'package:game/tools/login/login_page.dart';
|
||||
import 'package:game/tools/me/bt_game_pad_page.dart';
|
||||
import 'package:game/tools/me/edit_info_page.dart';
|
||||
import 'package:game/tools/me/feedback_page.dart';
|
||||
import 'package:game/tools/me/game_history_page.dart';
|
||||
|
|
@ -77,6 +78,23 @@ class _MyAppState extends State<MyApp> {
|
|||
case "SDKSuccess": //游戏Sdk是否初始化成功
|
||||
NetworkConfig.isGameSdk = methodCall.arguments['SDKSuccess'];
|
||||
break;
|
||||
|
||||
case "isBtOpen": //蓝牙状态
|
||||
NetworkConfig.isBtOpen = methodCall.arguments['isBtOpen'];
|
||||
EventBusUtil.fire(RefreshBtState());
|
||||
print("NetworkConfig.isBtOpen==${NetworkConfig.isBtOpen}");
|
||||
break;
|
||||
|
||||
case "btDevices": //蓝牙设备集合
|
||||
NetworkConfig.btDevices = List<String>.from(methodCall.arguments['btDevices']);
|
||||
print("NetworkConfig.btDevices==${NetworkConfig.btDevices}");
|
||||
EventBusUtil.fire(RefreshBtState());
|
||||
break;
|
||||
|
||||
case "connectionStatus": //蓝牙设备连接状态
|
||||
NetworkConfig.connectionStatus = methodCall.arguments['connectionStatus'];
|
||||
EventBusUtil.fire(RefreshBtState());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -115,6 +133,7 @@ class _MyAppState extends State<MyApp> {
|
|||
'/GameHistoryPage': (BuildContext context) => GameHistoryPage(),
|
||||
'/FeedbackPage': (BuildContext context) => FeedbackPage(),
|
||||
'/MessageCenterPage': (BuildContext context) => MessageCenterPage(),
|
||||
'/BtGamePadPage': (BuildContext context) => BtGamePadPage(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,11 @@ class NetworkConfig {
|
|||
static String orderId = ""; //订单号
|
||||
static SignBean? signData; //签到
|
||||
static ConfigBean? configBean; //app配置
|
||||
static bool isGameSdk = false; //游戏SDK是否启动成功
|
||||
static String gameId = ""; //游戏SDK是否启动成功
|
||||
static bool isGameSdk = false; //游戏SDK是否启动成功
|
||||
static bool isBtOpen = false; //蓝牙是否启动
|
||||
static List<String> btDevices = []; //蓝牙设备集合
|
||||
static int connectionStatus = 0; //蓝牙连接状态
|
||||
|
||||
static const String getAppConfig = "api/App/GetAppConfig"; //应用配置
|
||||
|
||||
|
|
@ -115,5 +118,4 @@ class NetworkConfig {
|
|||
static const String accountLogOff = "api/Account/AccountLogOff"; //注销账号
|
||||
|
||||
static const String getGameUserInfo = "api/Game/GetGameUserInfo"; //获取用户游戏详情数据
|
||||
|
||||
}
|
||||
|
|
|
|||
263
lib/tools/me/bt_game_pad_page.dart
Normal file
263
lib/tools/me/bt_game_pad_page.dart
Normal file
|
|
@ -0,0 +1,263 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
|
||||
import '../../common/EventBusUtil.dart';
|
||||
import '../../common/Global.dart';
|
||||
import '../../common/func.dart';
|
||||
import '../../dialog/bt_description_dialog.dart';
|
||||
import '../../network/NetworkConfig.dart';
|
||||
|
||||
class BtGamePadPage extends StatefulWidget {
|
||||
const BtGamePadPage({super.key});
|
||||
|
||||
@override
|
||||
State<BtGamePadPage> createState() => _BtGamePadPageState();
|
||||
}
|
||||
|
||||
class _BtGamePadPageState extends State<BtGamePadPage> {
|
||||
late StreamSubscription<RefreshBtState> _refreshBtStateEvent;
|
||||
|
||||
int currentBtIndex = -1;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
|
||||
///刷新用户信息
|
||||
_refreshBtStateEvent = EventBusUtil.listen((event) {
|
||||
setState(() {});
|
||||
});
|
||||
|
||||
//蓝牙已打开,获取蓝牙设备列表
|
||||
if (NetworkConfig.isBtOpen) {
|
||||
Map<String, dynamic> gameMap = {
|
||||
"getBtListDevices": "getBtListDevices",
|
||||
};
|
||||
|
||||
///传值初始化游戏token
|
||||
invokeNativeMethod("getBtListDevices", gameMap);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
super.dispose();
|
||||
_refreshBtStateEvent.cancel();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final size = MediaQuery.of(context).size;
|
||||
final h50 = size.width / 7.2;
|
||||
final s16 = size.width / 22.5;
|
||||
final l14 = size.width / 25.71428571428571;
|
||||
final w19 = size.width / 18.94736842105263;
|
||||
final h26 = size.width / 13.84615384615385;
|
||||
final w33 = size.width / 10.909090909090;
|
||||
final h18 = size.width / 20;
|
||||
final t20 = size.width / 18;
|
||||
final s13 = size.width / 27.692307692307;
|
||||
final w223 = size.width / 1.6143497757847;
|
||||
final h44 = size.width / 8.1818181818181;
|
||||
final w40 = size.width / 9;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFF17181A),
|
||||
body: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: size.width,
|
||||
height: h50,
|
||||
margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"蓝牙手柄",
|
||||
style: TextStyle(fontSize: s16, color: Color(0xFFD6D6D7)),
|
||||
),
|
||||
Positioned(
|
||||
left: l14,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Image(
|
||||
width: w19,
|
||||
height: h26,
|
||||
image: const AssetImage('assets/images/btn_fanhui.png'),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: l14,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
FunctionUtil.popDialog(context, BtDescriptionDialog());
|
||||
},
|
||||
child: Image(
|
||||
width: w19,
|
||||
height: h26,
|
||||
image: const AssetImage('assets/images/ic_describe.png'),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: l14, right: l14, top: l14),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"开启蓝牙",
|
||||
style: TextStyle(fontSize: l14, color: Color(0xFFD6D6D7)),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
//蓝牙开关
|
||||
Map<String, dynamic> gameMap = {
|
||||
"setBtState": !NetworkConfig.isBtOpen,
|
||||
};
|
||||
invokeNativeMethod("setBt", gameMap);
|
||||
},
|
||||
child: Image(
|
||||
width: w33,
|
||||
height: h18,
|
||||
image: AssetImage(NetworkConfig.isBtOpen ? 'assets/images/ic_bt_on.png' : 'assets/images/ic_bt_off.png'),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: l14, right: l14, top: t20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"连接状态",
|
||||
style: TextStyle(fontSize: l14, color: Color(0xFFD6D6D7)),
|
||||
),
|
||||
Text(
|
||||
NetworkConfig.connectionStatus == 0
|
||||
? "未连接"
|
||||
: NetworkConfig.connectionStatus == 1
|
||||
? "连接中"
|
||||
: NetworkConfig.connectionStatus == 2
|
||||
? "已连接"
|
||||
: "正在断开连接",
|
||||
style: TextStyle(fontSize: l14, color: NetworkConfig.connectionStatus == 2 ? Colors.green : Color(0xFFD6D6D7)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (NetworkConfig.connectionStatus == 2) {
|
||||
//进入手柄界面
|
||||
Map<String, dynamic> map = {
|
||||
"enterGamePad": "enterGamePad",
|
||||
};
|
||||
invokeNativeMethod("enterGamePad", map);
|
||||
} else {
|
||||
EasyLoading.showToast("请先连接设备");
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: w223,
|
||||
height: h44,
|
||||
margin: EdgeInsets.only(top: t20),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(color: Color(0xFF074CE7), borderRadius: BorderRadius.all(Radius.circular(22))),
|
||||
child: Text(
|
||||
"进入蓝牙手柄",
|
||||
style: TextStyle(fontSize: l14, color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: l14, right: l14, top: l14),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"可用设备",
|
||||
style: TextStyle(fontSize: l14, color: Color(0xFFD6D6D7)),
|
||||
),
|
||||
Image(
|
||||
width: w33,
|
||||
height: w33,
|
||||
image: AssetImage('assets/images/ic_bt_refresh.png'),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(left: l14, right: l14, top: l14),
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.all(0),
|
||||
itemCount: NetworkConfig.btDevices.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _btItem(index, w40);
|
||||
}),
|
||||
))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_btItem(index, w40) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
NetworkConfig.connectionStatus = 0;
|
||||
currentBtIndex = index;
|
||||
//点击连接设备
|
||||
Map<String, dynamic> gameMap = {
|
||||
"deviceIndex": index,
|
||||
};
|
||||
invokeNativeMethod("connectedDevice", gameMap);
|
||||
setState(() {});
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(bottom: 10),
|
||||
padding: EdgeInsets.all(5),
|
||||
decoration: BoxDecoration(
|
||||
color: currentBtIndex == index ? Color(0xFF202530) : Color(0x00FFFFFF),
|
||||
borderRadius: BorderRadius.all(Radius.circular(5)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Image(
|
||||
width: w40,
|
||||
height: w40,
|
||||
image: AssetImage('assets/images/ic_bt_device.png'),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 17),
|
||||
child: Text(
|
||||
"${NetworkConfig.btDevices[index]}",
|
||||
style: TextStyle(color: Color(0xFFD6D6D7)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 获取原生的值
|
||||
invokeNativeMethod(String method, Map<String, dynamic> map) async {
|
||||
dynamic args;
|
||||
try {
|
||||
args = await Global.method.invokeMethod(method, map);
|
||||
} on PlatformException catch (e) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -629,6 +629,45 @@ class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin {
|
|||
),
|
||||
),
|
||||
),
|
||||
|
||||
///蓝牙手柄
|
||||
GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () {
|
||||
Navigator.pushNamed(context, "/BtGamePadPage");
|
||||
},
|
||||
child: SizedBox(
|
||||
height: h60,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: l23),
|
||||
child: Image(
|
||||
width: w20,
|
||||
height: w20,
|
||||
image: const AssetImage('assets/images/ic_set.png'),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: l14),
|
||||
child: Text(
|
||||
"蓝牙手柄",
|
||||
style: TextStyle(fontSize: s14, color: Color(0xFFD6D6D7)),
|
||||
),
|
||||
),
|
||||
Expanded(child: Container()),
|
||||
Container(
|
||||
margin: EdgeInsets.only(right: l23),
|
||||
child: Image(
|
||||
width: l4,
|
||||
height: h8,
|
||||
image: AssetImage('assets/images/ic_arrow.png'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -80,11 +80,10 @@ class _StartPageState extends State<StartPage> {
|
|||
Map<String, dynamic> headersMap = Map<String, dynamic>.from(infoData);
|
||||
NetworkConfig.deviceID = headersMap["deviceID"];
|
||||
NetworkConfig.Language = headersMap["Language"]; //系统语言
|
||||
print("deviceID==${NetworkConfig.deviceID}");
|
||||
print("Language==${NetworkConfig.Language}");
|
||||
NetworkConfig.isBtOpen = headersMap["isBtOpen"]; //蓝牙
|
||||
print("isBtOpen==${NetworkConfig.isBtOpen}");
|
||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
NetworkConfig.deviceName = androidInfo.model;
|
||||
print("model==${androidInfo.model}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user