Selaa lähdekoodia

merge from dev-java

ZengGengSen 2 vuotta sitten
vanhempi
commit
193e8f27c1

+ 1 - 7
app/src/main/cpp/frontend/drivers/platform_unix.c

@@ -645,11 +645,7 @@ static void frontend_android_shutdown(bool unused)
 {
    (void)unused;
    /* Cleaner approaches don't work sadly. */
-//   exit(0);
-   JNIEnv *env = jni_thread_getenv();
-   CALL_VOID_METHOD_PARAM(env, g_android->activity->clazz,
-                          g_android->finishMe, 0);
-
+   exit(0);
 }
 
 #elif !defined(DINGUX)
@@ -2089,8 +2085,6 @@ static void frontend_unix_init(void *data)
          "setSustainedPerformanceMode", "(Z)V");
    GET_METHOD_ID(env, android_app->setScreenOrientation, class,
          "setScreenOrientation", "(I)V");
-   GET_METHOD_ID(env, android_app->finishMe, class,
-                 "FinishMe", "(I)V");
    GET_METHOD_ID(env, android_app->doVibrate, class,
          "doVibrate", "(IIII)V");
    GET_METHOD_ID(env, android_app->doHapticFeedback, class,

+ 0 - 1
app/src/main/cpp/frontend/drivers/platform_unix.h

@@ -168,7 +168,6 @@ struct android_app
    jmethodID getBatteryLevel;
    jmethodID setSustainedPerformanceMode;
    jmethodID setScreenOrientation;
-   jmethodID finishMe;
    jmethodID getUserLanguageString;
    jmethodID doVibrate;
    jmethodID doHapticFeedback;

+ 1 - 8
app/src/main/java/com/retroarch/browser/retroactivity/RetroActivityCommon.java

@@ -65,6 +65,7 @@ public abstract class RetroActivityCommon extends NativeActivity
   public static int RETRO_RUMBLE_WEAK = 1;
   public boolean sustainedPerformanceMode = true;
   public int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+
   public abstract void showExitDialog();
 
   @Override
@@ -196,14 +197,6 @@ DebugUtil.i(TAG,"onTick"+millisUntilFinished);
 
     return ret;
   }
-  public void FinishMe(int index) {
-    this.runOnUiThread(new Runnable() {
-      public void run() {
-        DebugUtil.i(TAG,"FinishMe");
-        finish();
-      }
-    });
-  }
 // https://stackoverflow.com/questions/4553650/how-to-check-device-natural-default-orientation-on-android-i-e-get-landscape/4555528#4555528
   public int getDeviceDefaultOrientation() {
     WindowManager windowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);

+ 88 - 2
app/src/main/java/com/xugame/gameconsole/MainActivity.java

@@ -9,19 +9,30 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
 import android.media.AudioManager;
+import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Environment;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceManager;
 import android.provider.Settings;
+import android.text.TextUtils;
 import android.util.Log;
 import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;
+import android.widget.Toast;
 
 import com.xugame.gameconsole.emulator.RetroArchEmulatorActivity;
 import com.xugame.gameconsole.preferences.UserPreferences;
-
+import com.xugame.gameconsole.util.Util;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -154,6 +165,7 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
                 +"\nDATADIR="+dataDirPath+"\nAPK="+dataSourcePath+
                 "\nSDCARD="+Environment.getExternalStorageDirectory().getAbsolutePath()+"\nEXTERNAL="
                 +external);
+        retro.putExtra("screenMode",screenMode);
     }
 
     @Override
@@ -182,15 +194,89 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
 
         finalStartup();
     }
-    private String corePath,romPath;
+    private String corePath,romPath,coreName;
+    private static int screenMode=0;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 //        setContentView(R.layout.activity_main);
 //        this.findView();
+        Util.init(this);
         PACKAGE_NAME = getPackageName();
         romPath=getIntent().getStringExtra("romPath");
         corePath=getIntent().getStringExtra("corePath");
+        coreName=getIntent().getStringExtra("coreName");
+        screenMode=getIntent().getIntExtra("screenMode",0);
+
+
+        checkCores();
+
+    }
+    private void checkCores(){
+        if(TextUtils.isEmpty(corePath)){
+            finish();
+        }
+        File file=new File(corePath);
+        if(file.exists()){
+            start();
+        }else {
+            startCopy(coreName,corePath);
+        }
+    }
+
+
+    private void startCopy(final String fileName, final String toPath) {
+        File file = new File(this.getFilesDir().getParent() + File.separator + "cores");
+        if (!file.exists())
+            file.mkdirs();
+        new AsyncTask<String, Integer, String>() {
+            @Override
+            protected String doInBackground(String... strings) {
+                copyFile(getFilesDir().getParent() + File.separator+"cores/" + fileName, fileName);
+                return null;
+            }
+
+            @Override
+            protected void onPostExecute(String s) {
+                start();
+                super.onPostExecute(s);
+            }
+        }.execute("");
+    }
+
+
+    private boolean copyFile(String file_path, String fileName) {
+        File baseFile=new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/arcade/cores/");
+        if(!baseFile.exists())//创建/arcade/cores文件夹
+            baseFile.mkdirs();
+
+        File file=new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/arcade/cores/"+fileName);
+        if(!file.exists())//检测cores文件夹下是否存在.so
+            return false;
+        try {
+            InputStream in = null;
+//            in = this.getResources().getAssets().open("xucores/"+fileName);
+            in= new FileInputStream(file);
+            BufferedOutputStream outStream
+                    = new BufferedOutputStream(new FileOutputStream(file_path, false));
+            byte[] buffer = new byte[1024];
+            int size;
+            while ((size = in.read(buffer)) > 0) {
+                outStream.write(buffer, 0, size);
+            }
+            in.close();
+            outStream.flush();
+            outStream.close();
+
+            return true;
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        return false;
+    }
+    private void start(){
         // Bind audio stream to hardware controls.
         setVolumeControlStream(AudioManager.STREAM_MUSIC);
 

+ 68 - 22
app/src/main/java/com/xugame/gameconsole/emulator/RetroArchEmulatorActivity.java

@@ -1,5 +1,6 @@
 package com.xugame.gameconsole.emulator;
 
+import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.hardware.input.InputManager;
@@ -15,6 +16,7 @@ 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;
+import com.xugame.gameconsole.util.Util;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -90,6 +92,21 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
             // This requires NVIDIA Android extensions (available on NVIDIA Shield), if they are not
             // available then nothing will be done
             if (retro.hasExtra("HIDEMOUSE")) hideMouseCursor();
+            int screenMode=retro.getIntExtra("screenMode",0);
+            if(screenMode>=0&&screenMode<3){
+                switch (screenMode) {
+                    case 0:
+                        setAspectRatio(AspectRatio.ASPECT_RATIO_CORE.getValue());
+                        break;
+                    case 1:
+                        setAspectRatio(AspectRatio.ASPECT_RATIO_FULL.getValue());
+                        break;
+                    case 2:
+                        setAspectRatio(AspectRatio.ASPECT_RATIO_CUSTOM.getValue());
+                        setCustomViewPort(Util.getSize(420), Util.getSize(87), Util.getSize(1080), Util.getSize(810));
+                        break;
+                }
+            }
         }
 
         //Checks if Android versions is above 9.0 (28) and enable the screen to write over notch if the user desires
@@ -134,35 +151,20 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
         // If QUITFOCUS parameter was set then completely exit Retroarch when focus is lost
         if (quitfocus) System.exit(0);
     }
-    boolean isSelect = false;
-    boolean isStart = false;
+
     @Override
     public boolean dispatchKeyEvent(KeyEvent event) {
         DebugUtil.i(TAG, "" + event.getKeyCode());
         if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
                 && event.getAction() == KeyEvent.ACTION_DOWN) {
-            showDialog();
+//            showDialog();
+            Intent intent=new Intent();//调出主菜单UI
+            ComponentName componentName=new ComponentName("com.xugame.gameconsoleMenu",
+                    "com.xugame.gameconsole.dialog.localgamesetting.LocalGameSettingDialog");
+           intent.setComponent(componentName);
+            startActivityForResult(intent,200);
             return super.dispatchKeyEvent(event);
         }
-        if (event.getAction() == KeyEvent.ACTION_DOWN) {
-            if (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_SELECT) {
-                isSelect = true;
-            }
-            if (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_START) {
-                isStart = true;
-            }
-            if(isSelect&&isStart){
-                isSelect=false;
-                isStart=false;
-                DebugUtil.i(TAG,"select +start click");
-            }
-        } if (event.getAction() == KeyEvent.ACTION_UP) {
-            if (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_SELECT) {
-                isSelect = false;
-            } else if (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_START) {
-                isStart = false;
-            }
-        }
 
         return super.dispatchKeyEvent(event);
     }
@@ -265,4 +267,48 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
 //                .setMessage("退出游戏?");
 //        alertDialog.show();
     }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        if (requestCode == 200) {
+            if (resultCode == 201) {//继续游戏
+                if (data != null) {
+                    int scanLine = data.getIntExtra("scanLine", 0);
+                    int screen = data.getIntExtra("screen", 0);
+                    DebugUtil.i(TAG,"scanline="+scanLine+"screen="+screen);
+
+                    if (screen >= 0 && screen < 3) {
+                        switch (screen) {
+                            case 0:
+                                setAspectRatio(AspectRatio.ASPECT_RATIO_CORE.getValue());
+                                break;
+                            case 1:
+                                setAspectRatio(AspectRatio.ASPECT_RATIO_FULL.getValue());
+                                break;
+                            case 2:
+                                setAspectRatio(AspectRatio.ASPECT_RATIO_CUSTOM.getValue());
+                                setCustomViewPort(Util.getSize(420), Util.getSize(87), Util.getSize(1080), Util.getSize(810));
+                                break;
+                        }
+                    }
+                    if (scanLine >= 0 && scanLine < 3) {
+                        switch (ScreenType.values()[scanLine]) {
+                            case NORMAL:
+                                switchFilter(null);
+                                break;
+                            case SAI_2X:
+                                switchFilter("/data/user/0/com.xugame.gameconsole/filters/video/2xSaI.filt");
+                                break;
+                            case SCANLINE:
+                                switchFilter("/data/user/0/com.xugame.gameconsole/filters/video/Scanline2x.filt");
+                                break;
+                        }
+                    }
+                }
+            } else if (resultCode == 0) {
+                exitLocalGame();
+            }
+        }
+        super.onActivityResult(requestCode, resultCode, data);
+    }
 }

+ 1 - 0
app/src/main/java/com/xugame/gameconsole/preferences/UserPreferences.java

@@ -132,6 +132,7 @@ public class UserPreferences {
         //设置没有触摸屏
         config.setString("input_overlay_enable", "false");
         config.setBoolean("log_verbosity", true);
+        config.setBoolean("fps_show", true);
         config.setInt("frontend_log_level", 1);
         config.setInt("libretro_log_level", 1);
 

+ 132 - 0
app/src/main/java/com/xugame/gameconsole/util/ResUtil.java

@@ -0,0 +1,132 @@
+package com.xugame.gameconsole.util;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.StateListDrawable;
+
+/**
+ * Created by Frank on 2016/11/23.
+ */
+
+public class ResUtil {
+    public static final String sPackageName = null;
+
+    public static int getStringID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "string", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "string", sPackageName);
+
+    }
+
+    public static int getStringGameID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "string", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "string", sPackageName);
+
+    }
+
+    public static int getDrawableID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "drawable", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "drawable", sPackageName);
+    }
+
+    public static int getColorID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "color", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "color", sPackageName);
+    }
+
+    public static int getLayoutID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "layout", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "layout", sPackageName);
+    }
+
+    public static int getAnimID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "anim", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "anim", sPackageName);
+    }
+
+    public static int getID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "id", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "id", sPackageName);
+    }
+
+    public static int getXmlID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "xml", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "xml", sPackageName);
+    }
+
+    public static int getDimID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "dimen", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "dimen", sPackageName);
+    }
+
+    public static int getStyleID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "style", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "style", sPackageName);
+    }
+
+    public static int getArrayID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "array", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "array", sPackageName);
+    }
+
+    public static int getRawID(Context context, String name) {
+        if (sPackageName == null)
+            return context.getResources().
+                    getIdentifier(name, "raw", context.getPackageName());
+        else
+            return context.getResources().
+                    getIdentifier(name, "raw", sPackageName);
+    }
+
+    public static StateListDrawable createSelector(Drawable normal, Drawable focused) {
+        StateListDrawable stateList = new StateListDrawable();
+        int stateFocused = android.R.attr.state_focused;
+
+        stateList.addState(new int[]{-stateFocused}, normal);
+        stateList.addState(new int[]{stateFocused}, focused);
+        return stateList;
+    }
+}

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1363 - 0
app/src/main/java/com/xugame/gameconsole/util/Util.java


Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä