Skip to content

Commit

Permalink
Use UICommon's game list code on Android
Browse files Browse the repository at this point in the history
Deduplicates code, and gets rid of some problems the old code had
(such as: bad performance when calling native functions, only one
disc showing up for multi-disc games, Wii banners being low-res,
unnecessarily much effort being needed for adding more metadata).
  • Loading branch information
JosJuice committed Jun 6, 2018
1 parent daee5a4 commit 1c027bc
Show file tree
Hide file tree
Showing 43 changed files with 975 additions and 1,573 deletions.
8 changes: 1 addition & 7 deletions Source/Android/app/src/main/AndroidManifest.xml
Expand Up @@ -71,13 +71,7 @@
</activity>

<service android:name=".services.DirectoryInitializationService"/>

<provider
android:name=".model.GameProvider"
android:authorities="${applicationId}.provider"
android:enabled="true"
android:exported="false">
</provider>
<service android:name=".services.GameFileCacheService"/>

<provider
android:name="android.support.v4.content.FileProvider"
Expand Down
Expand Up @@ -2,22 +2,19 @@

import android.app.Application;

import org.dolphinemu.dolphinemu.model.GameDatabase;
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
import org.dolphinemu.dolphinemu.utils.PermissionsHandler;

public class DolphinApplication extends Application
{
public static GameDatabase databaseHelper;

@Override
public void onCreate()
{
super.onCreate();

System.loadLibrary("main");

if (PermissionsHandler.hasWriteAccess(getApplicationContext()))
DirectoryInitializationService.startService(getApplicationContext());

databaseHelper = new GameDatabase(this);
}
}
Expand Up @@ -260,34 +260,6 @@ private NativeLibrary()
*/
public static native void SetConfig(String configFile, String Section, String Key, String Value);

/**
* Gets the embedded banner within the given ISO/ROM.
*
* @param filename the file path to the ISO/ROM.
*
* @return an integer array containing the color data for the banner.
*/
public static native int[] GetBanner(String filename);

/**
* Gets the embedded title of the given ISO/ROM.
*
* @param filename The file path to the ISO/ROM.
*
* @return the embedded title of the ISO/ROM.
*/
public static native String GetTitle(String filename);

public static native String GetDescription(String filename);
public static native String GetGameId(String filename);

public static native int GetCountry(String filename);

public static native String GetCompany(String filename);
public static native long GetFilesize(String filename);

public static native int GetPlatform(String filename);

/**
* Gets the Dolphin version string.
*
Expand Down Expand Up @@ -394,27 +366,6 @@ private NativeLibrary()
*/
public static native void RefreshWiimotes();

/**
* The methods C++ uses to find references to Java classes and methods
* are really expensive. Rather than calling them every time we want to
* run them, do it once when we load the native library.
*/
private static native void CacheClassesAndMethods();

static
{
try
{
System.loadLibrary("main");
}
catch (UnsatisfiedLinkError ex)
{
Log.error("[NativeLibrary] " + ex.toString());
}

CacheClassesAndMethods();
}

private static boolean alertResult = false;
public static boolean displayAlertMsg(final String caption, final String text, final boolean yesNo)
{
Expand Down
Expand Up @@ -36,6 +36,7 @@
import org.dolphinemu.dolphinemu.fragments.EmulationFragment;
import org.dolphinemu.dolphinemu.fragments.MenuFragment;
import org.dolphinemu.dolphinemu.fragments.SaveLoadStateFragment;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.ui.main.MainActivity;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
Expand Down Expand Up @@ -74,10 +75,12 @@ public final class EmulationActivity extends AppCompatActivity
private boolean activityRecreated;
private String mScreenPath;
private String mSelectedTitle;
private int mPlatform;
private String mPath;

public static final String EXTRA_SELECTED_GAME = "SelectedGame";
public static final String EXTRA_SELECTED_TITLE = "SelectedTitle";
public static final String EXTRA_PLATFORM = "Platform";
public static final String EXTRA_SCREEN_PATH = "ScreenPath";
public static final String EXTRA_GRID_POSITION = "GridPosition";

Expand Down Expand Up @@ -146,13 +149,14 @@ public final class EmulationActivity extends AppCompatActivity
buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT);
}

public static void launch(FragmentActivity activity, String path, String title, String screenshotPath, int position, View sharedView)
public static void launch(FragmentActivity activity, GameFile gameFile, int position, View sharedView)
{
Intent launcher = new Intent(activity, EmulationActivity.class);

launcher.putExtra(EXTRA_SELECTED_GAME, path);
launcher.putExtra(EXTRA_SELECTED_TITLE, title);
launcher.putExtra(EXTRA_SCREEN_PATH, screenshotPath);
launcher.putExtra(EXTRA_SELECTED_GAME, gameFile.getPath());
launcher.putExtra(EXTRA_SELECTED_TITLE, gameFile.getTitle());
launcher.putExtra(EXTRA_PLATFORM, gameFile.getPlatform());
launcher.putExtra(EXTRA_SCREEN_PATH, gameFile.getScreenshotPath());
launcher.putExtra(EXTRA_GRID_POSITION, position);

ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
Expand All @@ -176,6 +180,7 @@ protected void onCreate(Bundle savedInstanceState)
Intent gameToEmulate = getIntent();
mPath = gameToEmulate.getStringExtra(EXTRA_SELECTED_GAME);
mSelectedTitle = gameToEmulate.getStringExtra(EXTRA_SELECTED_TITLE);
mPlatform = gameToEmulate.getIntExtra(EXTRA_PLATFORM, 0);
mScreenPath = gameToEmulate.getStringExtra(EXTRA_SCREEN_PATH);
mPosition = gameToEmulate.getIntExtra(EXTRA_GRID_POSITION, -1);
activityRecreated = false;
Expand All @@ -186,7 +191,9 @@ protected void onCreate(Bundle savedInstanceState)
restoreState(savedInstanceState);
}

sIsGameCubeGame = Platform.fromNativeInt(NativeLibrary.GetPlatform(mPath)) == Platform.GAMECUBE;
// TODO: The accurate way to find out which console we're emulating is to
// first launch emulation and then ask the core which console we're emulating
sIsGameCubeGame = Platform.fromNativeInt(mPlatform) == Platform.GAMECUBE;
mDeviceHasTouchScreen = getPackageManager().hasSystemFeature("android.hardware.touchscreen");
mControllerMappingHelper = new ControllerMappingHelper();

Expand Down Expand Up @@ -284,6 +291,7 @@ protected void onSaveInstanceState(Bundle outState)
mEmulationFragment.saveTemporaryState();
outState.putString(EXTRA_SELECTED_GAME, mPath);
outState.putString(EXTRA_SELECTED_TITLE, mSelectedTitle);
outState.putInt(EXTRA_PLATFORM, mPlatform);
outState.putString(EXTRA_SCREEN_PATH, mScreenPath);
outState.putInt(EXTRA_GRID_POSITION, mPosition);
super.onSaveInstanceState(outState);
Expand All @@ -293,6 +301,7 @@ protected void restoreState(Bundle savedInstanceState)
{
mPath = savedInstanceState.getString(EXTRA_SELECTED_GAME);
mSelectedTitle = savedInstanceState.getString(EXTRA_SELECTED_TITLE);
mPlatform = savedInstanceState.getInt(EXTRA_PLATFORM);
mScreenPath = savedInstanceState.getString(EXTRA_SCREEN_PATH);
mPosition = savedInstanceState.getInt(EXTRA_GRID_POSITION);
}
Expand Down

0 comments on commit 1c027bc

Please sign in to comment.