paramsList) {
- if (sound_card != null && !sound_card.equals("None")) {
+ if (sound_card != null && !sound_card.equals("None") && enablevnc != 1) {
paramsList.add("-soundhw");
paramsList.add(sound_card);
}
@@ -384,7 +401,7 @@ public class StartVM {
if (this.cpuNum > 1 &&
(enablekvm == 1 || enable_mttcg == 1 || !Config.enableSMPOnlyOnKVM)) {
paramsList.add("-smp");
- paramsList.add("sockets="+"1"+",cores="+this.cpuNum+",threads="+this.cpuNum+"");
+ paramsList.add("sockets=" + "1" + ",cores=" + this.cpuNum + ",threads=" + this.cpuNum + "");
}
if (machine_type != null && !machine_type.equals("Default")) {
@@ -411,7 +428,11 @@ public class StartVM {
if (this.cpu != null && !cpu.equals("Default")) {
paramsList.add("-cpu");
- paramsList.add(cpu + ",+avx");
+ String cpuParams = null;
+ cpuParams += cpu;
+ if (enablleAvx)
+ cpuParams += ",+avx";
+ paramsList.add(cpuParams);
}
@@ -429,7 +450,7 @@ public class StartVM {
tcgParams += ",thread=multi";
else
tcgParams += ",thread=single";
- tcgParams += ",tb-size=2048";
+ tcgParams += ",tb-size=" + tbSize;
paramsList.add(tcgParams);
//#endif
}
diff --git a/app/src/main/java/com/vectras/qemu/utils/Machine.java b/app/src/main/java/com/vectras/qemu/utils/Machine.java
index 85716c2..e783172 100644
--- a/app/src/main/java/com/vectras/qemu/utils/Machine.java
+++ b/app/src/main/java/com/vectras/qemu/utils/Machine.java
@@ -1,13 +1,15 @@
package com.vectras.qemu.utils;
import android.app.Activity;
-import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
+
+import androidx.appcompat.app.AlertDialog;
+
import com.vectras.qemu.Config;
import com.vectras.vm.MainActivity;
import com.vectras.vm.R;
diff --git a/app/src/main/java/com/vectras/vm/Fragment/LoggerFragment.java b/app/src/main/java/com/vectras/vm/Fragment/LoggerFragment.java
index 0c16f6d..f124ccd 100644
--- a/app/src/main/java/com/vectras/vm/Fragment/LoggerFragment.java
+++ b/app/src/main/java/com/vectras/vm/Fragment/LoggerFragment.java
@@ -1,5 +1,6 @@
package com.vectras.vm.Fragment;
+import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -21,6 +22,7 @@ import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
+import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -28,6 +30,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.vectras.vm.R;
import com.vectras.vm.RomsManagerActivity;
import com.vectras.vm.MainActivity;
+import com.vectras.vm.VectrasApp;
import com.vectras.vm.adapter.LogsAdapter;
import com.vectras.vm.logger.VectrasStatus;
import com.vectras.vm.utils.UIUtils;
@@ -46,20 +49,21 @@ import java.util.TimerTask;
public class LoggerFragment extends Fragment {
View view;
- MainActivity activity = MainActivity.activity;
private final String CREDENTIAL_SHARED_PREF = "settings_prefs";
private LogsAdapter mLogAdapter;
private RecyclerView logList;
private Timer _timer = new Timer();
private TimerTask t;
+ Activity activity;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// TODO Auto-generated method stub
view = inflater.inflate(R.layout.fragment_logs, container, false);
- LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.activity);
- mLogAdapter = new LogsAdapter(layoutManager, MainActivity.activity);
+ activity = getActivity();
+ LinearLayoutManager layoutManager = new LinearLayoutManager(VectrasApp.getApp());
+ mLogAdapter = new LogsAdapter(layoutManager, VectrasApp.getApp());
logList = (RecyclerView) view.findViewById(R.id.recyclerLog);
logList.setAdapter(mLogAdapter);
logList.setLayoutManager(layoutManager);
diff --git a/app/src/main/java/com/vectras/vm/MainActivity.java b/app/src/main/java/com/vectras/vm/MainActivity.java
index fb9d999..c9d973c 100644
--- a/app/src/main/java/com/vectras/vm/MainActivity.java
+++ b/app/src/main/java/com/vectras/vm/MainActivity.java
@@ -6,6 +6,7 @@ import android.androidVNC.RfbProto;
import android.androidVNC.VncCanvas;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
+import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Dialog;
@@ -49,6 +50,7 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
+import androidx.recyclerview.widget.GridLayoutManager;
import androidx.vectordrawable.graphics.drawable.ArgbEvaluator;
import androidx.viewpager.widget.ViewPager;
@@ -71,6 +73,7 @@ import com.vectras.qemu.utils.Machine;
import com.vectras.qemu.utils.QmpClient;
import com.vectras.vm.Fragment.HomeFragment;
import com.vectras.vm.Fragment.LoggerFragment;
+import com.vectras.vm.MainRoms.AdapterMainRoms;
import com.vectras.vm.logger.VectrasStatus;
import com.vectras.vm.utils.AppUpdater;
import com.vectras.qemu.utils.FileInstaller;
@@ -146,7 +149,6 @@ public class MainActivity extends AppCompatActivity {
setupStrictMode();
execTimer();
checkAndLoadLibs();
- Config.logFilePath = Config.cacheDir + "/vectras/vectras-log.txt";
activity = this;
this.setContentView(R.layout.main);
this.setupWidgets();
@@ -446,7 +448,7 @@ public class MainActivity extends AppCompatActivity {
}
});
if (MainSettingsManager.getPromptUpdateVersion(activity))
- updateApp(true);
+ updateApp(false);
/*FirebaseUser user = mAuth.getCurrentUser();
TextView usernameTxt = findViewById(R.id.usernameTxt);
TextView emailTxt = findViewById(R.id.emailTxt);
@@ -476,6 +478,12 @@ public class MainActivity extends AppCompatActivity {
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
alertDialog.setTitle("JOIN US ON TELEGRAM");
+ TextView title = alertDialog.findViewById(R.id.title_text);
+ ObjectAnimator rgbAnim=ObjectAnimator.ofObject(title,"textColor",new ArgbEvaluator(), Color.RED,Color.GREEN,Color.BLUE);
+ rgbAnim.setDuration(1000);
+ rgbAnim.setRepeatMode(ValueAnimator.REVERSE);
+ rgbAnim.setRepeatCount(ValueAnimator.INFINITE);
+ rgbAnim.start();
alertDialog.setMessage("Join us on Telegram where we publish all the news and updates and receive your opinions and bugs");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "JOIN", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
@@ -533,6 +541,7 @@ public class MainActivity extends AppCompatActivity {
}
+ @SuppressLint("NotifyDataSetChanged")
@Override
public void onStart() {
super.onStart();
@@ -541,6 +550,8 @@ public class MainActivity extends AppCompatActivity {
} else {
Config.hd_if_type = "ide";
}
+ setupFolders();
+ Config.ui = MainSettingsManager.getVmUi(activity);
InterstitialAd.load(this, "ca-app-pub-3568137780412047/7745973511", adRequest,
new InterstitialAdLoadCallback() {
@Override
@@ -756,21 +767,18 @@ public class MainActivity extends AppCompatActivity {
}
public static void setupFolders() {
- Thread t = new Thread(new Runnable() {
- public void run() {
+ try {
+ Config.cacheDir = activity.getCacheDir().getAbsolutePath();
+ Config.storagedir = Environment.getDataDirectory().toString();
- Config.cacheDir = activity.getCacheDir().getAbsolutePath();
- Config.storagedir = Environment.getExternalStorageDirectory().toString();
+ // Create Temp folder
+ File folder = new File(Config.getTmpFolder());
+ if (!folder.exists())
+ folder. mkdirs();
- // Create Temp folder
- File folder = new File(Config.getTmpFolder());
- if (!folder.exists())
- folder.mkdirs();
+ } catch (Exception ignored) {
-
- }
- });
- t.start();
+ }
}
//XXX: sometimes this needs to be called from the main thread otherwise
diff --git a/app/src/main/java/com/vectras/vm/utils/UIUtils.java b/app/src/main/java/com/vectras/vm/utils/UIUtils.java
index 16d7beb..ad6201a 100644
--- a/app/src/main/java/com/vectras/vm/utils/UIUtils.java
+++ b/app/src/main/java/com/vectras/vm/utils/UIUtils.java
@@ -1,7 +1,7 @@
package com.vectras.vm.utils;
import android.app.Activity;
-import android.app.AlertDialog;
+import androidx.appcompat.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
diff --git a/app/src/main/java/org/libsdl/app/SDLActivity.java b/app/src/main/java/org/libsdl/app/SDLActivity.java
index c12258d..6c2c812 100644
--- a/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -207,11 +207,11 @@ public class SDLActivity extends AppCompatActivity {
mClipboardHandler = new SDLClipboardHandler_Old();
}
- //Vectras: override
+ //Limbo: override
// Set up the surface
//mSurface = new SDLSurface(getApplication());
- //Vectras: override
+ //Limbo: override
//mLayout = new RelativeLayout(this);
//mLayout.addView(mSurface);
@@ -1079,7 +1079,7 @@ public class SDLActivity extends AppCompatActivity {
mClipboardHandler.clipboardSetText(string);
}
- //Vectras:
+ //Limbo:
protected void runSDLMain(){
}
@@ -1105,7 +1105,7 @@ class SDLMain implements Runnable {
Log.v("SDL", "Running main function " + function + " from library " + library);
- //Vectras: we override
+ //Limbo: we override
//SDLActivity.nativeRunMain(library, function, arguments);
SDLActivity.mSingleton.runSDLMain();
@@ -1122,375 +1122,6 @@ class SDLMain implements Runnable {
}
-
-/**
- SDLSurface. This is what we draw on, so we need to know when it's created
- in order to do anything useful.
-
- Because of this, that's where we set up the SDL thread
-*/
-//Vectras: should be public
-class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
- View.OnKeyListener, View.OnTouchListener, SensorEventListener {
-
- // Sensors
- protected static SensorManager mSensorManager;
- protected static Display mDisplay;
-
- // Keep track of the surface size to normalize touch events
- protected static float mWidth, mHeight;
-
- // Startup
- public SDLSurface(Context context) {
- super(context);
- getHolder().addCallback(this);
-
- setFocusable(true);
- setFocusableInTouchMode(true);
- requestFocus();
- setOnKeyListener(this);
- setOnTouchListener(this);
-
- mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
- mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
-
- if (Build.VERSION.SDK_INT >= 12) {
- setOnGenericMotionListener(new SDLGenericMotionListener_API12());
- }
-
- // Some arbitrary defaults to avoid a potential division by zero
- mWidth = 1.0f;
- mHeight = 1.0f;
- }
-
- public void handlePause() {
- enableSensor(Sensor.TYPE_ACCELEROMETER, false);
- }
-
- public void handleResume() {
- setFocusable(true);
- setFocusableInTouchMode(true);
- requestFocus();
- setOnKeyListener(this);
- setOnTouchListener(this);
- enableSensor(Sensor.TYPE_ACCELEROMETER, true);
- }
-
- public Surface getNativeSurface() {
- return getHolder().getSurface();
- }
-
- // Called when we have a valid drawing surface
- @Override
- public void surfaceCreated(SurfaceHolder holder) {
- Log.v("SDL", "surfaceCreated()");
- holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
- }
-
- // Called when we lose the surface
- @Override
- public void surfaceDestroyed(SurfaceHolder holder) {
- Log.v("SDL", "surfaceDestroyed()");
-
- // Transition to pause, if needed
- SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED;
- SDLActivity.handleNativeState();
-
- SDLActivity.mIsSurfaceReady = false;
- SDLActivity.onNativeSurfaceDestroyed();
- }
-
- // Called when the surface is resized
- @Override
- public void surfaceChanged(SurfaceHolder holder,
- int format, int width, int height) {
- Log.v("SDL", "surfaceChanged()");
-
- int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default
- switch (format) {
- case PixelFormat.A_8:
- Log.v("SDL", "pixel format A_8");
- break;
- case PixelFormat.LA_88:
- Log.v("SDL", "pixel format LA_88");
- break;
- case PixelFormat.L_8:
- Log.v("SDL", "pixel format L_8");
- break;
- case PixelFormat.RGBA_4444:
- Log.v("SDL", "pixel format RGBA_4444");
- sdlFormat = 0x15421002; // SDL_PIXELFORMAT_RGBA4444
- break;
- case PixelFormat.RGBA_5551:
- Log.v("SDL", "pixel format RGBA_5551");
- sdlFormat = 0x15441002; // SDL_PIXELFORMAT_RGBA5551
- break;
- case PixelFormat.RGBA_8888:
- Log.v("SDL", "pixel format RGBA_8888");
- sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888
- break;
- case PixelFormat.RGBX_8888:
- Log.v("SDL", "pixel format RGBX_8888");
- sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888
- break;
- case PixelFormat.RGB_332:
- Log.v("SDL", "pixel format RGB_332");
- sdlFormat = 0x14110801; // SDL_PIXELFORMAT_RGB332
- break;
- case PixelFormat.RGB_565:
- Log.v("SDL", "pixel format RGB_565");
- sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565
- break;
- case PixelFormat.RGB_888:
- Log.v("SDL", "pixel format RGB_888");
- // Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead?
- sdlFormat = 0x16161804; // SDL_PIXELFORMAT_RGB888
- break;
- default:
- Log.v("SDL", "pixel format unknown " + format);
- break;
- }
-
- mWidth = width;
- mHeight = height;
- SDLActivity.onNativeResize(width, height, sdlFormat, mDisplay.getRefreshRate());
- Log.v("SDL", "Window size: " + width + "x" + height);
-
-
- boolean skip = false;
- int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation();
-
- if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
- {
- // Accept any
- }
- else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT)
- {
- if (mWidth > mHeight) {
- skip = true;
- }
- } else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
- if (mWidth < mHeight) {
- skip = true;
- }
- }
-
- // Special Patch for Square Resolution: Black Berry Passport
- if (skip) {
- double min = Math.min(mWidth, mHeight);
- double max = Math.max(mWidth, mHeight);
-
- if (max / min < 1.20) {
- Log.v("SDL", "Don't skip on such aspect-ratio. Could be a square resolution.");
- skip = false;
- }
- }
-
- if (skip) {
- Log.v("SDL", "Skip .. Surface is not ready.");
- SDLActivity.mIsSurfaceReady = false;
- return;
- }
-
- /* Surface is ready */
- SDLActivity.mIsSurfaceReady = true;
-
- /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
- SDLActivity.onNativeSurfaceChanged();
-
- SDLActivity.handleNativeState();
- }
-
- // Key events
- @Override
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- // Dispatch the different events depending on where they come from
- // Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
- // So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD
- //
- // Furthermore, it's possible a game controller has SOURCE_KEYBOARD and
- // SOURCE_JOYSTICK, while its key events arrive from the keyboard source
- // So, retrieve the device itself and check all of its sources
- if (SDLControllerManager.isDeviceSDLJoystick(event.getDeviceId())) {
- // Note that we process events with specific key codes here
- if (event.getAction() == KeyEvent.ACTION_DOWN) {
- if (SDLControllerManager.onNativePadDown(event.getDeviceId(), keyCode) == 0) {
- return true;
- }
- } else if (event.getAction() == KeyEvent.ACTION_UP) {
- if (SDLControllerManager.onNativePadUp(event.getDeviceId(), keyCode) == 0) {
- return true;
- }
- }
- }
-
- if ((event.getSource() & InputDevice.SOURCE_KEYBOARD) != 0) {
- if (event.getAction() == KeyEvent.ACTION_DOWN) {
- //Log.v("SDL", "key down: " + keyCode);
- if (SDLActivity.isTextInputEvent(event)) {
- SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1);
- }
- SDLActivity.onNativeKeyDown(keyCode);
- return true;
- }
- else if (event.getAction() == KeyEvent.ACTION_UP) {
- //Log.v("SDL", "key up: " + keyCode);
- SDLActivity.onNativeKeyUp(keyCode);
- return true;
- }
- }
-
- if ((event.getSource() & InputDevice.SOURCE_MOUSE) != 0) {
- // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
- // they are ignored here because sending them as mouse input to SDL is messy
- if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) {
- switch (event.getAction()) {
- case KeyEvent.ACTION_DOWN:
- case KeyEvent.ACTION_UP:
- // mark the event as handled or it will be handled by system
- // handling KEYCODE_BACK by system will call onBackPressed()
- return true;
- }
- }
- }
-
- return false;
- }
-
- // Touch events
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- /* Ref: http://developer.android.com/training/gestures/multi.html */
- final int touchDevId = event.getDeviceId();
- final int pointerCount = event.getPointerCount();
- int action = event.getActionMasked();
- int pointerFingerId;
- int mouseButton;
- int i = -1;
- float x,y,p;
-
- // !!! FIXME: dump this SDK check after 2.0.4 ships and require API14.
- if (event.getSource() == InputDevice.SOURCE_MOUSE && SDLActivity.mSeparateMouseAndTouch) {
- if (Build.VERSION.SDK_INT < 14) {
- mouseButton = 1; // all mouse buttons are the left button
- } else {
- try {
- mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event);
- } catch(Exception e) {
- mouseButton = 1; // oh well.
- }
- }
- SDLActivity.onSDLNativeMouse(mouseButton, action, event.getX(0), event.getY(0));
- } else {
- switch(action) {
- case MotionEvent.ACTION_MOVE:
- for (i = 0; i < pointerCount; i++) {
- pointerFingerId = event.getPointerId(i);
- x = event.getX(i) / mWidth;
- y = event.getY(i) / mHeight;
- p = event.getPressure(i);
- if (p > 1.0f) {
- // may be larger than 1.0f on some devices
- // see the documentation of getPressure(i)
- p = 1.0f;
- }
- SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
- }
- break;
-
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_DOWN:
- // Primary pointer up/down, the index is always zero
- i = 0;
- case MotionEvent.ACTION_POINTER_UP:
- case MotionEvent.ACTION_POINTER_DOWN:
- // Non primary pointer up/down
- if (i == -1) {
- i = event.getActionIndex();
- }
-
- pointerFingerId = event.getPointerId(i);
- x = event.getX(i) / mWidth;
- y = event.getY(i) / mHeight;
- p = event.getPressure(i);
- if (p > 1.0f) {
- // may be larger than 1.0f on some devices
- // see the documentation of getPressure(i)
- p = 1.0f;
- }
- SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
- break;
-
- case MotionEvent.ACTION_CANCEL:
- for (i = 0; i < pointerCount; i++) {
- pointerFingerId = event.getPointerId(i);
- x = event.getX(i) / mWidth;
- y = event.getY(i) / mHeight;
- p = event.getPressure(i);
- if (p > 1.0f) {
- // may be larger than 1.0f on some devices
- // see the documentation of getPressure(i)
- p = 1.0f;
- }
- SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p);
- }
- break;
-
- default:
- break;
- }
- }
-
- return true;
- }
-
- // Sensor events
- public void enableSensor(int sensortype, boolean enabled) {
- // TODO: This uses getDefaultSensor - what if we have >1 accels?
- if (enabled) {
- mSensorManager.registerListener(this,
- mSensorManager.getDefaultSensor(sensortype),
- SensorManager.SENSOR_DELAY_GAME, null);
- } else {
- mSensorManager.unregisterListener(this,
- mSensorManager.getDefaultSensor(sensortype));
- }
- }
-
- @Override
- public void onAccuracyChanged(Sensor sensor, int accuracy) {
- // TODO
- }
-
- @Override
- public void onSensorChanged(SensorEvent event) {
- if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
- float x, y;
- switch (mDisplay.getRotation()) {
- case Surface.ROTATION_90:
- x = -event.values[1];
- y = event.values[0];
- break;
- case Surface.ROTATION_270:
- x = event.values[1];
- y = -event.values[0];
- break;
- case Surface.ROTATION_180:
- x = -event.values[1];
- y = -event.values[0];
- break;
- default:
- x = event.values[0];
- y = event.values[1];
- break;
- }
- SDLActivity.onNativeAccel(-x / SensorManager.GRAVITY_EARTH,
- y / SensorManager.GRAVITY_EARTH,
- event.values[2] / SensorManager.GRAVITY_EARTH);
- }
- }
-}
-
/* This is a fake invisible editor view that receives the input and defines the
* pan&scan region
*/
diff --git a/app/src/main/java/org/libsdl/app/SDLSurface.java b/app/src/main/java/org/libsdl/app/SDLSurface.java
new file mode 100644
index 0000000..a53c3fa
--- /dev/null
+++ b/app/src/main/java/org/libsdl/app/SDLSurface.java
@@ -0,0 +1,384 @@
+package org.libsdl.app;
+
+import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.graphics.PixelFormat;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Build;
+import android.util.Log;
+import android.view.Display;
+import android.view.InputDevice;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.Surface;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.WindowManager;
+
+/**
+ * SDLSurface. This is what we draw on, so we need to know when it's created
+ * in order to do anything useful.
+ *
+ * Because of this, that's where we set up the SDL thread
+ */
+//Limbo: should be public
+public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
+ View.OnKeyListener, View.OnTouchListener, SensorEventListener {
+
+ // Sensors
+ protected static SensorManager mSensorManager;
+ protected static Display mDisplay;
+
+ // Keep track of the surface size to normalize touch events
+ protected static float mWidth, mHeight;
+
+ // Startup
+ public SDLSurface(Context context) {
+ super(context);
+ getHolder().addCallback(this);
+
+ setFocusable(true);
+ setFocusableInTouchMode(true);
+ requestFocus();
+ setOnKeyListener(this);
+ setOnTouchListener(this);
+
+ mDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
+ mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+
+ if (Build.VERSION.SDK_INT >= 12) {
+ setOnGenericMotionListener(new SDLGenericMotionListener_API12());
+ }
+
+ // Some arbitrary defaults to avoid a potential division by zero
+ mWidth = 1.0f;
+ mHeight = 1.0f;
+ }
+
+ public void handlePause() {
+ enableSensor(Sensor.TYPE_ACCELEROMETER, false);
+ }
+
+ public void handleResume() {
+ setFocusable(true);
+ setFocusableInTouchMode(true);
+ requestFocus();
+ setOnKeyListener(this);
+ setOnTouchListener(this);
+ enableSensor(Sensor.TYPE_ACCELEROMETER, true);
+ }
+
+ public Surface getNativeSurface() {
+ return getHolder().getSurface();
+ }
+
+ // Called when we have a valid drawing surface
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ Log.v("SDL", "surfaceCreated()");
+ holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
+ }
+
+ // Called when we lose the surface
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ Log.v("SDL", "surfaceDestroyed()");
+
+ // Transition to pause, if needed
+ SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED;
+ SDLActivity.handleNativeState();
+
+ SDLActivity.mIsSurfaceReady = false;
+ SDLActivity.onNativeSurfaceDestroyed();
+ }
+
+ // Called when the surface is resized
+ @Override
+ public void surfaceChanged(SurfaceHolder holder,
+ int format, int width, int height) {
+ Log.v("SDL", "surfaceChanged()");
+
+ int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default
+ switch (format) {
+ case PixelFormat.A_8:
+ Log.v("SDL", "pixel format A_8");
+ break;
+ case PixelFormat.LA_88:
+ Log.v("SDL", "pixel format LA_88");
+ break;
+ case PixelFormat.L_8:
+ Log.v("SDL", "pixel format L_8");
+ break;
+ case PixelFormat.RGBA_4444:
+ Log.v("SDL", "pixel format RGBA_4444");
+ sdlFormat = 0x15421002; // SDL_PIXELFORMAT_RGBA4444
+ break;
+ case PixelFormat.RGBA_5551:
+ Log.v("SDL", "pixel format RGBA_5551");
+ sdlFormat = 0x15441002; // SDL_PIXELFORMAT_RGBA5551
+ break;
+ case PixelFormat.RGBA_8888:
+ Log.v("SDL", "pixel format RGBA_8888");
+ sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888
+ break;
+ case PixelFormat.RGBX_8888:
+ Log.v("SDL", "pixel format RGBX_8888");
+ sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888
+ break;
+ case PixelFormat.RGB_332:
+ Log.v("SDL", "pixel format RGB_332");
+ sdlFormat = 0x14110801; // SDL_PIXELFORMAT_RGB332
+ break;
+ case PixelFormat.RGB_565:
+ Log.v("SDL", "pixel format RGB_565");
+ sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565
+ break;
+ case PixelFormat.RGB_888:
+ Log.v("SDL", "pixel format RGB_888");
+ // Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead?
+ sdlFormat = 0x16161804; // SDL_PIXELFORMAT_RGB888
+ break;
+ default:
+ Log.v("SDL", "pixel format unknown " + format);
+ break;
+ }
+
+ mWidth = width;
+ mHeight = height;
+ SDLActivity.onNativeResize(width, height, sdlFormat, mDisplay.getRefreshRate());
+ Log.v("SDL", "Window size: " + width + "x" + height);
+
+
+ boolean skip = false;
+ int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation();
+
+ if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
+ // Accept any
+ } else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
+ if (mWidth > mHeight) {
+ skip = true;
+ }
+ } else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
+ if (mWidth < mHeight) {
+ skip = true;
+ }
+ }
+
+ // Special Patch for Square Resolution: Black Berry Passport
+ if (skip) {
+ double min = Math.min(mWidth, mHeight);
+ double max = Math.max(mWidth, mHeight);
+
+ if (max / min < 1.20) {
+ Log.v("SDL", "Don't skip on such aspect-ratio. Could be a square resolution.");
+ skip = false;
+ }
+ }
+
+ if (skip) {
+ Log.v("SDL", "Skip .. Surface is not ready.");
+ SDLActivity.mIsSurfaceReady = false;
+ return;
+ }
+
+ /* Surface is ready */
+ SDLActivity.mIsSurfaceReady = true;
+
+ /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
+ SDLActivity.onNativeSurfaceChanged();
+
+ SDLActivity.handleNativeState();
+ }
+
+ // Key events
+ @Override
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ // Dispatch the different events depending on where they come from
+ // Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
+ // So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD
+ //
+ // Furthermore, it's possible a game controller has SOURCE_KEYBOARD and
+ // SOURCE_JOYSTICK, while its key events arrive from the keyboard source
+ // So, retrieve the device itself and check all of its sources
+ if (SDLControllerManager.isDeviceSDLJoystick(event.getDeviceId())) {
+ // Note that we process events with specific key codes here
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ if (SDLControllerManager.onNativePadDown(event.getDeviceId(), keyCode) == 0) {
+ return true;
+ }
+ } else if (event.getAction() == KeyEvent.ACTION_UP) {
+ if (SDLControllerManager.onNativePadUp(event.getDeviceId(), keyCode) == 0) {
+ return true;
+ }
+ }
+ }
+
+ if ((event.getSource() & InputDevice.SOURCE_KEYBOARD) != 0) {
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ //Log.v("SDL", "key down: " + keyCode);
+ if (SDLActivity.isTextInputEvent(event)) {
+ SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1);
+ }
+ SDLActivity.onNativeKeyDown(keyCode);
+ return true;
+ } else if (event.getAction() == KeyEvent.ACTION_UP) {
+ //Log.v("SDL", "key up: " + keyCode);
+ SDLActivity.onNativeKeyUp(keyCode);
+ return true;
+ }
+ }
+
+ if ((event.getSource() & InputDevice.SOURCE_MOUSE) != 0) {
+ // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
+ // they are ignored here because sending them as mouse input to SDL is messy
+ if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) {
+ switch (event.getAction()) {
+ case KeyEvent.ACTION_DOWN:
+ case KeyEvent.ACTION_UP:
+ // mark the event as handled or it will be handled by system
+ // handling KEYCODE_BACK by system will call onBackPressed()
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ // Touch events
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ /* Ref: http://developer.android.com/training/gestures/multi.html */
+ final int touchDevId = event.getDeviceId();
+ final int pointerCount = event.getPointerCount();
+ int action = event.getActionMasked();
+ int pointerFingerId;
+ int mouseButton;
+ int i = -1;
+ float x, y, p;
+
+ // !!! FIXME: dump this SDK check after 2.0.4 ships and require API14.
+ if (event.getSource() == InputDevice.SOURCE_MOUSE && SDLActivity.mSeparateMouseAndTouch) {
+ if (Build.VERSION.SDK_INT < 14) {
+ mouseButton = 1; // all mouse buttons are the left button
+ } else {
+ try {
+ mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event);
+ } catch (Exception e) {
+ mouseButton = 1; // oh well.
+ }
+ }
+ SDLActivity.onSDLNativeMouse(mouseButton, action, event.getX(0), event.getY(0));
+ } else {
+ switch (action) {
+ case MotionEvent.ACTION_MOVE:
+ for (i = 0; i < pointerCount; i++) {
+ pointerFingerId = event.getPointerId(i);
+ x = event.getX(i) / mWidth;
+ y = event.getY(i) / mHeight;
+ p = event.getPressure(i);
+ if (p > 1.0f) {
+ // may be larger than 1.0f on some devices
+ // see the documentation of getPressure(i)
+ p = 1.0f;
+ }
+ SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
+ }
+ break;
+
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_DOWN:
+ // Primary pointer up/down, the index is always zero
+ i = 0;
+ case MotionEvent.ACTION_POINTER_UP:
+ case MotionEvent.ACTION_POINTER_DOWN:
+ // Non primary pointer up/down
+ if (i == -1) {
+ i = event.getActionIndex();
+ }
+
+ pointerFingerId = event.getPointerId(i);
+ x = event.getX(i) / mWidth;
+ y = event.getY(i) / mHeight;
+ p = event.getPressure(i);
+ if (p > 1.0f) {
+ // may be larger than 1.0f on some devices
+ // see the documentation of getPressure(i)
+ p = 1.0f;
+ }
+ SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
+ break;
+
+ case MotionEvent.ACTION_CANCEL:
+ for (i = 0; i < pointerCount; i++) {
+ pointerFingerId = event.getPointerId(i);
+ x = event.getX(i) / mWidth;
+ y = event.getY(i) / mHeight;
+ p = event.getPressure(i);
+ if (p > 1.0f) {
+ // may be larger than 1.0f on some devices
+ // see the documentation of getPressure(i)
+ p = 1.0f;
+ }
+ SDLActivity.onSDLNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p);
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return true;
+ }
+
+ // Sensor events
+ public void enableSensor(int sensortype, boolean enabled) {
+ // TODO: This uses getDefaultSensor - what if we have >1 accels?
+ if (enabled) {
+ mSensorManager.registerListener(this,
+ mSensorManager.getDefaultSensor(sensortype),
+ SensorManager.SENSOR_DELAY_GAME, null);
+ } else {
+ mSensorManager.unregisterListener(this,
+ mSensorManager.getDefaultSensor(sensortype));
+ }
+ }
+
+ @Override
+ public void onAccuracyChanged(Sensor sensor, int accuracy) {
+ // TODO
+ }
+
+ @Override
+ public void onSensorChanged(SensorEvent event) {
+ if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
+ float x, y;
+ switch (mDisplay.getRotation()) {
+ case Surface.ROTATION_90:
+ x = -event.values[1];
+ y = event.values[0];
+ break;
+ case Surface.ROTATION_270:
+ x = event.values[1];
+ y = -event.values[0];
+ break;
+ case Surface.ROTATION_180:
+ x = -event.values[1];
+ y = -event.values[0];
+ break;
+ default:
+ x = event.values[0];
+ y = event.values[1];
+ break;
+ }
+ SDLActivity.onNativeAccel(-x / SensorManager.GRAVITY_EARTH,
+ y / SensorManager.GRAVITY_EARTH,
+ event.values[2] / SensorManager.GRAVITY_EARTH);
+ }
+ }
+}
diff --git a/app/src/main/res/drawable/ic_a.xml b/app/src/main/res/drawable/ic_a.xml
new file mode 100644
index 0000000..2669658
--- /dev/null
+++ b/app/src/main/res/drawable/ic_a.xml
@@ -0,0 +1,8 @@
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_t.xml b/app/src/main/res/drawable/ic_t.xml
new file mode 100644
index 0000000..07d6b26
--- /dev/null
+++ b/app/src/main/res/drawable/ic_t.xml
@@ -0,0 +1,6 @@
+
+
+
diff --git a/app/src/main/res/layout/activity_sdl.xml b/app/src/main/res/layout/activity_sdl.xml
index e199db1..61c08af 100644
--- a/app/src/main/res/layout/activity_sdl.xml
+++ b/app/src/main/res/layout/activity_sdl.xml
@@ -1,18 +1,14 @@
-
-
+ android:orientation="vertical" />
+
+
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_vnc.xml b/app/src/main/res/layout/activity_vnc.xml
index aba9c50..37465e0 100644
--- a/app/src/main/res/layout/activity_vnc.xml
+++ b/app/src/main/res/layout/activity_vnc.xml
@@ -1,6 +1,7 @@
+ android:keepScreenOn="true" />
@@ -62,4 +64,4 @@
android:layout_centerHorizontal="true" />
-
\ No newline at end of file
+
diff --git a/app/src/main/res/layout/controls_fragment.xml b/app/src/main/res/layout/controls_fragment.xml
index b457447..dfbf4da 100644
--- a/app/src/main/res/layout/controls_fragment.xml
+++ b/app/src/main/res/layout/controls_fragment.xml
@@ -195,6 +195,16 @@
android:paddingRight="10dp"
android:translationY="-6dp">
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+ -
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
index 83a55a0..07c02c5 100644
--- a/app/src/main/res/values-night/themes.xml
+++ b/app/src/main/res/values-night/themes.xml
@@ -65,7 +65,7 @@
- @anim/popup_in
- @anim/popup_out
-
-