Android: Always show Exit Emulation at bottom of menu

To make it easier to access on touchscreens.
This commit is contained in:
JosJuice 2020-08-16 16:22:41 +02:00
parent 6b68b76aed
commit cecec756ec
2 changed files with 40 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package org.dolphinemu.dolphinemu.fragments; package org.dolphinemu.dolphinemu.fragments;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -62,6 +63,14 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
return fragment; return fragment;
} }
// This is primarily intended to account for any navigation bar at the bottom of the screen
private int getBottomPaddingRequired()
{
Rect visibleFrame = new Rect();
requireActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(visibleFrame);
return visibleFrame.bottom - visibleFrame.top - getResources().getDisplayMetrics().heightPixels;
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{ {
@ -106,6 +115,21 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
options.findViewById(R.id.menu_screen_orientation).setVisibility(View.GONE); options.findViewById(R.id.menu_screen_orientation).setVisibility(View.GONE);
} }
int bottomPaddingRequired = getBottomPaddingRequired();
// Provide a safe zone between the navigation bar and Exit Emulation to avoid accidental touches
float density = getResources().getDisplayMetrics().density;
if (bottomPaddingRequired >= 32 * density)
{
bottomPaddingRequired += 32 * density;
}
if (bottomPaddingRequired > rootView.getPaddingBottom())
{
rootView.setPadding(rootView.getPaddingLeft(), rootView.getPaddingTop(),
rootView.getPaddingRight(), bottomPaddingRequired);
}
for (int childIndex = 0; childIndex < options.getChildCount(); childIndex++) for (int childIndex = 0; childIndex < options.getChildCount(); childIndex++)
{ {
Button button = (Button) options.getChildAt(childIndex); Button button = (Button) options.getChildAt(childIndex);
@ -113,6 +137,8 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
button.setOnClickListener(this); button.setOnClickListener(this);
} }
rootView.findViewById(R.id.menu_exit).setOnClickListener(this);
mTitleText = rootView.findViewById(R.id.text_game_title); mTitleText = rootView.findViewById(R.id.text_game_title);
String title = getArguments().getString(KEY_TITLE); String title = getArguments().getString(KEY_TITLE);
if (title != null) if (title != null)

View File

@ -4,6 +4,7 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingBottom="16dp"
android:background="@color/dolphin_blue_dark" android:background="@color/dolphin_blue_dark"
tools:layout_width="250dp"> tools:layout_width="250dp">
@ -89,13 +90,21 @@
android:text="@string/emulation_change_disc" android:text="@string/emulation_change_disc"
style="@style/InGameMenuOption"/> style="@style/InGameMenuOption"/>
<Button
android:id="@+id/menu_exit"
android:text="@string/emulation_exit"
style="@style/InGameMenuOption"/>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FFFFFF"
android:layout_marginTop="24dp"
android:layout_marginBottom="16dp"/>
<Button
android:id="@+id/menu_exit"
android:text="@string/emulation_exit"
style="@style/InGameMenuOption"/>
</LinearLayout> </LinearLayout>