Android cleanup and bugfixing

This commit is contained in:
wheremyfoodat 2024-02-29 22:52:44 +02:00
parent 02496b57eb
commit 914193a765
34 changed files with 153 additions and 332 deletions

View file

@ -30,6 +30,7 @@ public class BaseActivity extends AppCompatActivity {
private void applyTheme() { private void applyTheme() {
currentTheme = PandroidApplication.getThemeId(); currentTheme = PandroidApplication.getThemeId();
setTheme(currentTheme); setTheme(currentTheme);
if (GlobalConfig.get(GlobalConfig.KEY_APP_THEME) == GlobalConfig.THEME_ANDROID) { if (GlobalConfig.get(GlobalConfig.KEY_APP_THEME) == GlobalConfig.THEME_ANDROID) {
DynamicColors.applyToActivityIfAvailable(this); DynamicColors.applyToActivityIfAvailable(this);
} }

View file

@ -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) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder(); PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
builder.setAutoEnterEnabled(true); builder.setAutoEnterEnabled(true);
builder.setSeamlessResizeEnabled(true); builder.setSeamlessResizeEnabled(true);
} }
builder.setAspectRatio(new Rational(10, 14)); builder.setAspectRatio(new Rational(10, 14));
enterPictureInPictureMode(builder.build()); enterPictureInPictureMode(builder.build());
} }
@ -114,7 +115,7 @@ public class GameActivity extends BaseActivity implements EmulatorCallback {
InputHandler.reset(); InputHandler.reset();
if (GlobalConfig.get(GlobalConfig.KEY_PICTURE_IN_PICTURE)) { if (GlobalConfig.get(GlobalConfig.KEY_PICTURE_IN_PICTURE)) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
goToPictureInPicture(); enablePIP();
} }
} else { } else {
drawerFragment.open(); drawerFragment.open();
@ -158,8 +159,10 @@ public class GameActivity extends BaseActivity implements EmulatorCallback {
@Override @Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode); super.onPictureInPictureModeChanged(isInPictureInPictureMode);
changeOverlayVisibility(!isInPictureInPictureMode && GlobalConfig.get(GlobalConfig.KEY_SCREEN_GAMEPAD_VISIBLE)); changeOverlayVisibility(!isInPictureInPictureMode && GlobalConfig.get(GlobalConfig.KEY_SCREEN_GAMEPAD_VISIBLE));
findViewById(R.id.hide_screen_controller).setVisibility(isInPictureInPictureMode ? View.INVISIBLE : View.VISIBLE); findViewById(R.id.hide_screen_controller).setVisibility(isInPictureInPictureMode ? View.INVISIBLE : View.VISIBLE);
if (isInPictureInPictureMode) { if (isInPictureInPictureMode) {
getWindow().getDecorView().postDelayed(drawerFragment::close, 250); getWindow().getDecorView().postDelayed(drawerFragment::close, 250);
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
@ -173,6 +176,7 @@ public class GameActivity extends BaseActivity implements EmulatorCallback {
if (AlberDriver.HasRomLoaded()) { if (AlberDriver.HasRomLoaded()) {
AlberDriver.Finalize(); AlberDriver.Finalize();
} }
super.onDestroy(); super.onDestroy();
} }
} }

View file

@ -33,10 +33,10 @@ public class MainActivity extends BaseActivity implements NavigationBarView.OnIt
public void onBackPressed() { public void onBackPressed() {
if (navigationBar.getSelectedItemId() != R.id.games) { if (navigationBar.getSelectedItemId() != R.id.games) {
navigationBar.setSelectedItemId(R.id.games); navigationBar.setSelectedItemId(R.id.games);
return; } else {
}
super.onBackPressed(); super.onBackPressed();
} }
}
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {

View file

@ -18,11 +18,15 @@ public class BaseSheetDialog extends BottomSheetDialog {
private final LinearLayout contentView; private final LinearLayout contentView;
public BaseSheetDialog(@NonNull Context context) { public BaseSheetDialog(@NonNull Context context) {
super(CompatUtils.findActivity(context)); super(CompatUtils.findActivity(context));
int width = CompatUtils.findActivity(context).getWindow().getDecorView().getMeasuredWidth(); int width = CompatUtils.findActivity(context).getWindow().getDecorView().getMeasuredWidth();
int height = CompatUtils.findActivity(context).getWindow().getDecorView().getMeasuredHeight(); 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().setMaxWidth(width);
getBehavior().setMaxHeight((int) (height*0.87));
super.setContentView(R.layout.dialog_bottom_sheet); super.setContentView(R.layout.dialog_bottom_sheet);
contentView = super.findViewById(R.id.content); contentView = super.findViewById(R.id.content);
} }

View file

@ -61,6 +61,7 @@ public class GameAboutDialog extends BaseSheetDialog {
} }
} }
// Make a shortcut for a specific game
private void makeShortcut() { private void makeShortcut() {
Context context = CompatUtils.findActivity(getContext()); Context context = CompatUtils.findActivity(getContext());
ShortcutInfoCompat.Builder shortcut = new ShortcutInfoCompat.Builder(context, game.getId()); ShortcutInfoCompat.Builder shortcut = new ShortcutInfoCompat.Builder(context, game.getId());
@ -69,6 +70,7 @@ public class GameAboutDialog extends BaseSheetDialog {
} else { } else {
shortcut.setIcon(IconCompat.createWithResource(getContext(), R.mipmap.ic_launcher)); shortcut.setIcon(IconCompat.createWithResource(getContext(), R.mipmap.ic_launcher));
} }
shortcut.setActivity(new ComponentName(context, GameLauncher.class)); shortcut.setActivity(new ComponentName(context, GameLauncher.class));
shortcut.setLongLabel(game.getTitle()); shortcut.setLongLabel(game.getTitle());
shortcut.setShortLabel(game.getTitle()); shortcut.setShortLabel(game.getTitle());

View file

@ -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_title)).setText(game.getTitle());
((AppCompatTextView)drawerLayout.findViewById(R.id.game_publisher)).setText(game.getPublisher()); ((AppCompatTextView)drawerLayout.findViewById(R.id.game_publisher)).setText(game.getPublisher());
} }
@Override @Override

View file

@ -5,6 +5,7 @@ import com.panda3ds.pandroid.data.config.GlobalConfig;
public interface EmulatorCallback { public interface EmulatorCallback {
void onBackPressed(); void onBackPressed();
void swapScreens(int index); void swapScreens(int index);
default void swapScreens() { default void swapScreens() {
swapScreens(GlobalConfig.get(GlobalConfig.KEY_CURRENT_DS_LAYOUT) + 1); swapScreens(GlobalConfig.get(GlobalConfig.KEY_CURRENT_DS_LAYOUT) + 1);
} }

View file

@ -24,6 +24,7 @@ public class GameLauncher extends BaseActivity {
if (uri != null && uri.getScheme().equals("pandroid-game")) { if (uri != null && uri.getScheme().equals("pandroid-game")) {
String gameId = uri.getAuthority(); String gameId = uri.getAuthority();
GameMetadata game = GameUtils.findGameById(gameId); GameMetadata game = GameUtils.findGameById(gameId);
if (game != null) { if (game != null) {
GameUtils.launch(this, game); GameUtils.launch(this, game);
} else { } else {
@ -32,6 +33,7 @@ public class GameLauncher extends BaseActivity {
ShortcutManagerCompat.removeLongLivedShortcuts(this, Arrays.asList(gameId)); ShortcutManagerCompat.removeLongLivedShortcuts(this, Arrays.asList(gameId));
} }
} }
finish(); finish();
} }
} }

View file

@ -28,7 +28,7 @@ public class SettingsFragment extends BasePreferenceFragment {
Context context = PandroidApplication.getAppContext(); Context context = PandroidApplication.getAppContext();
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (Exception e) { } catch (Exception e) {
return "???"; return "Error: Unknown version";
} }
} }
} }

View file

@ -51,14 +51,14 @@ public class GamesFoldersPreferences extends BasePreferenceFragment implements A
screen.addPreference(preference); screen.addPreference(preference);
} }
Preference add = new Preference(screen.getContext()); Preference pref = new Preference(screen.getContext());
add.setTitle(R.string.import_folder); pref.setTitle(R.string.import_folder);
add.setIcon(R.drawable.ic_add); pref.setIcon(R.drawable.ic_add);
add.setOnPreferenceClickListener(preference -> { pref.setOnPreferenceClickListener(preference -> {
pickFolderRequest.launch(null); pickFolderRequest.launch(null);
return false; return false;
}); });
screen.addPreference(add); screen.addPreference(pref);
} }
private void showFolderInfo(GamesFolder folder) { private void showFolderInfo(GamesFolder folder) {
@ -83,6 +83,7 @@ public class GamesFoldersPreferences extends BasePreferenceFragment implements A
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (pickFolderRequest != null) { if (pickFolderRequest != null) {
pickFolderRequest.unregister(); pickFolderRequest.unregister();
pickFolderRequest = null; pickFolderRequest = null;

View file

@ -80,7 +80,7 @@ public class InputPreferences extends BasePreferenceFragment {
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
private void refreshScreenProfileList() { private void refreshScreenProfileList() {
PreferenceCategory category = findPreference(ID_GAMEPAD_PROFILE_LIST); PreferenceCategory category = findPreference(ID_GAMEPAD_PROFILE_LIST);
Preference add = category.getPreference(category.getPreferenceCount() - 1); Preference pref = category.getPreference(category.getPreferenceCount() - 1);
category.removeAll(); category.removeAll();
category.setOrderingAsAdded(true); category.setOrderingAsAdded(true);
@ -97,8 +97,8 @@ public class InputPreferences extends BasePreferenceFragment {
category.addPreference(item); category.addPreference(item);
} }
add.setOrder(category.getPreferenceCount()); pref.setOrder(category.getPreferenceCount());
category.addPreference(add); category.addPreference(pref);
} }
@Override @Override

View file

@ -23,6 +23,7 @@ public class ScreenLayoutsPreference extends BasePreferenceFragment {
public void refresh() { public void refresh() {
PreferenceScreen screen = getPreferenceScreen(); PreferenceScreen screen = getPreferenceScreen();
screen.removeAll(); screen.removeAll();
for (int i = 0; i < DsLayoutManager.getLayoutCount(); i++) { for (int i = 0; i < DsLayoutManager.getLayoutCount(); i++) {
Preference pref = new Preference(getPreferenceScreen().getContext()); Preference pref = new Preference(getPreferenceScreen().getContext());
pref.setIconSpaceReserved(false); pref.setIconSpaceReserved(false);

View file

@ -79,6 +79,7 @@ public class AppDataDocumentProvider extends DocumentsProvider {
.add(Root.COLUMN_TITLE, context().getString(R.string.app_name)) .add(Root.COLUMN_TITLE, context().getString(R.string.app_name))
.add(Root.COLUMN_MIME_TYPES, "*/*") .add(Root.COLUMN_MIME_TYPES, "*/*")
.add(Root.COLUMN_ICON, R.mipmap.ic_launcher); .add(Root.COLUMN_ICON, R.mipmap.ic_launcher);
return cursor; return cursor;
} }
@ -87,6 +88,7 @@ public class AppDataDocumentProvider extends DocumentsProvider {
File file = obtainFile(documentId); File file = obtainFile(documentId);
MatrixCursor cursor = new MatrixCursor(projection == null ? DEFAULT_DOCUMENT_PROJECTION : projection); MatrixCursor cursor = new MatrixCursor(projection == null ? DEFAULT_DOCUMENT_PROJECTION : projection);
includeFile(cursor, file); includeFile(cursor, file);
return cursor; return cursor;
} }
@ -126,17 +128,17 @@ public class AppDataDocumentProvider extends DocumentsProvider {
File parent = obtainFile(parentDocumentId); File parent = obtainFile(parentDocumentId);
File file = new File(parent, displayName); File file = new File(parent, displayName);
if (!parent.exists()) { 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 (Objects.equals(mimeType, Document.MIME_TYPE_DIR)) {
if (!file.mkdirs()) { if (!file.mkdirs()) {
throw new FileNotFoundException("Error on create directory"); throw new FileNotFoundException("Error while creating directory");
} }
} else { } else {
try { try {
if (!file.createNewFile()) { if (!file.createNewFile()) {
throw new Exception("Error on create file"); throw new Exception("Error while creating file");
} }
} catch (Exception e) { } catch (Exception e) {
throw new FileNotFoundException(e.getMessage()); throw new FileNotFoundException(e.getMessage());

View file

@ -64,6 +64,7 @@ public class GlobalConfig {
if (data.extras.has(key.name)) { if (data.extras.has(key.name)) {
return gson.fromJson(data.extras.getAsJsonObject(key.name), dataClass); return gson.fromJson(data.extras.getAsJsonObject(key.name), dataClass);
} }
return gson.fromJson("{}", dataClass); return gson.fromJson("{}", dataClass);
} }
@ -71,6 +72,7 @@ public class GlobalConfig {
if (data.extras.has(key.name)) { if (data.extras.has(key.name)) {
data.extras.remove(key.name); data.extras.remove(key.name);
} }
data.extras.add(key.name, gson.toJsonTree(value)); data.extras.add(key.name, gson.toJsonTree(value));
writeChanges(); writeChanges();
} }

View file

@ -86,6 +86,7 @@ public class GameMetadata {
if (icon != null) { if (icon != null) {
GameUtils.setGameIcon(id, icon); GameUtils.setGameIcon(id, icon);
} }
this.regions = new GameRegion[]{smdh.getRegion()}; this.regions = new GameRegion[]{smdh.getRegion()};
GameUtils.writeChanges(); GameUtils.writeChanges();
} }

View file

@ -12,7 +12,6 @@ import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
public class GamesFolder { public class GamesFolder {
private final String id = UUID.randomUUID().toString(); private final String id = UUID.randomUUID().toString();
private final String path; private final String path;
private final HashMap<String, GameMetadata> games = new HashMap<>(); private final HashMap<String, GameMetadata> games = new HashMap<>();
@ -44,6 +43,7 @@ public class GamesFolder {
games.remove(file); games.remove(file);
} }
} }
String unknown = PandroidApplication.getAppContext().getString(R.string.unknown); String unknown = PandroidApplication.getAppContext().getString(R.string.unknown);
for (String file: FileUtils.listFiles(path)) { for (String file: FileUtils.listFiles(path)) {
@ -51,8 +51,9 @@ public class GamesFolder {
if (FileUtils.isDirectory(path) || games.containsKey(file)) { if (FileUtils.isDirectory(path) || games.containsKey(file)) {
continue; continue;
} }
String ext = FileUtils.extension(path); 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]; 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)); games.put(file, new GameMetadata(new Uri.Builder().path(file).authority(id).scheme("folder").build().toString(), name, unknown));
} }

View file

@ -116,6 +116,7 @@ public class InputHandler {
} else if (!keyDownEvents.containsKey(code)) { } else if (!keyDownEvents.containsKey(code)) {
keyDownEvents.put(code, new InputEvent(code, 1.0f)); keyDownEvents.put(code, new InputEvent(code, 1.0f));
} }
for (InputEvent env: keyDownEvents.values()) { for (InputEvent env: keyDownEvents.values()) {
handleEvent(env); handleEvent(env);
} }

View file

@ -19,6 +19,7 @@ public class CompatUtils {
} else if ((context instanceof ContextWrapper)) { } else if ((context instanceof ContextWrapper)) {
return findActivity(((ContextWrapper) context).getBaseContext()); return findActivity(((ContextWrapper) context).getBaseContext());
} }
return ((Activity) context); 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()); return TypedValue.applyDimension(unit, size, PandroidApplication.getAppContext().getResources().getDisplayMetrics());
} }
} }

View file

@ -37,6 +37,7 @@ public class FileUtils {
if (uri.getScheme().equals("content") && uri.getPath().startsWith("/" + TREE_URI)) { if (uri.getScheme().equals("content") && uri.getPath().startsWith("/" + TREE_URI)) {
return DocumentFile.fromTreeUri(getContext(), uri); return DocumentFile.fromTreeUri(getContext(), uri);
} }
return singleFile; return singleFile;
} }
@ -264,18 +265,22 @@ public class FileUtils {
FileUtils.createFile(path, name); FileUtils.createFile(path, name);
InputStream in = getInputStream(source); InputStream in = getInputStream(source);
OutputStream out = getOutputStream(fullPath); 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; int length;
while ((length = in.read(buffer)) != -1) { while ((length = in.read(buffer)) != -1) {
out.write(buffer, 0, length); out.write(buffer, 0, length);
} }
out.flush(); out.flush();
out.close(); out.close();
in.close(); in.close();
} catch (Exception e) { } 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 false;
} }
return true; return true;
} }

View file

@ -163,6 +163,7 @@ public class GameUtils {
return game; return game;
} }
} }
return null; return null;
} }

View file

@ -38,9 +38,11 @@ class Bounds {
if (left > (width - right) - size) { if (left > (width - right) - size) {
right = (width - left) - size; right = (width - left) - size;
} }
if (top > (height - bottom) - size) { if (top > (height - bottom) - size) {
bottom = (height - top) - size; bottom = (height - top) - size;
} }
normalize(); normalize();
} }
} }

View file

@ -51,7 +51,7 @@ public class DsEditorView extends FrameLayout {
public DsEditorView(Context context, int index) { public DsEditorView(Context context, int index) {
super(context); super(context);
layout = (DsLayout) DsLayoutManager.createLayout(index); 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 colorBottomSelection = CompatUtils.resolveColor(context, androidx.appcompat.R.attr.colorPrimary);
int colorTopSelection = CompatUtils.resolveColor(context, com.google.android.material.R.attr.colorAccent); 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; layout.getCurrentModel().gravity = Gravity.TOP;
refreshLayout(); refreshLayout();
}); });
gravityAnchor.findViewById(R.id.center).setOnClickListener(v -> { gravityAnchor.findViewById(R.id.center).setOnClickListener(v -> {
layout.getCurrentModel().gravity = Gravity.CENTER; layout.getCurrentModel().gravity = Gravity.CENTER;
refreshLayout(); refreshLayout();
}); });
gravityAnchor.findViewById(R.id.down).setOnClickListener(v -> { gravityAnchor.findViewById(R.id.down).setOnClickListener(v -> {
layout.getCurrentModel().gravity = Gravity.BOTTOM; layout.getCurrentModel().gravity = Gravity.BOTTOM;
refreshLayout(); refreshLayout();
}); });
gravityAnchor.findViewById(R.id.revert).setOnClickListener(v -> { gravityAnchor.findViewById(R.id.revert).setOnClickListener(v -> {
layout.getCurrentModel().reverse = !layout.getCurrentModel().reverse; layout.getCurrentModel().reverse = !layout.getCurrentModel().reverse;
refreshLayout(); refreshLayout();
@ -87,7 +90,7 @@ public class DsEditorView extends FrameLayout {
{ {
modeSelectorLayout = (LinearLayout) inflater.inflate(R.layout.ds_editor_spinner, this, false); modeSelectorLayout = (LinearLayout) inflater.inflate(R.layout.ds_editor_spinner, this, false);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.ds_editor_spinner_label); 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 = modeSelectorLayout.findViewById(R.id.spinner);
modeSelector.setAdapter(spinnerAdapter); modeSelector.setAdapter(spinnerAdapter);
modeSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { modeSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@ -149,6 +152,7 @@ public class DsEditorView extends FrameLayout {
@Override @Override
public void draw(Canvas canvas) { public void draw(Canvas canvas) {
super.draw(canvas); super.draw(canvas);
if (this.width != getWidth() || this.height != getHeight()) { if (this.width != getWidth() || this.height != getHeight()) {
this.width = getWidth(); this.width = getWidth();
this.height = getHeight(); this.height = getHeight();
@ -172,12 +176,12 @@ public class DsEditorView extends FrameLayout {
spacePoint.setCenterPosition(primaryDisplay.width(), (int) (SIZE_DP * 15)); spacePoint.setCenterPosition(primaryDisplay.width(), (int) (SIZE_DP * 15));
spacePoint.setText(String.valueOf((int) (data.space * 100))); spacePoint.setText(String.valueOf((int) (data.space * 100)));
} }
}
break; break;
}
case SINGLE: case SINGLE:
case ABSOLUTE: { case ABSOLUTE: break;
}
break;
} }
this.topDisplay.setSize(topDisplay.width(), topDisplay.height()); this.topDisplay.setSize(topDisplay.width(), topDisplay.height());
@ -212,19 +216,23 @@ public class DsEditorView extends FrameLayout {
if (landscape) { if (landscape) {
addView(spacePoint); addView(spacePoint);
} }
}
break; break;
}
case ABSOLUTE: { case ABSOLUTE: {
addView(aspectRatioFixLayout, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER | Gravity.TOP)); addView(aspectRatioFixLayout, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER | Gravity.TOP));
addView(topDisplayResizer); addView(topDisplayResizer);
addView(bottomDisplayResizer); addView(bottomDisplayResizer);
}
break; break;
}
case SINGLE: { case SINGLE: {
addView(aspectRatioFixLayout, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER | Gravity.TOP)); addView(aspectRatioFixLayout, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER | Gravity.TOP));
}
break; break;
} }
}
((MaterialCheckBox) aspectRatioFixLayout.findViewById(R.id.checkbox)).setChecked(layout.getCurrentModel().lockAspect); ((MaterialCheckBox) aspectRatioFixLayout.findViewById(R.id.checkbox)).setChecked(layout.getCurrentModel().lockAspect);
modeSelector.setSelection(layout.getCurrentModel().mode.ordinal()); modeSelector.setSelection(layout.getCurrentModel().mode.ordinal());
@ -233,7 +241,6 @@ public class DsEditorView extends FrameLayout {
} }
private class PointView extends AppCompatTextView { private class PointView extends AppCompatTextView {
public PointView() { public PointView() {
super(DsEditorView.this.getContext()); super(DsEditorView.this.getContext());
setLayoutParams(new FrameLayout.LayoutParams((int) (SIZE_DP * 30), (int) (SIZE_DP * 30))); 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()); downEvent = new Vector2(event.getRawX(), event.getRawY());
return true; return true;
} }
preferred.move((int) (event.getRawX() - downEvent.x), (int) (event.getRawY() - downEvent.y)); preferred.move((int) (event.getRawX() - downEvent.x), (int) (event.getRawY() - downEvent.y));
downEvent.set(event.getRawX(), event.getRawY()); downEvent.set(event.getRawX(), event.getRawY());
refreshPoints(); refreshPoints();
@ -330,6 +338,7 @@ public class DsEditorView extends FrameLayout {
refreshPoints(); refreshPoints();
return true; return true;
} }
return false; return false;
} }
} }

View file

@ -102,12 +102,7 @@ class DsLayout implements ConsoleLayout {
(data.onlyTop ? bottomDisplay : topDisplay).set(0, 0, 0, 0); (data.onlyTop ? bottomDisplay : topDisplay).set(0, 0, 0, 0);
} }
// Relative layout: Organize screen position based on gravity and space, the space determined by the top screen size in landscape mode
/***
* RELATIVE LAYOUT:
* ORGANIZE SCREEN IN POSITION BASED IN GRAVITY
* AND SPACE, THE SPACE DETERMINE LANDSCAPE TOP SCREEN SIZE
*/
private void relative(Model data) { private void relative(Model data) {
int screenWidth = (int) screenSize.x; int screenWidth = (int) screenSize.x;
int screenHeight = (int) screenSize.y; int screenHeight = (int) screenSize.y;
@ -144,14 +139,15 @@ class DsLayout implements ConsoleLayout {
case Gravity.CENTER: { case Gravity.CENTER: {
bottomDisplay.offset(0, (screenHeight - bottomDisplay.height()) / 2); bottomDisplay.offset(0, (screenHeight - bottomDisplay.height()) / 2);
topDisplay.offset(0, (screenHeight - topDisplay.height()) / 2); topDisplay.offset(0, (screenHeight - topDisplay.height()) / 2);
}
break; break;
}
case Gravity.BOTTOM: { case Gravity.BOTTOM: {
bottomDisplay.offset(0, (screenHeight - bottomDisplay.height())); bottomDisplay.offset(0, (screenHeight - bottomDisplay.height()));
topDisplay.offset(0, (screenHeight - topDisplay.height())); topDisplay.offset(0, (screenHeight - topDisplay.height()));
}
break; break;
} }
}
} else { } else {
int topScreenHeight = (int) ((screenWidth / topSourceSize.x) * topSourceSize.y); int topScreenHeight = (int) ((screenWidth / topSourceSize.x) * topSourceSize.y);

View file

@ -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;
}
}

View file

@ -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;
}
}