diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2774bb2b49..c2abfb13ce 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -60,10 +60,11 @@ android:name="paulscode.android.mupen64plusae.GalleryActivity" android:exported="false" android:label="@string/GalleryActivity_title" - android:launchMode="singleTask" > + android:launchMode="singleTask" + android:theme="@style/Theme.AppCompat.NoActionBar" > @@ -73,7 +74,7 @@ @@ -168,13 +169,13 @@ This behavior is specified in android:configChanges below. --> diff --git a/doc/GameActivity.ucls b/doc/GameActivity.ucls index c4f5a19b56..73b3659dd8 100644 --- a/doc/GameActivity.ucls +++ b/doc/GameActivity.ucls @@ -1,6 +1,6 @@ - @@ -9,7 +9,7 @@ - @@ -17,7 +17,7 @@ - @@ -25,7 +25,7 @@ - @@ -34,7 +34,7 @@ @@ -43,7 +43,7 @@ @@ -60,7 +60,7 @@ - @@ -69,7 +69,7 @@ - diff --git a/jni/SDL2/src/core/android/SDL_android.c b/jni/SDL2/src/core/android/SDL_android.c index b7d1ff6d1c..bed6a39599 100644 --- a/jni/SDL2/src/core/android/SDL_android.c +++ b/jni/SDL2/src/core/android/SDL_android.c @@ -107,6 +107,11 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) return JNI_VERSION_1_4; } +void JNI_OnUnload(JavaVM *vm, void *reserved) +{ + pthread_key_delete(mThreadKey); +} + // Called before SDL_main() to initialize JNI bindings void SDL_Android_Init(JNIEnv* mEnv, jclass cls) { diff --git a/jni/ae-bridge/ae_exports.cpp b/jni/ae-bridge/ae_exports.cpp index c780f040d7..5d8628219a 100644 --- a/jni/ae-bridge/ae_exports.cpp +++ b/jni/ae-bridge/ae_exports.cpp @@ -48,6 +48,7 @@ static void *handleFront; // libmupen64plus-ui-console.so // Function types typedef jint (*pJNI_OnLoad) (JavaVM* vm, void* reserved); +typedef void (*pJNI_OnUnload) (JavaVM *vm, void *reserved); typedef int (*pAeiInit) (JNIEnv* env, jclass cls); typedef int (*pSdlInit) (JNIEnv* env, jclass cls); typedef void (*pSdlSetScreen) (int width, int height, Uint32 format); @@ -175,6 +176,11 @@ extern "C" DECLSPEC void SDLCALL Java_paulscode_android_mupen64plusae_jni_Native // Clear stale error messages dlerror(); + // Find and call the JNI_OnUnLoad functions from the SDL2 library + pJNI_OnUnload JNI_OnUnLoad = (pJNI_OnUnload) locateFunction(handleSDL, "SDL2", "JNI_OnUnload"); + JNI_OnUnLoad(mVm, mReserved); + JNI_OnUnLoad = NULL; + // Nullify function pointers so that they can no longer be used aeiInit = NULL; sdlInit = NULL; diff --git a/jni/mupen64plus-video-gliden64/.gitignore b/jni/mupen64plus-video-gliden64/.gitignore index aab6c1c9f4..72e8ffc0db 100644 --- a/jni/mupen64plus-video-gliden64/.gitignore +++ b/jni/mupen64plus-video-gliden64/.gitignore @@ -1,4 +1 @@ -*.cpp -*.h -*.sh -*.txt +* diff --git a/res/layout/game_activity.xml b/res/layout/game_activity.xml index f952bb8a70..55675471ec 100644 --- a/res/layout/game_activity.xml +++ b/res/layout/game_activity.xml @@ -4,14 +4,14 @@ android:layout_height="match_parent" android:orientation="vertical" > - - - + android:key="screenRoot" > . + * + * Authors: littleguy77 + */ + +package paulscode.android.mupen64plusae; + +import paulscode.android.mupen64plusae.game.GameActivity; +import paulscode.android.mupen64plusae.game.GameActivityXperiaPlay; +import paulscode.android.mupen64plusae.input.DiagnosticActivity; +import paulscode.android.mupen64plusae.persistent.GamePrefsActivity; +import paulscode.android.mupen64plusae.persistent.GlobalPrefsActivity; +import paulscode.android.mupen64plusae.profile.ControllerProfileActivity; +import paulscode.android.mupen64plusae.profile.EmulationProfileActivity; +import paulscode.android.mupen64plusae.profile.ManageControllerProfilesActivity; +import paulscode.android.mupen64plusae.profile.ManageEmulationProfilesActivity; +import paulscode.android.mupen64plusae.profile.ManageTouchscreenProfilesActivity; +import paulscode.android.mupen64plusae.profile.TouchscreenProfileActivity; +import android.annotation.SuppressLint; +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.text.TextUtils; + +/** + * Utility class that encapsulates and standardizes interactions between activities. + */ +public class ActivityHelper +{ + /** + * Keys used to pass data to activities via the intent extras bundle. It's good practice to + * namespace the keys to avoid conflicts with other apps. By convention this is usually the + * package name but it's not a strict requirement. We'll use the fully qualified name of this + * class since it's easy to get. + */ + public static class Keys + { + private static final String NAMESPACE = Keys.class.getCanonicalName() + "."; + //@formatter:off + public static final String ROM_PATH = NAMESPACE + "ROM_PATH"; + public static final String ROM_MD5 = NAMESPACE + "ROM_MD5"; + public static final String CHEAT_ARGS = NAMESPACE + "CHEAT_ARGS"; + public static final String DO_RESTART = NAMESPACE + "DO_RESTART"; + public static final String PROFILE_NAME = NAMESPACE + "PROFILE_NAME"; + public static final String MENU_DISPLAY_MODE = NAMESPACE + "MENU_DISPLAY_MODE"; + //@formatter:on + } + + public static void launchUri( Context context, int resId ) + { + launchUri( context, context.getString( resId ) ); + } + + public static void launchUri( Context context, String uriString ) + { + launchUri( context, Uri.parse( uriString ) ); + } + + public static void launchUri( Context context, Uri uri ) + { + context.startActivity( new Intent( Intent.ACTION_VIEW, uri ) ); + } + + @SuppressLint( "InlinedApi" ) + public static void launchPlainText( Context context, String text, CharSequence chooserTitle ) + { + // See http://android-developers.blogspot.com/2012/02/share-with-intents.html + Intent intent = new Intent( android.content.Intent.ACTION_SEND ); + intent.setType( "text/plain" ); + intent.addFlags( Intent.FLAG_ACTIVITY_NEW_DOCUMENT ); + intent.putExtra( Intent.EXTRA_TEXT, text ); + // intent.putExtra( Intent.EXTRA_SUBJECT, subject ); + // intent.putExtra( Intent.EXTRA_EMAIL, new String[] { emailTo } ); + context.startActivity( Intent.createChooser( intent, chooserTitle ) ); + } + + public static void restartActivity( Activity activity ) + { + activity.finish(); + activity.startActivity( activity.getIntent() ); + } + + public static void startSplashActivity( Context context ) + { + context.startActivity( new Intent( context, SplashActivity.class ) ); + } + + public static void startGalleryActivity( Context context, Uri romPath ) + { + startGalleryActivity( context, romPath == null ? null : romPath.getPath() ); + } + + public static void startGalleryActivity( Context context, String romPath ) + { + Intent intent = new Intent( context, GalleryActivity.class ); + if( !TextUtils.isEmpty( romPath ) ) + intent.putExtra( ActivityHelper.Keys.ROM_PATH, romPath ); + context.startActivity( intent ); + } + + public static void startGameActivity( Context context, String romPath, String romMd5, + String cheatArgs, boolean doRestart, boolean isXperiaPlay ) + { + Intent intent = isXperiaPlay + ? new Intent( context, GameActivityXperiaPlay.class ) + : new Intent( context, GameActivity.class ); + intent.putExtra( ActivityHelper.Keys.ROM_PATH, romPath ); + intent.putExtra( ActivityHelper.Keys.ROM_MD5, romMd5 ); + intent.putExtra( ActivityHelper.Keys.CHEAT_ARGS, cheatArgs ); + intent.putExtra( ActivityHelper.Keys.DO_RESTART, doRestart ); + context.startActivity( intent ); + } + + public static void startGlobalPrefsActivity( Context context ) + { + startGlobalPrefsActivity( context, 0 ); + } + + public static void startGlobalPrefsActivity( Context context, int menuDisplayMode ) + { + Intent intent = new Intent( context, GlobalPrefsActivity.class ); + intent.putExtra( ActivityHelper.Keys.MENU_DISPLAY_MODE, menuDisplayMode ); + context.startActivity( intent ); + } + + public static void startGamePrefsActivity( Context context, String romPath, String romMd5 ) + { + Intent intent = new Intent( context, GamePrefsActivity.class ); + intent.putExtra( ActivityHelper.Keys.ROM_PATH, romPath ); + intent.putExtra( ActivityHelper.Keys.ROM_MD5, romMd5 ); + context.startActivity( intent ); + } + + public static void startManageEmulationProfilesActivity( Context context ) + { + context.startActivity( new Intent( context, ManageEmulationProfilesActivity.class ) ); + } + + public static void startManageTouchscreenProfilesActivity( Context context ) + { + context.startActivity( new Intent( context, ManageTouchscreenProfilesActivity.class ) ); + } + + public static void startManageControllerProfilesActivity( Context context ) + { + context.startActivity( new Intent( context, ManageControllerProfilesActivity.class ) ); + } + + public static void startEmulationProfileActivity( Context context, String profileName ) + { + Intent intent = new Intent( context, EmulationProfileActivity.class ); + intent.putExtra( ActivityHelper.Keys.PROFILE_NAME, profileName ); + context.startActivity( intent ); + } + + public static void startTouchscreenProfileActivity( Context context, String profileName ) + { + Intent intent = new Intent( context, TouchscreenProfileActivity.class ); + intent.putExtra( ActivityHelper.Keys.PROFILE_NAME, profileName ); + context.startActivity( intent ); + } + + public static void startControllerProfileActivity( Context context, String profileName ) + { + Intent intent = new Intent( context, ControllerProfileActivity.class ); + intent.putExtra( ActivityHelper.Keys.PROFILE_NAME, profileName ); + context.startActivity( intent ); + } + + public static void startDiagnosticActivity( Context context ) + { + context.startActivity( new Intent( context, DiagnosticActivity.class ) ); + } +} diff --git a/src/paulscode/android/mupen64plusae/GalleryActivity.java b/src/paulscode/android/mupen64plusae/GalleryActivity.java index c7255c71ad..ff649f39e5 100755 --- a/src/paulscode/android/mupen64plusae/GalleryActivity.java +++ b/src/paulscode/android/mupen64plusae/GalleryActivity.java @@ -34,21 +34,19 @@ import paulscode.android.mupen64plusae.dialog.Prompt.PromptConfirmListener; import paulscode.android.mupen64plusae.dialog.ScanRomsDialog; import paulscode.android.mupen64plusae.dialog.ScanRomsDialog.ScanRomsDialogListener; -import paulscode.android.mupen64plusae.input.DiagnosticActivity; import paulscode.android.mupen64plusae.persistent.AppData; import paulscode.android.mupen64plusae.persistent.ConfigFile; import paulscode.android.mupen64plusae.persistent.ConfigFile.ConfigSection; -import paulscode.android.mupen64plusae.persistent.UserPrefs; -import paulscode.android.mupen64plusae.profile.ManageControllerProfilesActivity; -import paulscode.android.mupen64plusae.profile.ManageEmulationProfilesActivity; -import paulscode.android.mupen64plusae.profile.ManageTouchscreenProfilesActivity; +import paulscode.android.mupen64plusae.persistent.GamePrefs; +import paulscode.android.mupen64plusae.persistent.GamePrefsActivity; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import paulscode.android.mupen64plusae.task.CacheRomInfoTask; import paulscode.android.mupen64plusae.task.CacheRomInfoTask.CacheRomInfoListener; import paulscode.android.mupen64plusae.task.ComputeMd5Task; import paulscode.android.mupen64plusae.task.ComputeMd5Task.ComputeMd5Listener; import paulscode.android.mupen64plusae.util.DeviceUtil; import paulscode.android.mupen64plusae.util.Notifier; -import paulscode.android.mupen64plusae.util.Utility; +import paulscode.android.mupen64plusae.util.RomHeader; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.AlertDialog.Builder; @@ -71,6 +69,7 @@ import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.util.DisplayMetrics; +import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; @@ -86,7 +85,7 @@ public class GalleryActivity extends ActionBarActivity implements ComputeMd5List // App data and user preferences private AppData mAppData = null; - private UserPrefs mUserPrefs = null; + private GlobalPrefs mGlobalPrefs = null; // Widgets private RecyclerView mGridView; @@ -120,7 +119,7 @@ protected void onNewIntent( Intent intent ) // If the activity is already running and is launched again (e.g. from a file manager app), // the existing instance will be reused rather than a new one created. This behavior is // specified in the manifest (launchMode = singleTask). In that situation, any activities - // above this on the stack (e.g. GameActivity, PlayMenuActivity) will be destroyed + // above this on the stack (e.g. GameActivity, GamePrefsActivity) will be destroyed // gracefully and onNewIntent() will be called on this instance. onCreate() will NOT be // called again on this instance. Currently, the only info that may be passed via the intent // is the selected game path, so we only need to refresh that aspect of the UI. This will @@ -134,13 +133,12 @@ protected void onNewIntent( Intent intent ) @Override protected void onCreate( Bundle savedInstanceState ) { - super.setTheme( android.support.v7.appcompat.R.style.Theme_AppCompat_NoActionBar ); super.onCreate( savedInstanceState ); // Get app data and user preferences mAppData = new AppData( this ); - mUserPrefs = new UserPrefs( this ); - mUserPrefs.enforceLocale( this ); + mGlobalPrefs = new GlobalPrefs( this ); + mGlobalPrefs.enforceLocale( this ); int lastVer = mAppData.getLastAppVersionCode(); int currVer = mAppData.appVersionCode; @@ -159,7 +157,7 @@ protected void onCreate( Bundle savedInstanceState ) Bundle extras = getIntent().getExtras(); if( extras != null ) { - String givenRomPath = extras.getString( Keys.Extras.ROM_PATH ); + String givenRomPath = extras.getString( ActivityHelper.Keys.ROM_PATH ); if( !TextUtils.isEmpty( givenRomPath ) ) launchPlayMenuActivity( givenRomPath ); } @@ -167,7 +165,7 @@ protected void onCreate( Bundle savedInstanceState ) // Lay out the content setContentView( R.layout.gallery_activity ); mGridView = (RecyclerView) findViewById( R.id.gridview ); - refreshGrid( new ConfigFile( mUserPrefs.romInfoCache_cfg ) ); + refreshGrid( new ConfigFile( mGlobalPrefs.romInfoCache_cfg ) ); // Update the grid layout galleryMaxWidth = (int) getResources().getDimension( R.dimen.galleryImageWidth ); @@ -352,7 +350,7 @@ public boolean onCreateOptionsMenu( Menu menu ) public boolean onMenuItemActionCollapse( MenuItem item ) { mSearchQuery = ""; - refreshGrid( new ConfigFile( mUserPrefs.romInfoCache_cfg ) ); + refreshGrid( new ConfigFile( mGlobalPrefs.romInfoCache_cfg ) ); return true; } @@ -375,7 +373,7 @@ public boolean onQueryTextSubmit( String query ) public boolean onQueryTextChange( String query ) { mSearchQuery = query; - refreshGrid( new ConfigFile( mUserPrefs.romInfoCache_cfg ) ); + refreshGrid( new ConfigFile( mGlobalPrefs.romInfoCache_cfg ) ); return false; } } ); @@ -402,28 +400,28 @@ public boolean onOptionsItemSelected( MenuItem item ) mDrawerLayout.closeDrawer( GravityCompat.START ); return true; case R.id.menuItem_settings: - startActivity( new Intent( this, SettingsGlobalActivity.class ) ); + ActivityHelper.startGlobalPrefsActivity( this ); return true; case R.id.menuItem_emulationProfiles: - startActivity( new Intent( this, ManageEmulationProfilesActivity.class ) ); + ActivityHelper.startManageEmulationProfilesActivity( this ); return true; case R.id.menuItem_touchscreenProfiles: - startActivity( new Intent( this, ManageTouchscreenProfilesActivity.class ) ); + ActivityHelper.startManageTouchscreenProfilesActivity( this ); return true; case R.id.menuItem_controllerProfiles: - startActivity( new Intent( this, ManageControllerProfilesActivity.class ) ); + ActivityHelper.startManageControllerProfilesActivity( this ); return true; case R.id.menuItem_faq: popupFaq(); return true; case R.id.menuItem_helpForum: - Utility.launchUri( GalleryActivity.this, R.string.uri_forum ); + ActivityHelper.launchUri( GalleryActivity.this, R.string.uri_forum ); return true; case R.id.menuItem_controllerDiagnostics: - startActivity( new Intent( this, DiagnosticActivity.class ) ); + ActivityHelper.startDiagnosticActivity( this ); return true; case R.id.menuItem_reportBug: - Utility.launchUri( GalleryActivity.this, R.string.uri_bugReport ); + ActivityHelper.launchUri( GalleryActivity.this, R.string.uri_bugReport ); return true; case R.id.menuItem_appVersion: popupAppVersion(); @@ -439,10 +437,10 @@ public boolean onOptionsItemSelected( MenuItem item ) popupHardwareInfo(); return true; case R.id.menuItem_credits: - Utility.launchUri( GalleryActivity.this, R.string.uri_credits ); + ActivityHelper.launchUri( GalleryActivity.this, R.string.uri_credits ); return true; case R.id.menuItem_localeOverride: - mUserPrefs.changeLocale( this ); + mGlobalPrefs.changeLocale( this ); return true; default: return super.onOptionsItemSelected( item ); @@ -467,8 +465,7 @@ public void updateSidebar() @Override public void onAction() { - PlayMenuActivity.action = PlayMenuActivity.ACTION_RESUME; - launchPlayMenuActivity( finalItem.romFile.getAbsolutePath(), finalItem.md5 ); + launchGameActivity( finalItem.romFile.getAbsolutePath(), finalItem.md5, false ); } } ); @@ -486,8 +483,7 @@ public void onAction() @Override public void onConfirm() { - PlayMenuActivity.action = PlayMenuActivity.ACTION_RESTART; - launchPlayMenuActivity( finalItem.romFile.getAbsolutePath(), finalItem.md5 ); + launchGameActivity( finalItem.romFile.getAbsolutePath(), finalItem.md5, true ); } } ); } @@ -499,8 +495,8 @@ public void onConfirm() @Override public void onAction() { - PlayMenuActivity.action = null; - launchPlayMenuActivity( finalItem.romFile.getAbsolutePath(), finalItem.md5 ); + GamePrefsActivity.action = null; + ActivityHelper.startGamePrefsActivity( GalleryActivity.this, finalItem.romFile.getAbsolutePath(), finalItem.md5 ); } } ); } @@ -570,18 +566,7 @@ public void onBackPressed() @Override public void onComputeMd5Finished( File file, String md5 ) { - launchPlayMenuActivity( file.getAbsolutePath(), md5 ); - } - - private void launchPlayMenuActivity( String romPath, String md5 ) - { - if( !TextUtils.isEmpty( romPath ) && !TextUtils.isEmpty( md5 ) ) - { - Intent intent = new Intent( GalleryActivity.this, PlayMenuActivity.class ); - intent.putExtra( Keys.Extras.ROM_PATH, romPath ); - intent.putExtra( Keys.Extras.ROM_MD5, md5 ); - startActivity( intent ); - } + ActivityHelper.startGamePrefsActivity( this, file.getAbsolutePath(), md5 ); } private void promptSearchPath( File startDir ) @@ -590,17 +575,17 @@ private void promptSearchPath( File startDir ) if( startDir == null || !startDir.exists() ) startDir = new File( Environment.getExternalStorageDirectory().getAbsolutePath() ); - ScanRomsDialog dialog = new ScanRomsDialog( this, startDir, mUserPrefs.getSearchZips(), - mUserPrefs.getDownloadArt(), mUserPrefs.getClearGallery(), + ScanRomsDialog dialog = new ScanRomsDialog( this, startDir, mGlobalPrefs.getSearchZips(), + mGlobalPrefs.getDownloadArt(), mGlobalPrefs.getClearGallery(), new ScanRomsDialogListener() { @Override public void onDialogClosed( File file, int which, boolean searchZips, boolean downloadArt, boolean clearGallery ) { - mUserPrefs.putSearchZips( searchZips ); - mUserPrefs.putDownloadArt( downloadArt ); - mUserPrefs.putClearGallery( clearGallery ); + mGlobalPrefs.putSearchZips( searchZips ); + mGlobalPrefs.putDownloadArt( downloadArt ); + mGlobalPrefs.putClearGallery( clearGallery ); if( which == DialogInterface.BUTTON_POSITIVE ) { // Search this folder for ROMs @@ -625,9 +610,9 @@ private void refreshRoms( final File startDir ) { // Asynchronously search for ROMs mCacheRomInfoTask = new CacheRomInfoTask( this, startDir, mAppData.mupen64plus_ini, - mUserPrefs.romInfoCache_cfg, mUserPrefs.coverArtDir, mUserPrefs.unzippedRomsDir, - mUserPrefs.getSearchZips(), mUserPrefs.getDownloadArt(), - mUserPrefs.getClearGallery(), this ); + mGlobalPrefs.romInfoCache_cfg, mGlobalPrefs.coverArtDir, mGlobalPrefs.unzippedRomsDir, + mGlobalPrefs.getSearchZips(), mGlobalPrefs.getDownloadArt(), + mGlobalPrefs.getClearGallery(), this ); mCacheRomInfoTask.execute(); } @@ -653,7 +638,7 @@ private void refreshGrid( ConfigFile config ) List items = new ArrayList(); List recentItems = null; int currentTime = 0; - if( mUserPrefs.isRecentShown ) + if( mGlobalPrefs.isRecentShown ) { recentItems = new ArrayList(); currentTime = (int) ( new Date().getTime() / 1000 ); @@ -665,7 +650,7 @@ private void refreshGrid( ConfigFile config ) { ConfigSection section = config.get( md5 ); String goodName; - if( mUserPrefs.isFullNameShown || !section.keySet().contains( "baseName" ) ) + if( mGlobalPrefs.isFullNameShown || !section.keySet().contains( "baseName" ) ) goodName = section.get( "goodName" ); else goodName = section.get( "baseName" ); @@ -697,7 +682,7 @@ private void refreshGrid( ConfigFile config ) GalleryItem item = new GalleryItem( this, md5, goodName, romPath, artPath, lastPlayed ); items.add( item ); - if( mUserPrefs.isRecentShown + if( mGlobalPrefs.isRecentShown && currentTime - item.lastPlayed <= 60 * 60 * 24 * 7 ) // 7 days recentItems.add( item ); } @@ -708,7 +693,7 @@ private void refreshGrid( ConfigFile config ) Collections.sort( recentItems, new GalleryItem.RecentlyPlayedComparator() ); List combinedItems = items; - if( mUserPrefs.isRecentShown && recentItems.size() > 0 ) + if( mGlobalPrefs.isRecentShown && recentItems.size() > 0 ) { combinedItems = new ArrayList(); @@ -778,14 +763,7 @@ private void popupShareableText( String title, final String message ) @Override public void onClick( DialogInterface dialog, int which ) { - // See http://android-developers.blogspot.com/2012/02/share-with-intents.html - Intent intent = new Intent( android.content.Intent.ACTION_SEND ); - intent.setType( "text/plain" ); - intent.addFlags( Intent.FLAG_ACTIVITY_NEW_DOCUMENT ); - intent.putExtra( Intent.EXTRA_TEXT, message ); - // intent.putExtra( Intent.EXTRA_SUBJECT, subject ); - // intent.putExtra( Intent.EXTRA_EMAIL, new String[] { emailTo } ); - startActivity( Intent.createChooser( intent, getText( R.string.actionShare_title ) ) ); + ActivityHelper.launchPlainText( GalleryActivity.this, message, getText( R.string.actionShare_title ) ); } }; @@ -812,15 +790,67 @@ protected void onResume() private void refreshViews() { // Refresh the preferences object in case another activity changed the data - mUserPrefs = new UserPrefs( this ); + mGlobalPrefs = new GlobalPrefs( this ); // Set the sidebar opacity on the two sidebars mDrawerList.setBackgroundDrawable( new DrawerDrawable( - mUserPrefs.displayActionBarTransparency ) ); + mGlobalPrefs.displayActionBarTransparency ) ); mGameSidebar.setBackgroundDrawable( new DrawerDrawable( - mUserPrefs.displayActionBarTransparency ) ); + mGlobalPrefs.displayActionBarTransparency ) ); // Refresh the gallery - refreshGrid( new ConfigFile( mUserPrefs.romInfoCache_cfg ) ); + refreshGrid( new ConfigFile( mGlobalPrefs.romInfoCache_cfg ) ); + } + + public void launchGameActivity( String romPath, String romMd5, boolean isRestarting ) + { + RomHeader romHeader = new RomHeader( romPath ); + GamePrefs gamePrefs = new GamePrefs( this, romMd5, romHeader ); +// TODO FIXME +// // Popup the multi-player dialog if necessary and abort if any players are unassigned +// RomDatabase romDatabase = new RomDatabase( mAppData.mupen64plus_ini ); +// RomDetail romDetail = romDatabase.lookupByMd5WithFallback( romMd5, new File( romPath ) ); +// if( romDetail.players > 1 && gamePrefs.playerMap.isEnabled() +// && mGlobalPrefs.getPlayerMapReminder() ) +// { +// gamePrefs.playerMap.removeUnavailableMappings(); +// boolean needs1 = gamePrefs.isControllerEnabled1 && !gamePrefs.playerMap.isMapped( 1 ); +// boolean needs2 = gamePrefs.isControllerEnabled2 && !gamePrefs.playerMap.isMapped( 2 ); +// boolean needs3 = gamePrefs.isControllerEnabled3 && !gamePrefs.playerMap.isMapped( 3 ) +// && romDetail.players > 2; +// boolean needs4 = gamePrefs.isControllerEnabled4 && !gamePrefs.playerMap.isMapped( 4 ) +// && romDetail.players > 3; +// +// if( needs1 || needs2 || needs3 || needs4 ) +// { +// @SuppressWarnings( "deprecation" ) +// PlayerMapPreference pref = (PlayerMapPreference) findPreference( "playerMap" ); +// pref.show(); +// return; +// } +// } + + // Make sure that the storage is accessible + if( !mAppData.isSdCardAccessible() ) + { + Log.e( "GalleryActivity", "SD Card not accessible" ); + Notifier.showToast( this, R.string.toast_sdInaccessible ); + return; + } + + // Notify user that the game activity is starting + Notifier.showToast( this, R.string.toast_launchingEmulator ); + + // Update the ConfigSection with the new value for lastPlayed + String lastPlayed = Integer.toString( (int) ( new Date().getTime() / 1000 ) ); + ConfigFile config = new ConfigFile( mGlobalPrefs.romInfoCache_cfg ); + if( config != null ) + { + config.put( romMd5, "lastPlayed", lastPlayed ); + config.save(); + } + + // Launch the game activity + ActivityHelper.startGameActivity( this, romPath, romMd5, gamePrefs.getCheatArgs(), isRestarting, mGlobalPrefs.isTouchpadEnabled ); } } diff --git a/src/paulscode/android/mupen64plusae/Keys.java b/src/paulscode/android/mupen64plusae/Keys.java deleted file mode 100644 index 2ef4d59f9b..0000000000 --- a/src/paulscode/android/mupen64plusae/Keys.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Mupen64PlusAE, an N64 emulator for the Android platform - * - * Copyright (C) 2013 Paul Lamb - * - * This file is part of Mupen64PlusAE. - * - * Mupen64PlusAE is free software: you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Mupen64PlusAE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Mupen64PlusAE. If - * not, see . - * - * Authors: littleguy77 - */ -package paulscode.android.mupen64plusae; - -/** - * Just a simple class to consolidate all strings used as keys throughout the app. Keys are - * typically used to pass data between activities (in the extras bundle) and to persist data (in - * shared preferences, config files, etc.). - */ -public class Keys -{ - /** - * Keys used to pass data to activities via the intent extras bundle. It's good practice to - * namespace the keys to avoid conflicts with other apps. By convention this is usually the - * package name but it's not a strict requirement. We'll use the fully qualified name of this - * class since it's easy to get. - */ - public static class Extras - { - private static final String NAMESPACE = Extras.class.getCanonicalName() + "."; - //@formatter:off - public static final String ROM_PATH = NAMESPACE + "ROM_PATH"; - public static final String ROM_MD5 = NAMESPACE + "ROM_MD5"; - public static final String CHEAT_ARGS = NAMESPACE + "CHEAT_ARGS"; - public static final String DO_RESTART = NAMESPACE + "DO_RESTART"; - public static final String PROFILE_NAME = NAMESPACE + "PROFILE_NAME"; - public static final String MENU_DISPLAY_MODE = NAMESPACE + "MENU_DISPLAY_MODE"; - //@formatter:on - } - - public static class Prefs - { - - } - - public static class Config - { - - } -} diff --git a/src/paulscode/android/mupen64plusae/SplashActivity.java b/src/paulscode/android/mupen64plusae/SplashActivity.java index 7648586b53..c9703a62cf 100644 --- a/src/paulscode/android/mupen64plusae/SplashActivity.java +++ b/src/paulscode/android/mupen64plusae/SplashActivity.java @@ -27,7 +27,7 @@ import paulscode.android.mupen64plusae.cheat.CheatUtils; import paulscode.android.mupen64plusae.persistent.AppData; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import paulscode.android.mupen64plusae.preference.PrefUtil; import paulscode.android.mupen64plusae.task.ExtractAssetsTask; import paulscode.android.mupen64plusae.task.ExtractAssetsTask.ExtractAssetsListener; @@ -36,10 +36,8 @@ import paulscode.android.mupen64plusae.util.Notifier; import tv.ouya.console.api.OuyaFacade; import android.app.Activity; -import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; -import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; @@ -83,7 +81,7 @@ public class SplashActivity extends Activity implements ExtractAssetsListener // App data and user preferences private AppData mAppData = null; - private UserPrefs mUserPrefs = null; + private GlobalPrefs mGlobalPrefs = null; private SharedPreferences mPrefs = null; // These constants must match the keys used in res/xml/preferences*.xml @@ -111,8 +109,8 @@ public void onCreate( Bundle savedInstanceState ) // Get app data and user preferences mAppData = new AppData( this ); - mUserPrefs = new UserPrefs( this ); - mUserPrefs.enforceLocale( this ); + mGlobalPrefs = new GlobalPrefs( this ); + mGlobalPrefs.enforceLocale( this ); mPrefs = PreferenceManager.getDefaultSharedPreferences( this ); // Ensure that any missing preferences are populated with defaults (e.g. preference added to @@ -136,7 +134,7 @@ public void onCreate( Bundle savedInstanceState ) // @formatter:on // Refresh the preference data wrapper - mUserPrefs = new UserPrefs( this ); + mGlobalPrefs = new GlobalPrefs( this ); // Initialize the OUYA interface if running on OUYA if( AppData.IS_OUYA_HARDWARE ) @@ -152,7 +150,7 @@ public void onCreate( Bundle savedInstanceState ) setContentView( R.layout.splash_activity ); mTextView = (TextView) findViewById( R.id.mainText ); - if( mUserPrefs.isBigScreenMode ) + if( mGlobalPrefs.isBigScreenMode ) { ImageView splash = (ImageView) findViewById( R.id.mainImage ); splash.setImageResource( R.drawable.publisherlogo_ouya ); @@ -179,8 +177,11 @@ public void run() } else { - // Assets already extracted, just launch next activity - launchGalleryActivity(); + // Assets already extracted, just launch gallery activity, passing ROM path if it was provided externally + ActivityHelper.startGalleryActivity( SplashActivity.this, getIntent().getData() ); + + // We never want to come back to this activity, so finish it + finish(); } } }; @@ -199,11 +200,16 @@ public void onExtractAssetsFinished( List failures ) { if( failures.size() == 0 ) { - // Extraction succeeded, record new asset version, merge cheats, and launch next activity + // Extraction succeeded, record new asset version and merge cheats mTextView.setText( R.string.assetExtractor_finished ); mAppData.putAssetVersion( ASSET_VERSION ); - CheatUtils.mergeCheatFiles( mAppData.mupencheat_default, mUserPrefs.customCheats_txt, mAppData.mupencheat_txt ); - launchGalleryActivity(); + CheatUtils.mergeCheatFiles( mAppData.mupencheat_default, mGlobalPrefs.customCheats_txt, mAppData.mupencheat_txt ); + + // Launch gallery activity, passing ROM path if it was provided externally + ActivityHelper.startGalleryActivity( this, getIntent().getData() ); + + // We never want to come back to this activity, so finish it + finish(); } else { @@ -219,17 +225,4 @@ public void onExtractAssetsFinished( List failures ) mTextView.setText( Html.fromHtml( textHtml ) ); } } - - private void launchGalleryActivity( ) - { - // Launch the activity, passing ROM path if it was provided externally - Intent intent = new Intent( this, GalleryActivity.class ); - Uri dataUri = getIntent().getData(); - if( dataUri != null ) - intent.putExtra( Keys.Extras.ROM_PATH, dataUri.getPath() ); - startActivity( intent ); - - // We never want to come back to this activity, so finish it - finish(); - } } diff --git a/src/paulscode/android/mupen64plusae/cheat/CheatEditorActivity.java b/src/paulscode/android/mupen64plusae/cheat/CheatEditorActivity.java index c064c8ed59..3af58e223e 100755 --- a/src/paulscode/android/mupen64plusae/cheat/CheatEditorActivity.java +++ b/src/paulscode/android/mupen64plusae/cheat/CheatEditorActivity.java @@ -27,12 +27,12 @@ import org.mupen64plusae.v3.alpha.R; -import paulscode.android.mupen64plusae.Keys; +import paulscode.android.mupen64plusae.ActivityHelper; import paulscode.android.mupen64plusae.cheat.CheatUtils.Cheat; import paulscode.android.mupen64plusae.dialog.Prompt; import paulscode.android.mupen64plusae.dialog.Prompt.PromptTextListener; import paulscode.android.mupen64plusae.persistent.AppData; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import paulscode.android.mupen64plusae.util.RomHeader; import android.annotation.SuppressLint; import android.app.AlertDialog; @@ -96,7 +96,7 @@ public View getView( int position, View convertView, ViewGroup parent ) private final ArrayList cheats = new ArrayList(); private CheatListAdapter cheatListAdapter = null; private AppData mAppData = null; - private UserPrefs mUserPrefs = null; + private GlobalPrefs mGlobalPrefs = null; private RomHeader mRomHeader = null; @Override @@ -104,14 +104,14 @@ protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); mAppData = new AppData( this ); - mUserPrefs = new UserPrefs( this ); - mUserPrefs.enforceLocale( this ); + mGlobalPrefs = new GlobalPrefs( this ); + mGlobalPrefs.enforceLocale( this ); // Get the ROM header info Bundle extras = getIntent().getExtras(); if( extras == null ) throw new Error( "ROM path must be passed via the extras bundle when starting CheatEditorActivity" ); - String romPath = extras.getString( Keys.Extras.ROM_PATH ); + String romPath = extras.getString( ActivityHelper.Keys.ROM_PATH ); if( TextUtils.isEmpty( romPath ) ) throw new Error( "ROM path must be passed via the extras bundle when starting CheatEditorActivity" ); mRomHeader = new RomHeader( new File( romPath ) ); @@ -134,7 +134,7 @@ private void reload( String crc ) // Get the appropriate section of the config file, using CRC as the key CheatFile mupencheat_default = new CheatFile( mAppData.mupencheat_default ); - CheatFile usrcheat_txt = new CheatFile( mUserPrefs.customCheats_txt ); + CheatFile usrcheat_txt = new CheatFile( mGlobalPrefs.customCheats_txt ); cheats.addAll( CheatUtils.populate( crc, mupencheat_default, true, this ) ); cheats.addAll( CheatUtils.populate( crc, usrcheat_txt, false, this ) ); cheatListAdapter = new CheatListAdapter( this, cheats ); @@ -143,7 +143,7 @@ private void reload( String crc ) private void save( String crc ) { - CheatFile usrcheat_txt = new CheatFile( mUserPrefs.customCheats_txt ); + CheatFile usrcheat_txt = new CheatFile( mGlobalPrefs.customCheats_txt ); CheatFile mupencheat_txt = new CheatFile( mAppData.mupencheat_txt ); CheatUtils.save( crc, usrcheat_txt, cheats, mRomHeader, this, false ); CheatUtils.save( crc, mupencheat_txt, cheats, mRomHeader, this, true ); diff --git a/src/paulscode/android/mupen64plusae/GameActivity.java b/src/paulscode/android/mupen64plusae/game/GameActivity.java similarity index 96% rename from src/paulscode/android/mupen64plusae/GameActivity.java rename to src/paulscode/android/mupen64plusae/game/GameActivity.java index 35068734d3..5ce4db61a4 100644 --- a/src/paulscode/android/mupen64plusae/GameActivity.java +++ b/src/paulscode/android/mupen64plusae/game/GameActivity.java @@ -18,8 +18,9 @@ * * Authors: littleguy77 */ -package paulscode.android.mupen64plusae; +package paulscode.android.mupen64plusae.game; +import paulscode.android.mupen64plusae.jni.CoreInterface; import android.app.Activity; import android.os.Bundle; import android.view.Menu; diff --git a/src/paulscode/android/mupen64plusae/GameActivityXperiaPlay.java b/src/paulscode/android/mupen64plusae/game/GameActivityXperiaPlay.java similarity index 96% rename from src/paulscode/android/mupen64plusae/GameActivityXperiaPlay.java rename to src/paulscode/android/mupen64plusae/game/GameActivityXperiaPlay.java index addbf6cb72..130bc7c7e2 100644 --- a/src/paulscode/android/mupen64plusae/GameActivityXperiaPlay.java +++ b/src/paulscode/android/mupen64plusae/game/GameActivityXperiaPlay.java @@ -18,8 +18,9 @@ * * Authors: littleguy77 */ -package paulscode.android.mupen64plusae; +package paulscode.android.mupen64plusae.game; +import paulscode.android.mupen64plusae.jni.CoreInterface; import android.annotation.TargetApi; import android.app.NativeActivity; import android.os.Bundle; diff --git a/src/paulscode/android/mupen64plusae/GameLifecycleHandler.java b/src/paulscode/android/mupen64plusae/game/GameLifecycleHandler.java similarity index 88% rename from src/paulscode/android/mupen64plusae/GameLifecycleHandler.java rename to src/paulscode/android/mupen64plusae/game/GameLifecycleHandler.java index 0752cfb2e4..989fb49d96 100644 --- a/src/paulscode/android/mupen64plusae/GameLifecycleHandler.java +++ b/src/paulscode/android/mupen64plusae/game/GameLifecycleHandler.java @@ -18,12 +18,13 @@ * * Authors: paulscode, lioncash, littleguy77 */ -package paulscode.android.mupen64plusae; +package paulscode.android.mupen64plusae.game; import java.util.ArrayList; import org.mupen64plusae.v3.alpha.R; +import paulscode.android.mupen64plusae.ActivityHelper; import paulscode.android.mupen64plusae.hack.MogaHack; import paulscode.android.mupen64plusae.input.AbstractController; import paulscode.android.mupen64plusae.input.PeripheralController; @@ -36,12 +37,13 @@ import paulscode.android.mupen64plusae.input.provider.KeyProvider; import paulscode.android.mupen64plusae.input.provider.KeyProvider.ImeFormula; import paulscode.android.mupen64plusae.input.provider.MogaProvider; +import paulscode.android.mupen64plusae.jni.CoreInterface; import paulscode.android.mupen64plusae.jni.NativeConstants; import paulscode.android.mupen64plusae.jni.NativeExports; import paulscode.android.mupen64plusae.jni.NativeXperiaTouchpad; import paulscode.android.mupen64plusae.persistent.AppData; import paulscode.android.mupen64plusae.persistent.GamePrefs; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import paulscode.android.mupen64plusae.profile.ControllerProfile; import paulscode.android.mupen64plusae.util.RomHeader; import android.annotation.SuppressLint; @@ -131,7 +133,7 @@ public class GameLifecycleHandler implements View.OnKeyListener, SurfaceHolder.C private boolean mIsSurface = false; // true if the surface is available // App data and user preferences - private UserPrefs mUserPrefs; + private GlobalPrefs mGlobalPrefs; private GamePrefs mGamePrefs; public GameLifecycleHandler( Activity activity ) @@ -145,10 +147,10 @@ public GameLifecycleHandler( Activity activity ) Bundle extras = mActivity.getIntent().getExtras(); if( extras == null ) throw new Error( "ROM path and MD5 must be passed via the extras bundle when starting GameActivity" ); - mRomPath = extras.getString( Keys.Extras.ROM_PATH ); - mRomMd5 = extras.getString( Keys.Extras.ROM_MD5 ); - mCheatArgs = extras.getString( Keys.Extras.CHEAT_ARGS ); - mDoRestart = extras.getBoolean( Keys.Extras.DO_RESTART, false ); + mRomPath = extras.getString( ActivityHelper.Keys.ROM_PATH ); + mRomMd5 = extras.getString( ActivityHelper.Keys.ROM_MD5 ); + mCheatArgs = extras.getString( ActivityHelper.Keys.CHEAT_ARGS ); + mDoRestart = extras.getBoolean( ActivityHelper.Keys.DO_RESTART, false ); if( TextUtils.isEmpty( mRomPath ) || TextUtils.isEmpty( mRomMd5 ) ) throw new Error( "ROM path and MD5 must be passed via the extras bundle when starting GameActivity" ); } @@ -164,14 +166,14 @@ public void onCreateBegin( Bundle savedInstanceState ) MogaHack.init( mMogaController, mActivity ); // Get app data and user preferences - mUserPrefs = new UserPrefs( mActivity ); + mGlobalPrefs = new GlobalPrefs( mActivity ); mGamePrefs = new GamePrefs( mActivity, mRomMd5, new RomHeader( mRomPath ) ); - mUserPrefs.enforceLocale( mActivity ); + mGlobalPrefs.enforceLocale( mActivity ); // For Honeycomb, let the action bar overlay the rendered view (rather than squeezing it) // For earlier APIs, remove the title bar to yield more space Window window = mActivity.getWindow(); - if( mUserPrefs.isActionBarAvailable ) + if( mGlobalPrefs.isActionBarAvailable ) window.requestFeature( Window.FEATURE_ACTION_BAR_OVERLAY ); else window.requestFeature( Window.FEATURE_NO_TITLE ); @@ -183,10 +185,10 @@ public void onCreateBegin( Bundle savedInstanceState ) window.setFlags( LayoutParams.FLAG_KEEP_SCREEN_ON, LayoutParams.FLAG_KEEP_SCREEN_ON ); // Set the screen orientation - mActivity.setRequestedOrientation( mUserPrefs.displayOrientation ); + mActivity.setRequestedOrientation( mGlobalPrefs.displayOrientation ); // If the orientation changes, the screensize info changes, so we must refresh dependencies - mUserPrefs = new UserPrefs( mActivity ); + mGlobalPrefs = new GlobalPrefs( mActivity ); } @TargetApi( 11 ) @@ -208,32 +210,32 @@ public void onCreateEnd( Bundle savedInstanceState ) mSurface.getHolder().addCallback( this ); // Update the GameSurface size - mSurface.getHolder().setFixedSize( mUserPrefs.videoRenderWidth, mUserPrefs.videoRenderHeight ); + mSurface.getHolder().setFixedSize( mGlobalPrefs.videoRenderWidth, mGlobalPrefs.videoRenderHeight ); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mSurface.getLayoutParams(); - params.width = mUserPrefs.videoSurfaceWidth; - params.height = mUserPrefs.videoSurfaceHeight; - params.gravity = mUserPrefs.displayPosition | Gravity.CENTER_HORIZONTAL; + params.width = mGlobalPrefs.videoSurfaceWidth; + params.height = mGlobalPrefs.videoSurfaceHeight; + params.gravity = mGlobalPrefs.displayPosition | Gravity.CENTER_HORIZONTAL; mSurface.setLayoutParams( params ); // Configure the action bar introduced in higher Android versions - if( mUserPrefs.isActionBarAvailable ) + if( mGlobalPrefs.isActionBarAvailable ) { mActivity.getActionBar().hide(); ColorDrawable color = new ColorDrawable( Color.parseColor( "#303030" ) ); - color.setAlpha( mUserPrefs.displayActionBarTransparency ); + color.setAlpha( mGlobalPrefs.displayActionBarTransparency ); mActivity.getActionBar().setBackgroundDrawable( color ); } // Initialize the screen elements - if( mGamePrefs.isTouchscreenEnabled || mUserPrefs.isFpsEnabled ) + if( mGamePrefs.isTouchscreenEnabled || mGlobalPrefs.isFpsEnabled ) { // The touch map and overlay are needed to display frame rate and/or controls mTouchscreenMap = new VisibleTouchMap( mActivity.getResources() ); - mTouchscreenMap.load( mUserPrefs.touchscreenSkin, mGamePrefs.touchscreenProfile, - mUserPrefs.isTouchscreenAnimated, mUserPrefs.isFpsEnabled, - mUserPrefs.touchscreenScale, mUserPrefs.touchscreenTransparency ); + mTouchscreenMap.load( mGlobalPrefs.touchscreenSkin, mGamePrefs.touchscreenProfile, + mGlobalPrefs.isTouchscreenAnimated, mGlobalPrefs.isFpsEnabled, + mGlobalPrefs.touchscreenScale, mGlobalPrefs.touchscreenTransparency ); mOverlay.initialize( mTouchscreenMap, !mGamePrefs.isTouchscreenHidden, - mUserPrefs.isFpsEnabled, mUserPrefs.isTouchscreenAnimated ); + mGlobalPrefs.isFpsEnabled, mGlobalPrefs.isTouchscreenAnimated ); } // Initialize user interface devices @@ -317,7 +319,7 @@ public boolean onKey( View view, int keyCode, KeyEvent event ) // For devices with an action bar, absorb all back key presses // and toggle the action bar - if( keyCode == KeyEvent.KEYCODE_BACK && mUserPrefs.isActionBarAvailable ) + if( keyCode == KeyEvent.KEYCODE_BACK && mGlobalPrefs.isActionBarAvailable ) { if( keyDown ) toggleActionBar(); @@ -350,12 +352,12 @@ private void initControllers( View inputSource ) { // Create the map for the touchpad TouchMap touchpadMap = new TouchMap( mActivity.getResources() ); - touchpadMap.load( mUserPrefs.touchpadSkin, mUserPrefs.touchpadProfile, false ); + touchpadMap.load( mGlobalPrefs.touchpadSkin, mGlobalPrefs.touchpadProfile, false ); touchpadMap.resize( NativeXperiaTouchpad.PAD_WIDTH, NativeXperiaTouchpad.PAD_HEIGHT ); // Create the touchpad controller touchpadController = new TouchController( touchpadMap, inputSource, null, vibrator, - TouchController.AUTOHOLD_METHOD_DISABLED, mUserPrefs.isTouchpadFeedbackEnabled, + TouchController.AUTOHOLD_METHOD_DISABLED, mGlobalPrefs.isTouchpadFeedbackEnabled, null ); mControllers.add( touchpadController ); @@ -368,8 +370,8 @@ private void initControllers( View inputSource ) { // Create the touchscreen controller TouchController touchscreenController = new TouchController( mTouchscreenMap, - inputSource, mOverlay, vibrator, mUserPrefs.touchscreenAutoHold, - mUserPrefs.isTouchscreenFeedbackEnabled, mGamePrefs.touchscreenAutoHoldables ); + inputSource, mOverlay, vibrator, mGlobalPrefs.touchscreenAutoHold, + mGlobalPrefs.isTouchscreenFeedbackEnabled, mGamePrefs.touchscreenAutoHoldables ); mControllers.add( touchscreenController ); // If using touchpad & touchscreen together... @@ -388,7 +390,7 @@ private void initControllers( View inputSource ) // Create the input providers shared among all peripheral controllers mKeyProvider = new KeyProvider( inputSource, ImeFormula.DEFAULT, - mUserPrefs.unmappableKeyCodes ); + mGlobalPrefs.unmappableKeyCodes ); MogaProvider mogaProvider = new MogaProvider( mMogaController ); AbstractProvider axisProvider = AppData.IS_HONEYCOMB_MR1 ? new AxisProvider( inputSource ) @@ -432,7 +434,7 @@ private void hideSystemBars() View view = mSurface.getRootView(); if( view != null ) { - if( AppData.IS_KITKAT && mUserPrefs.isImmersiveModeEnabled ) + if( AppData.IS_KITKAT && mGlobalPrefs.isImmersiveModeEnabled ) view.setSystemUiVisibility( View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN diff --git a/src/paulscode/android/mupen64plusae/GameMenuHandler.java b/src/paulscode/android/mupen64plusae/game/GameMenuHandler.java similarity index 92% rename from src/paulscode/android/mupen64plusae/GameMenuHandler.java rename to src/paulscode/android/mupen64plusae/game/GameMenuHandler.java index 3e1ce33c42..a7fee40101 100644 --- a/src/paulscode/android/mupen64plusae/GameMenuHandler.java +++ b/src/paulscode/android/mupen64plusae/game/GameMenuHandler.java @@ -18,17 +18,19 @@ * * Authors: littleguy77, Paul Lamb */ -package paulscode.android.mupen64plusae; +package paulscode.android.mupen64plusae.game; import org.mupen64plusae.v3.alpha.R; -import paulscode.android.mupen64plusae.CoreInterface.OnStateCallbackListener; +import paulscode.android.mupen64plusae.ActivityHelper; +import paulscode.android.mupen64plusae.jni.CoreInterface; +import paulscode.android.mupen64plusae.jni.CoreInterface.OnStateCallbackListener; import paulscode.android.mupen64plusae.jni.NativeConstants; import paulscode.android.mupen64plusae.jni.NativeExports; import paulscode.android.mupen64plusae.jni.NativeInput; import paulscode.android.mupen64plusae.persistent.AppData; import paulscode.android.mupen64plusae.persistent.GamePrefs; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import paulscode.android.mupen64plusae.util.Notifier; import paulscode.android.mupen64plusae.util.RomHeader; import android.annotation.TargetApi; @@ -47,7 +49,7 @@ public class GameMenuHandler implements OnStateCallbackListener private final String mRomMd5; private final RomHeader mRomHeader; - private UserPrefs mUserPrefs; + private GlobalPrefs mGlobalPrefs; private GamePrefs mGamePrefs; public GameMenuHandler( Activity activity ) @@ -58,8 +60,8 @@ public GameMenuHandler( Activity activity ) Bundle extras = mActivity.getIntent().getExtras(); if( extras == null ) throw new Error( "ROM path and MD5 must be passed via the extras bundle when starting GameActivity" ); - String romPath = extras.getString( Keys.Extras.ROM_PATH ); - mRomMd5 = extras.getString( Keys.Extras.ROM_MD5 ); + String romPath = extras.getString( ActivityHelper.Keys.ROM_PATH ); + mRomMd5 = extras.getString( ActivityHelper.Keys.ROM_MD5 ); if( TextUtils.isEmpty( romPath ) || TextUtils.isEmpty( mRomMd5 ) ) throw new Error( "ROM path and MD5 must be passed via the extras bundle when starting GameActivity" ); mRomHeader = new RomHeader( romPath ); @@ -86,14 +88,14 @@ public void onCreateOptionsMenu( Menu menu ) mActivity.getMenuInflater().inflate( R.menu.game_activity, menu ); // Get the app data and user prefs after the activity has been created - mUserPrefs = new UserPrefs( mActivity ); + mGlobalPrefs = new GlobalPrefs( mActivity ); mGamePrefs = new GamePrefs( mActivity, mRomMd5, mRomHeader ); // Initialize the pak menus (reverse order since some get hidden) - initializePakMenu( menu, 4, mGamePrefs.isPlugged4, mUserPrefs.getPakType( 4 ) ); - initializePakMenu( menu, 3, mGamePrefs.isPlugged3, mUserPrefs.getPakType( 3 ) ); - initializePakMenu( menu, 2, mGamePrefs.isPlugged2, mUserPrefs.getPakType( 2 ) ); - initializePakMenu( menu, 1, mGamePrefs.isPlugged1, mUserPrefs.getPakType( 1 ) ); + initializePakMenu( menu, 4, mGamePrefs.isPlugged4, mGlobalPrefs.getPakType( 4 ) ); + initializePakMenu( menu, 3, mGamePrefs.isPlugged3, mGlobalPrefs.getPakType( 3 ) ); + initializePakMenu( menu, 2, mGamePrefs.isPlugged2, mGlobalPrefs.getPakType( 2 ) ); + initializePakMenu( menu, 1, mGamePrefs.isPlugged1, mGlobalPrefs.getPakType( 1 ) ); } public void onPrepareOptionsMenu( Menu menu ) @@ -289,7 +291,7 @@ public void onOptionsItemSelected( MenuItem item ) public void setPak( int player, int pakType, MenuItem item ) { // Persist the value - mUserPrefs.putPakType( player, pakType ); + mGlobalPrefs.putPakType( player, pakType ); // Set the pak in the core NativeInput.setConfig( player - 1, true, pakType ); diff --git a/src/paulscode/android/mupen64plusae/GameOverlay.java b/src/paulscode/android/mupen64plusae/game/GameOverlay.java similarity index 97% rename from src/paulscode/android/mupen64plusae/GameOverlay.java rename to src/paulscode/android/mupen64plusae/game/GameOverlay.java index 7efbc2d365..6a20eebde3 100644 --- a/src/paulscode/android/mupen64plusae/GameOverlay.java +++ b/src/paulscode/android/mupen64plusae/game/GameOverlay.java @@ -18,10 +18,11 @@ * * Authors: littleguy77 */ -package paulscode.android.mupen64plusae; +package paulscode.android.mupen64plusae.game; import paulscode.android.mupen64plusae.input.TouchController; import paulscode.android.mupen64plusae.input.map.VisibleTouchMap; +import paulscode.android.mupen64plusae.jni.CoreInterface; import paulscode.android.mupen64plusae.util.DeviceUtil; import android.content.Context; import android.graphics.Canvas; diff --git a/src/paulscode/android/mupen64plusae/GameSurface.java b/src/paulscode/android/mupen64plusae/game/GameSurface.java similarity index 99% rename from src/paulscode/android/mupen64plusae/GameSurface.java rename to src/paulscode/android/mupen64plusae/game/GameSurface.java index c8afd19020..a43161e5e4 100644 --- a/src/paulscode/android/mupen64plusae/GameSurface.java +++ b/src/paulscode/android/mupen64plusae/game/GameSurface.java @@ -18,7 +18,7 @@ * * Authors: Paul Lamb, littleguy77, Gillou68310 */ -package paulscode.android.mupen64plusae; +package paulscode.android.mupen64plusae.game; import javax.microedition.khronos.egl.EGL10; import javax.microedition.khronos.egl.EGLConfig; diff --git a/src/paulscode/android/mupen64plusae/input/DiagnosticActivity.java b/src/paulscode/android/mupen64plusae/input/DiagnosticActivity.java index 234aefc279..2e549c4fda 100644 --- a/src/paulscode/android/mupen64plusae/input/DiagnosticActivity.java +++ b/src/paulscode/android/mupen64plusae/input/DiagnosticActivity.java @@ -27,7 +27,7 @@ import paulscode.android.mupen64plusae.hack.MogaHack; import paulscode.android.mupen64plusae.input.provider.AbstractProvider; import paulscode.android.mupen64plusae.persistent.AppData; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import paulscode.android.mupen64plusae.util.DeviceUtil; import android.annotation.TargetApi; import android.app.Activity; @@ -50,7 +50,7 @@ public class DiagnosticActivity extends Activity implements ControllerListener public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); - new UserPrefs( this ).enforceLocale( this ); + new GlobalPrefs( this ).enforceLocale( this ); setContentView( R.layout.diagnostic_activity ); // TODO: Remove hack after MOGA SDK is fixed diff --git a/src/paulscode/android/mupen64plusae/input/PeripheralController.java b/src/paulscode/android/mupen64plusae/input/PeripheralController.java index 46bd95d1e2..a58c31a2b6 100644 --- a/src/paulscode/android/mupen64plusae/input/PeripheralController.java +++ b/src/paulscode/android/mupen64plusae/input/PeripheralController.java @@ -22,10 +22,10 @@ import java.util.ArrayList; -import paulscode.android.mupen64plusae.CoreInterface; import paulscode.android.mupen64plusae.input.map.InputMap; import paulscode.android.mupen64plusae.input.map.PlayerMap; import paulscode.android.mupen64plusae.input.provider.AbstractProvider; +import paulscode.android.mupen64plusae.jni.CoreInterface; import paulscode.android.mupen64plusae.jni.NativeExports; import paulscode.android.mupen64plusae.persistent.AppData; import paulscode.android.mupen64plusae.util.SafeMethods; diff --git a/src/paulscode/android/mupen64plusae/input/map/VisibleTouchMap.java b/src/paulscode/android/mupen64plusae/input/map/VisibleTouchMap.java index dba4596160..43dc720096 100644 --- a/src/paulscode/android/mupen64plusae/input/map/VisibleTouchMap.java +++ b/src/paulscode/android/mupen64plusae/input/map/VisibleTouchMap.java @@ -22,7 +22,7 @@ import java.util.concurrent.CopyOnWriteArrayList; -import paulscode.android.mupen64plusae.GameOverlay; +import paulscode.android.mupen64plusae.game.GameOverlay; import paulscode.android.mupen64plusae.persistent.ConfigFile; import paulscode.android.mupen64plusae.profile.Profile; import paulscode.android.mupen64plusae.util.Image; diff --git a/src/paulscode/android/mupen64plusae/CoreInterface.java b/src/paulscode/android/mupen64plusae/jni/CoreInterface.java similarity index 94% rename from src/paulscode/android/mupen64plusae/CoreInterface.java rename to src/paulscode/android/mupen64plusae/jni/CoreInterface.java index 887e66484a..b10d94e942 100644 --- a/src/paulscode/android/mupen64plusae/CoreInterface.java +++ b/src/paulscode/android/mupen64plusae/jni/CoreInterface.java @@ -18,7 +18,7 @@ * * Authors: Paul Lamb, littleguy77 */ -package paulscode.android.mupen64plusae; +package paulscode.android.mupen64plusae.jni; import java.io.File; import java.util.ArrayList; @@ -30,15 +30,10 @@ import paulscode.android.mupen64plusae.dialog.Prompt.PromptFileListener; import paulscode.android.mupen64plusae.dialog.Prompt.PromptIntegerListener; import paulscode.android.mupen64plusae.dialog.Prompt.PromptTextListener; -import paulscode.android.mupen64plusae.jni.NativeConfigFiles; -import paulscode.android.mupen64plusae.jni.NativeConstants; -import paulscode.android.mupen64plusae.jni.NativeExports; -import paulscode.android.mupen64plusae.jni.NativeImports; -import paulscode.android.mupen64plusae.jni.NativeInput; -import paulscode.android.mupen64plusae.jni.NativeSDL; +import paulscode.android.mupen64plusae.game.GameSurface; import paulscode.android.mupen64plusae.persistent.AppData; import paulscode.android.mupen64plusae.persistent.GamePrefs; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import paulscode.android.mupen64plusae.util.Notifier; import paulscode.android.mupen64plusae.util.RomHeader; import paulscode.android.mupen64plusae.util.Utility; @@ -95,7 +90,7 @@ public interface OnFpsChangedListener // User/app data - used by NativeImports, NativeSDL protected static AppData sAppData = null; - protected static UserPrefs sUserPrefs = null; + protected static GlobalPrefs sGlobalPrefs = null; protected static GamePrefs sGamePrefs = null; // Audio/video objects - used by NativeSDL @@ -141,9 +136,9 @@ public static void initialize( Activity activity, GameSurface surface, String ro sActivity = activity; sSurface = surface; sAppData = new AppData( sActivity ); - sUserPrefs = new UserPrefs( sActivity ); + sGlobalPrefs = new GlobalPrefs( sActivity ); sGamePrefs = new GamePrefs( sActivity, romMd5, new RomHeader( romPath ) ); - NativeConfigFiles.syncConfigFiles( sGamePrefs, sUserPrefs, sAppData ); + NativeConfigFiles.syncConfigFiles( sGamePrefs, sGlobalPrefs, sAppData ); // Make sure various directories exist so that we can write to them new File( sGamePrefs.sramDataDir ).mkdirs(); @@ -152,8 +147,8 @@ public static void initialize( Activity activity, GameSurface surface, String ro new File( sGamePrefs.userSaveDir ).mkdirs(); new File( sGamePrefs.screenshotDir ).mkdirs(); new File( sGamePrefs.coreUserConfigDir ).mkdirs(); - new File( sUserPrefs.coreUserDataDir ).mkdirs(); - new File( sUserPrefs.coreUserCacheDir ).mkdirs(); + new File( sGlobalPrefs.coreUserDataDir ).mkdirs(); + new File( sGlobalPrefs.coreUserCacheDir ).mkdirs(); sAutoSavePath = sGamePrefs.autoSaveDir + "/yyyy-mm-dd-hh-mm-ss.sav"; } @@ -207,10 +202,10 @@ public void run() { // Initialize input-android plugin (even if we aren't going to use it) NativeInput.init(); - NativeInput.setConfig( 0, sGamePrefs.isPlugged1, sUserPrefs.getPakType( 1 ) ); - NativeInput.setConfig( 1, sGamePrefs.isPlugged2, sUserPrefs.getPakType( 2 ) ); - NativeInput.setConfig( 2, sGamePrefs.isPlugged3, sUserPrefs.getPakType( 3 ) ); - NativeInput.setConfig( 3, sGamePrefs.isPlugged4, sUserPrefs.getPakType( 4 ) ); + NativeInput.setConfig( 0, sGamePrefs.isPlugged1, sGlobalPrefs.getPakType( 1 ) ); + NativeInput.setConfig( 1, sGamePrefs.isPlugged2, sGlobalPrefs.getPakType( 2 ) ); + NativeInput.setConfig( 2, sGamePrefs.isPlugged3, sGlobalPrefs.getPakType( 3 ) ); + NativeInput.setConfig( 3, sGamePrefs.isPlugged4, sGlobalPrefs.getPakType( 4 ) ); ArrayList arglist = new ArrayList(); arglist.add( "mupen64plus" ); @@ -218,7 +213,7 @@ public void run() arglist.add( sAppData.coreLib ); arglist.add( "--configdir" ); arglist.add( sGamePrefs.coreUserConfigDir ); - if( !sUserPrefs.isFramelimiterEnabled ) + if( !sGlobalPrefs.isFramelimiterEnabled ) { arglist.add( "--nospeedlimit" ); } @@ -228,7 +223,7 @@ public void run() arglist.add( sCheatOptions ); } arglist.add( sRomPath ); - int result = NativeExports.emuStart( sUserPrefs.coreUserDataDir, sUserPrefs.coreUserCacheDir, arglist.toArray() ); + int result = NativeExports.emuStart( sGlobalPrefs.coreUserDataDir, sGlobalPrefs.coreUserCacheDir, arglist.toArray() ); if( result != 0 ) { // Messages match return codes from mupen64plus-ui-console/main.c diff --git a/src/paulscode/android/mupen64plusae/jni/NativeConfigFiles.java b/src/paulscode/android/mupen64plusae/jni/NativeConfigFiles.java index e8acffdb86..bd3142bd02 100644 --- a/src/paulscode/android/mupen64plusae/jni/NativeConfigFiles.java +++ b/src/paulscode/android/mupen64plusae/jni/NativeConfigFiles.java @@ -23,7 +23,7 @@ import paulscode.android.mupen64plusae.persistent.AppData; import paulscode.android.mupen64plusae.persistent.ConfigFile; import paulscode.android.mupen64plusae.persistent.GamePrefs; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; public class NativeConfigFiles { @@ -32,19 +32,19 @@ public class NativeConfigFiles /** * Populates the core configuration files with the user preferences. */ - public static void syncConfigFiles( GamePrefs game, UserPrefs user, AppData appData ) + public static void syncConfigFiles( GamePrefs game, GlobalPrefs global, AppData appData ) { //@formatter:off // gln64 config file ConfigFile gln64_conf = new ConfigFile( appData.gln64_conf ); - gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "window width", String.valueOf( user.videoRenderWidth ) ); - gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "window height", String.valueOf( user.videoRenderHeight ) ); + gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "window width", String.valueOf( global.videoRenderWidth ) ); + gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "window height", String.valueOf( global.videoRenderHeight ) ); gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "auto frameskip", boolToNum( game.isGln64AutoFrameskipEnabled ) ); gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "max frameskip", String.valueOf( game.gln64MaxFrameskip ) ); - gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "polygon offset hack", boolToNum( user.isPolygonOffsetHackEnabled ) ); - gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "polygon offset factor", String.valueOf( user.videoPolygonOffset ) ); - gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "polygon offset units", String.valueOf( user.videoPolygonOffset ) ); + gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "polygon offset hack", boolToNum( global.isPolygonOffsetHackEnabled ) ); + gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "polygon offset factor", String.valueOf( global.videoPolygonOffset ) ); + gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "polygon offset units", String.valueOf( global.videoPolygonOffset ) ); gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "enable fog", boolToNum( game.isGln64FogEnabled ) ); gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "texture 2xSAI", boolToNum( game.isGln64SaiEnabled ) ); gln64_conf.put( ConfigFile.SECTIONLESS_NAME, "enable alpha test", boolToNum( game.isGln64AlphaTestEnabled ) ); @@ -59,8 +59,8 @@ public static void syncConfigFiles( GamePrefs game, UserPrefs user, AppData appD ConfigFile mupen64plus_cfg = new ConfigFile( game.mupen64plus_cfg ); mupen64plus_cfg.put( "Audio-SDL", "Version", "1.000000" ); // Mupen64Plus SDL Audio Plugin config parameter version number - mupen64plus_cfg.put( "Audio-SDL", "SWAP_CHANNELS", boolToTF( user.audioSwapChannels ) ); // Swaps left and right channels - mupen64plus_cfg.put( "Audio-SDL", "SECONDARY_BUFFER_SIZE", String.valueOf( user.audioSecondaryBufferSize ) ); // Size of secondary buffer in output samples. This is SDL's hardware buffer. + mupen64plus_cfg.put( "Audio-SDL", "SWAP_CHANNELS", boolToTF( global.audioSwapChannels ) ); // Swaps left and right channels + mupen64plus_cfg.put( "Audio-SDL", "SECONDARY_BUFFER_SIZE", String.valueOf( global.audioSecondaryBufferSize ) ); // Size of secondary buffer in output samples. This is SDL's hardware buffer. mupen64plus_cfg.put( "Core", "Version", "1.010000" ); // Mupen64Plus Core config parameter set version number. Please don't change this version number. mupen64plus_cfg.put( "Core", "OnScreenDisplay", "False" ); // Draw on-screen display if True, otherwise don't draw OSD @@ -104,27 +104,27 @@ public static void syncConfigFiles( GamePrefs game, UserPrefs user, AppData appD mupen64plus_cfg.put( "UI-Console", "Version", "1.000000" ); // Mupen64Plus UI-Console config parameter set version number. Please don't change this version number. mupen64plus_cfg.put( "UI-Console", "PluginDir", '"' + appData.libsDir + '"' ); // Directory in which to search for plugins mupen64plus_cfg.put( "UI-Console", "VideoPlugin", '"' + game.videoPlugin.path + '"' ); // Filename of video plugin - mupen64plus_cfg.put( "UI-Console", "AudioPlugin", '"' + user.audioPlugin.path + '"' ); // Filename of audio plugin + mupen64plus_cfg.put( "UI-Console", "AudioPlugin", '"' + global.audioPlugin.path + '"' ); // Filename of audio plugin mupen64plus_cfg.put( "UI-Console", "InputPlugin", '"' + appData.inputLib + '"' ); // Filename of input plugin mupen64plus_cfg.put( "UI-Console", "RspPlugin", '"' + appData.rspLib + '"' ); // Filename of RSP plugin mupen64plus_cfg.put( "Video-General", "Fullscreen", "False" ); // Use fullscreen mode if True, or windowed mode if False - mupen64plus_cfg.put( "Video-General", "ScreenWidth", String.valueOf( user.videoRenderWidth ) ); // Width of output window or fullscreen width - mupen64plus_cfg.put( "Video-General", "ScreenHeight", String.valueOf( user.videoRenderHeight ) ); // Height of output window or fullscreen height + mupen64plus_cfg.put( "Video-General", "ScreenWidth", String.valueOf( global.videoRenderWidth ) ); // Width of output window or fullscreen width + mupen64plus_cfg.put( "Video-General", "ScreenHeight", String.valueOf( global.videoRenderHeight ) ); // Height of output window or fullscreen height mupen64plus_cfg.put( "Video-General", "VerticalSync", "False" ); // If true, activate the SDL_GL_SWAP_CONTROL attribute mupen64plus_cfg.put( "Video-Glide64mk2", "vsync", "False" ); // Vertical sync mupen64plus_cfg.put( "Video-Glide64mk2", "wrpAnisotropic", "False" ); // Wrapper Anisotropic Filtering mupen64plus_cfg.put( "Video-Glide64mk2", "fb_read_always", "0" ); // Read framebuffer every frame (may be slow use only for effects that need it e.g. Banjo Kazooie, DK64 transitions) - mupen64plus_cfg.put( "Video-Glide64mk2", "force_polygon_offset", boolToNum( user.isPolygonOffsetHackEnabled ) ); // If true, use polygon offset values specified below - mupen64plus_cfg.put( "Video-Glide64mk2", "polygon_offset_factor", String.valueOf( user.videoPolygonOffset ) ); // Specifies a scale factor that is used to create a variable depth offset for each polygon - mupen64plus_cfg.put( "Video-Glide64mk2", "polygon_offset_units", String.valueOf( user.videoPolygonOffset ) ); // Is multiplied by an implementation-specific value to create a constant depth offset + mupen64plus_cfg.put( "Video-Glide64mk2", "force_polygon_offset", boolToNum( global.isPolygonOffsetHackEnabled ) ); // If true, use polygon offset values specified below + mupen64plus_cfg.put( "Video-Glide64mk2", "polygon_offset_factor", String.valueOf( global.videoPolygonOffset ) ); // Specifies a scale factor that is used to create a variable depth offset for each polygon + mupen64plus_cfg.put( "Video-Glide64mk2", "polygon_offset_units", String.valueOf( global.videoPolygonOffset ) ); // Is multiplied by an implementation-specific value to create a constant depth offset mupen64plus_cfg.put( "Video-Glide64mk2", "autoframeskip", boolToNum( game.isGlide64AutoFrameskipEnabled ) ); mupen64plus_cfg.put( "Video-Glide64mk2", "maxframeskip", String.valueOf( game.glide64MaxFrameskip ) ); - mupen64plus_cfg.put( "Video-Rice", "ForcePolygonOffset", boolToTF( user.isPolygonOffsetHackEnabled ) ); // If true, use polygon offset values specified below - mupen64plus_cfg.put( "Video-Rice", "PolygonOffsetFactor", String.valueOf( user.videoPolygonOffset ) ); // Specifies a scale factor that is used to create a variable depth offset for each polygon - mupen64plus_cfg.put( "Video-Rice", "PolygonOffsetUnits", String.valueOf( user.videoPolygonOffset ) ); // Is multiplied by an implementation-specific value to create a constant depth offset + mupen64plus_cfg.put( "Video-Rice", "ForcePolygonOffset", boolToTF( global.isPolygonOffsetHackEnabled ) ); // If true, use polygon offset values specified below + mupen64plus_cfg.put( "Video-Rice", "PolygonOffsetFactor", String.valueOf( global.videoPolygonOffset ) ); // Specifies a scale factor that is used to create a variable depth offset for each polygon + mupen64plus_cfg.put( "Video-Rice", "PolygonOffsetUnits", String.valueOf( global.videoPolygonOffset ) ); // Is multiplied by an implementation-specific value to create a constant depth offset mupen64plus_cfg.put( "Video-Rice", "ScreenUpdateSetting", game.riceScreenUpdateType ); // Control when the screen will be updated (0=ROM default, 1=VI origin update, 2=VI origin change, 3=CI change, 4=first CI change, 5=first primitive draw, 6=before screen clear, 7=after screen drawn) mupen64plus_cfg.put( "Video-Rice", "FastTextureLoading", boolToTF( game.isRiceFastTextureLoadingEnabled ) ); // Use a faster algorithm to speed up texture loading and CRC computation mupen64plus_cfg.put( "Video-Rice", "SkipFrame", boolToTF( game.isRiceAutoFrameskipEnabled ) ); // If this option is enabled, the plugin will skip every other frame diff --git a/src/paulscode/android/mupen64plusae/jni/NativeExports.java b/src/paulscode/android/mupen64plusae/jni/NativeExports.java index 62f8b13811..8b7415a18f 100644 --- a/src/paulscode/android/mupen64plusae/jni/NativeExports.java +++ b/src/paulscode/android/mupen64plusae/jni/NativeExports.java @@ -20,7 +20,6 @@ */ package paulscode.android.mupen64plusae.jni; -import paulscode.android.mupen64plusae.CoreInterface; /** * Call-outs made from Java to the native ae-exports library. Any function names changed here should diff --git a/src/paulscode/android/mupen64plusae/jni/NativeImports.java b/src/paulscode/android/mupen64plusae/jni/NativeImports.java index 238557a6a9..c9f9d79346 100644 --- a/src/paulscode/android/mupen64plusae/jni/NativeImports.java +++ b/src/paulscode/android/mupen64plusae/jni/NativeImports.java @@ -20,7 +20,6 @@ */ package paulscode.android.mupen64plusae.jni; -import paulscode.android.mupen64plusae.CoreInterface; /** * Call-ins made from the native ae-imports library to Java. Any function names changed here should diff --git a/src/paulscode/android/mupen64plusae/jni/NativeInput.java b/src/paulscode/android/mupen64plusae/jni/NativeInput.java index a045282827..1ce34546b9 100644 --- a/src/paulscode/android/mupen64plusae/jni/NativeInput.java +++ b/src/paulscode/android/mupen64plusae/jni/NativeInput.java @@ -20,7 +20,6 @@ */ package paulscode.android.mupen64plusae.jni; -import paulscode.android.mupen64plusae.CoreInterface; /** * Calls made between the native input-android library and Java. Any function names changed here diff --git a/src/paulscode/android/mupen64plusae/jni/NativeSDL.java b/src/paulscode/android/mupen64plusae/jni/NativeSDL.java index 4ededb4bbd..d989173e4f 100644 --- a/src/paulscode/android/mupen64plusae/jni/NativeSDL.java +++ b/src/paulscode/android/mupen64plusae/jni/NativeSDL.java @@ -22,7 +22,6 @@ import javax.microedition.khronos.egl.EGL10; -import paulscode.android.mupen64plusae.CoreInterface; import paulscode.android.mupen64plusae.util.SafeMethods; import android.media.AudioFormat; import android.media.AudioManager; diff --git a/src/paulscode/android/mupen64plusae/persistent/GamePrefs.java b/src/paulscode/android/mupen64plusae/persistent/GamePrefs.java index 861b5ecf92..d9458ac0c7 100644 --- a/src/paulscode/android/mupen64plusae/persistent/GamePrefs.java +++ b/src/paulscode/android/mupen64plusae/persistent/GamePrefs.java @@ -2,7 +2,10 @@ import java.util.Collections; import java.util.HashSet; +import java.util.Map; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.mupen64plusae.v3.alpha.R; @@ -177,16 +180,19 @@ public class GamePrefs private final SharedPreferences mPreferences; + private final RomHeader mHeader; + public GamePrefs( Context context, String romMd5, RomHeader header ) { final AppData appData = new AppData( context ); - final UserPrefs userPrefs = new UserPrefs( context ); + final GlobalPrefs globalPrefs = new GlobalPrefs( context ); sharedPrefsName = romMd5.replace(' ', '_' ) + "_preferences"; mPreferences = context.getSharedPreferences( sharedPrefsName, Context.MODE_PRIVATE ); + mHeader = header; // Game-specific data - gameDataDir = String.format( "%s/GameData/%s %s %s", userPrefs.userDataDir, header.name, header.countrySymbol, romMd5 ); + gameDataDir = String.format( "%s/GameData/%s %s %s", globalPrefs.userDataDir, header.name, header.countrySymbol, romMd5 ); sramDataDir = gameDataDir + "/SramData"; autoSaveDir = gameDataDir + "/AutoSaves"; slotSaveDir = gameDataDir + "/SlotSaves"; @@ -197,27 +203,27 @@ public GamePrefs( Context context, String romMd5, RomHeader header ) // Emulation profile emulationProfile = loadProfile( mPreferences, "emulationProfile", - UserPrefs.DEFAULT_EMULATION_PROFILE_DEFAULT, - userPrefs.emulationProfiles_cfg, appData.emulationProfiles_cfg ); + GlobalPrefs.DEFAULT_EMULATION_PROFILE_DEFAULT, + globalPrefs.emulationProfiles_cfg, appData.emulationProfiles_cfg ); // Touchscreen profile touchscreenProfile = loadProfile( mPreferences, "touchscreenProfile", - UserPrefs.DEFAULT_TOUCHSCREEN_PROFILE_DEFAULT, - userPrefs.touchscreenProfiles_cfg, appData.touchscreenProfiles_cfg ); + GlobalPrefs.DEFAULT_TOUCHSCREEN_PROFILE_DEFAULT, + globalPrefs.touchscreenProfiles_cfg, appData.touchscreenProfiles_cfg ); // Controller profiles controllerProfile1 = loadControllerProfile( mPreferences, "controllerProfile1", - UserPrefs.DEFAULT_CONTROLLER_PROFILE_DEFAULT, - userPrefs.controllerProfiles_cfg, appData.controllerProfiles_cfg ); + GlobalPrefs.DEFAULT_CONTROLLER_PROFILE_DEFAULT, + globalPrefs.controllerProfiles_cfg, appData.controllerProfiles_cfg ); controllerProfile2 = loadControllerProfile( mPreferences, "controllerProfile2", "", - userPrefs.controllerProfiles_cfg, appData.controllerProfiles_cfg ); + globalPrefs.controllerProfiles_cfg, appData.controllerProfiles_cfg ); controllerProfile3 = loadControllerProfile( mPreferences, "controllerProfile3", "", - userPrefs.controllerProfiles_cfg, appData.controllerProfiles_cfg ); + globalPrefs.controllerProfiles_cfg, appData.controllerProfiles_cfg ); controllerProfile4 = loadControllerProfile( mPreferences, "controllerProfile4", "", - userPrefs.controllerProfiles_cfg, appData.controllerProfiles_cfg ); + globalPrefs.controllerProfiles_cfg, appData.controllerProfiles_cfg ); // Player map playerMap = new PlayerMap( mPreferences.getString( "playerMap", "" ) ); @@ -280,7 +286,7 @@ public GamePrefs( Context context, String romMd5, RomHeader header ) if( layout.equals( "Mupen64Plus-AE-Analog" ) || layout.equals( "Mupen64Plus-AE-All" ) ) { - if( userPrefs.isTouchscreenAnimated ) + if( globalPrefs.isTouchscreenAnimated ) layout += "-Stick"; else layout += "-Nostick"; @@ -303,8 +309,8 @@ public GamePrefs( Context context, String romMd5, RomHeader header ) .sqrt( ( screenWidthInches * screenWidthInches ) + ( screenHeightInches * screenHeightInches ) ); if( screenSizeInches >= Utility.MINIMUM_TABLET_SIZE - || userPrefs.displayOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - || userPrefs.displayOrientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT ) + || globalPrefs.displayOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + || globalPrefs.displayOrientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT ) { layout += "-Half-Height"; } @@ -325,14 +331,14 @@ public GamePrefs( Context context, String romMd5, RomHeader header ) else { // Touchscreen disabled, profile is null - if( userPrefs.isFpsEnabled ) + if( globalPrefs.isFpsEnabled ) { folder = appData.touchscreenSkinsDir + context.getString( R.string.touchscreenLayout_fpsOnly ); } touchscreenAutoHoldables = null; } - isTouchscreenHidden = !isTouchscreenEnabled || userPrefs.touchscreenTransparency == 0; + isTouchscreenHidden = !isTouchscreenEnabled || globalPrefs.touchscreenTransparency == 0; isTouchscreenCustom = isCustom; touchscreenLayout = folder; @@ -348,15 +354,46 @@ public GamePrefs( Context context, String romMd5, RomHeader header ) numControllers += isControllerEnabled2 ? 1 : 0; numControllers += isControllerEnabled3 ? 1 : 0; numControllers += isControllerEnabled4 ? 1 : 0; - playerMap.setEnabled( numControllers > 1 && !userPrefs.isControllerShared ); + playerMap.setEnabled( numControllers > 1 && !globalPrefs.isControllerShared ); // Determine which players are "plugged in" - isPlugged1 = isControllerEnabled1 || isTouchscreenEnabled || userPrefs.isTouchpadEnabled; + isPlugged1 = isControllerEnabled1 || isTouchscreenEnabled || globalPrefs.isTouchpadEnabled; isPlugged2 = isControllerEnabled2; isPlugged3 = isControllerEnabled3; isPlugged4 = isControllerEnabled4; } + public String getCheatArgs() + { + if( !isCheatOptionsShown ) + return ""; + + final Pattern pattern = Pattern.compile( "^" + mHeader.crc + " Cheat(\\d+)" ); + StringBuilder builder = null; + Map map = mPreferences.getAll(); + for (String key : map.keySet()) + { + Matcher matcher = pattern.matcher( key ); + if ( matcher.matches() && matcher.groupCount() > 0 ) + { + int value = mPreferences.getInt( key, 0 ); + if (value > 0) + { + int index = Integer.parseInt( matcher.group( 1 ) ); + + if (builder == null) + builder = new StringBuilder(); + else + builder.append( ',' ); + builder.append( index ); + builder.append( '-' ); + builder.append( value - 1 ); + } + } + } + return builder == null ? "" : builder.toString(); + } + private static Profile loadProfile( SharedPreferences prefs, String key, String defaultName, String customPath, String builtinPath ) { diff --git a/src/paulscode/android/mupen64plusae/PlayMenuActivity.java b/src/paulscode/android/mupen64plusae/persistent/GamePrefsActivity.java similarity index 69% rename from src/paulscode/android/mupen64plusae/PlayMenuActivity.java rename to src/paulscode/android/mupen64plusae/persistent/GamePrefsActivity.java index cdd4593caa..6bf4f7ee78 100644 --- a/src/paulscode/android/mupen64plusae/PlayMenuActivity.java +++ b/src/paulscode/android/mupen64plusae/persistent/GamePrefsActivity.java @@ -18,14 +18,14 @@ * * Authors: Paul Lamb */ -package paulscode.android.mupen64plusae; +package paulscode.android.mupen64plusae.persistent; import java.io.File; import java.util.ArrayList; -import java.util.Date; import org.mupen64plusae.v3.alpha.R; +import paulscode.android.mupen64plusae.ActivityHelper; import paulscode.android.mupen64plusae.cheat.CheatEditorActivity; import paulscode.android.mupen64plusae.cheat.CheatFile; import paulscode.android.mupen64plusae.cheat.CheatFile.CheatSection; @@ -35,18 +35,12 @@ import paulscode.android.mupen64plusae.dialog.Prompt; import paulscode.android.mupen64plusae.dialog.Prompt.PromptConfirmListener; import paulscode.android.mupen64plusae.hack.MogaHack; -import paulscode.android.mupen64plusae.persistent.AppData; -import paulscode.android.mupen64plusae.persistent.ConfigFile; -import paulscode.android.mupen64plusae.persistent.GamePrefs; -import paulscode.android.mupen64plusae.persistent.UserPrefs; import paulscode.android.mupen64plusae.preference.PlayerMapPreference; import paulscode.android.mupen64plusae.preference.PrefUtil; import paulscode.android.mupen64plusae.preference.ProfilePreference; -import paulscode.android.mupen64plusae.util.Notifier; import paulscode.android.mupen64plusae.util.RomDatabase; import paulscode.android.mupen64plusae.util.RomDatabase.RomDetail; import paulscode.android.mupen64plusae.util.RomHeader; -import paulscode.android.mupen64plusae.util.Utility; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; @@ -54,7 +48,6 @@ import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceActivity; -import android.preference.PreferenceCategory; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; import android.text.TextUtils; @@ -62,21 +55,17 @@ import com.bda.controller.Controller; -public class PlayMenuActivity extends PreferenceActivity implements OnPreferenceClickListener, +public class GamePrefsActivity extends PreferenceActivity implements OnPreferenceClickListener, OnSharedPreferenceChangeListener { // These constants must match the keys used in res/xml/preferences_play.xml + private static final String SCREEN_ROOT = "screenRoot"; private static final String SCREEN_CHEATS = "screenCheats"; - - private static final String CATEGORY_GAME_SETTINGS = "categoryGameSettings"; private static final String CATEGORY_CHEATS = "categoryCheats"; - public static final String ACTION_RESUME = "actionResume"; - public static final String ACTION_RESTART = "actionRestart"; private static final String ACTION_CHEAT_EDITOR = "actionCheatEditor"; private static final String ACTION_WIKI = "actionWiki"; private static final String ACTION_RESET_GAME_PREFS = "actionResetGamePrefs"; - private static final String ACTION_EXIT = "actionExit"; private static final String EMULATION_PROFILE = "emulationProfile"; private static final String TOUCHSCREEN_PROFILE = "touchscreenProfile"; @@ -89,7 +78,7 @@ public class PlayMenuActivity extends PreferenceActivity implements OnPreference // App data and user preferences private AppData mAppData = null; - private UserPrefs mUserPrefs = null; + private GlobalPrefs mGlobalPrefs = null; private GamePrefs mGamePrefs = null; private SharedPreferences mPrefs = null; @@ -126,8 +115,8 @@ protected void onCreate( Bundle savedInstanceState ) Bundle extras = getIntent().getExtras(); if( extras == null ) throw new Error( "ROM path and MD5 must be passed via the extras bundle" ); - mRomPath = extras.getString( Keys.Extras.ROM_PATH ); - mRomMd5 = extras.getString( Keys.Extras.ROM_MD5 ); + mRomPath = extras.getString( ActivityHelper.Keys.ROM_PATH ); + mRomMd5 = extras.getString( ActivityHelper.Keys.ROM_MD5 ); if( TextUtils.isEmpty( mRomPath ) || TextUtils.isEmpty( mRomMd5 ) ) throw new Error( "ROM path and MD5 must be passed via the extras bundle" ); @@ -139,9 +128,9 @@ protected void onCreate( Bundle savedInstanceState ) // Get app data and user preferences mAppData = new AppData( this ); mRomHeader = new RomHeader( mRomPath ); - mUserPrefs = new UserPrefs( this ); + mGlobalPrefs = new GlobalPrefs( this ); mGamePrefs = new GamePrefs( this, mRomMd5, mRomHeader ); - mUserPrefs.enforceLocale( this ); + mGlobalPrefs.enforceLocale( this ); mPrefs = getSharedPreferences( mGamePrefs.sharedPrefsName, MODE_PRIVATE ); // Get the detailed info about the ROM @@ -171,7 +160,7 @@ protected void onCreate( Bundle savedInstanceState ) // Remove wiki menu item if not applicable if( TextUtils.isEmpty( mRomDetail.wikiUrl ) ) { - PrefUtil.removePreference( this, CATEGORY_GAME_SETTINGS, ACTION_WIKI ); + PrefUtil.removePreference( this, SCREEN_ROOT, ACTION_WIKI ); } // Setup controller profiles settings based on ROM's number of players @@ -181,18 +170,18 @@ protected void onCreate( Bundle savedInstanceState ) findPreference( CONTROLLER_PROFILE1 ).setTitle( R.string.controllerProfile_title ); // Remove unneeded preference items - PrefUtil.removePreference( this, CATEGORY_GAME_SETTINGS, CONTROLLER_PROFILE2 ); - PrefUtil.removePreference( this, CATEGORY_GAME_SETTINGS, CONTROLLER_PROFILE3 ); - PrefUtil.removePreference( this, CATEGORY_GAME_SETTINGS, CONTROLLER_PROFILE4 ); - PrefUtil.removePreference( this, CATEGORY_GAME_SETTINGS, PLAYER_MAP ); + PrefUtil.removePreference( this, SCREEN_ROOT, CONTROLLER_PROFILE2 ); + PrefUtil.removePreference( this, SCREEN_ROOT, CONTROLLER_PROFILE3 ); + PrefUtil.removePreference( this, SCREEN_ROOT, CONTROLLER_PROFILE4 ); + PrefUtil.removePreference( this, SCREEN_ROOT, PLAYER_MAP ); } else { // Remove unneeded preference items if( mRomDetail.players < 4 ) - PrefUtil.removePreference( this, CATEGORY_GAME_SETTINGS, CONTROLLER_PROFILE4 ); + PrefUtil.removePreference( this, SCREEN_ROOT, CONTROLLER_PROFILE4 ); if( mRomDetail.players < 3 ) - PrefUtil.removePreference( this, CATEGORY_GAME_SETTINGS, CONTROLLER_PROFILE3 ); + PrefUtil.removePreference( this, SCREEN_ROOT, CONTROLLER_PROFILE3 ); // Configure the player map preference PlayerMapPreference playerPref = (PlayerMapPreference) findPreference( PLAYER_MAP ); @@ -210,22 +199,6 @@ protected void onResume() mPrefs.registerOnSharedPreferenceChangeListener( this ); mMogaController.onResume(); refreshViews(); - - if( ACTION_RESUME.equals( action ) ) - { - action = ACTION_EXIT; - launchGame( false ); - } - else if( ACTION_RESTART.equals( action ) ) - { - action = ACTION_EXIT; - launchGame( true ); - } - else if( ACTION_EXIT.equals( action ) ) - { - action = null; - finish(); - } } @Override @@ -265,25 +238,25 @@ private void refreshViews() mPrefs.unregisterOnSharedPreferenceChangeListener( this ); // Refresh the preferences objects - mUserPrefs = new UserPrefs( this ); + mGlobalPrefs = new GlobalPrefs( this ); mGamePrefs = new GamePrefs( this, mRomMd5, mRomHeader ); // Populate the profile preferences mEmulationProfile.populateProfiles( mAppData.emulationProfiles_cfg, - mUserPrefs.emulationProfiles_cfg, mUserPrefs.getEmulationProfileDefault() ); + mGlobalPrefs.emulationProfiles_cfg, mGlobalPrefs.getEmulationProfileDefault() ); mTouchscreenProfile.populateProfiles( mAppData.touchscreenProfiles_cfg, - mUserPrefs.touchscreenProfiles_cfg, mUserPrefs.getTouchscreenProfileDefault() ); + mGlobalPrefs.touchscreenProfiles_cfg, mGlobalPrefs.getTouchscreenProfileDefault() ); mControllerProfile1.populateProfiles( mAppData.controllerProfiles_cfg, - mUserPrefs.controllerProfiles_cfg, mUserPrefs.getControllerProfileDefault() ); + mGlobalPrefs.controllerProfiles_cfg, mGlobalPrefs.getControllerProfileDefault() ); mControllerProfile2.populateProfiles( mAppData.controllerProfiles_cfg, - mUserPrefs.controllerProfiles_cfg, "" ); + mGlobalPrefs.controllerProfiles_cfg, "" ); mControllerProfile3.populateProfiles( mAppData.controllerProfiles_cfg, - mUserPrefs.controllerProfiles_cfg, "" ); + mGlobalPrefs.controllerProfiles_cfg, "" ); mControllerProfile4.populateProfiles( mAppData.controllerProfiles_cfg, - mUserPrefs.controllerProfiles_cfg, "" ); + mGlobalPrefs.controllerProfiles_cfg, "" ); // Refresh the preferences objects in case populate* changed a value - mUserPrefs = new UserPrefs( this ); + mGlobalPrefs = new GlobalPrefs( this ); mGamePrefs = new GamePrefs( this, mRomMd5, mRomHeader ); // Set cheats screen summary text @@ -334,12 +307,12 @@ public boolean onPreferenceClick( Preference preference ) if( key.equals( ACTION_CHEAT_EDITOR ) ) { Intent intent = new Intent( this, CheatEditorActivity.class ); - intent.putExtra( Keys.Extras.ROM_PATH, mRomPath ); + intent.putExtra( ActivityHelper.Keys.ROM_PATH, mRomPath ); startActivityForResult( intent, 111 ); } else if( key.equals( ACTION_WIKI ) ) { - Utility.launchUri( this, mRomDetail.wikiUrl ); + ActivityHelper.launchUri( this, mRomDetail.wikiUrl ); } else if( key.equals( ACTION_RESET_GAME_PREFS ) ) { @@ -352,7 +325,7 @@ private void buildCheatsCategory( final String crc ) { mCategoryCheats.removeAll(); - Log.v( "PlayMenuActivity", "building from CRC = " + crc ); + Log.v( "GamePrefsActivity", "building from CRC = " + crc ); if( crc == null ) return; @@ -361,7 +334,7 @@ private void buildCheatsCategory( final String crc ) CheatSection cheatSection = mupencheat_txt.match( "^" + crc.replace( ' ', '-' ) + ".*" ); if( cheatSection == null ) { - Log.w( "PlayMenuActivity", "No cheat section found for '" + crc + "'" ); + Log.w( "GamePrefsActivity", "No cheat section found for '" + crc + "'" ); return; } ArrayList cheats = new ArrayList(); @@ -400,88 +373,6 @@ private void buildCheatsCategory( final String crc ) } } - private void launchGame( boolean isRestarting ) - { - // Popup the multi-player dialog if necessary and abort if any players are unassigned - if( mRomDetail.players > 1 && mGamePrefs.playerMap.isEnabled() - && mUserPrefs.getPlayerMapReminder() ) - { - mGamePrefs.playerMap.removeUnavailableMappings(); - boolean needs1 = mGamePrefs.isControllerEnabled1 && !mGamePrefs.playerMap.isMapped( 1 ); - boolean needs2 = mGamePrefs.isControllerEnabled2 && !mGamePrefs.playerMap.isMapped( 2 ); - boolean needs3 = mGamePrefs.isControllerEnabled3 && !mGamePrefs.playerMap.isMapped( 3 ) - && mRomDetail.players > 2; - boolean needs4 = mGamePrefs.isControllerEnabled4 && !mGamePrefs.playerMap.isMapped( 4 ) - && mRomDetail.players > 3; - - if( needs1 || needs2 || needs3 || needs4 ) - { - @SuppressWarnings( "deprecation" ) - PlayerMapPreference pref = (PlayerMapPreference) findPreference( "playerMap" ); - pref.show(); - return; - } - } - - // Make sure that the storage is accessible - if( !mAppData.isSdCardAccessible() ) - { - Log.e( "CheatMenuHandler", "SD Card not accessible in method onPreferenceClick" ); - Notifier.showToast( this, R.string.toast_sdInaccessible ); - return; - } - - // Notify user that the game activity is starting - Notifier.showToast( this, R.string.toast_launchingEmulator ); - - // Update the ConfigSection with the new value for lastPlayed - String lastPlayed = Integer.toString( (int) ( new Date().getTime() / 1000 ) ); - ConfigFile config = new ConfigFile( mUserPrefs.romInfoCache_cfg ); - if( config != null ) - { - config.put( mRomMd5, "lastPlayed", lastPlayed ); - config.save(); - } - - // Launch the appropriate game activity - Intent intent = mUserPrefs.isTouchpadEnabled ? new Intent( this, - GameActivityXperiaPlay.class ) : new Intent( this, GameActivity.class ); - - // Pass the startup info via the intent - intent.putExtra( Keys.Extras.ROM_PATH, mRomPath ); - intent.putExtra( Keys.Extras.ROM_MD5, mRomMd5 ); - intent.putExtra( Keys.Extras.CHEAT_ARGS, getCheatArgs() ); - intent.putExtra( Keys.Extras.DO_RESTART, isRestarting ); - - startActivity( intent ); - } - - @SuppressWarnings( "deprecation" ) - private String getCheatArgs() - { - String cheatArgs = null; - - PreferenceCategory cheatsCategory = (PreferenceCategory) findPreference( CATEGORY_CHEATS ); - if( cheatsCategory != null ) - { - for( int i = 0; i < cheatsCategory.getPreferenceCount(); i++ ) - { - CheatPreference pref = (CheatPreference) cheatsCategory.getPreference( i ); - if( pref.isCheatEnabled() ) - { - if( cheatArgs == null ) - cheatArgs = ""; // First time through - else - cheatArgs += ","; - - cheatArgs += pref.getCheatCodeString( i ); - } - } - } - - return cheatArgs; - } - private void actionResetGamePrefs() { String title = getString( R.string.confirm_title ); @@ -492,9 +383,9 @@ private void actionResetGamePrefs() public void onConfirm() { // Reset the user preferences - mPrefs.unregisterOnSharedPreferenceChangeListener( PlayMenuActivity.this ); + mPrefs.unregisterOnSharedPreferenceChangeListener( GamePrefsActivity.this ); mPrefs.edit().clear().commit(); - PreferenceManager.setDefaultValues( PlayMenuActivity.this, R.xml.preferences_game, true ); + PreferenceManager.setDefaultValues( GamePrefsActivity.this, R.xml.preferences_game, true ); // Also reset any manual overrides the user may have made in the config file File configFile = new File( mGamePrefs.mupen64plus_cfg ); @@ -502,8 +393,7 @@ public void onConfirm() configFile.delete(); // Rebuild the menu system by restarting the activity - finish(); - startActivity( getIntent() ); + ActivityHelper.restartActivity( GamePrefsActivity.this ); } } ); } diff --git a/src/paulscode/android/mupen64plusae/persistent/UserPrefs.java b/src/paulscode/android/mupen64plusae/persistent/GlobalPrefs.java similarity index 99% rename from src/paulscode/android/mupen64plusae/persistent/UserPrefs.java rename to src/paulscode/android/mupen64plusae/persistent/GlobalPrefs.java index af261b2169..a34d8ea511 100644 --- a/src/paulscode/android/mupen64plusae/persistent/UserPrefs.java +++ b/src/paulscode/android/mupen64plusae/persistent/GlobalPrefs.java @@ -29,6 +29,7 @@ import org.apache.commons.lang.WordUtils; import org.mupen64plusae.v3.alpha.R; +import paulscode.android.mupen64plusae.ActivityHelper; import paulscode.android.mupen64plusae.jni.NativeConstants; import paulscode.android.mupen64plusae.persistent.AppData.HardwareInfo; import paulscode.android.mupen64plusae.persistent.ConfigFile.ConfigSection; @@ -82,7 +83,7 @@ * rather than at the point of use. This could improve application performance if the value is used * often, such as the frame refresh loop of a game. */ -public class UserPrefs +public class GlobalPrefs { /** The parent directory containing all user-writable data files. */ public final String userDataDir; @@ -260,7 +261,7 @@ public class UserPrefs @SuppressWarnings( "deprecation" ) @SuppressLint( "InlinedApi" ) @TargetApi( 17 ) - public UserPrefs( Context context ) + public GlobalPrefs( Context context ) { AppData appData = new AppData( context ); mPreferences = PreferenceManager.getDefaultSharedPreferences( context ); @@ -544,8 +545,7 @@ public void onClick( DialogInterface dialog, int which ) if( which >= 0 && which != currentIndex ) { mPreferences.edit().putString( KEY_LOCALE_OVERRIDE, mLocaleCodes[which] ).commit(); - activity.finish(); - activity.startActivity( activity.getIntent() ); + ActivityHelper.restartActivity( activity ); } } } ); diff --git a/src/paulscode/android/mupen64plusae/SettingsGlobalActivity.java b/src/paulscode/android/mupen64plusae/persistent/GlobalPrefsActivity.java similarity index 86% rename from src/paulscode/android/mupen64plusae/SettingsGlobalActivity.java rename to src/paulscode/android/mupen64plusae/persistent/GlobalPrefsActivity.java index 67579a520f..a531bca315 100644 --- a/src/paulscode/android/mupen64plusae/SettingsGlobalActivity.java +++ b/src/paulscode/android/mupen64plusae/persistent/GlobalPrefsActivity.java @@ -18,17 +18,15 @@ * * Authors: littleguy77 */ -package paulscode.android.mupen64plusae; +package paulscode.android.mupen64plusae.persistent; import org.mupen64plusae.v3.alpha.R; +import paulscode.android.mupen64plusae.ActivityHelper; import paulscode.android.mupen64plusae.dialog.Prompt; import paulscode.android.mupen64plusae.dialog.Prompt.PromptConfirmListener; -import paulscode.android.mupen64plusae.persistent.AppData; -import paulscode.android.mupen64plusae.persistent.UserPrefs; import paulscode.android.mupen64plusae.preference.PrefUtil; import android.annotation.TargetApi; -import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; @@ -37,7 +35,7 @@ import android.preference.PreferenceActivity; import android.preference.PreferenceManager; -public class SettingsGlobalActivity extends PreferenceActivity implements OnPreferenceClickListener, +public class GlobalPrefsActivity extends PreferenceActivity implements OnPreferenceClickListener, OnSharedPreferenceChangeListener { // These constants must match the keys used in res/xml/preferences.xml @@ -71,7 +69,7 @@ public class SettingsGlobalActivity extends PreferenceActivity implements OnPref // App data and user preferences private AppData mAppData = null; - private UserPrefs mUserPrefs = null; + private GlobalPrefs mGlobalPrefs = null; private SharedPreferences mPrefs = null; @SuppressWarnings( "deprecation" ) @@ -82,15 +80,15 @@ protected void onCreate( Bundle savedInstanceState ) // Get app data and user preferences mAppData = new AppData( this ); - mUserPrefs = new UserPrefs( this ); - mUserPrefs.enforceLocale( this ); + mGlobalPrefs = new GlobalPrefs( this ); + mGlobalPrefs.enforceLocale( this ); mPrefs = PreferenceManager.getDefaultSharedPreferences( this ); // Load user preference menu structure from XML and update view addPreferencesFromResource( R.xml.preferences_global ); // Refresh the preference data wrapper - mUserPrefs = new UserPrefs( this ); + mGlobalPrefs = new GlobalPrefs( this ); // Handle certain menu items that require extra processing or aren't actually preferences PrefUtil.setOnPreferenceClickListener( this, ACTION_RELOAD_ASSETS, this ); @@ -102,7 +100,7 @@ protected void onCreate( Bundle savedInstanceState ) if( !AppData.IS_KITKAT ) PrefUtil.removePreference( this, CATEGORY_DISPLAY, DISPLAY_IMMERSIVE_MODE ); - if( !mUserPrefs.isActionBarAvailable ) + if( !mGlobalPrefs.isActionBarAvailable ) PrefUtil.removePreference( this, CATEGORY_DISPLAY, DISPLAY_ACTION_BAR_TRANSPARENCY ); if( !mAppData.hardwareInfo.isXperiaPlay ) @@ -112,7 +110,7 @@ protected void onCreate( Bundle savedInstanceState ) Bundle extras = getIntent().getExtras(); if( extras != null ) { - int mode = extras.getInt( Keys.Extras.MENU_DISPLAY_MODE, 0 ); + int mode = extras.getInt( ActivityHelper.Keys.MENU_DISPLAY_MODE, 0 ); if( mode == 1 ) { // Remove distractions if this was launched from TouchscreenProfileActivity @@ -155,8 +153,7 @@ public void onSharedPreferenceChanged( SharedPreferences sharedPreferences, Stri { // Sometimes one preference change affects the hierarchy or layout of the views. In this // case it's easier just to restart the activity than try to figure out what to fix. - finish(); - startActivity( getIntent() ); + ActivityHelper.restartActivity( this ); } else { @@ -169,15 +166,15 @@ public void onSharedPreferenceChanged( SharedPreferences sharedPreferences, Stri private void refreshViews() { // Refresh the preferences object - mUserPrefs = new UserPrefs( this ); + mGlobalPrefs = new GlobalPrefs( this ); // Enable polygon offset pref if flicker reduction is custom - PrefUtil.enablePreference( this, VIDEO_POLYGON_OFFSET, mUserPrefs.videoHardwareType == VIDEO_HARDWARE_TYPE_CUSTOM ); + PrefUtil.enablePreference( this, VIDEO_POLYGON_OFFSET, mGlobalPrefs.videoHardwareType == VIDEO_HARDWARE_TYPE_CUSTOM ); // Enable audio prefs if audio is enabled - PrefUtil.enablePreference( this, AUDIO_BUFFER_SIZE, mUserPrefs.audioPlugin.enabled ); - PrefUtil.enablePreference( this, AUDIO_SYNCHRONIZE, mUserPrefs.audioPlugin.enabled ); - PrefUtil.enablePreference( this, AUDIO_SWAP_CHANNELS, mUserPrefs.audioPlugin.enabled ); + PrefUtil.enablePreference( this, AUDIO_BUFFER_SIZE, mGlobalPrefs.audioPlugin.enabled ); + PrefUtil.enablePreference( this, AUDIO_SYNCHRONIZE, mGlobalPrefs.audioPlugin.enabled ); + PrefUtil.enablePreference( this, AUDIO_SWAP_CHANNELS, mGlobalPrefs.audioPlugin.enabled ); } @Override @@ -203,7 +200,7 @@ else if( key.equals( ACTION_RESET_USER_PREFS ) ) private void actionReloadAssets() { mAppData.putAssetVersion( 0 ); - startActivity( new Intent( this, SplashActivity.class ) ); + ActivityHelper.startSplashActivity( this ); finish(); } @@ -217,13 +214,12 @@ private void actionResetUserPrefs() public void onConfirm() { // Reset the user preferences - mPrefs.unregisterOnSharedPreferenceChangeListener( SettingsGlobalActivity.this ); + mPrefs.unregisterOnSharedPreferenceChangeListener( GlobalPrefsActivity.this ); mPrefs.edit().clear().commit(); - PreferenceManager.setDefaultValues( SettingsGlobalActivity.this, R.xml.preferences_global, true ); + PreferenceManager.setDefaultValues( GlobalPrefsActivity.this, R.xml.preferences_global, true ); // Rebuild the menu system by restarting the activity - finish(); - startActivity( getIntent() ); + ActivityHelper.restartActivity( GlobalPrefsActivity.this ); } } ); } diff --git a/src/paulscode/android/mupen64plusae/preference/PlayerMapPreference.java b/src/paulscode/android/mupen64plusae/preference/PlayerMapPreference.java index 8a6bf8711c..138656594c 100644 --- a/src/paulscode/android/mupen64plusae/preference/PlayerMapPreference.java +++ b/src/paulscode/android/mupen64plusae/preference/PlayerMapPreference.java @@ -27,7 +27,7 @@ import paulscode.android.mupen64plusae.dialog.Prompt; import paulscode.android.mupen64plusae.dialog.Prompt.PromptInputCodeListener; import paulscode.android.mupen64plusae.input.map.PlayerMap; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import android.content.Context; import android.content.DialogInterface; import android.content.res.TypedArray; @@ -122,7 +122,7 @@ protected void onBindDialogView( View view ) super.onBindDialogView( view ); // Set the member variables - UserPrefs prefs = new UserPrefs( getContext() ); + GlobalPrefs prefs = new GlobalPrefs( getContext() ); mUnmappableKeyCodes = prefs.unmappableKeyCodes; mMap.deserialize( mValue ); @@ -197,7 +197,7 @@ public void onClick( View view ) @Override public void onCheckedChanged( CompoundButton buttonView, boolean isChecked ) { - new UserPrefs( getContext() ).putPlayerMapReminder( isChecked ); + new GlobalPrefs( getContext() ).putPlayerMapReminder( isChecked ); } private void promptPlayer( final int player ) diff --git a/src/paulscode/android/mupen64plusae/profile/ControllerProfileActivity.java b/src/paulscode/android/mupen64plusae/profile/ControllerProfileActivity.java index bb2e83618a..e345af9d9d 100644 --- a/src/paulscode/android/mupen64plusae/profile/ControllerProfileActivity.java +++ b/src/paulscode/android/mupen64plusae/profile/ControllerProfileActivity.java @@ -25,7 +25,7 @@ import org.mupen64plusae.v3.alpha.R; -import paulscode.android.mupen64plusae.Keys; +import paulscode.android.mupen64plusae.ActivityHelper; import paulscode.android.mupen64plusae.dialog.Prompt; import paulscode.android.mupen64plusae.dialog.Prompt.ListItemTwoTextIconPopulator; import paulscode.android.mupen64plusae.dialog.Prompt.PromptConfirmListener; @@ -43,7 +43,7 @@ import paulscode.android.mupen64plusae.persistent.AppData; import paulscode.android.mupen64plusae.persistent.ConfigFile; import paulscode.android.mupen64plusae.persistent.ConfigFile.ConfigSection; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; @@ -88,7 +88,7 @@ public class ControllerProfileActivity extends Activity implements OnInputListen private ControllerProfile mProfile; // User preferences wrapper - private UserPrefs mUserPrefs; + private GlobalPrefs mGlobalPrefs; // Command information private String[] mCommandNames; @@ -117,8 +117,8 @@ public void onCreate( Bundle savedInstanceState ) MogaHack.init( mMogaController, this ); // Get the user preferences wrapper - mUserPrefs = new UserPrefs( this ); - mUserPrefs.enforceLocale( this ); + mGlobalPrefs = new GlobalPrefs( this ); + mGlobalPrefs.enforceLocale( this ); // Get the command info mCommandNames = getResources().getStringArray( R.array.inputMapActivity_entries ); @@ -133,18 +133,18 @@ public void onCreate( Bundle savedInstanceState ) Bundle extras = getIntent().getExtras(); if( extras == null ) throw new Error( "Invalid usage: bundle must indicate profile name" ); - String name = extras.getString( Keys.Extras.PROFILE_NAME ); + String name = extras.getString( ActivityHelper.Keys.PROFILE_NAME ); if( TextUtils.isEmpty( name ) ) throw new Error( "Invalid usage: profile name cannot be null or empty" ); - mConfigFile = new ConfigFile( mUserPrefs.controllerProfiles_cfg ); + mConfigFile = new ConfigFile( mGlobalPrefs.controllerProfiles_cfg ); ConfigSection section = mConfigFile.get( name ); if( section == null ) throw new Error( "Invalid usage: profile name not found in config file" ); mProfile = new ControllerProfile( false, section ); // Set up input listeners - mUnmappableInputCodes = mUserPrefs.unmappableKeyCodes; - if( !mUserPrefs.isBigScreenMode ) + mUnmappableInputCodes = mGlobalPrefs.unmappableKeyCodes; + if( !mGlobalPrefs.isBigScreenMode ) { mKeyProvider = new KeyProvider( ImeFormula.DEFAULT, mUnmappableInputCodes ); mKeyProvider.registerListener( this ); @@ -164,7 +164,7 @@ public void onCreate( Bundle savedInstanceState ) setTitle( mProfile.name + " : " + mProfile.comment ); // Initialize the layout - if( mUserPrefs.isBigScreenMode ) + if( mGlobalPrefs.isBigScreenMode ) initLayoutBigScreenMode(); else initLayoutDefault(); @@ -280,7 +280,7 @@ private void setupButton( int resId, int index ) public boolean onCreateOptionsMenu( Menu menu ) { getMenuInflater().inflate( R.menu.controller_profile_activity, menu ); - menu.findItem( R.id.menuItem_exit ).setVisible( !mUserPrefs.isBigScreenMode ); + menu.findItem( R.id.menuItem_exit ).setVisible( !mGlobalPrefs.isBigScreenMode ); return super.onCreateOptionsMenu( menu ); } @@ -413,7 +413,7 @@ public void onDialogClosed( int inputCode, int hardwareId, int which ) @Override public boolean onKeyDown( int keyCode, KeyEvent event ) { - if( mUserPrefs.isBigScreenMode ) + if( mGlobalPrefs.isBigScreenMode ) return super.onKeyDown( keyCode, event ); else return mKeyProvider.onKey( keyCode, event ) || super.onKeyDown( keyCode, event ); @@ -422,7 +422,7 @@ public boolean onKeyDown( int keyCode, KeyEvent event ) @Override public boolean onKeyUp( int keyCode, KeyEvent event ) { - if( mUserPrefs.isBigScreenMode ) + if( mGlobalPrefs.isBigScreenMode ) return super.onKeyUp( keyCode, event ); else return mKeyProvider.onKey( keyCode, event ) || super.onKeyUp( keyCode, event ); @@ -434,7 +434,7 @@ public boolean onGenericMotionEvent( MotionEvent event ) { if( !AppData.IS_HONEYCOMB_MR1 ) return false; - else if( mUserPrefs.isBigScreenMode ) + else if( mGlobalPrefs.isBigScreenMode ) return super.onGenericMotionEvent( event ); else return mAxisProvider.onGenericMotion( event ) || super.onGenericMotionEvent( event ); diff --git a/src/paulscode/android/mupen64plusae/profile/EmulationProfileActivity.java b/src/paulscode/android/mupen64plusae/profile/EmulationProfileActivity.java index 6683637ce9..1ea62d1080 100644 --- a/src/paulscode/android/mupen64plusae/profile/EmulationProfileActivity.java +++ b/src/paulscode/android/mupen64plusae/profile/EmulationProfileActivity.java @@ -22,7 +22,7 @@ import org.mupen64plusae.v3.alpha.R; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import paulscode.android.mupen64plusae.preference.PrefUtil; import paulscode.android.mupen64plusae.task.ExtractTexturesTask; import paulscode.android.mupen64plusae.task.ExtractTexturesTask.ExtractTexturesListener; @@ -67,7 +67,7 @@ protected int getPrefsResId() @Override protected String getConfigFilePath() { - return new UserPrefs( this ).emulationProfiles_cfg; + return new GlobalPrefs( this ).emulationProfiles_cfg; } @SuppressWarnings( "deprecation" ) @@ -138,8 +138,8 @@ private void processTexturePak( final String filename ) dialog.show(); // Asynchronously extract textures and dismiss popup - UserPrefs userPrefs = new UserPrefs( EmulationProfileActivity.this ); - new ExtractTexturesTask( filename, userPrefs.hiResTextureDir, new ExtractTexturesListener() + GlobalPrefs globalPrefs = new GlobalPrefs( EmulationProfileActivity.this ); + new ExtractTexturesTask( filename, globalPrefs.hiResTextureDir, new ExtractTexturesListener() { @Override public void onExtractTexturesFinished( boolean success ) diff --git a/src/paulscode/android/mupen64plusae/profile/ManageControllerProfilesActivity.java b/src/paulscode/android/mupen64plusae/profile/ManageControllerProfilesActivity.java index 2c378b2e78..9721f67801 100644 --- a/src/paulscode/android/mupen64plusae/profile/ManageControllerProfilesActivity.java +++ b/src/paulscode/android/mupen64plusae/profile/ManageControllerProfilesActivity.java @@ -20,15 +20,14 @@ */ package paulscode.android.mupen64plusae.profile; -import paulscode.android.mupen64plusae.Keys; -import android.content.Intent; +import paulscode.android.mupen64plusae.ActivityHelper; public class ManageControllerProfilesActivity extends ManageProfilesActivity { @Override protected String getConfigFilePath( boolean isBuiltin ) { - return isBuiltin ? mAppData.controllerProfiles_cfg : mUserPrefs.controllerProfiles_cfg; + return isBuiltin ? mAppData.controllerProfiles_cfg : mGlobalPrefs.controllerProfiles_cfg; } @Override @@ -40,20 +39,18 @@ protected String getNoDefaultProfile() @Override protected String getDefaultProfile() { - return mUserPrefs.getControllerProfileDefault(); + return mGlobalPrefs.getControllerProfileDefault(); } @Override protected void putDefaultProfile( String name ) { - mUserPrefs.putControllerProfileDefault( name ); + mGlobalPrefs.putControllerProfileDefault( name ); } @Override protected void onEditProfile( Profile profile ) { - Intent intent = new Intent( this, ControllerProfileActivity.class ); - intent.putExtra( Keys.Extras.PROFILE_NAME, profile.name ); - startActivity( intent ); + ActivityHelper.startControllerProfileActivity( this, profile.name ); } } diff --git a/src/paulscode/android/mupen64plusae/profile/ManageEmulationProfilesActivity.java b/src/paulscode/android/mupen64plusae/profile/ManageEmulationProfilesActivity.java index c5bcacdacf..9c0c8efa5e 100644 --- a/src/paulscode/android/mupen64plusae/profile/ManageEmulationProfilesActivity.java +++ b/src/paulscode/android/mupen64plusae/profile/ManageEmulationProfilesActivity.java @@ -20,41 +20,38 @@ */ package paulscode.android.mupen64plusae.profile; -import paulscode.android.mupen64plusae.Keys; -import paulscode.android.mupen64plusae.persistent.UserPrefs; -import android.content.Intent; +import paulscode.android.mupen64plusae.ActivityHelper; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; public class ManageEmulationProfilesActivity extends ManageProfilesActivity { @Override protected String getConfigFilePath( boolean isBuiltin ) { - return isBuiltin ? mAppData.emulationProfiles_cfg : mUserPrefs.emulationProfiles_cfg; + return isBuiltin ? mAppData.emulationProfiles_cfg : mGlobalPrefs.emulationProfiles_cfg; } @Override protected String getNoDefaultProfile() { - return UserPrefs.DEFAULT_EMULATION_PROFILE_DEFAULT; + return GlobalPrefs.DEFAULT_EMULATION_PROFILE_DEFAULT; } @Override protected String getDefaultProfile() { - return mUserPrefs.getEmulationProfileDefault(); + return mGlobalPrefs.getEmulationProfileDefault(); } @Override protected void putDefaultProfile( String name ) { - mUserPrefs.putEmulationProfileDefault( name ); + mGlobalPrefs.putEmulationProfileDefault( name ); } @Override protected void onEditProfile( Profile profile ) { - Intent intent = new Intent( this, EmulationProfileActivity.class ); - intent.putExtra( Keys.Extras.PROFILE_NAME, profile.name ); - startActivity( intent ); + ActivityHelper.startEmulationProfileActivity( this, profile.name ); } } diff --git a/src/paulscode/android/mupen64plusae/profile/ManageProfilesActivity.java b/src/paulscode/android/mupen64plusae/profile/ManageProfilesActivity.java index 49438d3198..d985f52424 100644 --- a/src/paulscode/android/mupen64plusae/profile/ManageProfilesActivity.java +++ b/src/paulscode/android/mupen64plusae/profile/ManageProfilesActivity.java @@ -31,7 +31,7 @@ import paulscode.android.mupen64plusae.dialog.Prompt.PromptConfirmListener; import paulscode.android.mupen64plusae.persistent.AppData; import paulscode.android.mupen64plusae.persistent.ConfigFile; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -117,7 +117,7 @@ abstract public class ManageProfilesActivity extends ListActivity protected AppData mAppData; /** The user preferences wrapper, available as a convenience to subclasses. */ - protected UserPrefs mUserPrefs; + protected GlobalPrefs mGlobalPrefs; private final List mProfileNames = new ArrayList(); @@ -126,8 +126,8 @@ protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); mAppData = new AppData( this ); - mUserPrefs = new UserPrefs( this ); - mUserPrefs.enforceLocale( this ); + mGlobalPrefs = new GlobalPrefs( this ); + mGlobalPrefs.enforceLocale( this ); // Get the config files from the subclass-specified paths String customPath = getConfigFilePath( false ); diff --git a/src/paulscode/android/mupen64plusae/profile/ManageTouchscreenProfilesActivity.java b/src/paulscode/android/mupen64plusae/profile/ManageTouchscreenProfilesActivity.java index 59cfc332e0..76fd25b93f 100644 --- a/src/paulscode/android/mupen64plusae/profile/ManageTouchscreenProfilesActivity.java +++ b/src/paulscode/android/mupen64plusae/profile/ManageTouchscreenProfilesActivity.java @@ -20,15 +20,14 @@ */ package paulscode.android.mupen64plusae.profile; -import paulscode.android.mupen64plusae.Keys; -import android.content.Intent; +import paulscode.android.mupen64plusae.ActivityHelper; public class ManageTouchscreenProfilesActivity extends ManageProfilesActivity { @Override protected String getConfigFilePath( boolean isBuiltin ) { - return isBuiltin ? mAppData.touchscreenProfiles_cfg : mUserPrefs.touchscreenProfiles_cfg; + return isBuiltin ? mAppData.touchscreenProfiles_cfg : mGlobalPrefs.touchscreenProfiles_cfg; } @Override @@ -40,20 +39,18 @@ protected String getNoDefaultProfile() @Override protected String getDefaultProfile() { - return mUserPrefs.getTouchscreenProfileDefault(); + return mGlobalPrefs.getTouchscreenProfileDefault(); } @Override protected void putDefaultProfile( String name ) { - mUserPrefs.putTouchscreenProfileDefault( name ); + mGlobalPrefs.putTouchscreenProfileDefault( name ); } @Override protected void onEditProfile( Profile profile ) { - Intent intent = new Intent( this, TouchscreenProfileActivity.class ); - intent.putExtra( Keys.Extras.PROFILE_NAME, profile.name ); - startActivity( intent ); + ActivityHelper.startTouchscreenProfileActivity( this, profile.name ); } } diff --git a/src/paulscode/android/mupen64plusae/profile/ProfileActivity.java b/src/paulscode/android/mupen64plusae/profile/ProfileActivity.java index 9992834859..772675aefc 100644 --- a/src/paulscode/android/mupen64plusae/profile/ProfileActivity.java +++ b/src/paulscode/android/mupen64plusae/profile/ProfileActivity.java @@ -20,10 +20,10 @@ */ package paulscode.android.mupen64plusae.profile; -import paulscode.android.mupen64plusae.Keys; +import paulscode.android.mupen64plusae.ActivityHelper; import paulscode.android.mupen64plusae.persistent.ConfigFile; import paulscode.android.mupen64plusae.persistent.ConfigFile.ConfigSection; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; @@ -111,13 +111,13 @@ protected void onCreate( Bundle savedInstanceState ) super.onCreate( savedInstanceState ); // Set locale - new UserPrefs( this ).enforceLocale( this ); + new GlobalPrefs( this ).enforceLocale( this ); // Load the profile; fail fast if there are any programmer usage errors Bundle extras = getIntent().getExtras(); if( extras == null ) throw new Error( "Invalid usage: bundle must indicate profile name" ); - mProfileName = extras.getString( Keys.Extras.PROFILE_NAME ); + mProfileName = extras.getString( ActivityHelper.Keys.PROFILE_NAME ); if( TextUtils.isEmpty( mProfileName ) ) throw new Error( "Invalid usage: profile name cannot be null or empty" ); diff --git a/src/paulscode/android/mupen64plusae/profile/TouchscreenProfileActivity.java b/src/paulscode/android/mupen64plusae/profile/TouchscreenProfileActivity.java index 3f9743119e..6f623350b2 100644 --- a/src/paulscode/android/mupen64plusae/profile/TouchscreenProfileActivity.java +++ b/src/paulscode/android/mupen64plusae/profile/TouchscreenProfileActivity.java @@ -23,17 +23,16 @@ import org.apache.commons.lang.ArrayUtils; import org.mupen64plusae.v3.alpha.R; -import paulscode.android.mupen64plusae.GameOverlay; -import paulscode.android.mupen64plusae.Keys; -import paulscode.android.mupen64plusae.SettingsGlobalActivity; +import paulscode.android.mupen64plusae.ActivityHelper; import paulscode.android.mupen64plusae.dialog.SeekBarGroup; +import paulscode.android.mupen64plusae.game.GameOverlay; import paulscode.android.mupen64plusae.input.AbstractController; import paulscode.android.mupen64plusae.input.map.TouchMap; import paulscode.android.mupen64plusae.input.map.VisibleTouchMap; import paulscode.android.mupen64plusae.persistent.AppData; import paulscode.android.mupen64plusae.persistent.ConfigFile; import paulscode.android.mupen64plusae.persistent.ConfigFile.ConfigSection; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.ActionBar; @@ -42,7 +41,6 @@ import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; -import android.content.Intent; import android.graphics.Color; import android.graphics.Point; import android.graphics.Rect; @@ -93,7 +91,7 @@ public class TouchscreenProfileActivity extends Activity implements OnTouchListe private Profile mProfile; // User preferences wrapper - private UserPrefs mUserPrefs; + private GlobalPrefs mGlobalPrefs; // Visual elements private VisibleTouchMap mTouchscreenMap; @@ -121,17 +119,17 @@ protected void onCreate( Bundle savedInstanceState ) super.onCreate( savedInstanceState ); // Get the user preferences wrapper - mUserPrefs = new UserPrefs( this ); - mUserPrefs.enforceLocale( this ); + mGlobalPrefs = new GlobalPrefs( this ); + mGlobalPrefs.enforceLocale( this ); // Load the profile; fail fast if there are any programmer usage errors Bundle extras = getIntent().getExtras(); if( extras == null ) throw new Error( "Invalid usage: bundle must indicate profile name" ); - String name = extras.getString( Keys.Extras.PROFILE_NAME ); + String name = extras.getString( ActivityHelper.Keys.PROFILE_NAME ); if( TextUtils.isEmpty( name ) ) throw new Error( "Invalid usage: profile name cannot be null or empty" ); - mConfigFile = new ConfigFile( mUserPrefs.touchscreenProfiles_cfg ); + mConfigFile = new ConfigFile( mGlobalPrefs.touchscreenProfiles_cfg ); ConfigSection section = mConfigFile.get( name ); if( section == null ) throw new Error( "Invalid usage: profile name not found in config file" ); @@ -160,7 +158,7 @@ protected void onCreate( Bundle savedInstanceState ) // For Honeycomb, let the action bar overlay the rendered view (rather than squeezing it) // For earlier APIs, remove the title bar to yield more space Window window = getWindow(); - if( mUserPrefs.isActionBarAvailable ) + if( mGlobalPrefs.isActionBarAvailable ) window.requestFeature( Window.FEATURE_ACTION_BAR_OVERLAY ); else window.requestFeature( Window.FEATURE_NO_TITLE ); @@ -174,11 +172,11 @@ protected void onCreate( Bundle savedInstanceState ) mOverlay = (GameOverlay) findViewById( R.id.gameOverlay ); // Configure the action bar introduced in higher Android versions - if( mUserPrefs.isActionBarAvailable ) + if( mGlobalPrefs.isActionBarAvailable ) { getActionBar().hide(); ColorDrawable color = new ColorDrawable( Color.parseColor( "#303030" ) ); - color.setAlpha( mUserPrefs.displayActionBarTransparency ); + color.setAlpha( mGlobalPrefs.displayActionBarTransparency ); getActionBar().setBackgroundDrawable( color ); // onOptionsMenuClosed is not called due to a bug in Android: @@ -197,16 +195,16 @@ public void onMenuVisibilityChanged( boolean isVisible ) // Initialize the touchmap and overlay mTouchscreenMap = new VisibleTouchMap( getResources() ); mOverlay.setOnTouchListener( this ); - mOverlay.initialize( mTouchscreenMap, true, mUserPrefs.isFpsEnabled, mUserPrefs.isTouchscreenAnimated ); + mOverlay.initialize( mTouchscreenMap, true, mGlobalPrefs.isFpsEnabled, mGlobalPrefs.isTouchscreenAnimated ); } @TargetApi( 11 ) private void refresh() { // Reposition the assets and refresh the overlay and options menu - mTouchscreenMap.load( mUserPrefs.touchscreenSkin, mProfile, - mUserPrefs.isTouchscreenAnimated, true, mUserPrefs.touchscreenScale, - mUserPrefs.touchscreenTransparency ); + mTouchscreenMap.load( mGlobalPrefs.touchscreenSkin, mProfile, + mGlobalPrefs.isTouchscreenAnimated, true, mGlobalPrefs.touchscreenScale, + mGlobalPrefs.touchscreenTransparency ); mOverlay.postInvalidate(); if( AppData.IS_HONEYCOMB ) invalidateOptionsMenu(); @@ -218,13 +216,13 @@ protected void onResume() super.onResume(); // Refresh in case the global settings changed - mUserPrefs = new UserPrefs( this ); + mGlobalPrefs = new GlobalPrefs( this ); // Update the dummy GameSurface size in case global settings changed FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mSurface.getLayoutParams(); - params.width = mUserPrefs.videoSurfaceWidth; - params.height = mUserPrefs.videoSurfaceHeight; - params.gravity = mUserPrefs.displayPosition | Gravity.CENTER_HORIZONTAL; + params.width = mGlobalPrefs.videoSurfaceWidth; + params.height = mGlobalPrefs.videoSurfaceHeight; + params.gravity = mGlobalPrefs.displayPosition | Gravity.CENTER_HORIZONTAL; mSurface.setLayoutParams( params ); // Refresh the touchscreen controls @@ -291,9 +289,7 @@ public boolean onMenuItemSelected( int featureId, MenuItem item ) switch( item.getItemId() ) { case R.id.menuItem_globalSettings: - Intent intent = new Intent( this, SettingsGlobalActivity.class ); - intent.putExtra( Keys.Extras.MENU_DISPLAY_MODE, 1 ); - startActivity( intent ); + ActivityHelper.startGlobalPrefsActivity( this, 1 ); return true; case R.id.menuItem_exit: finish(); @@ -399,7 +395,7 @@ private void hideSystemBars() View view = mSurface.getRootView(); if( view != null ) { - if( AppData.IS_KITKAT && mUserPrefs.isImmersiveModeEnabled ) + if( AppData.IS_KITKAT && mGlobalPrefs.isImmersiveModeEnabled ) view.setSystemUiVisibility( View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN @@ -426,7 +422,7 @@ public boolean onTouch( View v, MotionEvent event ) dragging = false; dragAsset = ""; - if( AppData.IS_KITKAT && mUserPrefs.isImmersiveModeEnabled ) + if( AppData.IS_KITKAT && mGlobalPrefs.isImmersiveModeEnabled ) { // ignore edge swipes. // unfortunately KitKat lacks a way to do this on its own, diff --git a/src/paulscode/android/mupen64plusae/util/CrashHandler.java b/src/paulscode/android/mupen64plusae/util/CrashHandler.java index b790373796..9cc8bd20ad 100644 --- a/src/paulscode/android/mupen64plusae/util/CrashHandler.java +++ b/src/paulscode/android/mupen64plusae/util/CrashHandler.java @@ -26,7 +26,7 @@ import java.lang.Thread.UncaughtExceptionHandler; import java.util.Locale; -import paulscode.android.mupen64plusae.persistent.UserPrefs; +import paulscode.android.mupen64plusae.persistent.GlobalPrefs; import android.content.Context; import android.util.Log; @@ -59,9 +59,9 @@ public void uncaughtException( Thread thread, Throwable ex ) try { // Setup crash log - UserPrefs user = new UserPrefs( mContext ); + GlobalPrefs globalPrefs = new GlobalPrefs( mContext ); String filename = String.format( Locale.US, "%s/Crash_%s_%03d.txt", - user.crashLogDir, Utility.getDateString(), System.currentTimeMillis() % 1000 ); + globalPrefs.crashLogDir, Utility.getDateString(), System.currentTimeMillis() % 1000 ); File log = new File( filename ); log.getParentFile().mkdirs(); diff --git a/src/paulscode/android/mupen64plusae/util/Utility.java b/src/paulscode/android/mupen64plusae/util/Utility.java index 685cb0ea18..d44252ac96 100644 --- a/src/paulscode/android/mupen64plusae/util/Utility.java +++ b/src/paulscode/android/mupen64plusae/util/Utility.java @@ -27,10 +27,6 @@ import java.util.Date; import java.util.Locale; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; - /** * Utility class which collects a bunch of commonly used methods into one class. */ @@ -65,29 +61,6 @@ public static> T clamp( T val, T min, T max ) return min; } - /** - * Launches a URI from a resource in a given context. - * - * @param context The context to launch a URI from. - * @param resId The ID of the resource to create the URI from. - */ - public static void launchUri( Context context, int resId ) - { - launchUri( context, context.getString( resId ) ); - } - - /** - * Launches a URI from a string in a given context. - * - * @param context The context to launch a URI from. - * @param uri The URI to launch. - */ - public static void launchUri( Context context, String uri ) - { - Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( uri ) ); - context.startActivity( intent ); - } - public static String getDateString() { return getDateString( new Date() );