add swap screen in drawer

This commit is contained in:
gabriel 2024-02-26 16:14:14 -04:00
parent dcda78de97
commit e24dca78f1
9 changed files with 33 additions and 16 deletions

View file

@ -3,7 +3,6 @@ package com.panda3ds.pandroid.app;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
@ -17,7 +16,7 @@ import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.app.game.AlberInputListener;
import com.panda3ds.pandroid.app.game.DrawerFragment;
import com.panda3ds.pandroid.app.game.EmulatorListener;
import com.panda3ds.pandroid.app.game.EmulatorCallback;
import com.panda3ds.pandroid.data.config.GlobalConfig;
import com.panda3ds.pandroid.input.InputHandler;
import com.panda3ds.pandroid.input.InputMap;
@ -28,7 +27,7 @@ import com.panda3ds.pandroid.view.ds.DsLayoutManager;
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;
import com.panda3ds.pandroid.view.utils.PerformanceView;
public class GameActivity extends BaseActivity implements EmulatorListener {
public class GameActivity extends BaseActivity implements EmulatorCallback {
private final DrawerFragment drawerFragment = new DrawerFragment();
private final AlberInputListener inputListener = new AlberInputListener(this);
private ConsoleRenderer renderer;
@ -113,7 +112,7 @@ public class GameActivity extends BaseActivity implements EmulatorListener {
}
@Override
public void switchDualScreenLayout() {
public void swapScreens() {
currentDsLayout = currentDsLayout + 1 < DsLayoutManager.getLayoutCount() ? currentDsLayout + 1 : 0;
renderer.setLayout(DsLayoutManager.createLayout(currentDsLayout));
}

View file

@ -11,8 +11,8 @@ import java.util.Objects;
public class AlberInputListener implements Function<InputEvent> {
private final EmulatorListener emulator;
public AlberInputListener(EmulatorListener emulator) { this.emulator = emulator; }
private final EmulatorCallback emulator;
public AlberInputListener(EmulatorCallback emulator) { this.emulator = emulator; }
private final Vector2 axis = new Vector2(0.0f, 0.0f);
@ -50,7 +50,7 @@ public class AlberInputListener implements Function<InputEvent> {
break;
case CHANGE_DS_LAYOUT:
if (!event.isDown()){
emulator.switchDualScreenLayout();
emulator.swapScreens();
}
break;
default:

View file

@ -14,7 +14,6 @@ import androidx.appcompat.widget.AppCompatTextView;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import com.google.android.material.navigation.NavigationView;
import com.panda3ds.pandroid.AlberDriver;
@ -25,10 +24,12 @@ import com.panda3ds.pandroid.view.gamesgrid.GameIconView;
public class DrawerFragment extends Fragment implements DrawerLayout.DrawerListener, NavigationView.OnNavigationItemSelectedListener {
private DrawerLayout drawerContainer;
private EmulatorCallback emulator;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
emulator = ((EmulatorCallback) requireActivity());
drawerContainer = requireActivity().findViewById(R.id.drawer_container);
drawerContainer.removeDrawerListener(this);
drawerContainer.addDrawerListener(this);
@ -113,6 +114,9 @@ public class DrawerFragment extends Fragment implements DrawerLayout.DrawerListe
int id = item.getItemId();
if (id == R.id.resume) {
close();
} else if (id == R.id.ds_switch) {
emulator.swapScreens();
close();
} else if (id == R.id.exit) {
requireActivity().finish();
} else if (id == R.id.lua_script) {

View file

@ -0,0 +1,7 @@
package com.panda3ds.pandroid.app.game;
public interface EmulatorCallback {
void onBackPressed();
void swapScreens();
}

View file

@ -1,7 +0,0 @@
package com.panda3ds.pandroid.app.game;
public interface EmulatorListener {
void onBackPressed();
void switchDualScreenLayout();
}

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M21,3L3,3c-1.11,0 -2,0.89 -2,2v14c0,1.11 0.89,2 2,2h18c1.11,0 2,-0.89 2,-2L23,5c0,-1.11 -0.89,-2 -2,-2zM21,19.02L3,19.02L3,4.98h18v14.04zM10,12L8,12l4,-4 4,4h-2v4h-4v-4z"/>
</vector>

View file

@ -10,6 +10,10 @@
android:id="@+id/resume"
android:icon="@drawable/ic_shortcut"
android:title="@string/resume" />
<item
android:id="@+id/ds_switch"
android:icon="@drawable/ic_switch_screen"
android:title="@string/swap_screen"/>
<item
android:id="@+id/exit"
android:icon="@drawable/ic_exit"

View file

@ -74,4 +74,5 @@
<string name="dual_screen_layouts">Dual Screen layouts</string>
<string name="dual_screen_layouts_summary">Change layout of console screens.</string>
<string name="click_to_change">Click to change</string>
<string name="swap_screen">Swap screen</string>
</resources>

View file

@ -134,7 +134,7 @@
app:iconSpaceReserved="false"/>
<Preference
app:title="Switch dual screen layout"
app:title="@string/swap_screen"
app:key="CHANGE_DS_LAYOUT"
app:summary="none"
app:iconSpaceReserved="false"/>