Explorar el Código

add retroarch emulator activity

wangyongj hace 2 años
padre
commit
05f5fd2c70

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -22,6 +22,7 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+        <activity android:name=".emulator.RetroArchEmulatorActivity"></activity>
     </application>
 
 </manifest>

+ 39 - 1
app/src/main/java/com/xugame/gameconsole/MainActivity.java

@@ -2,13 +2,51 @@ package com.xugame.gameconsole;
 
 import androidx.appcompat.app.AppCompatActivity;
 
+import android.content.Intent;
 import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+
+import com.xugame.gameconsole.emulator.RetroArchEmulatorActivity;
+
+public class MainActivity extends AppCompatActivity implements View.OnClickListener {
+    private EditText mETRom, mETLib, mETConfig;
+    private Button mBtnLocalGame, mBtnNetP1, mBtnNetP2;
 
-public class MainActivity extends AppCompatActivity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
+        this.findView();
+    }
+
+    private void findView() {
+        this.mBtnLocalGame = findViewById(R.id.btn_start_local_game);
+        this.mBtnNetP1 = findViewById(R.id.btn_start_net_game_p1);
+        this.mBtnNetP2 = findViewById(R.id.btn_start_net_game_p2);
+        this.mETRom = findViewById(R.id.et_rom);
+        this.mETLib = findViewById(R.id.et_libs);
+        this.mETConfig = findViewById(R.id.et_config);
+        this.mBtnLocalGame.setOnClickListener(this);
+        this.mBtnNetP1.setOnClickListener(this);
+        this.mBtnNetP1.setOnClickListener(this);
+    }
+
+
+    @Override
+    public void onClick(View view) {
+        if (view == mBtnLocalGame) {
+            Intent intent = new Intent(this, RetroArchEmulatorActivity.class);
+            String romPath = mETRom.getText().toString();
+            String libPath = mETLib.getText().toString();
+            String configPath = mETConfig.getText().toString();
+            intent.putExtra("rom_path", romPath);
+            intent.putExtra("lib_path", libPath);
+            intent.putExtra("config_path", configPath);
+            startActivity(intent);
+        }
+
     }
 }

+ 47 - 0
app/src/main/java/com/xugame/gameconsole/emulator/RetroArchEmulatorActivity.java

@@ -0,0 +1,47 @@
+package com.xugame.gameconsole.emulator;
+
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Environment;
+
+import androidx.annotation.Nullable;
+
+import com.xugame.gameconsole.R;
+
+public class RetroArchEmulatorActivity extends Activity {
+    private static final String TAG = "RetroArchEmulatorActivityTAG";
+    private String romPath, libsPath, configPath;
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.retro_arch_layout);
+        parserIntent();
+        startGame();
+    }
+
+    private void parserIntent() {
+        Intent intent = getIntent();
+        romPath = intent.getStringExtra("rom_path");
+        libsPath = intent.getStringExtra("lib_path");
+        configPath = intent.getStringExtra("config_path");
+    }
+
+    private void startGame() {
+        Intent retro=new Intent();
+        retro.setComponent(new ComponentName("com.retroarch.aarch64",
+                "com.retroarch.browser.retroactivity.RetroActivityFuture"));
+        retro.putExtra("ROM", romPath);
+        retro.putExtra("LIBRETRO", libsPath);
+        retro.putExtra("CONFIGFILE", configPath);
+        retro.putExtra("IME", "com.android.inputmethod.latin/.LatinIME");
+        retro.putExtra("DATADIR", "/data/user/0/com.retroarch.aarch64");
+        retro.putExtra("APK", "/data/app/com.retroarch.aarch64-1/base.apk");
+        retro.putExtra("SDCARD", Environment.getExternalStorageDirectory().getAbsolutePath());
+        String external = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/com.retroarch.aarch64/files";
+        retro.putExtra("EXTERNAL", external);
+        startActivity(retro);
+    }
+}

+ 65 - 11
app/src/main/res/layout/activity_main.xml

@@ -1,18 +1,72 @@
 <?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"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/main_layout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    tools:context=".MainActivity">
+    android:orientation="vertical">
 
-    <TextView
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal">
+
+        <EditText
+            android:id="@+id/et_rom"
+            android:layout_width="1000px"
+            android:layout_height="wrap_content"
+            android:hint="input rom path"
+            android:textColor="#000000"
+            android:textColorHint="#c0c0c0"></EditText>
+
+
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal">
+
+        <EditText
+            android:id="@+id/et_libs"
+            android:layout_width="1000px"
+            android:layout_height="wrap_content"
+            android:hint="input lib so path"
+            android:textColor="#000000"
+            android:textColorHint="#c0c0c0"></EditText>
+
+    </LinearLayout>
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal">
+        <EditText
+            android:id="@+id/et_config"
+            android:layout_width="1000px"
+            android:layout_height="wrap_content"
+            android:hint="input config path"
+            android:textColor="#000000"
+            android:textColorHint="#c0c0c0"></EditText>
+
+    </LinearLayout>
+    <Button
+        android:id="@+id/btn_start_local_game"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:text="Hello World!"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        android:text="START LOCAL"></Button>
+
+    <Button
+        android:id="@+id/btn_start_net_game_p1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+
+        android:text="START P1"></Button>
+
+    <Button
+        android:id="@+id/btn_start_net_game_p2"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_margin="0px"
+        android:text="START P1"></Button>
+
 
-</androidx.constraintlayout.widget.ConstraintLayout>
+</LinearLayout>

+ 6 - 0
app/src/main/res/layout/retro_arch_layout.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+</RelativeLayout>