Merge pull request #6086 from hackbar/cleanup2

Android: various cleanups in UI code
This commit is contained in:
Leo Lam 2017-09-28 17:53:02 +02:00 committed by GitHub
commit 235f86021a
12 changed files with 52 additions and 69 deletions

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="application_id">org.dolphinemu.dolphinemu.debug</string>
</resources>

View File

@ -15,7 +15,6 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.adapters.FileAdapter;
import org.dolphinemu.dolphinemu.model.GameDatabase;
@ -28,7 +27,7 @@ import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
*/
public class AddDirectoryActivity extends AppCompatActivity implements FileAdapter.FileClickListener
{
public static final String KEY_CURRENT_PATH = BuildConfig.APPLICATION_ID + ".path";
private static final String KEY_CURRENT_PATH = "path";
private FileAdapter mAdapter;
private Toolbar mToolbar;

View File

@ -72,6 +72,11 @@ public final class EmulationActivity extends AppCompatActivity
private static boolean mIsGameCubeGame;
private enum MenuType
{
SAVE, LOAD
}
/**
* Handlers are a way to pass a message to an Activity telling it to do something
* on the UI thread. This Handler responds to any message, even blank ones, by
@ -522,14 +527,14 @@ public final class EmulationActivity extends AppCompatActivity
case MENU_ACTION_SAVE_ROOT:
if (!mDeviceHasTouchScreen)
{
showMenu(SaveStateFragment.FRAGMENT_ID);
showMenu(MenuType.SAVE);
}
return;
case MENU_ACTION_LOAD_ROOT:
if (!mDeviceHasTouchScreen)
{
showMenu(LoadStateFragment.FRAGMENT_ID);
showMenu(MenuType.LOAD);
}
return;
@ -862,18 +867,18 @@ public final class EmulationActivity extends AppCompatActivity
});
}
private void showMenu(int menuId)
private void showMenu(MenuType menuId)
{
Fragment fragment;
switch (menuId)
{
case SaveStateFragment.FRAGMENT_ID:
case SAVE:
fragment = SaveStateFragment.newInstance();
mSubmenuFragmentTag = SaveStateFragment.FRAGMENT_TAG;
break;
case LoadStateFragment.FRAGMENT_ID:
case LOAD:
fragment = LoadStateFragment.newInstance();
mSubmenuFragmentTag = LoadStateFragment.FRAGMENT_TAG;
break;

View File

@ -12,7 +12,6 @@ import android.widget.TextView;
import com.squareup.picasso.Picasso;
import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
@ -20,12 +19,12 @@ import de.hdodenhof.circleimageview.CircleImageView;
public final class GameDetailsDialog extends DialogFragment
{
public static final String ARGUMENT_GAME_TITLE = BuildConfig.APPLICATION_ID + ".game_title";
public static final String ARGUMENT_GAME_DESCRIPTION = BuildConfig.APPLICATION_ID + ".game_description";
public static final String ARGUMENT_GAME_COUNTRY = BuildConfig.APPLICATION_ID + ".game_country";
public static final String ARGUMENT_GAME_DATE = BuildConfig.APPLICATION_ID + ".game_date";
public static final String ARGUMENT_GAME_PATH = BuildConfig.APPLICATION_ID + ".game_path";
public static final String ARGUMENT_GAME_SCREENSHOT_PATH = BuildConfig.APPLICATION_ID + ".game_screenshot_path";
private static final String ARG_GAME_TITLE = "game_title";
private static final String ARG_GAME_DESCRIPTION = "game_description";
private static final String ARG_GAME_COUNTRY = "game_country";
private static final String ARG_GAME_DATE = "game_date";
private static final String ARG_GAME_PATH = "game_path";
private static final String ARG_GAME_SCREENSHOT_PATH = "game_screenshot_path";
// TODO Add all of this to the Loader in GameActivity.java
public static GameDetailsDialog newInstance(String title, String description, int country, String company, String path, String screenshotPath)
@ -33,12 +32,12 @@ public final class GameDetailsDialog extends DialogFragment
GameDetailsDialog fragment = new GameDetailsDialog();
Bundle arguments = new Bundle();
arguments.putString(ARGUMENT_GAME_TITLE, title);
arguments.putString(ARGUMENT_GAME_DESCRIPTION, description);
arguments.putInt(ARGUMENT_GAME_COUNTRY, country);
arguments.putString(ARGUMENT_GAME_DATE, company);
arguments.putString(ARGUMENT_GAME_PATH, path);
arguments.putString(ARGUMENT_GAME_SCREENSHOT_PATH, screenshotPath);
arguments.putString(ARG_GAME_TITLE, title);
arguments.putString(ARG_GAME_DESCRIPTION, description);
arguments.putInt(ARG_GAME_COUNTRY, country);
arguments.putString(ARG_GAME_DATE, company);
arguments.putString(ARG_GAME_PATH, path);
arguments.putString(ARG_GAME_SCREENSHOT_PATH, screenshotPath);
fragment.setArguments(arguments);
return fragment;
@ -61,13 +60,13 @@ public final class GameDetailsDialog extends DialogFragment
FloatingActionButton buttonLaunch = (FloatingActionButton) contents.findViewById(R.id.button_launch);
int countryIndex = getArguments().getInt(ARGUMENT_GAME_COUNTRY);
int countryIndex = getArguments().getInt(ARG_GAME_COUNTRY);
String country = getResources().getStringArray(R.array.countryNames)[countryIndex];
textTitle.setText(getArguments().getString(ARGUMENT_GAME_TITLE));
textDescription.setText(getArguments().getString(ARGUMENT_GAME_DESCRIPTION));
textTitle.setText(getArguments().getString(ARG_GAME_TITLE));
textDescription.setText(getArguments().getString(ARG_GAME_DESCRIPTION));
textCountry.setText(country);
textDate.setText(getArguments().getString(ARGUMENT_GAME_DATE));
textDate.setText(getArguments().getString(ARG_GAME_DATE));
buttonLaunch.setOnClickListener(new View.OnClickListener()
{
@ -76,9 +75,9 @@ public final class GameDetailsDialog extends DialogFragment
{
// Start the emulation activity and send the path of the clicked ROM to it.
EmulationActivity.launch(getActivity(),
getArguments().getString(ARGUMENT_GAME_PATH),
getArguments().getString(ARGUMENT_GAME_TITLE),
getArguments().getString(ARGUMENT_GAME_SCREENSHOT_PATH),
getArguments().getString(ARG_GAME_PATH),
getArguments().getString(ARG_GAME_TITLE),
getArguments().getString(ARG_GAME_SCREENSHOT_PATH),
-1,
imageGameScreen);
}
@ -86,7 +85,7 @@ public final class GameDetailsDialog extends DialogFragment
// Fill in the view contents.
Picasso.with(imageGameScreen.getContext())
.load(getArguments().getString(ARGUMENT_GAME_SCREENSHOT_PATH))
.load(getArguments().getString(ARG_GAME_SCREENSHOT_PATH))
.fit()
.centerCrop()
.noFade()

View File

@ -12,7 +12,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.overlay.InputOverlay;
@ -20,9 +19,9 @@ import org.dolphinemu.dolphinemu.utils.Log;
public final class EmulationFragment extends Fragment implements SurfaceHolder.Callback
{
public static final String FRAGMENT_TAG = BuildConfig.APPLICATION_ID + ".emulation_fragment";
public static final String FRAGMENT_TAG = "emulation_fragment";
private static final String ARGUMENT_GAME_PATH = BuildConfig.APPLICATION_ID + ".game_path";
private static final String ARG_GAME_PATH = "game_path";
private SharedPreferences mPreferences;
@ -40,7 +39,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
EmulationFragment fragment = new EmulationFragment();
Bundle arguments = new Bundle();
arguments.putString(ARGUMENT_GAME_PATH, path);
arguments.putString(ARG_GAME_PATH, path);
fragment.setArguments(arguments);
return fragment;
@ -238,7 +237,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
Log.info("[EmulationFragment] Starting emulation: " + mSurface);
// Start emulation using the provided Surface.
String path = getArguments().getString(ARGUMENT_GAME_PATH);
String path = getArguments().getString(ARG_GAME_PATH);
NativeLibrary.Run(path);
}
};

View File

@ -10,14 +10,12 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridLayout;
import org.dolphinemu.dolphinemu.BuildConfig;
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 = BuildConfig.APPLICATION_ID + ".load_state";
public static final int FRAGMENT_ID = R.layout.fragment_state_load;
public static final String FRAGMENT_TAG = "load_state";
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
static {
@ -42,7 +40,7 @@ public final class LoadStateFragment extends Fragment implements View.OnClickLis
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(FRAGMENT_ID, container, false);
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++)

View File

@ -11,14 +11,11 @@ import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
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;
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
static {
@ -35,7 +32,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(FRAGMENT_ID, container, false);
View rootView = inflater.inflate(R.layout.fragment_ingame_menu, container, false);
LinearLayout options = (LinearLayout) rootView.findViewById(R.id.layout_options);
for (int childIndex = 0; childIndex < options.getChildCount(); childIndex++)

View File

@ -10,14 +10,12 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridLayout;
import org.dolphinemu.dolphinemu.BuildConfig;
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 = BuildConfig.APPLICATION_ID + ".save_state";
public static final int FRAGMENT_ID = R.layout.fragment_state_save;
public static final String FRAGMENT_TAG = "save_state";
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
static {
@ -42,7 +40,7 @@ public final class SaveStateFragment extends Fragment implements View.OnClickLis
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(FRAGMENT_ID, container, false);
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++)

View File

@ -10,13 +10,12 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.adapters.GameAdapter;
public final class PlatformGamesFragment extends Fragment implements PlatformGamesView
{
private static final String ARG_PLATFORM = BuildConfig.APPLICATION_ID + ".PLATFORM";
private static final String ARG_PLATFORM = "platform";
private PlatformGamesPresenter mPresenter = new PlatformGamesPresenter(this);

View File

@ -10,7 +10,6 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.model.settings.SettingSection;
@ -19,6 +18,8 @@ import java.util.HashMap;
public final class SettingsActivity extends AppCompatActivity implements SettingsActivityView
{
private static final String ARG_FILE_NAME = "file_name";
private static final String FRAGMENT_TAG = "settings";
private SettingsActivityPresenter mPresenter = new SettingsActivityPresenter(this);
@Override
@ -29,7 +30,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
setContentView(R.layout.activity_settings);
Intent launcher = getIntent();
String filename = launcher.getStringExtra(ARGUMENT_FILE_NAME);
String filename = launcher.getStringExtra(ARG_FILE_NAME);
mPresenter.onCreate(savedInstanceState, filename);
}
@ -93,7 +94,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
transaction.addToBackStack(null);
mPresenter.addToStack();
}
transaction.replace(R.id.frame_content, SettingsFragment.newInstance(menuTag), SettingsFragment.FRAGMENT_TAG);
transaction.replace(R.id.frame_content, SettingsFragment.newInstance(menuTag), FRAGMENT_TAG);
transaction.commit();
}
@ -170,16 +171,14 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
private SettingsFragment getFragment()
{
return (SettingsFragment) getFragmentManager().findFragmentByTag(SettingsFragment.FRAGMENT_TAG);
return (SettingsFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
}
public static final String ARGUMENT_FILE_NAME = BuildConfig.APPLICATION_ID + ".file_name";
public static void launch(Context context, String menuTag)
{
Intent settings = new Intent(context, SettingsActivity.class);
settings.putExtra(ARGUMENT_FILE_NAME, menuTag);
settings.putExtra(ARG_FILE_NAME, menuTag);
context.startActivity(settings);
}

View File

@ -2,9 +2,6 @@ package org.dolphinemu.dolphinemu.ui.settings;
import android.os.Bundle;
import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.DolphinApplication;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.model.settings.SettingSection;
import org.dolphinemu.dolphinemu.utils.Log;
@ -15,7 +12,7 @@ import java.util.HashMap;
public final class SettingsActivityPresenter
{
private static final String SHOULD_SAVE = BuildConfig.APPLICATION_ID + ".should_save";
private static final String KEY_SHOULD_SAVE = "should_save";
private SettingsActivityView mView;
@ -43,7 +40,7 @@ public final class SettingsActivityPresenter
}
else
{
mShouldSave = savedInstanceState.getBoolean(SHOULD_SAVE);
mShouldSave = savedInstanceState.getBoolean(KEY_SHOULD_SAVE);
}
}
@ -106,7 +103,7 @@ public final class SettingsActivityPresenter
public void saveState(Bundle outState)
{
outState.putBoolean(SHOULD_SAVE, mShouldSave);
outState.putBoolean(KEY_SHOULD_SAVE, mShouldSave);
}
public void onGcPadSettingChanged(String key, int value)

View File

@ -11,7 +11,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.model.settings.Setting;
import org.dolphinemu.dolphinemu.model.settings.SettingSection;
@ -24,6 +23,8 @@ import java.util.HashMap;
public final class SettingsFragment extends Fragment implements SettingsFragmentView
{
private static final String ARGUMENT_MENU_TAG = "menu_tag";
private SettingsFragmentPresenter mPresenter = new SettingsFragmentPresenter(this);
private SettingsActivityView mActivity;
@ -174,10 +175,6 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
mActivity.onExtensionSettingChanged(key, value);
}
public static final String FRAGMENT_TAG = BuildConfig.APPLICATION_ID + ".fragment.settings";
public static final String ARGUMENT_MENU_TAG = FRAGMENT_TAG + ".menu_tag";
public static Fragment newInstance(String menuTag)
{
SettingsFragment fragment = new SettingsFragment();