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.fragments.EmulationFragment;
import org.dolphinemu.dolphinemu.fragments.LoadStateFragment;
import org.dolphinemu.dolphinemu.fragments.MenuFragment;
import org.dolphinemu.dolphinemu.fragments.SaveStateFragment;
import java.util.List;
@ -40,7 +41,7 @@ public final class EmulationActivity extends AppCompatActivity
private FrameLayout mFrameEmulation;
private LinearLayout mMenuLayout;
private String mMenuFragmentTag;
private String mSubmenuFragmentTag;
// So that MainActivity knows which view to invalidate before the return animation.
private int mPosition;
@ -67,6 +68,7 @@ public final class EmulationActivity extends AppCompatActivity
};
private String mScreenPath;
private FrameLayout mFrameContent;
private String mSelectedTitle;
@Override
protected void onCreate(Bundle savedInstanceState)
@ -129,7 +131,7 @@ public final class EmulationActivity extends AppCompatActivity
Intent gameToEmulate = getIntent();
String path = gameToEmulate.getStringExtra("SelectedGame");
String title = gameToEmulate.getStringExtra("SelectedTitle");
mSelectedTitle = gameToEmulate.getStringExtra("SelectedTitle");
mScreenPath = gameToEmulate.getStringExtra("ScreenPath");
mPosition = gameToEmulate.getIntExtra("GridPosition", -1);
@ -175,8 +177,6 @@ public final class EmulationActivity extends AppCompatActivity
}
});
setTitle(title);
// Instantiate an EmulationFragment.
EmulationFragment emulationFragment = EmulationFragment.newInstance(path);
@ -184,6 +184,21 @@ public final class EmulationActivity extends AppCompatActivity
getFragmentManager().beginTransaction()
.add(R.id.frame_emulation_fragment, emulationFragment, EmulationFragment.FRAGMENT_TAG)
.commit();
if (mDeviceHasTouchScreen)
{
setTitle(mSelectedTitle);
}
else
{
MenuFragment menuFragment = (MenuFragment) getFragmentManager()
.findFragmentById(R.id.fragment_menu);
if (menuFragment != null)
{
menuFragment.setTitleText(mSelectedTitle);
}
}
}
@Override
@ -240,7 +255,7 @@ public final class EmulationActivity extends AppCompatActivity
{
if (!mDeviceHasTouchScreen)
{
if (mMenuFragmentTag != null)
if (mSubmenuFragmentTag != null)
{
removeMenu();
}
@ -579,12 +594,12 @@ public final class EmulationActivity extends AppCompatActivity
{
case SaveStateFragment.FRAGMENT_ID:
fragment = SaveStateFragment.newInstance();
mMenuFragmentTag = SaveStateFragment.FRAGMENT_TAG;
mSubmenuFragmentTag = SaveStateFragment.FRAGMENT_TAG;
break;
case LoadStateFragment.FRAGMENT_ID:
fragment = LoadStateFragment.newInstance();
mMenuFragmentTag = LoadStateFragment.FRAGMENT_TAG;
mSubmenuFragmentTag = LoadStateFragment.FRAGMENT_TAG;
break;
default:
@ -593,15 +608,15 @@ public final class EmulationActivity extends AppCompatActivity
getFragmentManager().beginTransaction()
.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();
}
private void removeMenu()
{
if (mMenuFragmentTag != null)
if (mSubmenuFragmentTag != null)
{
final Fragment fragment = getFragmentManager().findFragmentByTag(mMenuFragmentTag);
final Fragment fragment = getFragmentManager().findFragmentByTag(mSubmenuFragmentTag);
if (fragment != null)
{
@ -632,11 +647,16 @@ public final class EmulationActivity extends AppCompatActivity
Log.e("DolphinEmu", "[EmulationActivity] Fragment not found, can't remove.");
}
mMenuFragmentTag = null;
mSubmenuFragmentTag = null;
}
else
{
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.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.dolphinemu.dolphinemu.BuildConfig;
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 int FRAGMENT_ID = R.layout.fragment_ingame_menu;
private TextView mTitleText;
@Nullable
@Override
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);
}
mTitleText = (TextView) rootView.findViewById(R.id.text_game_title);
return rootView;
}
@ -39,4 +44,9 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
{
((EmulationActivity) getActivity()).onMenuItemClicked(button.getId());
}
public void setTitleText(String title)
{
mTitleText.setText(title);
}
}

View File

@ -1,13 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dolphin_blue_dark"
android:paddingTop="32dp"
android:paddingBottom="32dp"
tools:layout_width="250dp"
>
<TextView
android:id="@+id/text_game_title"
android:layout_width="match_parent"
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"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<LinearLayout
android:id="@+id/layout_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/menu_take_screenshot"
android:text="@string/overlay_screenshot"
@ -44,3 +65,5 @@
style="@style/InGameMenuOption"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@ -127,7 +127,7 @@
</style>
<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:textColor">@android:color/white</item>
<item name="android:textAllCaps">false</item>