Merge pull request #6087 from hackbar/cleanup3

Android: UI cleanup, including combining Save/LoadStateFragment into one
This commit is contained in:
Markus Wick 2017-10-05 08:54:38 +02:00 committed by GitHub
commit 428f0fa69b
8 changed files with 168 additions and 294 deletions

View File

@ -37,9 +37,8 @@ import com.squareup.picasso.Picasso;
import org.dolphinemu.dolphinemu.NativeLibrary; 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.MenuFragment; import org.dolphinemu.dolphinemu.fragments.MenuFragment;
import org.dolphinemu.dolphinemu.fragments.SaveStateFragment; import org.dolphinemu.dolphinemu.fragments.SaveLoadStateFragment;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter; import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.ui.platform.Platform; import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.Animations; import org.dolphinemu.dolphinemu.utils.Animations;
@ -54,14 +53,13 @@ import static java.lang.annotation.RetentionPolicy.SOURCE;
public final class EmulationActivity extends AppCompatActivity public final class EmulationActivity extends AppCompatActivity
{ {
private static final String FRAGMENT_SUBMENU_TAG = "submenu";
private View mDecorView; private View mDecorView;
private ImageView mImageView; private ImageView mImageView;
private FrameLayout mFrameEmulation; private FrameLayout mFrameEmulation;
private LinearLayout mMenuLayout; private LinearLayout mMenuLayout;
private String mSubmenuFragmentTag;
private SharedPreferences mPreferences; private SharedPreferences mPreferences;
// So that MainActivity knows which view to invalidate before the return animation. // So that MainActivity knows which view to invalidate before the return animation.
@ -70,6 +68,7 @@ public final class EmulationActivity extends AppCompatActivity
private boolean mDeviceHasTouchScreen; private boolean mDeviceHasTouchScreen;
private boolean mSystemUiVisible; private boolean mSystemUiVisible;
private boolean mMenuVisible; private boolean mMenuVisible;
private boolean mSubMenuVisible = false;
private static boolean mIsGameCubeGame; private static boolean mIsGameCubeGame;
@ -156,8 +155,23 @@ public final class EmulationActivity extends AppCompatActivity
buttonsActionsMap.append(R.id.menu_emulation_load_4, EmulationActivity.MENU_ACTION_LOAD_SLOT4); buttonsActionsMap.append(R.id.menu_emulation_load_4, EmulationActivity.MENU_ACTION_LOAD_SLOT4);
buttonsActionsMap.append(R.id.menu_emulation_load_5, EmulationActivity.MENU_ACTION_LOAD_SLOT5); buttonsActionsMap.append(R.id.menu_emulation_load_5, EmulationActivity.MENU_ACTION_LOAD_SLOT5);
buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT); buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT);
}
public static void launch(Activity activity, String path, String title, String screenshotPath, int position, View sharedView)
{
Intent launcher = new Intent(activity, EmulationActivity.class);
launcher.putExtra("SelectedGame", path);
launcher.putExtra("SelectedTitle", title);
launcher.putExtra("ScreenPath", screenshotPath);
launcher.putExtra("GridPosition", position);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
activity,
sharedView,
"image_game_screenshot");
activity.startActivityForResult(launcher, MainPresenter.REQUEST_EMULATE_GAME, options.toBundle());
} }
@Override @Override
@ -356,7 +370,7 @@ public final class EmulationActivity extends AppCompatActivity
{ {
if (!mDeviceHasTouchScreen) if (!mDeviceHasTouchScreen)
{ {
if (mSubmenuFragmentTag != null) if (mSubMenuVisible)
{ {
removeSubMenu(); removeSubMenu();
} }
@ -528,14 +542,14 @@ public final class EmulationActivity extends AppCompatActivity
case MENU_ACTION_SAVE_ROOT: case MENU_ACTION_SAVE_ROOT:
if (!mDeviceHasTouchScreen) if (!mDeviceHasTouchScreen)
{ {
showMenu(MenuType.SAVE); showMenu(SaveLoadStateFragment.SaveOrLoad.SAVE);
} }
return; return;
case MENU_ACTION_LOAD_ROOT: case MENU_ACTION_LOAD_ROOT:
if (!mDeviceHasTouchScreen) if (!mDeviceHasTouchScreen)
{ {
showMenu(MenuType.LOAD); showMenu(SaveLoadStateFragment.SaveOrLoad.LOAD);
} }
return; return;
@ -868,68 +882,44 @@ public final class EmulationActivity extends AppCompatActivity
}); });
} }
private void showMenu(MenuType menuId) private void showMenu(SaveLoadStateFragment.SaveOrLoad saveOrLoad)
{ {
Fragment fragment; Fragment fragment = SaveLoadStateFragment.newInstance(saveOrLoad);
switch (menuId)
{
case SAVE:
fragment = SaveStateFragment.newInstance();
mSubmenuFragmentTag = SaveStateFragment.FRAGMENT_TAG;
break;
case LOAD:
fragment = LoadStateFragment.newInstance();
mSubmenuFragmentTag = LoadStateFragment.FRAGMENT_TAG;
break;
default:
return;
}
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, mSubmenuFragmentTag) .replace(R.id.frame_submenu, fragment, FRAGMENT_SUBMENU_TAG)
.commit(); .commit();
mSubMenuVisible = true;
} }
private void removeSubMenu() private void removeSubMenu()
{ {
if (mSubmenuFragmentTag != null) final Fragment fragment = getFragmentManager().findFragmentByTag(FRAGMENT_SUBMENU_TAG);
if (fragment != null)
{ {
final Fragment fragment = getFragmentManager().findFragmentByTag(mSubmenuFragmentTag); // When removing a fragment without replacement, its animation must be done
// manually beforehand.
if (fragment != null) Animations.fadeViewOutToRight(fragment.getView())
{ .withEndAction(new Runnable()
// When removing a fragment without replacement, its animation must be done {
// manually beforehand. @Override
Animations.fadeViewOutToRight(fragment.getView()) public void run()
.withEndAction(new Runnable()
{ {
@Override if (mMenuVisible)
public void run()
{ {
if (mMenuVisible) getFragmentManager().beginTransaction()
{ .remove(fragment)
getFragmentManager().beginTransaction() .commit();
.remove(fragment)
.commit();
}
} }
}); }
} });
else
{
Log.error("[EmulationActivity] Fragment not found, can't remove.");
}
mSubmenuFragmentTag = null;
} }
else else
{ {
Log.error("[EmulationActivity] Fragment Tag empty."); Log.error("[EmulationActivity] Fragment not found, can't remove.");
} }
mSubMenuVisible = false;
} }
public String getSelectedTitle() public String getSelectedTitle()
@ -941,21 +931,4 @@ public final class EmulationActivity extends AppCompatActivity
{ {
return mIsGameCubeGame; return mIsGameCubeGame;
} }
public static void launch(Activity activity, String path, String title, String screenshotPath, int position, View sharedView)
{
Intent launcher = new Intent(activity, EmulationActivity.class);
launcher.putExtra("SelectedGame", path);
launcher.putExtra("SelectedTitle", title);
launcher.putExtra("ScreenPath", screenshotPath);
launcher.putExtra("GridPosition", position);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
activity,
sharedView,
"image_game_screenshot");
activity.startActivityForResult(launcher, MainPresenter.REQUEST_EMULATE_GAME, options.toBundle());
}
} }

View File

@ -1,69 +0,0 @@
package org.dolphinemu.dolphinemu.fragments;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridLayout;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
public final class LoadStateFragment extends Fragment implements View.OnClickListener
{
public static final String FRAGMENT_TAG = "load_state";
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
static {
buttonsActionsMap.append(R.id.menu_emulation_load_1, EmulationActivity.MENU_ACTION_LOAD_SLOT1);
buttonsActionsMap.append(R.id.menu_emulation_load_2, EmulationActivity.MENU_ACTION_LOAD_SLOT2);
buttonsActionsMap.append(R.id.menu_emulation_load_3, EmulationActivity.MENU_ACTION_LOAD_SLOT3);
buttonsActionsMap.append(R.id.menu_emulation_load_4, EmulationActivity.MENU_ACTION_LOAD_SLOT4);
buttonsActionsMap.append(R.id.menu_emulation_load_5, EmulationActivity.MENU_ACTION_LOAD_SLOT5);
buttonsActionsMap.append(R.id.menu_emulation_load_6, EmulationActivity.MENU_ACTION_LOAD_SLOT6);
}
public static LoadStateFragment newInstance()
{
LoadStateFragment fragment = new LoadStateFragment();
// TODO Add any appropriate arguments to this fragment.
return fragment;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_state_load, container, false);
GridLayout grid = (GridLayout) rootView.findViewById(R.id.grid_state_slots);
for (int childIndex = 0; childIndex < grid.getChildCount(); childIndex++)
{
Button button = (Button) grid.getChildAt(childIndex);
button.setOnClickListener(this);
}
// So that item clicked to start this Fragment is no longer the focused item.
grid.requestFocus();
return rootView;
}
@SuppressWarnings("WrongConstant")
@Override
public void onClick(View button)
{
int action = buttonsActionsMap.get(button.getId(), -1);
if (action >= 0)
{
((EmulationActivity) getActivity()).handleMenuAction(action);
}
}
}

View File

@ -0,0 +1,100 @@
package org.dolphinemu.dolphinemu.fragments;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridLayout;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
public final class SaveLoadStateFragment extends Fragment implements View.OnClickListener
{
public enum SaveOrLoad
{
SAVE, LOAD
}
private static final String KEY_SAVEORLOAD = "saveorload";
private static SparseIntArray saveButtonsActionsMap = new SparseIntArray();
static {
saveButtonsActionsMap.append(R.id.loadsave_state_button_1, EmulationActivity.MENU_ACTION_SAVE_SLOT1);
saveButtonsActionsMap.append(R.id.loadsave_state_button_2, EmulationActivity.MENU_ACTION_SAVE_SLOT2);
saveButtonsActionsMap.append(R.id.loadsave_state_button_3, EmulationActivity.MENU_ACTION_SAVE_SLOT3);
saveButtonsActionsMap.append(R.id.loadsave_state_button_4, EmulationActivity.MENU_ACTION_SAVE_SLOT4);
saveButtonsActionsMap.append(R.id.loadsave_state_button_5, EmulationActivity.MENU_ACTION_SAVE_SLOT5);
saveButtonsActionsMap.append(R.id.loadsave_state_button_6, EmulationActivity.MENU_ACTION_SAVE_SLOT6);
}
private static SparseIntArray loadButtonsActionsMap = new SparseIntArray();
static {
loadButtonsActionsMap.append(R.id.loadsave_state_button_1, EmulationActivity.MENU_ACTION_LOAD_SLOT1);
loadButtonsActionsMap.append(R.id.loadsave_state_button_2, EmulationActivity.MENU_ACTION_LOAD_SLOT2);
loadButtonsActionsMap.append(R.id.loadsave_state_button_3, EmulationActivity.MENU_ACTION_LOAD_SLOT3);
loadButtonsActionsMap.append(R.id.loadsave_state_button_4, EmulationActivity.MENU_ACTION_LOAD_SLOT4);
loadButtonsActionsMap.append(R.id.loadsave_state_button_5, EmulationActivity.MENU_ACTION_LOAD_SLOT5);
loadButtonsActionsMap.append(R.id.loadsave_state_button_6, EmulationActivity.MENU_ACTION_LOAD_SLOT6);
}
private SaveOrLoad mSaveOrLoad;
public static SaveLoadStateFragment newInstance(SaveOrLoad saveOrLoad)
{
SaveLoadStateFragment fragment = new SaveLoadStateFragment();
Bundle arguments = new Bundle();
arguments.putSerializable(KEY_SAVEORLOAD, saveOrLoad);
fragment.setArguments(arguments);
return fragment;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mSaveOrLoad = (SaveOrLoad) getArguments().getSerializable(KEY_SAVEORLOAD);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_saveload_state, container, false);
GridLayout grid = (GridLayout) rootView.findViewById(R.id.grid_state_slots);
for (int childIndex = 0; childIndex < grid.getChildCount(); childIndex++)
{
Button button = (Button) grid.getChildAt(childIndex);
button.setOnClickListener(this);
}
// So that item clicked to start this Fragment is no longer the focused item.
grid.requestFocus();
return rootView;
}
@SuppressWarnings("WrongConstant")
@Override
public void onClick(View button)
{
int action = 0;
switch(mSaveOrLoad)
{
case SAVE:
action = saveButtonsActionsMap.get(button.getId(), -1);
break;
case LOAD:
action = loadButtonsActionsMap.get(button.getId(), -1);
}
if (action >= 0)
{
((EmulationActivity) getActivity()).handleMenuAction(action);
}
}
}

View File

@ -1,69 +0,0 @@
package org.dolphinemu.dolphinemu.fragments;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridLayout;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
public final class SaveStateFragment extends Fragment implements View.OnClickListener
{
public static final String FRAGMENT_TAG = "save_state";
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
static {
buttonsActionsMap.append(R.id.menu_emulation_save_1, EmulationActivity.MENU_ACTION_SAVE_SLOT1);
buttonsActionsMap.append(R.id.menu_emulation_save_2, EmulationActivity.MENU_ACTION_SAVE_SLOT2);
buttonsActionsMap.append(R.id.menu_emulation_save_3, EmulationActivity.MENU_ACTION_SAVE_SLOT3);
buttonsActionsMap.append(R.id.menu_emulation_save_4, EmulationActivity.MENU_ACTION_SAVE_SLOT4);
buttonsActionsMap.append(R.id.menu_emulation_save_5, EmulationActivity.MENU_ACTION_SAVE_SLOT5);
buttonsActionsMap.append(R.id.menu_emulation_save_6, EmulationActivity.MENU_ACTION_SAVE_SLOT6);
}
public static SaveStateFragment newInstance()
{
SaveStateFragment fragment = new SaveStateFragment();
// TODO Add any appropriate arguments to this fragment.
return fragment;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_state_save, container, false);
GridLayout grid = (GridLayout) rootView.findViewById(R.id.grid_state_slots);
for (int childIndex = 0; childIndex < grid.getChildCount(); childIndex++)
{
Button button = (Button) grid.getChildAt(childIndex);
button.setOnClickListener(this);
}
// So that item clicked to start this Fragment is no longer the focused item.
grid.requestFocus();
return rootView;
}
@SuppressWarnings("WrongConstant")
@Override
public void onClick(View button)
{
int action = buttonsActionsMap.get(button.getId(), -1);
if (action >= 0)
{
((EmulationActivity) getActivity()).handleMenuAction(action);
}
}
}

View File

@ -22,6 +22,13 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
private static final String FRAGMENT_TAG = "settings"; private static final String FRAGMENT_TAG = "settings";
private SettingsActivityPresenter mPresenter = new SettingsActivityPresenter(this); private SettingsActivityPresenter mPresenter = new SettingsActivityPresenter(this);
public static void launch(Context context, String menuTag)
{
Intent settings = new Intent(context, SettingsActivity.class);
settings.putExtra(ARG_FILE_NAME, menuTag);
context.startActivity(settings);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
{ {
@ -173,13 +180,4 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
{ {
return (SettingsFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG); return (SettingsFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
} }
public static void launch(Context context, String menuTag)
{
Intent settings = new Intent(context, SettingsActivity.class);
settings.putExtra(ARG_FILE_NAME, menuTag);
context.startActivity(settings);
}
} }

View File

@ -30,6 +30,17 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
private SettingsAdapter mAdapter; private SettingsAdapter mAdapter;
public static Fragment newInstance(String menuTag)
{
SettingsFragment fragment = new SettingsFragment();
Bundle arguments = new Bundle();
arguments.putString(ARGUMENT_MENU_TAG, menuTag);
fragment.setArguments(arguments);
return fragment;
}
@Override @Override
public void onAttach(Context context) public void onAttach(Context context)
{ {
@ -175,14 +186,4 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
mActivity.onExtensionSettingChanged(key, value); mActivity.onExtensionSettingChanged(key, value);
} }
public static Fragment newInstance(String menuTag)
{
SettingsFragment fragment = new SettingsFragment();
Bundle arguments = new Bundle();
arguments.putString(ARGUMENT_MENU_TAG, menuTag);
fragment.setArguments(arguments);
return fragment;
}
} }

View File

@ -14,42 +14,42 @@
android:layout_gravity="center"> android:layout_gravity="center">
<Button <Button
android:id="@+id/menu_emulation_load_1" android:id="@+id/loadsave_state_button_1"
android:layout_width="128dp" android:layout_width="128dp"
android:layout_height="128dp" android:layout_height="128dp"
android:text="@string/emulation_slot1" android:text="@string/emulation_slot1"
style="@style/OverlayInGameMenuOption"/> style="@style/OverlayInGameMenuOption"/>
<Button <Button
android:id="@+id/menu_emulation_load_2" android:id="@+id/loadsave_state_button_2"
android:layout_width="128dp" android:layout_width="128dp"
android:layout_height="128dp" android:layout_height="128dp"
android:text="@string/emulation_slot2" android:text="@string/emulation_slot2"
style="@style/OverlayInGameMenuOption"/> style="@style/OverlayInGameMenuOption"/>
<Button <Button
android:id="@+id/menu_emulation_load_3" android:id="@+id/loadsave_state_button_3"
android:layout_width="128dp" android:layout_width="128dp"
android:layout_height="128dp" android:layout_height="128dp"
android:text="@string/emulation_slot3" android:text="@string/emulation_slot3"
style="@style/OverlayInGameMenuOption"/> style="@style/OverlayInGameMenuOption"/>
<Button <Button
android:id="@+id/menu_emulation_load_4" android:id="@+id/loadsave_state_button_4"
android:layout_width="128dp" android:layout_width="128dp"
android:layout_height="128dp" android:layout_height="128dp"
android:text="@string/emulation_slot4" android:text="@string/emulation_slot4"
style="@style/OverlayInGameMenuOption"/> style="@style/OverlayInGameMenuOption"/>
<Button <Button
android:id="@+id/menu_emulation_load_5" android:id="@+id/loadsave_state_button_5"
android:layout_width="128dp" android:layout_width="128dp"
android:layout_height="128dp" android:layout_height="128dp"
android:text="@string/emulation_slot5" android:text="@string/emulation_slot5"
style="@style/OverlayInGameMenuOption"/> style="@style/OverlayInGameMenuOption"/>
<Button <Button
android:id="@+id/menu_emulation_load_6" android:id="@+id/loadsave_state_button_6"
android:layout_width="128dp" android:layout_width="128dp"
android:layout_height="128dp" android:layout_height="128dp"
android:text="@string/emulation_slot6" android:text="@string/emulation_slot6"
@ -57,4 +57,4 @@
</GridLayout> </GridLayout>
</FrameLayout> </FrameLayout>

View File

@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#af000000"
android:orientation="vertical">
<GridLayout
android:id="@+id/grid_state_slots"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="3"
android:rowCount="2"
android:layout_gravity="center">
<Button
android:id="@+id/menu_emulation_save_1"
android:layout_width="128dp"
android:layout_height="128dp"
android:text="@string/emulation_slot1"
style="@style/OverlayInGameMenuOption"/>
<Button
android:id="@+id/menu_emulation_save_2"
android:layout_width="128dp"
android:layout_height="128dp"
android:text="@string/emulation_slot2"
style="@style/OverlayInGameMenuOption"/>
<Button
android:id="@+id/menu_emulation_save_3"
android:layout_width="128dp"
android:layout_height="128dp"
android:text="@string/emulation_slot3"
style="@style/OverlayInGameMenuOption"/>
<Button
android:id="@+id/menu_emulation_save_4"
android:layout_width="128dp"
android:layout_height="128dp"
android:text="@string/emulation_slot4"
style="@style/OverlayInGameMenuOption"/>
<Button
android:id="@+id/menu_emulation_save_5"
android:layout_width="128dp"
android:layout_height="128dp"
android:text="@string/emulation_slot5"
style="@style/OverlayInGameMenuOption"/>
<Button
android:id="@+id/menu_emulation_save_6"
android:layout_width="128dp"
android:layout_height="128dp"
android:text="@string/emulation_slot6"
style="@style/OverlayInGameMenuOption"/>
</GridLayout>
</FrameLayout>