Skip to content
Permalink
Browse files
Merge pull request #6087 from hackbar/cleanup3
Android: UI cleanup, including combining Save/LoadStateFragment into one
  • Loading branch information
degasus committed Oct 5, 2017
2 parents 1e6b670 + e4c2d75 commit 428f0fa
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 294 deletions.
@@ -37,9 +37,8 @@
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 org.dolphinemu.dolphinemu.fragments.SaveLoadStateFragment;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.Animations;
@@ -54,14 +53,13 @@

public final class EmulationActivity extends AppCompatActivity
{
private static final String FRAGMENT_SUBMENU_TAG = "submenu";
private View mDecorView;
private ImageView mImageView;

private FrameLayout mFrameEmulation;
private LinearLayout mMenuLayout;

private String mSubmenuFragmentTag;

private SharedPreferences mPreferences;

// 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 mSystemUiVisible;
private boolean mMenuVisible;
private boolean mSubMenuVisible = false;

private static boolean mIsGameCubeGame;

@@ -156,8 +155,23 @@ public void handleMessage(Message msg)
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_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
@@ -356,7 +370,7 @@ public void onBackPressed()
{
if (!mDeviceHasTouchScreen)
{
if (mSubmenuFragmentTag != null)
if (mSubMenuVisible)
{
removeSubMenu();
}
@@ -528,14 +542,14 @@ public void handleMenuAction(@MenuAction int menuAction)
case MENU_ACTION_SAVE_ROOT:
if (!mDeviceHasTouchScreen)
{
showMenu(MenuType.SAVE);
showMenu(SaveLoadStateFragment.SaveOrLoad.SAVE);
}
return;

case MENU_ACTION_LOAD_ROOT:
if (!mDeviceHasTouchScreen)
{
showMenu(MenuType.LOAD);
showMenu(SaveLoadStateFragment.SaveOrLoad.LOAD);
}
return;

@@ -868,68 +882,44 @@ public boolean onPreDraw()
});
}

private void showMenu(MenuType menuId)
private void showMenu(SaveLoadStateFragment.SaveOrLoad saveOrLoad)
{
Fragment fragment;

switch (menuId)
{
case SAVE:
fragment = SaveStateFragment.newInstance();
mSubmenuFragmentTag = SaveStateFragment.FRAGMENT_TAG;
break;

case LOAD:
fragment = LoadStateFragment.newInstance();
mSubmenuFragmentTag = LoadStateFragment.FRAGMENT_TAG;
break;

default:
return;
}

Fragment fragment = SaveLoadStateFragment.newInstance(saveOrLoad);
getFragmentManager().beginTransaction()
.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();
mSubMenuVisible = true;
}

private void removeSubMenu()
{
if (mSubmenuFragmentTag != null)
{
final Fragment fragment = getFragmentManager().findFragmentByTag(mSubmenuFragmentTag);
final Fragment fragment = getFragmentManager().findFragmentByTag(FRAGMENT_SUBMENU_TAG);

if (fragment != null)
{
// When removing a fragment without replacement, its animation must be done
// manually beforehand.
Animations.fadeViewOutToRight(fragment.getView())
.withEndAction(new Runnable()
if (fragment != null)
{
// When removing a fragment without replacement, its animation must be done
// manually beforehand.
Animations.fadeViewOutToRight(fragment.getView())
.withEndAction(new Runnable()
{
@Override
public void run()
{
@Override
public void run()
if (mMenuVisible)
{
if (mMenuVisible)
{
getFragmentManager().beginTransaction()
.remove(fragment)
.commit();
}
getFragmentManager().beginTransaction()
.remove(fragment)
.commit();
}
});
}
else
{
Log.error("[EmulationActivity] Fragment not found, can't remove.");
}

mSubmenuFragmentTag = null;
}
});
}
else
{
Log.error("[EmulationActivity] Fragment Tag empty.");
Log.error("[EmulationActivity] Fragment not found, can't remove.");
}
mSubMenuVisible = false;
}

public String getSelectedTitle()
@@ -941,21 +931,4 @@ public static boolean isGameCubeGame()
{
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());
}
}

This file was deleted.

@@ -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);
}
}
}

0 comments on commit 428f0fa

Please sign in to comment.