Skip to content

Commit

Permalink
fix drawarlayout
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan09811 authored Feb 6, 2024
1 parent 9a59547 commit e4428c9
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
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;
Expand Down Expand Up @@ -47,7 +49,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
((AppCompatTextView)view.findViewById(R.id.game_publisher)).setText(game.getPublisher());

((NavigationView)view.findViewById(R.id.action_navigation)).setNavigationItemSelectedListener(this);
((NavigationView)view.findViewById(R.id.others_navigation)).setNavigationItemSelectedListener(this);
}

@Override
Expand Down Expand Up @@ -80,6 +81,17 @@ public void close() {
}
}

private void changeScreenOrientation() {
int currentOrientation = getResources().getConfiguration().orientation;

// Change the orientation
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}

@Override
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {}

Expand All @@ -106,6 +118,8 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
requireActivity().finish();
} else if (id == R.id.lua_script){
new LuaDialogFragment().show(getParentFragmentManager(), null);
} else if (id == R.id.change_orientation) {
changeScreenOrientation();
}

return false;
Expand Down
147 changes: 69 additions & 78 deletions src/pandroid/app/src/main/res/layout/fragment_game_drawer.xml
Original file line number Diff line number Diff line change
@@ -1,106 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?colorSurface">


<!-- Main content layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:minHeight="190dp"
android:background="?colorSurfaceVariant">

<com.google.android.material.card.MaterialCardView
android:layout_width="90dp"
android:layout_height="90dp"
app:cardCornerRadius="10dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp">

<com.panda3ds.pandroid.view.gamesgrid.GameIconView
android:id="@+id/game_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?colorSurface"/>

</com.google.android.material.card.MaterialCardView>
android:layout_height="match_parent"
android:orientation="vertical">

<!-- Game related content -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_marginBottom="20dp">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/game_title"
android:layout_width="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:minHeight="190dp"
android:background="?colorSurfaceVariant">

<com.google.android.material.card.MaterialCardView
android:layout_width="90dp"
android:layout_height="90dp"
app:cardCornerRadius="10dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp">

<com.panda3ds.pandroid.view.gamesgrid.GameIconView
android:id="@+id/game_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?colorSurface"/>

</com.google.android.material.card.MaterialCardView>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="?colorOnSurfaceVariant"
android:paddingBottom="4dp"
android:orientation="vertical"
android:gravity="center"
android:textStyle="bold"
android:textSize="19sp"/>

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/game_publisher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="?colorOnSurfaceVariant"
android:textSize="14sp"/>
android:layout_marginBottom="20dp">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/game_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="?colorOnSurfaceVariant"
android:paddingBottom="4dp"
android:gravity="center"
android:textStyle="bold"
android:ellipsize="marquee"
style="?attr/textAppearanceTitleSmall"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:textSize="19sp"/>

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/game_publisher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="?colorOnSurfaceVariant"
android:textSize="14sp"/>

</LinearLayout>

</LinearLayout>

</LinearLayout>

<ScrollView
android:layout_width="match_parent"
<!-- Drawer content layout -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp">
android:orientation="vertical"
android:gravity="start"
android:layout_marginTop="195dp">

<LinearLayout
<com.google.android.material.navigation.NavigationView
android:id="@+id/action_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
app:menu="@menu/game_drawer_settings"
android:background="?colorSurface"
android:theme="@style/Widget.App.NavigationView"
app:subheaderTextAppearance="@style/TextAppearanceGameDrawerSubTitle"/>

<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/actions"
style="@style/TextAppearanceGameDrawerSubTitle"/>

<com.google.android.material.navigation.NavigationView
android:id="@+id/action_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/game_drawer_actions"
android:background="?colorSurface"/>

<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/others"
style="@style/TextAppearanceGameDrawerSubTitle"/>

<com.google.android.material.navigation.NavigationView
android:id="@+id/others_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/game_drawer_others"
android:background="?colorSurface"/>

</LinearLayout>

</ScrollView>
</LinearLayout>

</LinearLayout>
</androidx.drawerlayout.widget.DrawerLayout>
11 changes: 0 additions & 11 deletions src/pandroid/app/src/main/res/menu/game_drawer_actions.xml

This file was deleted.

7 changes: 0 additions & 7 deletions src/pandroid/app/src/main/res/menu/game_drawer_others.xml

This file was deleted.

35 changes: 35 additions & 0 deletions src/pandroid/app/src/main/res/menu/game_drawer_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:divider="@null"
android:dividerHeight="0dp">
<item
android:id="@+id/header_actions"
android:title="Actions">
<menu>

<item
android:id="@+id/resume"
android:icon="@drawable/ic_shortcut"
android:title="@string/resume" />
<item
android:id="@+id/exit"
android:icon="@drawable/ic_exit"
android:title="@string/exit"/>

</menu>
</item>
<item
android:id="@+id/header_others"
android:title="Others">
<menu>

<item
android:id="@+id/change_orientation"
android:icon="@drawable/ic_rotate_screen"
android:title="Rotate" />
<item
android:id="@+id/lua_script"
android:icon="@drawable/ic_code"
android:title="@string/lua_script" />
</menu>
</item>
</menu>

0 comments on commit e4428c9

Please sign in to comment.