forked from wheremyfoodat/Panda3DS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pandroid: Drawer (wheremyfoodat#356)
* Drawer initial commit * Translate drawer, and remove redundant code * bonk --------- Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com>
- Loading branch information
1 parent
e536f5d
commit 02d506f
Showing
14 changed files
with
286 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/game/DrawerFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.panda3ds.pandroid.app.game; | ||
|
||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.widget.AppCompatTextView; | ||
import androidx.drawerlayout.widget.DrawerLayout; | ||
import androidx.fragment.app.Fragment; | ||
|
||
import com.google.android.material.navigation.NavigationView; | ||
import com.panda3ds.pandroid.AlberDriver; | ||
import com.panda3ds.pandroid.R; | ||
import com.panda3ds.pandroid.data.game.GameMetadata; | ||
import com.panda3ds.pandroid.utils.GameUtils; | ||
import com.panda3ds.pandroid.view.gamesgrid.GameIconView; | ||
|
||
public class DrawerFragment extends Fragment implements DrawerLayout.DrawerListener, NavigationView.OnNavigationItemSelectedListener { | ||
private DrawerLayout drawerContainer; | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
drawerContainer = requireActivity().findViewById(R.id.drawer_container); | ||
drawerContainer.removeDrawerListener(this); | ||
drawerContainer.addDrawerListener(this); | ||
drawerContainer.setScrimColor(Color.argb(160, 0,0,0)); | ||
drawerContainer.setVisibility(View.GONE); | ||
|
||
return inflater.inflate(R.layout.fragment_game_drawer, container, false); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
drawerContainer.setVisibility(View.GONE); | ||
|
||
GameMetadata game = GameUtils.getCurrentGame(); | ||
|
||
((GameIconView)view.findViewById(R.id.game_icon)).setImageBitmap(game.getIcon()); | ||
((AppCompatTextView)view.findViewById(R.id.game_title)).setText(game.getTitle()); | ||
((AppCompatTextView)view.findViewById(R.id.game_publisher)).setText(game.getPublisher()); | ||
|
||
((NavigationView)view.findViewById(R.id.action_navigation)).setNavigationItemSelectedListener(this); | ||
} | ||
|
||
@Override | ||
public void onDetach() { | ||
drawerContainer.removeDrawerListener(this); | ||
super.onDetach(); | ||
} | ||
|
||
private void refreshLayout() { | ||
drawerContainer.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY); | ||
drawerContainer.requestLayout(); | ||
drawerContainer.invalidate(); | ||
drawerContainer.forceLayout(); | ||
} | ||
|
||
public void open() { | ||
if (!drawerContainer.isOpen()) { | ||
drawerContainer.setVisibility(View.VISIBLE); | ||
drawerContainer.open(); | ||
drawerContainer.postDelayed(this::refreshLayout, 20); | ||
} | ||
} | ||
|
||
public void close() { | ||
if (drawerContainer.isOpen()) { | ||
drawerContainer.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {} | ||
|
||
@Override | ||
public void onDrawerOpened(@NonNull View drawerView) { | ||
AlberDriver.Pause(); | ||
} | ||
|
||
@Override | ||
public void onDrawerClosed(@NonNull View drawerView) { | ||
drawerContainer.setVisibility(View.GONE); | ||
AlberDriver.Resume(); | ||
} | ||
|
||
@Override | ||
public void onDrawerStateChanged(int newState) {} | ||
|
||
@Override | ||
public boolean onNavigationItemSelected(@NonNull MenuItem item) { | ||
int id = item.getItemId(); | ||
if (id == R.id.resume) { | ||
close(); | ||
} else if (id == R.id.exit) { | ||
requireActivity().onBackPressed(); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public boolean isOpened() { | ||
return drawerContainer.isOpen(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:autoMirrored="true" android:height="24dp" | ||
android:tint="#000000" android:viewportHeight="24" | ||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M10.09,15.59L11.5,17l5,-5 -5,-5 -1.41,1.41L12.67,11H3v2h9.67l-2.58,2.59zM19,3H5c-1.11,0 -2,0.9 -2,2v4h2V5h14v14H5v-4H3v4c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:autoMirrored="true" android:height="24dp" | ||
android:tint="#000000" android:viewportHeight="24" | ||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M21,11l-6,-6v5H8c-2.76,0 -5,2.24 -5,5v4h2v-4c0,-1.65 1.35,-3 3,-3h7v5L21,11z"/> | ||
</vector> |
24 changes: 24 additions & 0 deletions
24
src/pandroid/app/src/main/res/layout/drawer_game_container.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.drawerlayout.widget.DrawerLayout | ||
android:id="@+id/drawer_container" | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"/> | ||
|
||
<com.google.android.material.navigation.NavigationView | ||
android:layout_width="wrap_content" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="start"> | ||
|
||
<FrameLayout | ||
android:id="@+id/drawer_fragment" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"/> | ||
|
||
</com.google.android.material.navigation.NavigationView> | ||
|
||
</androidx.drawerlayout.widget.DrawerLayout> |
92 changes: 92 additions & 0 deletions
92
src/pandroid/app/src/main/res/layout/fragment_game_drawer.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:orientation="vertical" | ||
android:background="?colorSurface"> | ||
|
||
|
||
<androidx.appcompat.widget.LinearLayoutCompat | ||
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"> | ||
|
||
<androidx.cardview.widget.CardView | ||
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"/> | ||
|
||
</androidx.cardview.widget.CardView> | ||
|
||
<androidx.appcompat.widget.LinearLayoutCompat | ||
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:layout_height="wrap_content" | ||
android:text="@string/app_name" | ||
android:textColor="?colorOnSurfaceVariant" | ||
android:paddingBottom="4dp" | ||
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"/> | ||
|
||
</androidx.appcompat.widget.LinearLayoutCompat> | ||
|
||
</androidx.appcompat.widget.LinearLayoutCompat> | ||
|
||
<ScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_marginTop="10dp"> | ||
|
||
<androidx.appcompat.widget.LinearLayoutCompat | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<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.LinearLayoutCompat> | ||
|
||
</ScrollView> | ||
|
||
</androidx.appcompat.widget.LinearLayoutCompat> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,6 @@ | |
|
||
</FrameLayout> | ||
|
||
<include layout="@layout/drawer_game_container"/> | ||
|
||
</FrameLayout> |
11 changes: 11 additions & 0 deletions
11
src/pandroid/app/src/main/res/menu/game_drawer_actions.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters