Run clang-format on .java files

This commit is contained in:
offtkp 2023-11-28 21:41:57 +02:00
parent a40e74a15d
commit ed0864d24f
24 changed files with 634 additions and 771 deletions

View file

@ -1 +0,0 @@
/build

View file

@ -36,11 +36,7 @@ android {
} }
dependencies { dependencies {
implementation("androidx.appcompat:appcompat:1.6.1") implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.8.0") implementation("com.google.android.material:material:1.8.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4") implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
} }

View file

@ -1,10 +1,7 @@
package com.panda3ds.pandroid; package com.panda3ds.pandroid;
public class AlberDriver { public class AlberDriver {
AlberDriver() { super(); }
AlberDriver() {
super();
}
public static native void Initialize(); public static native void Initialize();
public static native void RunFrame(int fbo); public static native void RunFrame(int fbo);
@ -18,7 +15,5 @@ public class AlberDriver {
public static native void TouchScreenUp(); public static native void TouchScreenUp();
public static native void TouchScreenDown(int x, int y); public static native void TouchScreenDown(int x, int y);
static { static { System.loadLibrary("Alber"); }
System.loadLibrary("Alber");
}
} }

View file

@ -2,5 +2,4 @@ package com.panda3ds.pandroid.app;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
public class BaseActivity extends AppCompatActivity { public class BaseActivity extends AppCompatActivity {}
}

View file

@ -9,9 +9,7 @@ import android.view.WindowManager;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.panda3ds.pandroid.R; import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.utils.Constants; import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.view.PandaGlSurfaceView; import com.panda3ds.pandroid.view.PandaGlSurfaceView;
@ -26,8 +24,7 @@ public class GameActivity extends BaseActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Intent intent = getIntent(); Intent intent = getIntent();
if(!intent.hasExtra(Constants.EXTRA_PATH)){ if (!intent.hasExtra(Constants.EXTRA_PATH)) {
setContentView(new FrameLayout(this)); setContentView(new FrameLayout(this));
Toast.makeText(this, "Invalid rom path!", Toast.LENGTH_LONG).show(); Toast.makeText(this, "Invalid rom path!", Toast.LENGTH_LONG).show();
finish(); finish();
@ -38,19 +35,16 @@ public class GameActivity extends BaseActivity {
setContentView(R.layout.game_activity); setContentView(R.layout.game_activity);
((FrameLayout)findViewById(R.id.panda_gl_frame)) ((FrameLayout) findViewById(R.id.panda_gl_frame))
.addView(pandaSurface, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); .addView(pandaSurface, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
controllerLayout = findViewById(R.id.controller_layout); controllerLayout = findViewById(R.id.controller_layout);
controllerLayout.initialize(); controllerLayout.initialize();
((CheckBox)findViewById(R.id.hide_screen_controller)) ((CheckBox) findViewById(R.id.hide_screen_controller)).setOnCheckedChangeListener((buttonView, isChecked) -> {
.setOnCheckedChangeListener((buttonView, isChecked) -> { findViewById(R.id.overlay_controller).setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
findViewById(R.id.overlay_controller)
.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
}); });
} }
@Override @Override

View file

@ -1,5 +1,7 @@
package com.panda3ds.pandroid.app; package com.panda3ds.pandroid.app;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.provider.Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION; import static android.provider.Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION;
import android.content.Intent; import android.content.Intent;
@ -7,15 +9,10 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.R; import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.utils.PathUtils; import com.panda3ds.pandroid.utils.PathUtils;
public class MainActivity extends BaseActivity { public class MainActivity extends BaseActivity {
@ -38,15 +35,13 @@ public class MainActivity extends BaseActivity {
startActivity(intent); startActivity(intent);
} }
} else { } else {
ActivityCompat.requestPermissions(this, new String[]{READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE); ActivityCompat.requestPermissions(this, new String[] {READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
ActivityCompat.requestPermissions(this, new String[]{WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE); ActivityCompat.requestPermissions(this, new String[] {WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
} }
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
findViewById(R.id.load_rom).setOnClickListener(v->{ findViewById(R.id.load_rom).setOnClickListener(v -> { openFile(); });
openFile();
});
} }
@Override @Override
@ -55,8 +50,7 @@ public class MainActivity extends BaseActivity {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
String path = PathUtils.getPath(getApplicationContext(), data.getData()); String path = PathUtils.getPath(getApplicationContext(), data.getData());
Toast.makeText(getApplicationContext(), "pandroid opening " + path, Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(), "pandroid opening " + path, Toast.LENGTH_LONG).show();
startActivity(new Intent(this, GameActivity.class) startActivity(new Intent(this, GameActivity.class).putExtra(Constants.EXTRA_PATH, path));
.putExtra(Constants.EXTRA_PATH, path));
} }
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
} }

View file

@ -1,23 +1,17 @@
package com.panda3ds.pandroid.math; package com.panda3ds.pandroid.math;
public class Vector2 { public class Vector2 {
public float x,y; public float x, y;
public Vector2(Vector2 value){ public Vector2(Vector2 value) { this(value.x, value.y); }
this(value.x,value.y);
}
public Vector2(float x, float y){ public Vector2(float x, float y) {
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
public float distanceTo(Vector2 vec){ public float distanceTo(Vector2 vec) { return distance(x, y, vec.x, vec.y); }
return distance(x,y,vec.x, vec.y);
}
public static float distance(float x, float y, float x2, float y2){ public static float distance(float x, float y, float x2, float y2) { return (float) Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2)); }
return (float) Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
}
public void set(float x, float y) { public void set(float x, float y) {
this.x = x; this.x = x;

View file

@ -1,7 +1,6 @@
package com.panda3ds.pandroid.utils; package com.panda3ds.pandroid.utils;
public class Constants { public class Constants {
public static final int INPUT_KEY_UP = 1 << 6; public static final int INPUT_KEY_UP = 1 << 6;
public static final int INPUT_KEY_DOWN = 1 << 7; public static final int INPUT_KEY_DOWN = 1 << 7;
public static final int INPUT_KEY_LEFT = 1 << 5; public static final int INPUT_KEY_LEFT = 1 << 5;

View file

@ -10,44 +10,37 @@ import android.provider.DocumentsContract;
import android.provider.MediaStore; import android.provider.MediaStore;
public class PathUtils { public class PathUtils {
public static String getPath(final Context context, final Uri uri) { public static String getPath(final Context context, final Uri uri) {
// DocumentProvider // DocumentProvider
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) {
if (isExternalStorageDocument(uri)) { // ExternalStorageProvider
if (isExternalStorageDocument(uri)) {// ExternalStorageProvider
final String docId = DocumentsContract.getDocumentId(uri); final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":"); final String[] split = docId.split(":");
final String type = split[0]; final String type = split[0];
String storageDefinition; String storageDefinition;
if ("primary".equalsIgnoreCase(type)) {
if("primary".equalsIgnoreCase(type)){
return Environment.getExternalStorageDirectory() + "/" + split[1]; return Environment.getExternalStorageDirectory() + "/" + split[1];
} else { } else {
if (Environment.isExternalStorageRemovable()) {
if(Environment.isExternalStorageRemovable()){
storageDefinition = "EXTERNAL_STORAGE"; storageDefinition = "EXTERNAL_STORAGE";
} else{ } else {
storageDefinition = "SECONDARY_STORAGE"; storageDefinition = "SECONDARY_STORAGE";
} }
return System.getenv(storageDefinition) + "/" + split[1]; return System.getenv(storageDefinition) + "/" + split[1];
} }
} else if (isDownloadsDocument(uri)) {// DownloadsProvider } else if (isDownloadsDocument(uri)) { // DownloadsProvider
final String id = DocumentsContract.getDocumentId(uri); final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId( final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
return getDataColumn(context, contentUri, null, null); return getDataColumn(context, contentUri, null, null);
} else if (isMediaDocument(uri)) {// MediaProvider } else if (isMediaDocument(uri)) { // MediaProvider
final String docId = DocumentsContract.getDocumentId(uri); final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":"); final String[] split = docId.split(":");
final String type = split[0]; final String type = split[0];
@ -62,22 +55,19 @@ public class PathUtils {
} }
final String selection = "_id=?"; final String selection = "_id=?";
final String[] selectionArgs = new String[]{ final String[] selectionArgs = new String[] {split[1]};
split[1]
};
return getDataColumn(context, contentUri, selection, selectionArgs); return getDataColumn(context, contentUri, selection, selectionArgs);
} }
} else if ("content".equalsIgnoreCase(uri.getScheme())) {// MediaStore (and general) } else if ("content".equalsIgnoreCase(uri.getScheme())) { // MediaStore (and general)
// Return the remote address // Return the remote address
if (isGooglePhotosUri(uri)) if (isGooglePhotosUri(uri)) return uri.getLastPathSegment();
return uri.getLastPathSegment();
return getDataColumn(context, uri, null, null); return getDataColumn(context, uri, null, null);
} else if ("file".equalsIgnoreCase(uri.getScheme())) {// File } else if ("file".equalsIgnoreCase(uri.getScheme())) { // File
return uri.getPath(); return uri.getPath();
} }
@ -85,12 +75,9 @@ public class PathUtils {
} }
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
Cursor cursor = null; Cursor cursor = null;
final String column = "_data"; final String column = "_data";
final String[] projection = { final String[] projection = {column};
column
};
try { try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
@ -99,27 +86,16 @@ public class PathUtils {
return cursor.getString(column_index); return cursor.getString(column_index);
} }
} finally { } finally {
if (cursor != null) if (cursor != null) cursor.close();
cursor.close();
} }
return null; return null;
} }
public static boolean isExternalStorageDocument(Uri uri) { return "com.android.externalstorage.documents".equals(uri.getAuthority()); }
public static boolean isExternalStorageDocument(Uri uri) { public static boolean isDownloadsDocument(Uri uri) { return "com.android.providers.downloads.documents".equals(uri.getAuthority()); }
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
public static boolean isMediaDocument(Uri uri) { return "com.android.providers.media.documents".equals(uri.getAuthority()); }
public static boolean isDownloadsDocument(Uri uri) { public static boolean isGooglePhotosUri(Uri uri) { return "com.google.android.apps.photos.content".equals(uri.getAuthority()); }
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
public static boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
}
} }

View file

@ -1,22 +1,20 @@
package com.panda3ds.pandroid.view; package com.panda3ds.pandroid.view;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import static android.opengl.GLES32.*; import static android.opengl.GLES32.*;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Rect; import android.graphics.Rect;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.util.Log; import android.util.Log;
import com.panda3ds.pandroid.AlberDriver; import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.view.renderer.layout.ConsoleLayout; import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer; import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;
import com.panda3ds.pandroid.view.renderer.layout.ConsoleLayout;
import com.panda3ds.pandroid.view.renderer.layout.DefaultScreenLayout; import com.panda3ds.pandroid.view.renderer.layout.DefaultScreenLayout;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer { public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer {
private final String romPath; private final String romPath;
private ConsoleLayout displayLayout; private ConsoleLayout displayLayout;
private int screenWidth, screenHeight; private int screenWidth, screenHeight;
@ -35,10 +33,10 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
if (screenTexture != 0) { if (screenTexture != 0) {
glDeleteTextures(1, new int[]{screenTexture}, 0); glDeleteTextures(1, new int[] {screenTexture}, 0);
} }
if (screenFbo != 0) { if (screenFbo != 0) {
glDeleteFramebuffers(1, new int[]{screenFbo}, 0); glDeleteFramebuffers(1, new int[] {screenFbo}, 0);
} }
super.finalize(); super.finalize();
} }
@ -79,19 +77,15 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer
Rect bottomScreen = displayLayout.getBottomDisplayBounds(); Rect bottomScreen = displayLayout.getBottomDisplayBounds();
glBlitFramebuffer( glBlitFramebuffer(
0, Constants.N3DS_FULL_HEIGHT, 0, Constants.N3DS_FULL_HEIGHT, Constants.N3DS_WIDTH, Constants.N3DS_HALF_HEIGHT, topScreen.left, screenHeight - topScreen.top,
Constants.N3DS_WIDTH, Constants.N3DS_HALF_HEIGHT, topScreen.right, screenHeight - topScreen.bottom, GL_COLOR_BUFFER_BIT, GL_LINEAR
topScreen.left, screenHeight - topScreen.top, );
topScreen.right, screenHeight - topScreen.bottom,
GL_COLOR_BUFFER_BIT, GL_LINEAR);
// Remove the black bars on the bottom screen // Remove the black bars on the bottom screen
glBlitFramebuffer( glBlitFramebuffer(
40, Constants.N3DS_HALF_HEIGHT, 40, Constants.N3DS_HALF_HEIGHT, Constants.N3DS_WIDTH - 40, 0, bottomScreen.left, screenHeight - bottomScreen.top, bottomScreen.right,
Constants.N3DS_WIDTH - 40, 0, screenHeight - bottomScreen.bottom, GL_COLOR_BUFFER_BIT, GL_LINEAR
bottomScreen.left, screenHeight - bottomScreen.top, );
bottomScreen.right, screenHeight - bottomScreen.bottom,
GL_COLOR_BUFFER_BIT, GL_LINEAR);
} }
} }

View file

@ -4,9 +4,7 @@ import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.panda3ds.pandroid.math.Vector2; import com.panda3ds.pandroid.math.Vector2;
import com.panda3ds.pandroid.utils.Constants; import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.view.controller.TouchEvent; import com.panda3ds.pandroid.view.controller.TouchEvent;
@ -26,9 +24,7 @@ public class PandaGlSurfaceView extends GLSurfaceView implements TouchScreenNode
setRenderer(renderer); setRenderer(renderer);
} }
public ConsoleRenderer getRenderer() { public ConsoleRenderer getRenderer() { return renderer; }
return renderer;
}
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

View file

@ -2,7 +2,6 @@ package com.panda3ds.pandroid.view;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import com.panda3ds.pandroid.AlberDriver; import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.R; import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.utils.Constants; import com.panda3ds.pandroid.utils.Constants;
@ -11,52 +10,39 @@ import com.panda3ds.pandroid.view.controller.nodes.Button;
import com.panda3ds.pandroid.view.controller.nodes.Joystick; import com.panda3ds.pandroid.view.controller.nodes.Joystick;
public class PandaLayoutController extends ControllerLayout { public class PandaLayoutController extends ControllerLayout {
public PandaLayoutController(Context context) { public PandaLayoutController(Context context) { super(context); }
super(context);
}
public PandaLayoutController(Context context, AttributeSet attrs) { public PandaLayoutController(Context context, AttributeSet attrs) { super(context, attrs); }
super(context, attrs);
}
public PandaLayoutController(Context context, AttributeSet attrs, int defStyleAttr) { public PandaLayoutController(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
super(context, attrs, defStyleAttr);
}
public PandaLayoutController(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public PandaLayoutController(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
} }
public void initialize(){ public void initialize() {
int[] keyButtonList = { int[] keyButtonList = {R.id.button_a, Constants.INPUT_KEY_A, R.id.button_b, Constants.INPUT_KEY_B,
R.id.button_a, Constants.INPUT_KEY_A, R.id.button_y, Constants.INPUT_KEY_Y, R.id.button_x, Constants.INPUT_KEY_X,
R.id.button_b, Constants.INPUT_KEY_B,
R.id.button_y, Constants.INPUT_KEY_Y,
R.id.button_x, Constants.INPUT_KEY_X,
R.id.button_left, Constants.INPUT_KEY_LEFT, R.id.button_left, Constants.INPUT_KEY_LEFT, R.id.button_right, Constants.INPUT_KEY_RIGHT,
R.id.button_right, Constants.INPUT_KEY_RIGHT, R.id.button_up, Constants.INPUT_KEY_UP, R.id.button_down, Constants.INPUT_KEY_DOWN,
R.id.button_up, Constants.INPUT_KEY_UP,
R.id.button_down, Constants.INPUT_KEY_DOWN,
R.id.button_start, Constants.INPUT_KEY_START, R.id.button_start, Constants.INPUT_KEY_START, R.id.button_select, Constants.INPUT_KEY_SELECT,
R.id.button_select, Constants.INPUT_KEY_SELECT,
R.id.button_l, Constants.INPUT_KEY_L, R.id.button_l, Constants.INPUT_KEY_L, R.id.button_r, Constants.INPUT_KEY_R};
R.id.button_r, Constants.INPUT_KEY_R
};
for (int i = 0; i < keyButtonList.length; i+=2){ for (int i = 0; i < keyButtonList.length; i += 2) {
final int keyCode = keyButtonList[i+1]; final int keyCode = keyButtonList[i + 1];
((Button)findViewById(keyButtonList[i])).setStateListener((btn, pressed)->{ ((Button) findViewById(keyButtonList[i])).setStateListener((btn, pressed) -> {
if (pressed) AlberDriver.KeyDown(keyCode); if (pressed)
else AlberDriver.KeyUp(keyCode); AlberDriver.KeyDown(keyCode);
else
AlberDriver.KeyUp(keyCode);
}); });
} }
((Joystick)findViewById(R.id.left_analog)) ((Joystick) findViewById(R.id.left_analog)).setJoystickListener((joystick, axisX, axisY) -> {
.setJoystickListener((joystick, axisX, axisY) -> { AlberDriver.SetCirclepadAxis((int) (axisX * 0x9C), (int) (axisY * 0x9C) * -1);
AlberDriver.SetCirclepadAxis((int)(axisX*0x9C), (int)(axisY*0x9C)*-1);
}); });
refreshChildren(); refreshChildren();

View file

@ -7,51 +7,42 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import com.panda3ds.pandroid.math.Vector2; import com.panda3ds.pandroid.math.Vector2;
import com.panda3ds.pandroid.utils.Constants; import com.panda3ds.pandroid.utils.Constants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
public class ControllerLayout extends RelativeLayout { public class ControllerLayout extends RelativeLayout {
private final HashMap<Integer, ControllerNode> activeTouchEvents = new HashMap<>(); private final HashMap<Integer, ControllerNode> activeTouchEvents = new HashMap<>();
private final ArrayList<ControllerNode> controllerNodes = new ArrayList<>(); private final ArrayList<ControllerNode> controllerNodes = new ArrayList<>();
public ControllerLayout(Context context) { public ControllerLayout(Context context) { this(context, null); }
this(context,null);
}
public ControllerLayout(Context context, AttributeSet attrs) { public ControllerLayout(Context context, AttributeSet attrs) { this(context, attrs, 0); }
this(context, attrs,0);
}
public ControllerLayout(Context context, AttributeSet attrs, int defStyleAttr) { public ControllerLayout(Context context, AttributeSet attrs, int defStyleAttr) { this(context, attrs, defStyleAttr, 0); }
this(context, attrs, defStyleAttr,0 );
}
public ControllerLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public ControllerLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
} }
public void refreshChildren(){ public void refreshChildren() {
ArrayList<ControllerNode> nodes = new ArrayList<>(); ArrayList<ControllerNode> nodes = new ArrayList<>();
populateNodesArray(this, nodes); populateNodesArray(this, nodes);
//Need Reverse: First view is in back and last view is in front for respect android View hierarchy // Need Reverse: First view is in back and last view is in front for respect android View hierarchy
Collections.reverse(nodes); Collections.reverse(nodes);
controllerNodes.clear(); controllerNodes.clear();
controllerNodes.addAll(nodes); controllerNodes.addAll(nodes);
} }
private void populateNodesArray(ViewGroup group, ArrayList<ControllerNode> list){ private void populateNodesArray(ViewGroup group, ArrayList<ControllerNode> list) {
for (int i = 0; i < group.getChildCount(); i++){ for (int i = 0; i < group.getChildCount(); i++) {
View view = group.getChildAt(i); View view = group.getChildAt(i);
if(view instanceof ControllerNode){ if (view instanceof ControllerNode) {
list.add((ControllerNode) view); list.add((ControllerNode) view);
} else if (view instanceof ViewGroup) { } else if (view instanceof ViewGroup) {
populateNodesArray((ViewGroup) view, list); populateNodesArray((ViewGroup) view, list);
@ -63,20 +54,20 @@ public class ControllerLayout extends RelativeLayout {
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
int index = event.getActionIndex(); int index = event.getActionIndex();
switch (event.getActionMasked()){ switch (event.getActionMasked()) {
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_POINTER_UP: { case MotionEvent.ACTION_POINTER_UP: {
int id = event.getPointerId(index); int id = event.getPointerId(index);
processTouch(true, event.getX(index), event.getY(index), id); processTouch(true, event.getX(index), event.getY(index), id);
}break; } break;
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN: { case MotionEvent.ACTION_POINTER_DOWN: {
int id = event.getPointerId(index); int id = event.getPointerId(index);
processTouch(false, event.getX(index), event.getY(index), id); processTouch(false, event.getX(index), event.getY(index), id);
}break; } break;
case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_MOVE:
for (int id = 0; id < event.getPointerCount(); id++){ for (int id = 0; id < event.getPointerCount(); id++) {
processTouch(false, event.getX(id), event.getY(id), id); processTouch(false, event.getX(id), event.getY(id), id);
} }
break; break;
@ -84,27 +75,27 @@ public class ControllerLayout extends RelativeLayout {
return true; return true;
} }
private void processTouch(boolean up, float x, float y, int index){ private void processTouch(boolean up, float x, float y, int index) {
int[] globalPosition = new int[2]; int[] globalPosition = new int[2];
getLocationInWindow(globalPosition); getLocationInWindow(globalPosition);
int action = TouchEvent.ACTION_MOVE; int action = TouchEvent.ACTION_MOVE;
if ((!activeTouchEvents.containsKey(index))){ if ((!activeTouchEvents.containsKey(index))) {
if (up)return; if (up) return;
ControllerNode node = null; ControllerNode node = null;
for (ControllerNode item: controllerNodes){ for (ControllerNode item : controllerNodes) {
Vector2 pos = item.getPosition(); Vector2 pos = item.getPosition();
Vector2 size= item.getSize(); Vector2 size = item.getSize();
float cx = (pos.x - globalPosition[0]); float cx = (pos.x - globalPosition[0]);
float cy = (pos.y - globalPosition[1]); float cy = (pos.y - globalPosition[1]);
if(item.isVisible() && x > cx && x < cx+size.x && y > cy && y < cy+size.y){ if (item.isVisible() && x > cx && x < cx + size.x && y > cy && y < cy + size.y) {
node = item; node = item;
break; break;
} }
} }
if (node != null){ if (node != null) {
activeTouchEvents.put(index, node); activeTouchEvents.put(index, node);
action = TouchEvent.ACTION_DOWN; action = TouchEvent.ACTION_DOWN;
} else { } else {
@ -122,9 +113,9 @@ public class ControllerLayout extends RelativeLayout {
x -= pos.x; x -= pos.x;
y -= pos.y; y -= pos.y;
node.onTouch(new TouchEvent(x,y,action)); node.onTouch(new TouchEvent(x, y, action));
if(up){ if (up) {
activeTouchEvents.remove(index); activeTouchEvents.remove(index);
} }
} }
@ -152,5 +143,4 @@ public class ControllerLayout extends RelativeLayout {
public boolean onInterceptTouchEvent(MotionEvent ev) { public boolean onInterceptTouchEvent(MotionEvent ev) {
return true; return true;
} }
} }

View file

@ -1,16 +1,12 @@
package com.panda3ds.pandroid.view.controller; package com.panda3ds.pandroid.view.controller;
import android.view.View; import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.panda3ds.pandroid.math.Vector2; import com.panda3ds.pandroid.math.Vector2;
public interface ControllerNode { public interface ControllerNode {
@NonNull @NonNull
default Vector2 getPosition(){ default Vector2 getPosition() {
View me = (View) this; View me = (View) this;
int[] position = new int[2]; int[] position = new int[2];
@ -18,9 +14,7 @@ public interface ControllerNode {
return new Vector2(position[0], position[1]); return new Vector2(position[0], position[1]);
} }
default boolean isVisible(){ default boolean isVisible() { return ((View) this).isShown(); }
return ((View)this).isShown();
}
@NonNull Vector2 getSize(); @NonNull Vector2 getSize();

View file

@ -6,21 +6,15 @@ public class TouchEvent {
public static final int ACTION_UP = 2; public static final int ACTION_UP = 2;
private final int action; private final int action;
private final float x,y; private final float x, y;
public float getX() { public float getX() { return x; }
return x;
}
public float getY() { public float getY() { return y; }
return y;
}
public int getAction() { public int getAction() { return action; }
return action;
}
public TouchEvent(float x, float y, int action){ public TouchEvent(float x, float y, int action) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.action = action; this.action = action;

View file

@ -2,23 +2,15 @@ package com.panda3ds.pandroid.view.controller.nodes;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView; import androidx.appcompat.widget.AppCompatTextView;
import com.panda3ds.pandroid.view.controller.ControllerNode; import com.panda3ds.pandroid.view.controller.ControllerNode;
public abstract class BasicControllerNode extends AppCompatTextView implements ControllerNode { public abstract class BasicControllerNode extends AppCompatTextView implements ControllerNode {
public BasicControllerNode(@NonNull Context context) { public BasicControllerNode(@NonNull Context context) { super(context); }
super(context);
}
public BasicControllerNode(@NonNull Context context, @Nullable AttributeSet attrs) { public BasicControllerNode(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); }
super(context, attrs);
}
public BasicControllerNode(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { public BasicControllerNode(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
super(context, attrs, defStyleAttr);
}
} }

View file

@ -5,11 +5,9 @@ import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.Gravity; import android.view.Gravity;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView; import androidx.appcompat.widget.AppCompatTextView;
import com.panda3ds.pandroid.math.Vector2; import com.panda3ds.pandroid.math.Vector2;
import com.panda3ds.pandroid.view.controller.ControllerNode; import com.panda3ds.pandroid.view.controller.ControllerNode;
import com.panda3ds.pandroid.view.controller.TouchEvent; import com.panda3ds.pandroid.view.controller.TouchEvent;
@ -17,7 +15,7 @@ import com.panda3ds.pandroid.view.controller.listeners.ButtonStateListener;
public class Button extends BasicControllerNode { public class Button extends BasicControllerNode {
private boolean pressed = false; private boolean pressed = false;
private int width,height; private int width, height;
private ButtonStateListener stateListener; private ButtonStateListener stateListener;
@ -43,30 +41,26 @@ public class Button extends BasicControllerNode {
height = getHeight(); height = getHeight();
} }
private void init(){ private void init() {
setTextAlignment(TEXT_ALIGNMENT_CENTER); setTextAlignment(TEXT_ALIGNMENT_CENTER);
setGravity(Gravity.CENTER); setGravity(Gravity.CENTER);
} }
public void setStateListener(ButtonStateListener stateListener) { public void setStateListener(ButtonStateListener stateListener) { this.stateListener = stateListener; }
this.stateListener = stateListener;
}
public boolean isPressed() { public boolean isPressed() { return pressed; }
return pressed;
}
@NonNull @NonNull
@Override @Override
public Vector2 getSize() { public Vector2 getSize() {
return new Vector2(width,height); return new Vector2(width, height);
} }
@Override @Override
public void onTouch(TouchEvent event) { public void onTouch(TouchEvent event) {
pressed = event.getAction() != TouchEvent.ACTION_UP; pressed = event.getAction() != TouchEvent.ACTION_UP;
setAlpha(pressed ? 0.2F : 1.0F); setAlpha(pressed ? 0.2F : 1.0F);
if (stateListener != null){ if (stateListener != null) {
stateListener.onButtonPressedChange(this, pressed); stateListener.onButtonPressedChange(this, pressed);
} }
} }

View file

@ -6,32 +6,25 @@ import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView; import androidx.appcompat.widget.AppCompatTextView;
import com.panda3ds.pandroid.math.Vector2; import com.panda3ds.pandroid.math.Vector2;
import com.panda3ds.pandroid.view.controller.ControllerNode; import com.panda3ds.pandroid.view.controller.ControllerNode;
import com.panda3ds.pandroid.view.controller.TouchEvent; import com.panda3ds.pandroid.view.controller.TouchEvent;
import com.panda3ds.pandroid.view.controller.listeners.JoystickListener; import com.panda3ds.pandroid.view.controller.listeners.JoystickListener;
public class Joystick extends BasicControllerNode implements ControllerNode { public class Joystick extends BasicControllerNode implements ControllerNode {
private float stick_x = 0; private float stick_x = 0;
private float stick_y = 0; private float stick_y = 0;
private int size_width = 0; private int size_width = 0;
private int size_height= 0; private int size_height = 0;
private JoystickListener joystickListener; private JoystickListener joystickListener;
public Joystick(Context context) { public Joystick(Context context) { this(context, null); }
this(context,null);
}
public Joystick(Context context, AttributeSet attrs) { public Joystick(Context context, AttributeSet attrs) { this(context, attrs, 0); }
this(context, attrs,0);
}
public Joystick(Context context, AttributeSet attrs, int defStyleAttr) { public Joystick(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
@ -52,7 +45,7 @@ public class Joystick extends BasicControllerNode implements ControllerNode {
size_width = getWidth(); size_width = getWidth();
size_height = getHeight(); size_height = getHeight();
int analogIconSize = size_width-getPaddingLeft(); int analogIconSize = size_width - getPaddingLeft();
float middleIconSize = analogIconSize / 2.0F; float middleIconSize = analogIconSize / 2.0F;
float middle = size_width / 2.0F; float middle = size_width / 2.0F;
@ -65,65 +58,55 @@ public class Joystick extends BasicControllerNode implements ControllerNode {
float radius = Vector2.distance(0.0F, 0.0F, Math.abs(tx), Math.abs(ty)); float radius = Vector2.distance(0.0F, 0.0F, Math.abs(tx), Math.abs(ty));
radius = Math.min(maxDistance, radius); radius = Math.min(maxDistance, radius);
double deg = Math.atan2(ty,tx) * (180.0/Math.PI); double deg = Math.atan2(ty, tx) * (180.0 / Math.PI);
float rx = (float) (radius*Math.cos(Math.PI * 2 * deg/360.0)); float rx = (float) (radius * Math.cos(Math.PI * 2 * deg / 360.0));
float ry = (float) (radius*Math.sin(Math.PI * 2 * deg/360.0)); float ry = (float) (radius * Math.sin(Math.PI * 2 * deg / 360.0));
stick_x = Math.max(-1.0f, Math.min(1.0f, stick_x)); stick_x = Math.max(-1.0f, Math.min(1.0f, stick_x));
stick_y = Math.max(-1.0f, Math.min(1.0f, stick_y)); stick_y = Math.max(-1.0f, Math.min(1.0f, stick_y));
float x = middle - middleIconSize + rx;
float x = middle-middleIconSize+rx; float y = middle - middleIconSize + ry;
float y = middle-middleIconSize+ry;
Drawable foreground = getForeground(); Drawable foreground = getForeground();
if (foreground != null){ if (foreground != null) {
foreground.setBounds((int) x, (int) y, (int) (x+analogIconSize), (int) (y+analogIconSize)); foreground.setBounds((int) x, (int) y, (int) (x + analogIconSize), (int) (y + analogIconSize));
foreground.draw(canvas); foreground.draw(canvas);
} else { } else {
canvas.drawOval(x, y, x+analogIconSize,y+analogIconSize,paint); canvas.drawOval(x, y, x + analogIconSize, y + analogIconSize, paint);
} }
} }
public Vector2 getAxis() { public Vector2 getAxis() { return new Vector2(Math.max(-1.0F, Math.min(1.0F, stick_x)), Math.max(-1.0F, Math.min(1.0F, stick_y))); }
return new Vector2(
Math.max(-1.0F, Math.min(1.0F, stick_x)),
Math.max(-1.0F, Math.min(1.0F, stick_y))
);
}
public void setJoystickListener(JoystickListener joystickListener) { public void setJoystickListener(JoystickListener joystickListener) { this.joystickListener = joystickListener; }
this.joystickListener = joystickListener;
}
@NonNull @NonNull
@Override @Override
public Vector2 getSize() { public Vector2 getSize() {
return new Vector2(size_width,size_height); return new Vector2(size_width, size_height);
} }
@Override @Override
public void onTouch(TouchEvent event) { public void onTouch(TouchEvent event) {
float middle = size_width / 2.0F;
float middle = size_width/2.0F;
float x = event.getX(); float x = event.getX();
float y = event.getY(); float y = event.getY();
x = Math.max(0, Math.min(middle*2, x)); x = Math.max(0, Math.min(middle * 2, x));
y = Math.max(0, Math.min(middle*2, y)); y = Math.max(0, Math.min(middle * 2, y));
stick_x = ((x-middle)/middle); stick_x = ((x - middle) / middle);
stick_y = ((y-middle)/middle); stick_y = ((y - middle) / middle);
if (event.getAction() == TouchEvent.ACTION_UP){ if (event.getAction() == TouchEvent.ACTION_UP) {
stick_x = 0; stick_x = 0;
stick_y = 0; stick_y = 0;
} }
if (joystickListener != null){ if (joystickListener != null) {
joystickListener.onJoystickAxisChange(this, stick_x, stick_y); joystickListener.onJoystickAxisChange(this, stick_x, stick_y);
} }

View file

@ -3,7 +3,6 @@ package com.panda3ds.pandroid.view.controller.nodes;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import com.panda3ds.pandroid.AlberDriver; import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.R; import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.utils.Constants; import com.panda3ds.pandroid.utils.Constants;
@ -12,26 +11,26 @@ import com.panda3ds.pandroid.view.controller.TouchEvent;
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer; import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;
public interface TouchScreenNodeImpl extends ControllerNode { public interface TouchScreenNodeImpl extends ControllerNode {
default void onTouchScreenPress(ConsoleRenderer renderer, TouchEvent event){ default void onTouchScreenPress(ConsoleRenderer renderer, TouchEvent event) {
View me = (View) this; View me = (View) this;
boolean hasDownEvent = me.getTag(R.id.TagEventHasDown) != null && (boolean) me.getTag(R.id.TagEventHasDown); boolean hasDownEvent = me.getTag(R.id.TagEventHasDown) != null && (boolean) me.getTag(R.id.TagEventHasDown);
Rect bounds = renderer.getLayout().getBottomDisplayBounds();; Rect bounds = renderer.getLayout().getBottomDisplayBounds();
;
if (event.getX() >= bounds.left && event.getY() >= bounds.top && event.getX() <= bounds.right && event.getY() <= bounds.bottom){ if (event.getX() >= bounds.left && event.getY() >= bounds.top && event.getX() <= bounds.right && event.getY() <= bounds.bottom) {
int x = (int) (event.getX() - bounds.left); int x = (int) (event.getX() - bounds.left);
int y = (int) (event.getY() - bounds.top); int y = (int) (event.getY() - bounds.top);
x = Math.round((x/(float)bounds.width())*320); x = Math.round((x / (float) bounds.width()) * 320);
y = Math.round((y/(float)bounds.height())*240); y = Math.round((y / (float) bounds.height()) * 240);
AlberDriver.TouchScreenDown(x,y); AlberDriver.TouchScreenDown(x, y);
me.setTag(R.id.TagEventHasDown, true); me.setTag(R.id.TagEventHasDown, true);
} }
if (hasDownEvent && event.getAction() == TouchEvent.ACTION_UP){ if (hasDownEvent && event.getAction() == TouchEvent.ACTION_UP) {
AlberDriver.TouchScreenUp(); AlberDriver.TouchScreenUp();
me.setTag(R.id.TagEventHasDown, false); me.setTag(R.id.TagEventHasDown, false);
} }

View file

@ -1,7 +1,6 @@
package com.panda3ds.pandroid.view.renderer.layout; package com.panda3ds.pandroid.view.renderer.layout;
import android.graphics.Rect; import android.graphics.Rect;
import com.panda3ds.pandroid.math.Vector2; import com.panda3ds.pandroid.math.Vector2;
public interface ConsoleLayout { public interface ConsoleLayout {

View file

@ -2,7 +2,6 @@ package com.panda3ds.pandroid.view.renderer.layout;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Size; import android.util.Size;
import com.panda3ds.pandroid.math.Vector2; import com.panda3ds.pandroid.math.Vector2;
public class DefaultScreenLayout implements ConsoleLayout { public class DefaultScreenLayout implements ConsoleLayout {
@ -21,54 +20,51 @@ public class DefaultScreenLayout implements ConsoleLayout {
@Override @Override
public void setBottomDisplaySourceSize(int width, int height) { public void setBottomDisplaySourceSize(int width, int height) {
bottomSourceSize.set(width,height); bottomSourceSize.set(width, height);
updateBounds(); updateBounds();
} }
@Override @Override
public void setTopDisplaySourceSize(int width, int height) { public void setTopDisplaySourceSize(int width, int height) {
topSourceSize.set(width,height); topSourceSize.set(width, height);
updateBounds(); updateBounds();
} }
private void updateBounds(){ private void updateBounds() {
int screenWidth = (int) screenSize.x; int screenWidth = (int) screenSize.x;
int screenHeight = (int) screenSize.y; int screenHeight = (int) screenSize.y;
if (screenWidth > screenHeight){ if (screenWidth > screenHeight) {
int topDisplayWidth = (int) ((screenHeight / topSourceSize.y) * topSourceSize.x); int topDisplayWidth = (int) ((screenHeight / topSourceSize.y) * topSourceSize.x);
int topDisplayHeight = screenHeight; int topDisplayHeight = screenHeight;
if (topDisplayWidth > (screenWidth*0.7)){ if (topDisplayWidth > (screenWidth * 0.7)) {
topDisplayWidth = (int) (screenWidth * 0.7); topDisplayWidth = (int) (screenWidth * 0.7);
topDisplayHeight = (int) ((topDisplayWidth/topSourceSize.x)* topSourceSize.y); topDisplayHeight = (int) ((topDisplayWidth / topSourceSize.x) * topSourceSize.y);
} }
int bottomDisplayHeight = (int) (((screenWidth-topDisplayWidth)/ bottomSourceSize.x)* bottomSourceSize.y); int bottomDisplayHeight = (int) (((screenWidth - topDisplayWidth) / bottomSourceSize.x) * bottomSourceSize.y);
topDisplay.set(0, 0, topDisplayWidth, topDisplayHeight); topDisplay.set(0, 0, topDisplayWidth, topDisplayHeight);
bottomDisplay.set(topDisplayWidth, 0, topDisplayWidth+(screenWidth-topDisplayWidth), bottomDisplayHeight); bottomDisplay.set(topDisplayWidth, 0, topDisplayWidth + (screenWidth - topDisplayWidth), bottomDisplayHeight);
} else { } else {
int topScreenHeight = (int) ((screenWidth/ topSourceSize.x) * topSourceSize.y); int topScreenHeight = (int) ((screenWidth / topSourceSize.x) * topSourceSize.y);
topDisplay.set(0,0,screenWidth,topScreenHeight); topDisplay.set(0, 0, screenWidth, topScreenHeight);
int bottomDisplayHeight = (int)((screenWidth/ bottomSourceSize.x) * bottomSourceSize.y); int bottomDisplayHeight = (int) ((screenWidth / bottomSourceSize.x) * bottomSourceSize.y);
int bottomDisplayWidth = screenWidth; int bottomDisplayWidth = screenWidth;
int bottomDisplayX = 0; int bottomDisplayX = 0;
if (topScreenHeight + bottomDisplayHeight > screenHeight){ if (topScreenHeight + bottomDisplayHeight > screenHeight) {
bottomDisplayHeight = (screenHeight-topScreenHeight); bottomDisplayHeight = (screenHeight - topScreenHeight);
bottomDisplayWidth = (int) ((bottomDisplayHeight/ bottomSourceSize.y)*bottomSourceSize.x); bottomDisplayWidth = (int) ((bottomDisplayHeight / bottomSourceSize.y) * bottomSourceSize.x);
bottomDisplayX = (screenWidth-bottomDisplayX)/2; bottomDisplayX = (screenWidth - bottomDisplayX) / 2;
} }
topDisplay.set(0,0, screenWidth,topScreenHeight); topDisplay.set(0, 0, screenWidth, topScreenHeight);
bottomDisplay.set(bottomDisplayX, topScreenHeight, bottomDisplayX+bottomDisplayWidth,topScreenHeight+bottomDisplayHeight); bottomDisplay.set(bottomDisplayX, topScreenHeight, bottomDisplayX + bottomDisplayWidth, topScreenHeight + bottomDisplayHeight);
} }
} }
@Override @Override
public Rect getBottomDisplayBounds() { public Rect getBottomDisplayBounds() {
return bottomDisplay; return bottomDisplay;