فهرست منبع

change dialog

wangyongj 2 سال پیش
والد
کامیت
70a15ed58c

+ 80 - 33
app/src/main/java/com/xugame/gameconsole/dialog/gamemenu/GameMenuDialog.java

@@ -1,12 +1,15 @@
 package com.xugame.gameconsole.dialog.gamemenu;
 
 import android.content.Context;
+import android.graphics.Color;
 import android.view.KeyEvent;
 import android.view.View;
 import android.view.Window;
 import android.view.WindowManager;
 import android.widget.Button;
+import android.widget.CompoundButton;
 import android.widget.LinearLayout;
+import android.widget.RadioButton;
 import android.widget.RadioGroup;
 import android.widget.TextView;
 import android.widget.Toast;
@@ -18,6 +21,8 @@ import com.xugame.gameconsole.dialog.BaseDialog;
 import com.xugame.gameconsole.emulator.ScreenType;
 import com.xugame.gameconsole.util.DebugUtil;
 
+import java.util.HashMap;
+
 public class GameMenuDialog extends BaseDialog
         implements RadioGroup.OnCheckedChangeListener,
         View.OnClickListener {
@@ -30,7 +35,23 @@ public class GameMenuDialog extends BaseDialog
     private Context mContext;
     private int mReadArchiveIndex = 0;//读取存档下标
     private LinearLayout mKeySettingBg;
+    private Button mCommit;
     //UP/DOWN/LEFT/RIGHT/A/B/X/Y/L1/R1/L2/R2
+
+    private String[] KEYNAMES = {
+            "UP",
+            "DOWN",
+            "LEFT",
+            "RIGHT",
+            "A",
+            "B",
+            "X",
+            "Y",
+            "L1",
+            "R1",
+            "l2",
+            "R2",
+    };
     private int[] KEYS = {
             KeyEvent.KEYCODE_W,
             KeyEvent.KEYCODE_S,
@@ -43,12 +64,16 @@ public class GameMenuDialog extends BaseDialog
             KeyEvent.KEYCODE_I,
             KeyEvent.KEYCODE_O,
             KeyEvent.KEYCODE_3,
-            KeyEvent.KEYCODE_1};
+            KeyEvent.KEYCODE_1
+    };
+
+
     private Button mKeySwitch;
     private boolean isKeySettingRunning = false;
-    private int keySettingIndex=0;
-    private TextView[] mKeyNumText;
+    private int keySettingIndex = 0;
+    private RadioButton[] mKeyNumText;
     private TextView mKeyName;
+    private RadioGroup mKeyRadioGroup;
 
     public GameMenuDialog(Context context, GameMenuDialogListener listener) {
         super(context, R.style.DialogNoPadding);
@@ -57,8 +82,8 @@ public class GameMenuDialog extends BaseDialog
         setContentView(R.layout.dialog_gamemenu_layout);
         Window window = this.getWindow();
         WindowManager.LayoutParams wLp = window.getAttributes();
-        wLp.width = 1000;
-        wLp.height = 632;
+        wLp.width = 1200;
+        wLp.height = 832;
         wLp.dimAmount = 0.6f;//透明度
         window.setAttributes(wLp);
         this.initView();
@@ -82,21 +107,54 @@ public class GameMenuDialog extends BaseDialog
         readArchiveTexts[4] = findViewById(R.id.read_archive_5);
         mKeySettingBg = findViewById(R.id.key_setting_bg);
         mKeySwitch = findViewById(R.id.key_setting_switch);
-        mKeyName=findViewById(R.id.keyName);
+        mKeyName = findViewById(R.id.keyName);
+        mCommit = findViewById(R.id.key_setting_commit);
+        mKeyRadioGroup = findViewById(R.id.key_radio_grop);
 
         mKeySwitch.setOnClickListener(this);
-        mKeyNumText=new TextView[KEYS.length];
+        mKeyNumText = new RadioButton[KEYS.length];
         for (int i = 0; i < KEYS.length; i++) {
-            TextView textView = new TextView(mContext);
-            textView.setText("key-" + KEYS[i]);
-
-            LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
-                    LinearLayout.LayoutParams.WRAP_CONTENT);
+            RadioButton radioButton = new RadioButton(mContext);
+            radioButton.setText(KEYNAMES[i]);
+            radioButton.setTextColor(Color.BLACK);
+            RadioGroup.LayoutParams llp = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT,
+                    RadioGroup.LayoutParams.WRAP_CONTENT);
             llp.leftMargin = 10;
-            mKeySettingBg.addView(textView, llp);
-            mKeyNumText[i]=textView;
+            mKeyRadioGroup.addView(radioButton, llp);
+
+            final int index = i;
+            radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+                @Override
+                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+                    if (b) {
+                        mReadArchiveIndex = index;
+                        radioButton.setBackgroundColor(Color.GRAY);
+                        isKeySettingRunning = true;
+                    } else {
+                        radioButton.setBackgroundColor(Color.WHITE);
+                    }
+
+                }
+            });
+
+            mKeyNumText[i] = radioButton;
         }
 
+        //点击确定,上报新的按键
+        mCommit.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                DebugUtil.i(TAG, "click commit");
+                if (isKeySettingRunning) {
+                    Toast.makeText(mContext, "当前处于编辑状态", Toast.LENGTH_SHORT).show();
+                    return;
+                } else {
+                    if (mListener != null)
+                        mListener.onKeySettingNums(KEYS);
+                }
+            }
+        });
+
 
         for (int i = 0; i < archiveTexts.length; i++) {
             final int tempIndex = i;
@@ -162,26 +220,14 @@ public class GameMenuDialog extends BaseDialog
                 int devicesID = event.getDeviceId();
                 String devicesName = event.getDevice().getName();
                 int keyCode = event.getKeyCode();
-                DebugUtil.i(TAG,""+keyCode);
-                mKeyName.setText("按键ID:"+devicesID+"设备名:"+devicesName);
-
-                if(keySettingIndex<KEYS.length&&mKeyNumText!=null){
-                    mKeyNumText[keySettingIndex].setText("key-"+keyCode);
-                    keySettingIndex++;
-                }else {
-                    Toast.makeText(mContext,"设置完毕",Toast.LENGTH_SHORT).show();
-                    String tempKeyStr="";
-                    for (int num:KEYS){
-                        tempKeyStr+=num+"-";
-                    }
-                    DebugUtil.i(TAG,"key="+tempKeyStr);
-                    keySettingIndex=0;
-                    mKeySwitch.performClick();
-                    if(mListener!=null){
-                        mListener.onKeySettingNums(KEYS);
-                    }
-
+                DebugUtil.i(TAG, "" + keyCode);
+                mKeyName.setText("按键ID:" + devicesID + "   设备名:" + devicesName + "  keycode:" + keyCode);
+                if (mReadArchiveIndex < KEYS.length) {
+                    mKeyNumText[mReadArchiveIndex].setBackgroundColor(Color.WHITE);
+                    KEYS[mReadArchiveIndex] = keyCode;
                 }
+                isKeySettingRunning = false;
+
             }
             return true;
         } else {
@@ -190,6 +236,7 @@ public class GameMenuDialog extends BaseDialog
 
     }
 
+
     @Override
     public void onClick(View view) {
         if (view == mKeySwitch) {

+ 6 - 1
app/src/main/java/com/xugame/gameconsole/emulator/RetroArchEmulatorActivity.java

@@ -186,7 +186,12 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
             @Override
             public void onKeySettingNums(int[] keys) {
                 //设置完毕回调
-                DebugUtil.i(TAG,"onKeySettingNums");
+                String tempKeyStr = "";
+                for (int num : keys) {
+                    tempKeyStr += num + "-";
+                }
+                DebugUtil.i(TAG, "key=" + tempKeyStr);
+
             }
         });
         menuDialog.setCanceledOnTouchOutside(true);

+ 112 - 94
app/src/main/res/layout/dialog_gamemenu_layout.xml

@@ -1,184 +1,202 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
     android:layout_width="match_parent"
+    android:layout_height="match_parent"
     android:background="#ffffff"
-    android:layout_height="match_parent">
+    android:orientation="vertical">
 
     <Button
         android:id="@+id/resume_game"
-        android:text="继续游戏"
         android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
         android:focusable="false"
-        android:layout_height="wrap_content"></Button>
+        android:text="继续游戏"></Button>
 
     <Button
         android:id="@+id/stop_game"
-        android:text="退出游戏"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
         android:focusable="false"
+        android:text="退出游戏"></Button>
+
+    <RadioGroup
+        android:id="@+id/radio_gp_screen"
         android:layout_width="wrap_content"
-        android:layout_height="wrap_content"></Button>
-
-  <RadioGroup
-      android:id="@+id/radio_gp_screen"
-      android:layout_width="wrap_content"
-      android:orientation="horizontal"
-      android:focusable="false"
-      android:layout_marginTop="20dp"
-      android:layout_height="wrap_content">
-      <RadioButton
-          android:id="@+id/normal"
-          android:text="Normal"
-          android:textColor="#000000"
-          android:focusable="false"
-          android:checked="true"
-          android:layout_width="wrap_content"
-          android:layout_height="wrap_content"></RadioButton>
-      <RadioButton
-          android:id="@+id/sai_2x"
-          android:text="2xSaI"
-          android:focusable="false"
-          android:textColor="#000000"
-          android:layout_width="wrap_content"
-          android:layout_height="wrap_content"></RadioButton>
-      <RadioButton
-          android:id="@+id/scanline_game"
-          android:text="Scanline2x"
-          android:focusable="false"
-          android:textColor="#000000"
-          android:layout_width="wrap_content"
-          android:layout_height="wrap_content"></RadioButton>
-  </RadioGroup>
+        android:layout_height="wrap_content"
+        android:layout_marginTop="20dp"
+        android:focusable="false"
+        android:orientation="horizontal">
+
+        <RadioButton
+            android:id="@+id/normal"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:checked="true"
+            android:focusable="false"
+            android:text="Normal"
+            android:textColor="#000000"></RadioButton>
+
+        <RadioButton
+            android:id="@+id/sai_2x"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:focusable="false"
+            android:text="2xSaI"
+            android:textColor="#000000"></RadioButton>
+
+        <RadioButton
+            android:id="@+id/scanline_game"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:focusable="false"
+            android:text="Scanline2x"
+            android:textColor="#000000"></RadioButton>
+    </RadioGroup>
 
     <LinearLayout
         android:layout_width="wrap_content"
-        android:orientation="horizontal"
+        android:layout_height="wrap_content"
         android:layout_marginTop="20dp"
-        android:layout_height="wrap_content">
+        android:orientation="horizontal">
+
         <TextView
             android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
             android:text="写入存档:"
-            android:textColor="#000000"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:textColor="#000000"></TextView>
 
         <TextView
             android:id="@+id/archive_1"
             android:layout_width="wrap_content"
-            android:text="NULL"
-            android:textColor="#000000"
+            android:layout_height="wrap_content"
             android:layout_marginLeft="8dp"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:text="NULL"
+            android:textColor="#000000"></TextView>
+
         <TextView
             android:id="@+id/archive_2"
             android:layout_width="wrap_content"
-            android:text="NULL"
-            android:textColor="#000000"
+            android:layout_height="wrap_content"
             android:layout_marginLeft="8dp"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:text="NULL"
+            android:textColor="#000000"></TextView>
+
         <TextView
             android:id="@+id/archive_3"
             android:layout_width="wrap_content"
-            android:text="NULL"
-            android:textColor="#000000"
+            android:layout_height="wrap_content"
             android:layout_marginLeft="8dp"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:text="NULL"
+            android:textColor="#000000"></TextView>
+
         <TextView
             android:id="@+id/archive_4"
             android:layout_width="wrap_content"
-            android:text="NULL"
-            android:textColor="#000000"
+            android:layout_height="wrap_content"
             android:layout_marginLeft="8dp"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:text="NULL"
+            android:textColor="#000000"></TextView>
+
         <TextView
             android:id="@+id/archive_5"
             android:layout_width="wrap_content"
-            android:text="NULL"
-            android:textColor="#000000"
+            android:layout_height="wrap_content"
             android:layout_marginLeft="8dp"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:text="NULL"
+            android:textColor="#000000"></TextView>
     </LinearLayout>
 
 
     <LinearLayout
         android:layout_width="wrap_content"
-        android:orientation="horizontal"
+        android:layout_height="wrap_content"
         android:layout_marginTop="20dp"
-        android:layout_height="wrap_content">
+        android:orientation="horizontal">
+
         <TextView
             android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
             android:text="读取存档:"
-            android:textColor="#000000"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:textColor="#000000"></TextView>
 
         <TextView
             android:id="@+id/read_archive_1"
             android:layout_width="wrap_content"
-            android:text="NULL"
-            android:textColor="#000000"
+            android:layout_height="wrap_content"
             android:layout_marginLeft="8dp"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:text="NULL"
+            android:textColor="#000000"></TextView>
+
         <TextView
             android:id="@+id/read_archive_2"
             android:layout_width="wrap_content"
-            android:text="NULL"
-            android:textColor="#000000"
+            android:layout_height="wrap_content"
             android:layout_marginLeft="8dp"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:text="NULL"
+            android:textColor="#000000"></TextView>
+
         <TextView
             android:id="@+id/read_archive_3"
             android:layout_width="wrap_content"
-            android:text="NULL"
-            android:textColor="#000000"
+            android:layout_height="wrap_content"
             android:layout_marginLeft="8dp"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:text="NULL"
+            android:textColor="#000000"></TextView>
+
         <TextView
             android:id="@+id/read_archive_4"
             android:layout_width="wrap_content"
-            android:text="NULL"
-            android:textColor="#000000"
+            android:layout_height="wrap_content"
             android:layout_marginLeft="8dp"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:text="NULL"
+            android:textColor="#000000"></TextView>
+
         <TextView
             android:id="@+id/read_archive_5"
             android:layout_width="wrap_content"
-            android:text="NULL"
-            android:textColor="#000000"
+            android:layout_height="wrap_content"
             android:layout_marginLeft="8dp"
-            android:layout_height="wrap_content">
-        </TextView>
+            android:text="NULL"
+            android:textColor="#000000"></TextView>
     </LinearLayout>
 
     <LinearLayout
         android:id="@+id/key_setting_bg"
-        android:layout_marginTop="30px"
-        android:orientation="horizontal"
         android:layout_width="wrap_content"
-        android:layout_height="wrap_content">
+        android:layout_height="wrap_content"
+        android:layout_marginTop="30px"
+        android:orientation="horizontal">
 
     </LinearLayout>
+
     <Button
         android:id="@+id/key_setting_switch"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:visibility="gone"
         android:layout_marginTop="10px"
+        android:text="开始设置按键"></Button>
+
+
+    <RadioGroup
+        android:id="@+id/key_radio_grop"
+        android:orientation="horizontal"
         android:layout_width="wrap_content"
-        android:text="开始设置按键"
-        android:layout_height="wrap_content"></Button>
+        android:layout_height="wrap_content"></RadioGroup>
+
 
     <TextView
         android:id="@+id/keyName"
         android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="10px"
+        android:textColor="@color/black"></TextView>
+
+    <Button
+        android:id="@+id/key_setting_commit"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
         android:layout_marginTop="10px"
-        android:textColor="@color/black"
-        android:layout_height="wrap_content"></TextView>
+        android:text="确定"></Button>
 
 </LinearLayout>