فهرست منبع

Merge branch 'master' of http://8.136.234.80:10002/WangYongJun/GameConsole

ZengGengSen 2 سال پیش
والد
کامیت
86ee8e22b2

+ 157 - 0
app/src/main/java/com/xugame/gameconsole/dialog/BaseDialog.java

@@ -0,0 +1,157 @@
+package com.xugame.gameconsole.dialog;
+
+import android.app.Dialog;
+import android.app.Instrumentation;
+import android.content.Context;
+import android.os.CountDownTimer;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.WindowManager;
+
+import androidx.annotation.NonNull;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+
+
+public abstract class BaseDialog extends Dialog {
+    protected int IDLE_TIME = 1000 * 30;
+
+    protected boolean isFirstFocus = true;
+    private CountDownTimer mTimerIdle = null;
+
+    private ExecutorService mExecutorService;
+
+
+    protected BaseDialog(Context context, int themeResId) {
+        super(context, themeResId);
+        this.setCancelable(false);
+
+        this.hideNavigationBar();
+
+        this.setCanceledOnTouchOutside(false);
+
+        this.mExecutorService = Executors.newSingleThreadExecutor();
+    }
+
+
+    protected void stopIdleTimer() {
+        if (this.mTimerIdle != null)
+            this.mTimerIdle.cancel();
+    }
+
+    @Override
+    public void show() {
+        if (!isShowing())
+             super.show();
+    }
+
+    @Override
+    public void dismiss() {
+
+        this.stopIdleTimer();
+        super.dismiss();
+    }
+
+
+    protected void startIdleTimer() {
+        if (this.mTimerIdle != null)
+            this.mTimerIdle.cancel();
+        else {
+            this.mTimerIdle = new CountDownTimer(IDLE_TIME, 1000) {
+                @Override
+                public void onTick(long millisUntilFinished) {
+
+                }
+
+                @Override
+                public void onFinish() {
+//                    onIdleTimeout();
+                    startIdleTimer();
+                }
+            };
+        }
+
+        this.mTimerIdle.start();
+    }
+
+    protected BaseDialog(Context context) {
+        super(context);
+        this.setCancelable(false);
+        this.hideNavigationBar();
+
+        this.setCanceledOnTouchOutside(false);
+
+        this.mExecutorService = Executors.newSingleThreadExecutor();
+    }
+
+    protected BaseDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
+        super(context, cancelable, cancelListener);
+        this.setCancelable(false);
+        this.hideNavigationBar();
+    }
+
+    private void hideNavigationBar() {
+        int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+                | View.SYSTEM_UI_FLAG_FULLSCREEN
+                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
+
+        this.getWindow().getDecorView().setSystemUiVisibility(flags);
+        this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
+    }
+
+//    protected void focusSoundEffect() {
+//        if (this.isFirstFocus)
+//            this.isFirstFocus = false;
+//        else
+//            SoundManager.getInstance(this.getContext()).playSoundEffect(SoundType.NUM_FOCUS);
+//
+//    }
+
+    protected void sendKeyCode(int keyCode, KeyEvent event) {
+        KeyEvent keyEvent = new KeyEvent(event.getDownTime(),
+                event.getEventTime(),
+                event.getAction(),
+                keyCode,
+                event.getRepeatCount(),
+                event.getMetaState(),
+                event.getDeviceId(),
+                -100,
+                event.getFlags());
+        sendKeyCode(keyEvent);
+    }
+
+    private void sendKeyCode(final KeyEvent event) {
+        mExecutorService.execute(new Runnable() {
+
+            @Override
+            public void run() {
+                // TODO Auto-generated method stub
+                try {
+                    Instrumentation inst = new Instrumentation();
+                    inst.sendKeySync(event);
+                } catch (Exception e) {
+                }
+            }
+        });
+    }
+
+    @Override
+    public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
+        int keyCode = event.getKeyCode();
+        if (keyCode == 98 || keyCode == 99 || keyCode == 100 || keyCode == 101 || keyCode == 108) {
+            return true;
+        }
+        if (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_B) {
+            this.sendKeyCode(KeyEvent.KEYCODE_BACK, event);
+            return true;
+        } else if (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_A) {
+            this.sendKeyCode(KeyEvent.KEYCODE_DPAD_CENTER, event);
+            return true;
+        }
+        return super.dispatchKeyEvent(event);
+    }
+}

+ 113 - 0
app/src/main/java/com/xugame/gameconsole/dialog/gamemenu/GameMenuDialog.java

@@ -0,0 +1,113 @@
+package com.xugame.gameconsole.dialog.gamemenu;
+
+import android.content.Context;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.RadioGroup;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.xugame.gameconsole.R;
+import com.xugame.gameconsole.dialog.BaseDialog;
+import com.xugame.gameconsole.util.DebugUtil;
+
+public class GameMenuDialog extends BaseDialog
+        implements RadioGroup.OnCheckedChangeListener {
+    private static final String TAG = "GameMenuDialogTAG";
+    private RadioGroup mRadioGroup;
+    GameMenuDialogListener mListener;
+    SCREEN_TYPE mType = SCREEN_TYPE.NORMAL;
+    private TextView[] archiveTexts;
+    private TextView[] readArchiveTexts;
+    private Context mContext;
+    private int mReadArchiveIndex=0;//读取存档下标
+
+    public enum SCREEN_TYPE {
+        NORMAL,
+        SAI_2X,
+        SCANLINE,
+    }
+
+    public GameMenuDialog(Context context, GameMenuDialogListener listener) {
+        super(context, R.style.DialogNoPadding);
+        this.mListener = listener;
+        this.mContext=context;
+        setContentView(R.layout.dialog_gamemenu_layout);
+        Window window = this.getWindow();
+        WindowManager.LayoutParams wLp = window.getAttributes();
+        wLp.width = 800;
+        wLp.height = 632;
+        wLp.dimAmount = 0.6f;//透明度
+        window.setAttributes(wLp);
+        this.initView();
+    }
+
+    private void initView() {
+        mRadioGroup = findViewById(R.id.radio_gp_screen);
+        mRadioGroup.setOnCheckedChangeListener(this);
+        archiveTexts=new TextView[5];
+        readArchiveTexts=new TextView[5];
+        archiveTexts[0]=findViewById(R.id.archive_1);
+        archiveTexts[1]=findViewById(R.id.archive_2);
+        archiveTexts[2]=findViewById(R.id.archive_3);
+        archiveTexts[3]=findViewById(R.id.archive_4);
+        archiveTexts[4]=findViewById(R.id.archive_5);
+
+        readArchiveTexts[0]=findViewById(R.id.read_archive_1);
+        readArchiveTexts[1]=findViewById(R.id.read_archive_2);
+        readArchiveTexts[2]=findViewById(R.id.read_archive_3);
+        readArchiveTexts[3]=findViewById(R.id.read_archive_4);
+        readArchiveTexts[4]=findViewById(R.id.read_archive_5);
+
+        for (int i=0;i<archiveTexts.length;i++){
+            final  int tempIndex=i;
+            archiveTexts[i].setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View view) {
+                    Toast.makeText(mContext,"写入存档"+tempIndex,Toast.LENGTH_SHORT).show();
+                }
+            });
+        }
+
+        for (int i=0;i<readArchiveTexts.length;i++){
+            final  int tempIndex=i;
+            readArchiveTexts[i].setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View view) {
+                    mReadArchiveIndex=tempIndex;
+                    Toast.makeText(mContext,"读取存档"+tempIndex,Toast.LENGTH_SHORT).show();
+                }
+            });
+        }
+
+
+        findViewById(R.id.resume_game).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                if (mListener != null)
+                    mListener.onResumeGame(mType, mReadArchiveIndex);
+                dismiss();
+            }
+        });
+        findViewById(R.id.stop_game).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                if (mListener != null)
+                    mListener.onExitGame();
+                dismiss();
+            }
+        });
+    }
+
+    @Override
+    public void onCheckedChanged(RadioGroup radioGroup, int i) {
+        if (radioGroup.getCheckedRadioButtonId() == R.id.normal) {
+            mType=SCREEN_TYPE.NORMAL;
+        } else if (radioGroup.getCheckedRadioButtonId() == R.id.sai_2x) {
+            mType=SCREEN_TYPE.SAI_2X;
+        } else if (radioGroup.getCheckedRadioButtonId() == R.id.scanline_game) {
+            mType=SCREEN_TYPE.SCANLINE;
+        }
+    }
+}

+ 6 - 0
app/src/main/java/com/xugame/gameconsole/dialog/gamemenu/GameMenuDialogListener.java

@@ -0,0 +1,6 @@
+package com.xugame.gameconsole.dialog.gamemenu;
+
+public interface GameMenuDialogListener {
+    void onExitGame();
+    void onResumeGame(GameMenuDialog.SCREEN_TYPE type,int archiveIndex);
+}

+ 50 - 29
app/src/main/java/com/xugame/gameconsole/emulator/RetroArchEmulatorActivity.java

@@ -15,11 +15,14 @@ import android.util.Log;
 import android.view.KeyEvent;
 import android.view.View;
 import android.view.WindowManager;
+import android.widget.Toast;
 
 import androidx.annotation.Nullable;
 
 import com.xugame.gameconsole.MainActivity;
 import com.xugame.gameconsole.R;
+import com.xugame.gameconsole.dialog.gamemenu.GameMenuDialog;
+import com.xugame.gameconsole.dialog.gamemenu.GameMenuDialogListener;
 import com.xugame.gameconsole.preferences.ConfigFile;
 import com.xugame.gameconsole.preferences.UserPreferences;
 import com.xugame.gameconsole.util.DebugUtil;
@@ -36,6 +39,7 @@ import java.lang.reflect.Method;
 //        }
 public class RetroArchEmulatorActivity extends RetroActivityCamera {
     private static final String TAG = "RetroArchEmulatorActivityTAG";
+    private Context mCotext;
 
     // If set to true then Retroarch will completely exit when it loses focus
     private boolean quitfocus = false;
@@ -71,7 +75,7 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
                 String refresh = retro.getStringExtra("REFRESH");
 
                 // If REFRESH parameter is provided then try to set refreshrate accordingly
-                if(refresh != null) {
+                if (refresh != null) {
                     WindowManager.LayoutParams params = getWindow().getAttributes();
                     params.preferredRefreshRate = Integer.parseInt(refresh);
                     getWindow().setAttributes(params);
@@ -105,18 +109,20 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
             // Check for NVIDIA extensions and minimum SDK version
             Method mInputManager_setCursorVisibility;
-            try { mInputManager_setCursorVisibility =
-                    InputManager.class.getMethod("setCursorVisibility", boolean.class);
-            }
-            catch (NoSuchMethodException ex) {
+            try {
+                mInputManager_setCursorVisibility =
+                        InputManager.class.getMethod("setCursorVisibility", boolean.class);
+            } catch (NoSuchMethodException ex) {
                 return; // Extensions were not available so do nothing
             }
 
             // Hide the mouse cursor
             InputManager inputManager = (InputManager) getSystemService(Context.INPUT_SERVICE);
-            try { mInputManager_setCursorVisibility.invoke(inputManager, false); }
-            catch (InvocationTargetException ite) { }
-            catch (IllegalAccessException iae)    { }
+            try {
+                mInputManager_setCursorVisibility.invoke(inputManager, false);
+            } catch (InvocationTargetException ite) {
+            } catch (IllegalAccessException iae) {
+            }
         }
     }
 
@@ -130,9 +136,9 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
 
     @Override
     public boolean dispatchKeyEvent(KeyEvent event) {
-        DebugUtil.i(TAG,""+event.getKeyCode());
-        if(event.getKeyCode()==KeyEvent.KEYCODE_BACK
-        &&event.getAction()==KeyEvent.ACTION_DOWN){
+        DebugUtil.i(TAG, "" + event.getKeyCode());
+        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
+                && event.getAction() == KeyEvent.ACTION_DOWN) {
             showDialog();
             return true;
         }
@@ -141,27 +147,42 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
 
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
-        DebugUtil.i(TAG,"onKeyDown="+event.getKeyCode());
+        DebugUtil.i(TAG, "onKeyDown=" + event.getKeyCode());
         return super.onKeyDown(keyCode, event);
     }
 
     private void showDialog() {
-        AlertDialog.Builder alertDialog = new ProgressDialog.Builder(this)
-                .setTitle("Yes/No")
-                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
-                    @Override
-                    public void onClick(DialogInterface dialog, int which) {
-                        clickBack();
-                        dialog.dismiss();
-                    }
-                })
-                .setNegativeButton("No", new DialogInterface.OnClickListener() {
-                    @Override
-                    public void onClick(DialogInterface dialog, int which) {
-                        dialog.dismiss();
-                    }
-                })
-                .setMessage("退出游戏?");
-        alertDialog.show();
+        GameMenuDialog menuDialog = new GameMenuDialog(this, new GameMenuDialogListener() {
+            @Override
+            public void onExitGame() {
+                clickBack();
+            }
+
+            @Override
+            public void onResumeGame(GameMenuDialog.SCREEN_TYPE type, int archiveIndex) {
+                Toast.makeText(RetroArchEmulatorActivity.this, "画面设置为:" + type + "读取存档Index=" + archiveIndex, Toast.LENGTH_SHORT).show();
+            }
+        });
+        menuDialog.setCanceledOnTouchOutside(true);
+        menuDialog.show();
+
+
+//        AlertDialog.Builder alertDialog = new ProgressDialog.Builder(this)
+//                .setTitle("Yes/No")
+//                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+//                    @Override
+//                    public void onClick(DialogInterface dialog, int which) {
+//                        clickBack();
+//                        dialog.dismiss();
+//                    }
+//                })
+//                .setNegativeButton("No", new DialogInterface.OnClickListener() {
+//                    @Override
+//                    public void onClick(DialogInterface dialog, int which) {
+//                        dialog.dismiss();
+//                    }
+//                })
+//                .setMessage("退出游戏?");
+//        alertDialog.show();
     }
 }

+ 156 - 0
app/src/main/res/layout/dialog_gamemenu_layout.xml

@@ -0,0 +1,156 @@
+<?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:background="#ffffff"
+    android:layout_height="match_parent">
+
+    <Button
+        android:id="@+id/resume_game"
+        android:text="继续游戏"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"></Button>
+
+    <Button
+        android:id="@+id/stop_game"
+        android:text="退出游戏"
+        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:layout_marginTop="20dp"
+      android:layout_height="wrap_content">
+      <RadioButton
+          android:id="@+id/normal"
+          android:text="Normal"
+          android:textColor="#000000"
+          android:checked="true"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"></RadioButton>
+      <RadioButton
+          android:id="@+id/sai_2x"
+          android:text="2xSaI"
+          android:textColor="#000000"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"></RadioButton>
+      <RadioButton
+          android:id="@+id/scanline_game"
+          android:text="Scanline2x"
+          android:textColor="#000000"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"></RadioButton>
+  </RadioGroup>
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:orientation="horizontal"
+        android:layout_marginTop="20dp"
+        android:layout_height="wrap_content">
+        <TextView
+            android:layout_width="wrap_content"
+            android:text="写入存档:"
+            android:textColor="#000000"
+            android:layout_height="wrap_content">
+        </TextView>
+
+        <TextView
+            android:id="@+id/archive_1"
+            android:layout_width="wrap_content"
+            android:text="NULL"
+            android:textColor="#000000"
+            android:layout_marginLeft="8dp"
+            android:layout_height="wrap_content">
+        </TextView>
+        <TextView
+            android:id="@+id/archive_2"
+            android:layout_width="wrap_content"
+            android:text="NULL"
+            android:textColor="#000000"
+            android:layout_marginLeft="8dp"
+            android:layout_height="wrap_content">
+        </TextView>
+        <TextView
+            android:id="@+id/archive_3"
+            android:layout_width="wrap_content"
+            android:text="NULL"
+            android:textColor="#000000"
+            android:layout_marginLeft="8dp"
+            android:layout_height="wrap_content">
+        </TextView>
+        <TextView
+            android:id="@+id/archive_4"
+            android:layout_width="wrap_content"
+            android:text="NULL"
+            android:textColor="#000000"
+            android:layout_marginLeft="8dp"
+            android:layout_height="wrap_content">
+        </TextView>
+        <TextView
+            android:id="@+id/archive_5"
+            android:layout_width="wrap_content"
+            android:text="NULL"
+            android:textColor="#000000"
+            android:layout_marginLeft="8dp"
+            android:layout_height="wrap_content">
+        </TextView>
+    </LinearLayout>
+
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:orientation="horizontal"
+        android:layout_marginTop="20dp"
+        android:layout_height="wrap_content">
+        <TextView
+            android:layout_width="wrap_content"
+            android:text="读取存档:"
+            android:textColor="#000000"
+            android:layout_height="wrap_content">
+        </TextView>
+
+        <TextView
+            android:id="@+id/read_archive_1"
+            android:layout_width="wrap_content"
+            android:text="NULL"
+            android:textColor="#000000"
+            android:layout_marginLeft="8dp"
+            android:layout_height="wrap_content">
+        </TextView>
+        <TextView
+            android:id="@+id/read_archive_2"
+            android:layout_width="wrap_content"
+            android:text="NULL"
+            android:textColor="#000000"
+            android:layout_marginLeft="8dp"
+            android:layout_height="wrap_content">
+        </TextView>
+        <TextView
+            android:id="@+id/read_archive_3"
+            android:layout_width="wrap_content"
+            android:text="NULL"
+            android:textColor="#000000"
+            android:layout_marginLeft="8dp"
+            android:layout_height="wrap_content">
+        </TextView>
+        <TextView
+            android:id="@+id/read_archive_4"
+            android:layout_width="wrap_content"
+            android:text="NULL"
+            android:textColor="#000000"
+            android:layout_marginLeft="8dp"
+            android:layout_height="wrap_content">
+        </TextView>
+        <TextView
+            android:id="@+id/read_archive_5"
+            android:layout_width="wrap_content"
+            android:text="NULL"
+            android:textColor="#000000"
+            android:layout_marginLeft="8dp"
+            android:layout_height="wrap_content">
+        </TextView>
+    </LinearLayout>
+
+</LinearLayout>

+ 11 - 0
app/src/main/res/values/styles.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <style name="DialogNoPadding" parent="android:style/Theme.Dialog">
+        <item name="android:windowBackground">@android:color/transparent</item>
+        <item name="android:windowNoTitle">true</item>
+        <item name="android:windowIsFloating">true</item>
+        <item name="android:backgroundDimEnabled">false</item>
+
+    </style>
+
+</resources>