mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-07 19:41:38 +12:00
Android cleanup and bugfixing
This commit is contained in:
parent
02496b57eb
commit
914193a765
34 changed files with 153 additions and 332 deletions
|
@ -30,6 +30,7 @@ public class BaseActivity extends AppCompatActivity {
|
|||
private void applyTheme() {
|
||||
currentTheme = PandroidApplication.getThemeId();
|
||||
setTheme(currentTheme);
|
||||
|
||||
if (GlobalConfig.get(GlobalConfig.KEY_APP_THEME) == GlobalConfig.THEME_ANDROID) {
|
||||
DynamicColors.applyToActivityIfAvailable(this);
|
||||
}
|
||||
|
|
|
@ -95,13 +95,14 @@ public class GameActivity extends BaseActivity implements EmulatorCallback {
|
|||
}
|
||||
}
|
||||
|
||||
private void goToPictureInPicture() {
|
||||
private void enablePIP() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
builder.setAutoEnterEnabled(true);
|
||||
builder.setSeamlessResizeEnabled(true);
|
||||
}
|
||||
|
||||
builder.setAspectRatio(new Rational(10, 14));
|
||||
enterPictureInPictureMode(builder.build());
|
||||
}
|
||||
|
@ -114,7 +115,7 @@ public class GameActivity extends BaseActivity implements EmulatorCallback {
|
|||
InputHandler.reset();
|
||||
if (GlobalConfig.get(GlobalConfig.KEY_PICTURE_IN_PICTURE)) {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
||||
goToPictureInPicture();
|
||||
enablePIP();
|
||||
}
|
||||
} else {
|
||||
drawerFragment.open();
|
||||
|
@ -158,8 +159,10 @@ public class GameActivity extends BaseActivity implements EmulatorCallback {
|
|||
@Override
|
||||
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
|
||||
super.onPictureInPictureModeChanged(isInPictureInPictureMode);
|
||||
|
||||
changeOverlayVisibility(!isInPictureInPictureMode && GlobalConfig.get(GlobalConfig.KEY_SCREEN_GAMEPAD_VISIBLE));
|
||||
findViewById(R.id.hide_screen_controller).setVisibility(isInPictureInPictureMode ? View.INVISIBLE : View.VISIBLE);
|
||||
|
||||
if (isInPictureInPictureMode) {
|
||||
getWindow().getDecorView().postDelayed(drawerFragment::close, 250);
|
||||
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
||||
|
@ -173,6 +176,7 @@ public class GameActivity extends BaseActivity implements EmulatorCallback {
|
|||
if (AlberDriver.HasRomLoaded()) {
|
||||
AlberDriver.Finalize();
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,10 +33,10 @@ public class MainActivity extends BaseActivity implements NavigationBarView.OnIt
|
|||
public void onBackPressed() {
|
||||
if (navigationBar.getSelectedItemId() != R.id.games) {
|
||||
navigationBar.setSelectedItemId(R.id.games);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
|
|
|
@ -18,11 +18,15 @@ public class BaseSheetDialog extends BottomSheetDialog {
|
|||
private final LinearLayout contentView;
|
||||
public BaseSheetDialog(@NonNull Context context) {
|
||||
super(CompatUtils.findActivity(context));
|
||||
|
||||
int width = CompatUtils.findActivity(context).getWindow().getDecorView().getMeasuredWidth();
|
||||
int height = CompatUtils.findActivity(context).getWindow().getDecorView().getMeasuredHeight();
|
||||
getBehavior().setPeekHeight((int) (height*0.87));
|
||||
float heightScale = 0.87f; // What percentage of the screen's height to use up
|
||||
|
||||
getBehavior().setPeekHeight((int) (height * heightScale));
|
||||
getBehavior().setMaxHeight((int) (height * heightScale));
|
||||
getBehavior().setMaxWidth(width);
|
||||
getBehavior().setMaxHeight((int) (height*0.87));
|
||||
|
||||
super.setContentView(R.layout.dialog_bottom_sheet);
|
||||
contentView = super.findViewById(R.id.content);
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ public class GameAboutDialog extends BaseSheetDialog {
|
|||
}
|
||||
}
|
||||
|
||||
// Make a shortcut for a specific game
|
||||
private void makeShortcut() {
|
||||
Context context = CompatUtils.findActivity(getContext());
|
||||
ShortcutInfoCompat.Builder shortcut = new ShortcutInfoCompat.Builder(context, game.getId());
|
||||
|
@ -69,6 +70,7 @@ public class GameAboutDialog extends BaseSheetDialog {
|
|||
} else {
|
||||
shortcut.setIcon(IconCompat.createWithResource(getContext(), R.mipmap.ic_launcher));
|
||||
}
|
||||
|
||||
shortcut.setActivity(new ComponentName(context, GameLauncher.class));
|
||||
shortcut.setLongLabel(game.getTitle());
|
||||
shortcut.setShortLabel(game.getTitle());
|
||||
|
|
|
@ -61,7 +61,6 @@ public class DrawerFragment extends Fragment implements DrawerLayout.DrawerListe
|
|||
}
|
||||
((AppCompatTextView)drawerLayout.findViewById(R.id.game_title)).setText(game.getTitle());
|
||||
((AppCompatTextView)drawerLayout.findViewById(R.id.game_publisher)).setText(game.getPublisher());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.panda3ds.pandroid.data.config.GlobalConfig;
|
|||
public interface EmulatorCallback {
|
||||
void onBackPressed();
|
||||
void swapScreens(int index);
|
||||
|
||||
default void swapScreens() {
|
||||
swapScreens(GlobalConfig.get(GlobalConfig.KEY_CURRENT_DS_LAYOUT) + 1);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public class GameLauncher extends BaseActivity {
|
|||
if (uri != null && uri.getScheme().equals("pandroid-game")) {
|
||||
String gameId = uri.getAuthority();
|
||||
GameMetadata game = GameUtils.findGameById(gameId);
|
||||
|
||||
if (game != null) {
|
||||
GameUtils.launch(this, game);
|
||||
} else {
|
||||
|
@ -32,6 +33,7 @@ public class GameLauncher extends BaseActivity {
|
|||
ShortcutManagerCompat.removeLongLivedShortcuts(this, Arrays.asList(gameId));
|
||||
}
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class SettingsFragment extends BasePreferenceFragment {
|
|||
Context context = PandroidApplication.getAppContext();
|
||||
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
|
||||
} catch (Exception e) {
|
||||
return "???";
|
||||
return "Error: Unknown version";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,14 +51,14 @@ public class GamesFoldersPreferences extends BasePreferenceFragment implements A
|
|||
screen.addPreference(preference);
|
||||
}
|
||||
|
||||
Preference add = new Preference(screen.getContext());
|
||||
add.setTitle(R.string.import_folder);
|
||||
add.setIcon(R.drawable.ic_add);
|
||||
add.setOnPreferenceClickListener(preference -> {
|
||||
Preference pref = new Preference(screen.getContext());
|
||||
pref.setTitle(R.string.import_folder);
|
||||
pref.setIcon(R.drawable.ic_add);
|
||||
pref.setOnPreferenceClickListener(preference -> {
|
||||
pickFolderRequest.launch(null);
|
||||
return false;
|
||||
});
|
||||
screen.addPreference(add);
|
||||
screen.addPreference(pref);
|
||||
}
|
||||
|
||||
private void showFolderInfo(GamesFolder folder) {
|
||||
|
@ -83,6 +83,7 @@ public class GamesFoldersPreferences extends BasePreferenceFragment implements A
|
|||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (pickFolderRequest != null) {
|
||||
pickFolderRequest.unregister();
|
||||
pickFolderRequest = null;
|
||||
|
|
|
@ -80,7 +80,7 @@ public class InputPreferences extends BasePreferenceFragment {
|
|||
@SuppressLint("RestrictedApi")
|
||||
private void refreshScreenProfileList() {
|
||||
PreferenceCategory category = findPreference(ID_GAMEPAD_PROFILE_LIST);
|
||||
Preference add = category.getPreference(category.getPreferenceCount() - 1);
|
||||
Preference pref = category.getPreference(category.getPreferenceCount() - 1);
|
||||
category.removeAll();
|
||||
category.setOrderingAsAdded(true);
|
||||
|
||||
|
@ -97,8 +97,8 @@ public class InputPreferences extends BasePreferenceFragment {
|
|||
category.addPreference(item);
|
||||
}
|
||||
|
||||
add.setOrder(category.getPreferenceCount());
|
||||
category.addPreference(add);
|
||||
pref.setOrder(category.getPreferenceCount());
|
||||
category.addPreference(pref);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,6 +23,7 @@ public class ScreenLayoutsPreference extends BasePreferenceFragment {
|
|||
public void refresh() {
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
screen.removeAll();
|
||||
|
||||
for (int i = 0; i < DsLayoutManager.getLayoutCount(); i++) {
|
||||
Preference pref = new Preference(getPreferenceScreen().getContext());
|
||||
pref.setIconSpaceReserved(false);
|
||||
|
|
|
@ -79,6 +79,7 @@ public class AppDataDocumentProvider extends DocumentsProvider {
|
|||
.add(Root.COLUMN_TITLE, context().getString(R.string.app_name))
|
||||
.add(Root.COLUMN_MIME_TYPES, "*/*")
|
||||
.add(Root.COLUMN_ICON, R.mipmap.ic_launcher);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
|
@ -87,6 +88,7 @@ public class AppDataDocumentProvider extends DocumentsProvider {
|
|||
File file = obtainFile(documentId);
|
||||
MatrixCursor cursor = new MatrixCursor(projection == null ? DEFAULT_DOCUMENT_PROJECTION : projection);
|
||||
includeFile(cursor, file);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
|
@ -126,17 +128,17 @@ public class AppDataDocumentProvider extends DocumentsProvider {
|
|||
File parent = obtainFile(parentDocumentId);
|
||||
File file = new File(parent, displayName);
|
||||
if (!parent.exists()) {
|
||||
throw new FileNotFoundException("Parent don't exists");
|
||||
throw new FileNotFoundException("Parent doesn't exist");
|
||||
}
|
||||
|
||||
if (Objects.equals(mimeType, Document.MIME_TYPE_DIR)) {
|
||||
if (!file.mkdirs()) {
|
||||
throw new FileNotFoundException("Error on create directory");
|
||||
throw new FileNotFoundException("Error while creating directory");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if (!file.createNewFile()) {
|
||||
throw new Exception("Error on create file");
|
||||
throw new Exception("Error while creating file");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new FileNotFoundException(e.getMessage());
|
||||
|
|
|
@ -64,6 +64,7 @@ public class GlobalConfig {
|
|||
if (data.extras.has(key.name)) {
|
||||
return gson.fromJson(data.extras.getAsJsonObject(key.name), dataClass);
|
||||
}
|
||||
|
||||
return gson.fromJson("{}", dataClass);
|
||||
}
|
||||
|
||||
|
@ -71,6 +72,7 @@ public class GlobalConfig {
|
|||
if (data.extras.has(key.name)) {
|
||||
data.extras.remove(key.name);
|
||||
}
|
||||
|
||||
data.extras.add(key.name, gson.toJsonTree(value));
|
||||
writeChanges();
|
||||
}
|
||||
|
|
|
@ -86,6 +86,7 @@ public class GameMetadata {
|
|||
if (icon != null) {
|
||||
GameUtils.setGameIcon(id, icon);
|
||||
}
|
||||
|
||||
this.regions = new GameRegion[]{smdh.getRegion()};
|
||||
GameUtils.writeChanges();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.HashMap;
|
|||
import java.util.UUID;
|
||||
|
||||
public class GamesFolder {
|
||||
|
||||
private final String id = UUID.randomUUID().toString();
|
||||
private final String path;
|
||||
private final HashMap<String, GameMetadata> games = new HashMap<>();
|
||||
|
@ -44,6 +43,7 @@ public class GamesFolder {
|
|||
games.remove(file);
|
||||
}
|
||||
}
|
||||
|
||||
String unknown = PandroidApplication.getAppContext().getString(R.string.unknown);
|
||||
|
||||
for (String file: FileUtils.listFiles(path)) {
|
||||
|
@ -51,8 +51,9 @@ public class GamesFolder {
|
|||
if (FileUtils.isDirectory(path) || games.containsKey(file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String ext = FileUtils.extension(path);
|
||||
if (ext.equals("3ds") || ext.equals("3dsx")){
|
||||
if (ext.equals("3ds") || ext.equals("3dsx") || ext.equals("cci") || ext.equals("cxi") || ext.equals("app") || ext.equals("ncch")) {
|
||||
String name = FileUtils.getName(path).trim().split("\\.")[0];
|
||||
games.put(file, new GameMetadata(new Uri.Builder().path(file).authority(id).scheme("folder").build().toString(), name, unknown));
|
||||
}
|
||||
|
|
|
@ -116,6 +116,7 @@ public class InputHandler {
|
|||
} else if (!keyDownEvents.containsKey(code)) {
|
||||
keyDownEvents.put(code, new InputEvent(code, 1.0f));
|
||||
}
|
||||
|
||||
for (InputEvent env: keyDownEvents.values()) {
|
||||
handleEvent(env);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ public class CompatUtils {
|
|||
} else if ((context instanceof ContextWrapper)) {
|
||||
return findActivity(((ContextWrapper) context).getBaseContext());
|
||||
}
|
||||
|
||||
return ((Activity) context);
|
||||
}
|
||||
|
||||
|
@ -33,7 +34,7 @@ public class CompatUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static float applyDimen(int unit, int size) {
|
||||
public static float applyDimensions(int unit, int size) {
|
||||
return TypedValue.applyDimension(unit, size, PandroidApplication.getAppContext().getResources().getDisplayMetrics());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ public class FileUtils {
|
|||
if (uri.getScheme().equals("content") && uri.getPath().startsWith("/" + TREE_URI)) {
|
||||
return DocumentFile.fromTreeUri(getContext(), uri);
|
||||
}
|
||||
|
||||
return singleFile;
|
||||
}
|
||||
|
||||
|
@ -264,18 +265,22 @@ public class FileUtils {
|
|||
FileUtils.createFile(path, name);
|
||||
InputStream in = getInputStream(source);
|
||||
OutputStream out = getOutputStream(fullPath);
|
||||
byte[] buffer = new byte[1024 * 128]; //128 KB
|
||||
// Make a 128KB temp buffer used for copying in chunks
|
||||
byte[] buffer = new byte[1024 * 128];
|
||||
int length;
|
||||
|
||||
while ((length = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
out.flush();
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
Log.e(Constants.LOG_TAG, "ERROR ON COPY FILE", e);
|
||||
Log.e(Constants.LOG_TAG, "Error while trying to copy file", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -163,6 +163,7 @@ public class GameUtils {
|
|||
return game;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,9 +38,11 @@ class Bounds {
|
|||
if (left > (width - right) - size) {
|
||||
right = (width - left) - size;
|
||||
}
|
||||
|
||||
if (top > (height - bottom) - size) {
|
||||
bottom = (height - top) - size;
|
||||
}
|
||||
|
||||
normalize();
|
||||
}
|
||||
}
|
|
@ -51,7 +51,7 @@ public class DsEditorView extends FrameLayout {
|
|||
public DsEditorView(Context context, int index) {
|
||||
super(context);
|
||||
layout = (DsLayout) DsLayoutManager.createLayout(index);
|
||||
SIZE_DP = CompatUtils.applyDimen(TypedValue.COMPLEX_UNIT_DIP, 1);
|
||||
SIZE_DP = CompatUtils.applyDimensions(TypedValue.COMPLEX_UNIT_DIP, 1);
|
||||
int colorBottomSelection = CompatUtils.resolveColor(context, androidx.appcompat.R.attr.colorPrimary);
|
||||
int colorTopSelection = CompatUtils.resolveColor(context, com.google.android.material.R.attr.colorAccent);
|
||||
|
||||
|
@ -71,14 +71,17 @@ public class DsEditorView extends FrameLayout {
|
|||
layout.getCurrentModel().gravity = Gravity.TOP;
|
||||
refreshLayout();
|
||||
});
|
||||
|
||||
gravityAnchor.findViewById(R.id.center).setOnClickListener(v -> {
|
||||
layout.getCurrentModel().gravity = Gravity.CENTER;
|
||||
refreshLayout();
|
||||
});
|
||||
|
||||
gravityAnchor.findViewById(R.id.down).setOnClickListener(v -> {
|
||||
layout.getCurrentModel().gravity = Gravity.BOTTOM;
|
||||
refreshLayout();
|
||||
});
|
||||
|
||||
gravityAnchor.findViewById(R.id.revert).setOnClickListener(v -> {
|
||||
layout.getCurrentModel().reverse = !layout.getCurrentModel().reverse;
|
||||
refreshLayout();
|
||||
|
@ -87,7 +90,7 @@ public class DsEditorView extends FrameLayout {
|
|||
{
|
||||
modeSelectorLayout = (LinearLayout) inflater.inflate(R.layout.ds_editor_spinner, this, false);
|
||||
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.ds_editor_spinner_label);
|
||||
spinnerAdapter.addAll("SINGLE", "RELATIVE", "ABSOLUTE");
|
||||
spinnerAdapter.addAll("Single", "Relative", "Absolute");
|
||||
modeSelector = modeSelectorLayout.findViewById(R.id.spinner);
|
||||
modeSelector.setAdapter(spinnerAdapter);
|
||||
modeSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
|
@ -149,6 +152,7 @@ public class DsEditorView extends FrameLayout {
|
|||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
super.draw(canvas);
|
||||
|
||||
if (this.width != getWidth() || this.height != getHeight()) {
|
||||
this.width = getWidth();
|
||||
this.height = getHeight();
|
||||
|
@ -172,12 +176,12 @@ public class DsEditorView extends FrameLayout {
|
|||
spacePoint.setCenterPosition(primaryDisplay.width(), (int) (SIZE_DP * 15));
|
||||
spacePoint.setText(String.valueOf((int) (data.space * 100)));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SINGLE:
|
||||
case ABSOLUTE: {
|
||||
}
|
||||
break;
|
||||
case ABSOLUTE: break;
|
||||
}
|
||||
|
||||
this.topDisplay.setSize(topDisplay.width(), topDisplay.height());
|
||||
|
@ -212,19 +216,23 @@ public class DsEditorView extends FrameLayout {
|
|||
if (landscape) {
|
||||
addView(spacePoint);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ABSOLUTE: {
|
||||
addView(aspectRatioFixLayout, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER | Gravity.TOP));
|
||||
addView(topDisplayResizer);
|
||||
addView(bottomDisplayResizer);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SINGLE: {
|
||||
addView(aspectRatioFixLayout, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER | Gravity.TOP));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
((MaterialCheckBox) aspectRatioFixLayout.findViewById(R.id.checkbox)).setChecked(layout.getCurrentModel().lockAspect);
|
||||
|
||||
modeSelector.setSelection(layout.getCurrentModel().mode.ordinal());
|
||||
|
@ -233,7 +241,6 @@ public class DsEditorView extends FrameLayout {
|
|||
}
|
||||
|
||||
private class PointView extends AppCompatTextView {
|
||||
|
||||
public PointView() {
|
||||
super(DsEditorView.this.getContext());
|
||||
setLayoutParams(new FrameLayout.LayoutParams((int) (SIZE_DP * 30), (int) (SIZE_DP * 30)));
|
||||
|
@ -302,6 +309,7 @@ public class DsEditorView extends FrameLayout {
|
|||
downEvent = new Vector2(event.getRawX(), event.getRawY());
|
||||
return true;
|
||||
}
|
||||
|
||||
preferred.move((int) (event.getRawX() - downEvent.x), (int) (event.getRawY() - downEvent.y));
|
||||
downEvent.set(event.getRawX(), event.getRawY());
|
||||
refreshPoints();
|
||||
|
@ -330,6 +338,7 @@ public class DsEditorView extends FrameLayout {
|
|||
refreshPoints();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,12 +102,7 @@ class DsLayout implements ConsoleLayout {
|
|||
(data.onlyTop ? bottomDisplay : topDisplay).set(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* RELATIVE LAYOUT:
|
||||
* ORGANIZE SCREEN IN POSITION BASED IN GRAVITY
|
||||
* AND SPACE, THE SPACE DETERMINE LANDSCAPE TOP SCREEN SIZE
|
||||
*/
|
||||
// Relative layout: Organize screen position based on gravity and space, the space determined by the top screen size in landscape mode
|
||||
private void relative(Model data) {
|
||||
int screenWidth = (int) screenSize.x;
|
||||
int screenHeight = (int) screenSize.y;
|
||||
|
@ -144,14 +139,15 @@ class DsLayout implements ConsoleLayout {
|
|||
case Gravity.CENTER: {
|
||||
bottomDisplay.offset(0, (screenHeight - bottomDisplay.height()) / 2);
|
||||
topDisplay.offset(0, (screenHeight - topDisplay.height()) / 2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Gravity.BOTTOM: {
|
||||
bottomDisplay.offset(0, (screenHeight - bottomDisplay.height()));
|
||||
topDisplay.offset(0, (screenHeight - topDisplay.height()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
int topScreenHeight = (int) ((screenWidth / topSourceSize.x) * topSourceSize.y);
|
||||
|
|
|
@ -1,152 +0,0 @@
|
|||
package com.panda3ds.pandroid.view.renderer.layout;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.panda3ds.pandroid.math.Vector2;
|
||||
|
||||
public class RelativeScreenLayout implements ConsoleLayout {
|
||||
private final Rect topDisplay = new Rect();
|
||||
private final Rect bottomDisplay = new Rect();
|
||||
|
||||
private final Vector2 screenSize = new Vector2(1.0f, 1.0f);
|
||||
private final Vector2 topSourceSize = new Vector2(1.0f, 1.0f);
|
||||
private final Vector2 bottomSourceSize = new Vector2(1.0f, 1.0f);
|
||||
|
||||
private boolean landscapeReverse = false;
|
||||
private boolean portraitReverse = false;
|
||||
private float landscapeSpace = 0.6f;
|
||||
private int landscapeGravity = Gravity.CENTER;
|
||||
private int portraitGravity = Gravity.TOP;
|
||||
|
||||
@Override
|
||||
public void update(int screenWidth, int screenHeight) {
|
||||
screenSize.set(screenWidth, screenHeight);
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBottomDisplaySourceSize(int width, int height) {
|
||||
bottomSourceSize.set(width, height);
|
||||
updateBounds();
|
||||
}
|
||||
@Override
|
||||
public void setTopDisplaySourceSize(int width, int height) {
|
||||
topSourceSize.set(width, height);
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
public void setPortraitGravity(int portraitGravity) {
|
||||
this.portraitGravity = portraitGravity;
|
||||
}
|
||||
|
||||
public void setLandscapeGravity(int landscapeGravity) {
|
||||
this.landscapeGravity = landscapeGravity;
|
||||
}
|
||||
|
||||
public void setLandscapeSpace(float landscapeSpace) {
|
||||
this.landscapeSpace = landscapeSpace;
|
||||
}
|
||||
|
||||
public void setLandscapeReverse(boolean landscapeReverse) {
|
||||
this.landscapeReverse = landscapeReverse;
|
||||
}
|
||||
|
||||
public void setPortraitReverse(boolean portraitReverse) {
|
||||
this.portraitReverse = portraitReverse;
|
||||
}
|
||||
|
||||
private void updateBounds() {
|
||||
int screenWidth = (int) screenSize.x;
|
||||
int screenHeight = (int) screenSize.y;
|
||||
|
||||
Vector2 topSourceSize = this.topSourceSize;
|
||||
Vector2 bottomSourceSize = this.bottomSourceSize;
|
||||
|
||||
Rect topDisplay = this.topDisplay;
|
||||
Rect bottomDisplay = this.bottomDisplay;
|
||||
|
||||
if ((landscapeReverse && screenWidth > screenHeight) || (portraitReverse && screenWidth < screenHeight)){
|
||||
topSourceSize = this.bottomSourceSize;
|
||||
bottomSourceSize = this.topSourceSize;
|
||||
|
||||
topDisplay = this.bottomDisplay;
|
||||
bottomDisplay = this.topDisplay;
|
||||
}
|
||||
|
||||
if (screenWidth > screenHeight) {
|
||||
int topDisplayWidth = (int) ((screenHeight / topSourceSize.y) * topSourceSize.x);
|
||||
int topDisplayHeight = screenHeight;
|
||||
|
||||
if (topDisplayWidth > (screenWidth * landscapeSpace)) {
|
||||
topDisplayWidth = (int) (screenWidth * landscapeSpace);
|
||||
topDisplayHeight = (int) ((topDisplayWidth / topSourceSize.x) * topSourceSize.y);
|
||||
}
|
||||
|
||||
int bottomDisplayHeight = (int) (((screenWidth - topDisplayWidth) / bottomSourceSize.x) * bottomSourceSize.y);
|
||||
|
||||
topDisplay.set(0, 0, topDisplayWidth, topDisplayHeight);
|
||||
bottomDisplay.set(topDisplayWidth, 0, topDisplayWidth + (screenWidth - topDisplayWidth), bottomDisplayHeight);
|
||||
adjustHorizontalGravity();
|
||||
} else {
|
||||
int topScreenHeight = (int) ((screenWidth / topSourceSize.x) * topSourceSize.y);
|
||||
topDisplay.set(0, 0, screenWidth, topScreenHeight);
|
||||
|
||||
int bottomDisplayHeight = (int) ((screenWidth / bottomSourceSize.x) * bottomSourceSize.y);
|
||||
int bottomDisplayWidth = screenWidth;
|
||||
int bottomDisplayX = 0;
|
||||
|
||||
if (topScreenHeight + bottomDisplayHeight > screenHeight) {
|
||||
bottomDisplayHeight = (screenHeight - topScreenHeight);
|
||||
bottomDisplayWidth = (int) ((bottomDisplayHeight / bottomSourceSize.y) * bottomSourceSize.x);
|
||||
bottomDisplayX = (screenWidth - bottomDisplayX) / 2;
|
||||
}
|
||||
|
||||
topDisplay.set(0, 0, screenWidth, topScreenHeight);
|
||||
bottomDisplay.set(bottomDisplayX, topScreenHeight, bottomDisplayX + bottomDisplayWidth, topScreenHeight + bottomDisplayHeight);
|
||||
adjustVerticalGravity();
|
||||
}
|
||||
}
|
||||
|
||||
private void adjustHorizontalGravity(){
|
||||
int topOffset = 0;
|
||||
int bottomOffset = 0;
|
||||
switch (landscapeGravity){
|
||||
case Gravity.CENTER:{
|
||||
topOffset = (int) (screenSize.y - topDisplay.height())/2;
|
||||
bottomOffset = (int) (screenSize.y - bottomDisplay.height())/2;
|
||||
}break;
|
||||
case Gravity.BOTTOM:{
|
||||
topOffset = (int) (screenSize.y - topDisplay.height());
|
||||
bottomOffset = (int) (screenSize.y - bottomDisplay.height());
|
||||
}break;
|
||||
}
|
||||
topDisplay.offset(0, topOffset);
|
||||
bottomDisplay.offset(0, bottomOffset);
|
||||
}
|
||||
|
||||
private void adjustVerticalGravity(){
|
||||
int height = (topDisplay.height() + bottomDisplay.height());
|
||||
int space = 0;
|
||||
switch (portraitGravity){
|
||||
case Gravity.CENTER:{
|
||||
space = (int) (screenSize.y - height)/2;
|
||||
}break;
|
||||
case Gravity.BOTTOM:{
|
||||
space = (int) (screenSize.y - height);
|
||||
}break;
|
||||
}
|
||||
topDisplay.offset(0, space);
|
||||
bottomDisplay.offset(0,space);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rect getBottomDisplayBounds() {
|
||||
return bottomDisplay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rect getTopDisplayBounds() {
|
||||
return topDisplay;
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package com.panda3ds.pandroid.view.renderer.layout;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.panda3ds.pandroid.math.Vector2;
|
||||
|
||||
public class SingleScreenLayout implements ConsoleLayout {
|
||||
private final Rect topDisplay = new Rect();
|
||||
private final Rect bottomDisplay = new Rect();
|
||||
private final Vector2 screenSize = new Vector2(1.0f, 1.0f);
|
||||
private final Vector2 topSourceSize = new Vector2(1.0f, 1.0f);
|
||||
private final Vector2 bottomSourceSize = new Vector2(1.0f, 1.0f);
|
||||
private boolean top = true;
|
||||
|
||||
@Override
|
||||
public void update(int screenWidth, int screenHeight) {
|
||||
screenSize.set(screenWidth, screenHeight);
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBottomDisplaySourceSize(int width, int height) {
|
||||
bottomSourceSize.set(width, height);
|
||||
updateBounds();
|
||||
}
|
||||
@Override
|
||||
public void setTopDisplaySourceSize(int width, int height) {
|
||||
topSourceSize.set(width, height);
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
private void updateBounds() {
|
||||
int screenWidth = (int) screenSize.x;
|
||||
int screenHeight = (int) screenSize.y;
|
||||
Vector2 source = top ? topSourceSize : bottomSourceSize;
|
||||
Rect dest = top ? topDisplay : bottomDisplay;
|
||||
|
||||
int width = Math.round((screenHeight / source.y) * source.x);
|
||||
int height = screenHeight;
|
||||
int y = 0;
|
||||
int x = (screenWidth - width) / 2;
|
||||
if (width > screenWidth){
|
||||
width = screenWidth;
|
||||
height = Math.round((screenWidth / source.x) * source.y);
|
||||
x = 0;
|
||||
y = (screenHeight - height)/2;
|
||||
}
|
||||
dest.set(x, y, x + width, y+height);
|
||||
|
||||
(top ? bottomDisplay : topDisplay).set(0,0,0,0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rect getBottomDisplayBounds() {
|
||||
return bottomDisplay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rect getTopDisplayBounds() {
|
||||
return topDisplay;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue