Android TV: Add title text to in-game menu, and make the menu scrollable.

This commit is contained in:
sigmabeta 2015-07-05 00:11:25 -04:00
parent c0315fcf78
commit 12fd46e12d
4 changed files with 98 additions and 45 deletions

View File

@ -28,6 +28,7 @@ import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.fragments.EmulationFragment; import org.dolphinemu.dolphinemu.fragments.EmulationFragment;
import org.dolphinemu.dolphinemu.fragments.LoadStateFragment; import org.dolphinemu.dolphinemu.fragments.LoadStateFragment;
import org.dolphinemu.dolphinemu.fragments.MenuFragment;
import org.dolphinemu.dolphinemu.fragments.SaveStateFragment; import org.dolphinemu.dolphinemu.fragments.SaveStateFragment;
import java.util.List; import java.util.List;
@ -40,7 +41,7 @@ public final class EmulationActivity extends AppCompatActivity
private FrameLayout mFrameEmulation; private FrameLayout mFrameEmulation;
private LinearLayout mMenuLayout; private LinearLayout mMenuLayout;
private String mMenuFragmentTag; private String mSubmenuFragmentTag;
// So that MainActivity knows which view to invalidate before the return animation. // So that MainActivity knows which view to invalidate before the return animation.
private int mPosition; private int mPosition;
@ -67,6 +68,7 @@ public final class EmulationActivity extends AppCompatActivity
}; };
private String mScreenPath; private String mScreenPath;
private FrameLayout mFrameContent; private FrameLayout mFrameContent;
private String mSelectedTitle;
@Override @Override
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
@ -129,7 +131,7 @@ public final class EmulationActivity extends AppCompatActivity
Intent gameToEmulate = getIntent(); Intent gameToEmulate = getIntent();
String path = gameToEmulate.getStringExtra("SelectedGame"); String path = gameToEmulate.getStringExtra("SelectedGame");
String title = gameToEmulate.getStringExtra("SelectedTitle"); mSelectedTitle = gameToEmulate.getStringExtra("SelectedTitle");
mScreenPath = gameToEmulate.getStringExtra("ScreenPath"); mScreenPath = gameToEmulate.getStringExtra("ScreenPath");
mPosition = gameToEmulate.getIntExtra("GridPosition", -1); mPosition = gameToEmulate.getIntExtra("GridPosition", -1);
@ -175,8 +177,6 @@ public final class EmulationActivity extends AppCompatActivity
} }
}); });
setTitle(title);
// Instantiate an EmulationFragment. // Instantiate an EmulationFragment.
EmulationFragment emulationFragment = EmulationFragment.newInstance(path); EmulationFragment emulationFragment = EmulationFragment.newInstance(path);
@ -184,6 +184,21 @@ public final class EmulationActivity extends AppCompatActivity
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
.add(R.id.frame_emulation_fragment, emulationFragment, EmulationFragment.FRAGMENT_TAG) .add(R.id.frame_emulation_fragment, emulationFragment, EmulationFragment.FRAGMENT_TAG)
.commit(); .commit();
if (mDeviceHasTouchScreen)
{
setTitle(mSelectedTitle);
}
else
{
MenuFragment menuFragment = (MenuFragment) getFragmentManager()
.findFragmentById(R.id.fragment_menu);
if (menuFragment != null)
{
menuFragment.setTitleText(mSelectedTitle);
}
}
} }
@Override @Override
@ -240,7 +255,7 @@ public final class EmulationActivity extends AppCompatActivity
{ {
if (!mDeviceHasTouchScreen) if (!mDeviceHasTouchScreen)
{ {
if (mMenuFragmentTag != null) if (mSubmenuFragmentTag != null)
{ {
removeMenu(); removeMenu();
} }
@ -579,12 +594,12 @@ public final class EmulationActivity extends AppCompatActivity
{ {
case SaveStateFragment.FRAGMENT_ID: case SaveStateFragment.FRAGMENT_ID:
fragment = SaveStateFragment.newInstance(); fragment = SaveStateFragment.newInstance();
mMenuFragmentTag = SaveStateFragment.FRAGMENT_TAG; mSubmenuFragmentTag = SaveStateFragment.FRAGMENT_TAG;
break; break;
case LoadStateFragment.FRAGMENT_ID: case LoadStateFragment.FRAGMENT_ID:
fragment = LoadStateFragment.newInstance(); fragment = LoadStateFragment.newInstance();
mMenuFragmentTag = LoadStateFragment.FRAGMENT_TAG; mSubmenuFragmentTag = LoadStateFragment.FRAGMENT_TAG;
break; break;
default: default:
@ -593,15 +608,15 @@ public final class EmulationActivity extends AppCompatActivity
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
.setCustomAnimations(R.animator.menu_slide_in, R.animator.menu_slide_out) .setCustomAnimations(R.animator.menu_slide_in, R.animator.menu_slide_out)
.replace(R.id.frame_submenu, fragment, mMenuFragmentTag) .replace(R.id.frame_submenu, fragment, mSubmenuFragmentTag)
.commit(); .commit();
} }
private void removeMenu() private void removeMenu()
{ {
if (mMenuFragmentTag != null) if (mSubmenuFragmentTag != null)
{ {
final Fragment fragment = getFragmentManager().findFragmentByTag(mMenuFragmentTag); final Fragment fragment = getFragmentManager().findFragmentByTag(mSubmenuFragmentTag);
if (fragment != null) if (fragment != null)
{ {
@ -632,11 +647,16 @@ public final class EmulationActivity extends AppCompatActivity
Log.e("DolphinEmu", "[EmulationActivity] Fragment not found, can't remove."); Log.e("DolphinEmu", "[EmulationActivity] Fragment not found, can't remove.");
} }
mMenuFragmentTag = null; mSubmenuFragmentTag = null;
} }
else else
{ {
Log.e("DolphinEmu", "[EmulationActivity] Fragment Tag empty."); Log.e("DolphinEmu", "[EmulationActivity] Fragment Tag empty.");
} }
} }
public String getSelectedTitle()
{
return mSelectedTitle;
}
} }

View File

@ -8,6 +8,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
import org.dolphinemu.dolphinemu.BuildConfig; import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
@ -17,20 +18,24 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
{ {
public static final String FRAGMENT_TAG = BuildConfig.APPLICATION_ID + ".ingame_menu"; public static final String FRAGMENT_TAG = BuildConfig.APPLICATION_ID + ".ingame_menu";
public static final int FRAGMENT_ID = R.layout.fragment_ingame_menu; public static final int FRAGMENT_ID = R.layout.fragment_ingame_menu;
private TextView mTitleText;
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{ {
LinearLayout rootView = (LinearLayout) inflater.inflate(FRAGMENT_ID, container, false); View rootView = inflater.inflate(FRAGMENT_ID, container, false);
for (int childIndex = 0; childIndex < rootView.getChildCount(); childIndex++) LinearLayout options = (LinearLayout) rootView.findViewById(R.id.layout_options);
for (int childIndex = 0; childIndex < options.getChildCount(); childIndex++)
{ {
Button button = (Button) rootView.getChildAt(childIndex); Button button = (Button) options.getChildAt(childIndex);
button.setOnClickListener(this); button.setOnClickListener(this);
} }
mTitleText = (TextView) rootView.findViewById(R.id.text_game_title);
return rootView; return rootView;
} }
@ -39,4 +44,9 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
{ {
((EmulationActivity) getActivity()).onMenuItemClicked(button.getId()); ((EmulationActivity) getActivity()).onMenuItemClicked(button.getId());
} }
public void setTitleText(String title)
{
mTitleText.setText(title);
}
} }

View File

@ -1,46 +1,69 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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:background="@color/dolphin_blue_dark" android:background="@color/dolphin_blue_dark"
android:paddingTop="32dp" tools:layout_width="250dp"
android:paddingBottom="32dp"
> >
<Button <TextView
android:id="@+id/menu_take_screenshot" android:id="@+id/text_game_title"
android:text="@string/overlay_screenshot" android:layout_width="match_parent"
style="@style/InGameMenuOption"/> android:layout_height="wrap_content"
tools:text="The Legend of Zelda: The Wind Waker"
android:textColor="@android:color/white"
android:textSize="20sp"
android:layout_margin="32dp"/>
<Button <ScrollView
android:id="@+id/menu_quicksave" android:layout_width="match_parent"
android:text="@string/emulation_quicksave" android:layout_height="0dp"
style="@style/InGameMenuOption"/> android:layout_weight="1"
>
<Button <LinearLayout
android:id="@+id/menu_quickload" android:id="@+id/layout_options"
android:text="@string/emulation_quickload" android:layout_width="match_parent"
style="@style/InGameMenuOption"/> android:layout_height="wrap_content"
android:orientation="vertical">
<Button <Button
android:id="@+id/menu_emulation_save_root" android:id="@+id/menu_take_screenshot"
android:text="@string/overlay_savestate" android:text="@string/overlay_screenshot"
style="@style/InGameMenuOption"/> style="@style/InGameMenuOption"/>
<Button <Button
android:id="@+id/menu_emulation_load_root" android:id="@+id/menu_quicksave"
android:text="@string/overlay_loadstate" android:text="@string/emulation_quicksave"
style="@style/InGameMenuOption"/> style="@style/InGameMenuOption"/>
<Button <Button
android:id="@+id/menu_ingame_settings" android:id="@+id/menu_quickload"
android:text="@string/settings" android:text="@string/emulation_quickload"
style="@style/InGameMenuOption"/> style="@style/InGameMenuOption"/>
<Button <Button
android:id="@+id/menu_exit" android:id="@+id/menu_emulation_save_root"
android:text="@string/overlay_exit_emulation" android:text="@string/overlay_savestate"
style="@style/InGameMenuOption"/> style="@style/InGameMenuOption"/>
<Button
android:id="@+id/menu_emulation_load_root"
android:text="@string/overlay_loadstate"
style="@style/InGameMenuOption"/>
<Button
android:id="@+id/menu_ingame_settings"
android:text="@string/settings"
style="@style/InGameMenuOption"/>
<Button
android:id="@+id/menu_exit"
android:text="@string/overlay_exit_emulation"
style="@style/InGameMenuOption"/>
</LinearLayout>
</ScrollView>
</LinearLayout> </LinearLayout>

View File

@ -127,7 +127,7 @@
</style> </style>
<style name="InGameMenuOption" parent="Widget.AppCompat.Button.Borderless"> <style name="InGameMenuOption" parent="Widget.AppCompat.Button.Borderless">
<item name="android:textSize">20sp</item> <item name="android:textSize">16sp</item>
<item name="android:fontFamily">sans-serif-condensed</item> <item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textColor">@android:color/white</item> <item name="android:textColor">@android:color/white</item>
<item name="android:textAllCaps">false</item> <item name="android:textAllCaps">false</item>