[Android] Reshow game menu after leaving settings

This commit is contained in:
zilmar 2016-10-02 07:45:49 +11:00
parent df4ecbfee1
commit 628a0d769d
2 changed files with 129 additions and 120 deletions

View File

@ -66,7 +66,7 @@ import android.widget.ListAdapter;
import android.widget.TextView; import android.widget.TextView;
public class GalleryActivity extends AppCompatActivity implements IabBroadcastListener public class GalleryActivity extends AppCompatActivity implements IabBroadcastListener
{ {
//Progress dialog for ROM scan //Progress dialog for ROM scan
private ProgressDialog mProgress = null; private ProgressDialog mProgress = null;
@ -81,24 +81,25 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
public int galleryMaxWidth; public int galleryMaxWidth;
public int galleryHalfSpacing; public int galleryHalfSpacing;
public int galleryColumns = 2; public int galleryColumns = 2;
// Misc. // Misc.
private static List<GalleryItem> mGalleryItems = new ArrayList<GalleryItem>(); private static List<GalleryItem> mGalleryItems = new ArrayList<GalleryItem>();
private static List<GalleryItem> mRecentItems = new ArrayList<GalleryItem>(); private static List<GalleryItem> mRecentItems = new ArrayList<GalleryItem>();
private static GalleryActivity mActiveGalleryActivity = null; private static GalleryActivity mActiveGalleryActivity = null;
// The IAB helper object // The IAB helper object
IabHelper mIabHelper; IabHelper mIabHelper;
private boolean mHasSaveSupport = false; private boolean mHasSaveSupport = false;
// Provides purchase notification while this app is running // Provides purchase notification while this app is running
IabBroadcastReceiver mBroadcastReceiver; IabBroadcastReceiver mBroadcastReceiver;
public static final int GAME_DIR_REQUEST_CODE = 1; public static final int GAME_DIR_REQUEST_CODE = 1;
static final String SKU_SAVESUPPORT = "save_support"; static final String SKU_SAVESUPPORT = "save_support";
// (arbitrary) request code for the purchase flow // (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 10001; static final int RC_REQUEST = 10001;
static final int RC_SETTINGS = 10002;
@Override @Override
protected void onNewIntent( Intent intent ) protected void onNewIntent( Intent intent )
@ -112,30 +113,30 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
// is the selected game path, so we only need to refresh that aspect of the UI. This will // is the selected game path, so we only need to refresh that aspect of the UI. This will
// happen anyhow in onResume(), so we don't really need to do much here. // happen anyhow in onResume(), so we don't really need to do much here.
super.onNewIntent( intent ); super.onNewIntent( intent );
// Only remember the last intent used // Only remember the last intent used
setIntent( intent ); setIntent( intent );
} }
@Override @Override
protected void onCreate( Bundle savedInstanceState ) protected void onCreate( Bundle savedInstanceState )
{ {
super.onCreate( savedInstanceState ); super.onCreate( savedInstanceState );
mActiveGalleryActivity = this; mActiveGalleryActivity = this;
mIabHelper = new IabHelper(this, "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnfHFIq+X0oIvV+bwcvdqQv5GmpWLL6Bw8xE6MLFzXzUGUIUZBwQS6Cz5IC0UM76ujPDPqQPeGy/8oq/bswB5pHCz2iS4ySGalzFfYfeIDklOe+R1pLEqmHuwsR5o4b8rLePLGmUI7hA0kozOTb0i+epANV3Pj63i5XFZLA7RMi5I+YysoE9Fob6kCx0kb02AATacF0OXI9paE1izvsHhZcOIrT4TRMbGlZjBVE/pcJtoBDh33QKz/JBOXWvwnh+efqhVsq/UfA6jYI+U4Z4tsnWhem8DB6Kqj5EhClC6qCPmkBFiOabyKaqhI/urBtYOwxkW9erwtA6OcDoHm5J/JwIDAQAB"); mIabHelper = new IabHelper(this, "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnfHFIq+X0oIvV+bwcvdqQv5GmpWLL6Bw8xE6MLFzXzUGUIUZBwQS6Cz5IC0UM76ujPDPqQPeGy/8oq/bswB5pHCz2iS4ySGalzFfYfeIDklOe+R1pLEqmHuwsR5o4b8rLePLGmUI7hA0kozOTb0i+epANV3Pj63i5XFZLA7RMi5I+YysoE9Fob6kCx0kb02AATacF0OXI9paE1izvsHhZcOIrT4TRMbGlZjBVE/pcJtoBDh33QKz/JBOXWvwnh+efqhVsq/UfA6jYI+U4Z4tsnWhem8DB6Kqj5EhClC6qCPmkBFiOabyKaqhI/urBtYOwxkW9erwtA6OcDoHm5J/JwIDAQAB");
// enable debug logging (for a production application, you should set this to false). // enable debug logging (for a production application, you should set this to false).
mIabHelper.enableDebugLogging(true); mIabHelper.enableDebugLogging(true);
Log.d("GalleryActivity", "Starting setup."); Log.d("GalleryActivity", "Starting setup.");
mIabHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() mIabHelper.startSetup(new IabHelper.OnIabSetupFinishedListener()
{ {
public void onIabSetupFinished(IabResult result) public void onIabSetupFinished(IabResult result)
{ {
Log.d("GalleryActivity", "onIabSetupFinished."); Log.d("GalleryActivity", "onIabSetupFinished.");
if (!result.isSuccess()) if (!result.isSuccess())
{ {
// Oh noes, there was a problem. // Oh noes, there was a problem.
Log.d("GalleryActivity", "Problem setting up in-app billing: " + result); Log.d("GalleryActivity", "Problem setting up in-app billing: " + result);
@ -159,50 +160,50 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
// IAB is fully set up. Now, let's get an inventory of stuff we own. // IAB is fully set up. Now, let's get an inventory of stuff we own.
Log.d("GalleryActivity", "Setup successful. Querying inventory."); Log.d("GalleryActivity", "Setup successful. Querying inventory.");
try try
{ {
mIabHelper.queryInventoryAsync(mGotInventoryListener); mIabHelper.queryInventoryAsync(mGotInventoryListener);
} }
catch (IabAsyncInProgressException e) catch (IabAsyncInProgressException e)
{ {
//complain("Error querying inventory. Another async operation in progress."); //complain("Error querying inventory. Another async operation in progress.");
} }
} }
}); });
// Lay out the content // Lay out the content
setContentView( R.layout.gallery_activity ); setContentView( R.layout.gallery_activity );
mGridView = (RecyclerView) findViewById( R.id.gridview ); mGridView = (RecyclerView) findViewById( R.id.gridview );
mProgress = new ProgressDialog( null, this, getString( R.string.scanning_title ), "", getString( R.string.toast_pleaseWait ), false ); mProgress = new ProgressDialog( null, this, getString( R.string.scanning_title ), "", getString( R.string.toast_pleaseWait ), false );
// Load Cached Rom List // Load Cached Rom List
NativeExports.LoadRomList(); NativeExports.LoadRomList();
refreshGrid(); refreshGrid();
// Update the grid layout // Update the grid layout
galleryMaxWidth = (int) getResources().getDimension( R.dimen.galleryImageWidth ); galleryMaxWidth = (int) getResources().getDimension( R.dimen.galleryImageWidth );
galleryHalfSpacing = (int) getResources().getDimension( R.dimen.galleryHalfSpacing ); galleryHalfSpacing = (int) getResources().getDimension( R.dimen.galleryHalfSpacing );
DisplayMetrics metrics = new DisplayMetrics(); DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics( metrics ); getWindowManager().getDefaultDisplay().getMetrics( metrics );
int width = metrics.widthPixels - galleryHalfSpacing * 2; int width = metrics.widthPixels - galleryHalfSpacing * 2;
galleryColumns = (int) Math.ceil( width * 1.0 / ( galleryMaxWidth + galleryHalfSpacing * 2 ) ); galleryColumns = (int) Math.ceil( width * 1.0 / ( galleryMaxWidth + galleryHalfSpacing * 2 ) );
galleryWidth = width / galleryColumns - galleryHalfSpacing * 2; galleryWidth = width / galleryColumns - galleryHalfSpacing * 2;
GridLayoutManager layoutManager = (GridLayoutManager) mGridView.getLayoutManager(); GridLayoutManager layoutManager = (GridLayoutManager) mGridView.getLayoutManager();
layoutManager.setSpanCount( galleryColumns ); layoutManager.setSpanCount( galleryColumns );
// Add the toolbar to the activity (which supports the fancy menu/arrow animation) // Add the toolbar to the activity (which supports the fancy menu/arrow animation)
Toolbar toolbar = (Toolbar) findViewById( R.id.toolbar ); Toolbar toolbar = (Toolbar) findViewById( R.id.toolbar );
toolbar.setTitle( R.string.app_name ); toolbar.setTitle( R.string.app_name );
setSupportActionBar( toolbar ); setSupportActionBar( toolbar );
// Configure the navigation drawer // Configure the navigation drawer
mDrawerLayout = (DrawerLayout) findViewById( R.id.drawerLayout ); mDrawerLayout = (DrawerLayout) findViewById( R.id.drawerLayout );
mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, toolbar, 0, 0 ); mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, toolbar, 0, 0 );
mDrawerLayout.setDrawerListener( mDrawerToggle ); mDrawerLayout.setDrawerListener( mDrawerToggle );
// Configure the list in the navigation drawer // Configure the list in the navigation drawer
mDrawerList = (MenuListView) findViewById( R.id.drawerNavigation ); mDrawerList = (MenuListView) findViewById( R.id.drawerNavigation );
mDrawerList.setMenuResource( R.menu.gallery_drawer ); mDrawerList.setMenuResource( R.menu.gallery_drawer );
@ -216,9 +217,9 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
} }
} ); } );
} }
// Enables or disables the "please wait" screen. // Enables or disables the "please wait" screen.
void setWaitScreen(boolean set) void setWaitScreen(boolean set)
{ {
if (set) if (set)
{ {
@ -230,9 +231,9 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
} }
// Listener that's called when we finish querying the items and subscriptions we own // Listener that's called when we finish querying the items and subscriptions we own
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener()
{ {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{ {
Log.d("GalleryActivity", "Query inventory finished."); Log.d("GalleryActivity", "Query inventory finished.");
@ -260,14 +261,14 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
{ {
mHasSaveSupport = true; mHasSaveSupport = true;
} }
setWaitScreen(false); setWaitScreen(false);
} }
}; };
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener()
{ {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{ {
Log.d("GalleryActivity", "Purchase finished: " + result + ", purchase: " + purchase); Log.d("GalleryActivity", "Purchase finished: " + result + ", purchase: " + purchase);
// if we were disposed of in the meantime, quit. // if we were disposed of in the meantime, quit.
@ -280,10 +281,10 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
setWaitScreen(false); setWaitScreen(false);
return; return;
} }
Log.d("GalleryActivity", "Purchase successful."); Log.d("GalleryActivity", "Purchase successful.");
if (purchase.getSku().equals(SKU_SAVESUPPORT)) if (purchase.getSku().equals(SKU_SAVESUPPORT))
{ {
// bought the premium upgrade! // bought the premium upgrade!
Log.d("GalleryActivity", "Purchase is save support. Congratulating user."); Log.d("GalleryActivity", "Purchase is save support. Congratulating user.");
@ -293,8 +294,8 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
} }
} }
}; };
void alert(String message) void alert(String message)
{ {
AlertDialog.Builder bld = new AlertDialog.Builder(this); AlertDialog.Builder bld = new AlertDialog.Builder(this);
bld.setMessage(message); bld.setMessage(message);
@ -307,11 +308,11 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
{ {
// Received a broadcast notification that the inventory of items has changed // Received a broadcast notification that the inventory of items has changed
Log.d("GalleryActivity", "Received broadcast notification. Querying inventory."); Log.d("GalleryActivity", "Received broadcast notification. Querying inventory.");
try try
{ {
mIabHelper.queryInventoryAsync(mGotInventoryListener); mIabHelper.queryInventoryAsync(mGotInventoryListener);
} }
catch (IabAsyncInProgressException e) catch (IabAsyncInProgressException e)
{ {
//complain("Error querying inventory. Another async operation in progress."); //complain("Error querying inventory. Another async operation in progress.");
} }
@ -323,22 +324,22 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
super.onPostCreate( savedInstanceState ); super.onPostCreate( savedInstanceState );
mDrawerToggle.syncState(); mDrawerToggle.syncState();
} }
@Override @Override
public void onConfigurationChanged( Configuration newConfig ) public void onConfigurationChanged( Configuration newConfig )
{ {
super.onConfigurationChanged( newConfig ); super.onConfigurationChanged( newConfig );
mDrawerToggle.onConfigurationChanged( newConfig ); mDrawerToggle.onConfigurationChanged( newConfig );
} }
@Override @Override
public boolean onCreateOptionsMenu( Menu menu ) public boolean onCreateOptionsMenu( Menu menu )
{ {
getMenuInflater().inflate( R.menu.gallery_activity, menu ); getMenuInflater().inflate( R.menu.gallery_activity, menu );
return super.onCreateOptionsMenu( menu ); return super.onCreateOptionsMenu( menu );
} }
@Override @Override
public boolean onOptionsItemSelected( MenuItem item ) public boolean onOptionsItemSelected( MenuItem item )
{ {
@ -368,28 +369,28 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
return super.onOptionsItemSelected( item ); return super.onOptionsItemSelected( item );
} }
} }
private boolean HasAutoSave(File GameSaveDir) private boolean HasAutoSave(File GameSaveDir)
{ {
if (!GameSaveDir.exists() || !GameSaveDir.isDirectory()) if (!GameSaveDir.exists() || !GameSaveDir.isDirectory())
{ {
return false; return false;
} }
File[] fList = GameSaveDir.listFiles(); File[] fList = GameSaveDir.listFiles();
for (File file : fList) for (File file : fList)
{ {
String extension = ""; String extension = "";
int i = file.getName().lastIndexOf('.'); int i = file.getName().lastIndexOf('.');
if (i > 0) if (i > 0)
{ {
extension = file.getName().substring(i+1); extension = file.getName().substring(i+1);
} }
if (extension.equals("zip")) if (extension.equals("zip"))
{ {
i = file.getName().lastIndexOf('.', i - 1); i = file.getName().lastIndexOf('.', i - 1);
if (i > 0) if (i > 0)
{ {
extension = file.getName().substring(i+1); extension = file.getName().substring(i+1);
} }
@ -420,7 +421,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
return text; return text;
} }
} }
List<Item>menuItemLst = new ArrayList<Item>(); List<Item>menuItemLst = new ArrayList<Item>();
if (mHasSaveSupport) if (mHasSaveSupport)
{ {
@ -430,22 +431,22 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
else else
{ {
menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_lock)); menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_lock));
menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_lock)); menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_lock));
} }
menuItemLst.add(new Item("Restart", R.drawable.ic_refresh)); menuItemLst.add(new Item("Restart", R.drawable.ic_refresh));
if (ShowSettings && !NativeExports.SettingsLoadBool(SettingsID.UserInterface_BasicMode.getValue())) if (ShowSettings && !NativeExports.SettingsLoadBool(SettingsID.UserInterface_BasicMode.getValue()))
{ {
menuItemLst.add(new Item("Settings", R.drawable.ic_sliders)); menuItemLst.add(new Item("Settings", R.drawable.ic_sliders));
} }
Item[] itemsDynamic = new Item[menuItemLst .size()]; Item[] itemsDynamic = new Item[menuItemLst .size()];
itemsDynamic = menuItemLst.toArray(itemsDynamic); itemsDynamic = menuItemLst.toArray(itemsDynamic);
final Item[] items = itemsDynamic; final Item[] items = itemsDynamic;
final File SaveDir = GameSaveDir; final File SaveDir = GameSaveDir;
ListAdapter adapter = new ArrayAdapter<Item>( this, android.R.layout.select_dialog_item, android.R.id.text1, items) ListAdapter adapter = new ArrayAdapter<Item>( this, android.R.layout.select_dialog_item, android.R.id.text1, items)
{ {
public View getView(int position, View convertView, android.view.ViewGroup parent) public View getView(int position, View convertView, android.view.ViewGroup parent)
{ {
//Use super class to create the View //Use super class to create the View
View v = super.getView(position, convertView, parent); View v = super.getView(position, convertView, parent);
@ -465,7 +466,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
{ {
d.setColorFilter(Color.parseColor("#555555"), android.graphics.PorterDuff.Mode.SRC_ATOP); d.setColorFilter(Color.parseColor("#555555"), android.graphics.PorterDuff.Mode.SRC_ATOP);
} }
} }
//Put the image on the TextView //Put the image on the TextView
tv.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null); tv.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
@ -478,13 +479,13 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
} }
@Override @Override
public boolean areAllItemsEnabled() public boolean areAllItemsEnabled()
{ {
return true; return true;
} }
@Override @Override
public boolean isEnabled(int position) public boolean isEnabled(int position)
{ {
if (position == 1 && HasAutoSave(SaveDir) == false) if (position == 1 && HasAutoSave(SaveDir) == false)
{ {
@ -495,7 +496,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
return false; return false;
} }
return true; return true;
} }
}; };
final Context finalContext = this; final Context finalContext = this;
@ -505,7 +506,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
GameMenu.setAdapter(adapter, new DialogInterface.OnClickListener() GameMenu.setAdapter(adapter, new DialogInterface.OnClickListener()
{ {
@Override @Override
public void onClick(DialogInterface dialog, int item) public void onClick(DialogInterface dialog, int item)
{ {
if ((item == 0 || item == 1) && !mHasSaveSupport) if ((item == 0 || item == 1) && !mHasSaveSupport)
{ {
@ -513,19 +514,19 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
ResetPrompt ResetPrompt
.setTitle(getText(R.string.GetSaveSupport_title)) .setTitle(getText(R.string.GetSaveSupport_title))
.setMessage(getText(R.string.GetSaveSupport_message)) .setMessage(getText(R.string.GetSaveSupport_message))
.setPositiveButton(R.string.GetSaveSupport_OkButton, new DialogInterface.OnClickListener() .setPositiveButton(R.string.GetSaveSupport_OkButton, new DialogInterface.OnClickListener()
{ {
public void onClick(DialogInterface dialog, int id) public void onClick(DialogInterface dialog, int id)
{ {
setWaitScreen(true); setWaitScreen(true);
//Purchase save support //Purchase save support
try try
{ {
String payload = NativeExports.appVersion(); String payload = NativeExports.appVersion();
mIabHelper.launchPurchaseFlow(finalActivity, SKU_SAVESUPPORT, RC_REQUEST, mPurchaseFinishedListener, payload); mIabHelper.launchPurchaseFlow(finalActivity, SKU_SAVESUPPORT, RC_REQUEST, mPurchaseFinishedListener, payload);
} }
catch (IabAsyncInProgressException e) catch (IabAsyncInProgressException e)
{ {
setWaitScreen(false); setWaitScreen(false);
} }
} }
@ -536,23 +537,23 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
} }
if (item == 0) if (item == 0)
{ {
launchGameActivity(); launchGameActivity();
} }
else if (item == 1) else if (item == 1)
{ {
NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0); NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0);
NativeExports.ExternalEvent(SystemEvent.SysEvent_LoadMachineState.getValue()); NativeExports.ExternalEvent(SystemEvent.SysEvent_LoadMachineState.getValue());
launchGameActivity(); launchGameActivity();
} }
else if (item == 2) else if (item == 2)
{ {
AlertDialog.Builder ResetPrompt = new AlertDialog.Builder(finalContext); AlertDialog.Builder ResetPrompt = new AlertDialog.Builder(finalContext);
ResetPrompt ResetPrompt
.setTitle(getText(R.string.confirmResetGame_title)) .setTitle(getText(R.string.confirmResetGame_title))
.setMessage(getText(R.string.confirmResetGame_message)) .setMessage(getText(R.string.confirmResetGame_message))
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener()
{ {
public void onClick(DialogInterface dialog, int id) public void onClick(DialogInterface dialog, int id)
{ {
String[]entries = SaveDir.list(); String[]entries = SaveDir.list();
for(String s: entries) for(String s: entries)
@ -566,11 +567,11 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
}) })
.setNegativeButton(android.R.string.cancel, this) .setNegativeButton(android.R.string.cancel, this)
.show(); .show();
} }
else if (item == 3) else if (item == 3)
{ {
Intent SettingsIntent = new Intent(finalContext, GameSettingsActivity.class); Intent SettingsIntent = new Intent(finalContext, GameSettingsActivity.class);
startActivity( SettingsIntent ); startActivityForResult( SettingsIntent, RC_SETTINGS );
} }
} }
}); });
@ -584,19 +585,19 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
final File GameSaveDir = new File(InstantSaveDir,NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue())); final File GameSaveDir = new File(InstantSaveDir,NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue()));
if (GameSaveDir.exists() && !mHasSaveSupport) if (GameSaveDir.exists() && !mHasSaveSupport)
{ {
StartGameMenu(GameSaveDir, false); StartGameMenu(GameSaveDir, false);
} }
else else
{ {
if (HasAutoSave(GameSaveDir)) if (HasAutoSave(GameSaveDir))
{ {
NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0); NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0);
NativeExports.ExternalEvent(SystemEvent.SysEvent_LoadMachineState.getValue()); NativeExports.ExternalEvent(SystemEvent.SysEvent_LoadMachineState.getValue());
} }
launchGameActivity(); launchGameActivity();
} }
} }
public boolean onGalleryItemLongClick( GalleryItem item ) public boolean onGalleryItemLongClick( GalleryItem item )
{ {
NativeExports.LoadGame(item.romFile.getAbsolutePath()); NativeExports.LoadGame(item.romFile.getAbsolutePath());
@ -606,12 +607,20 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
StartGameMenu(GameSaveDir, true); StartGameMenu(GameSaveDir, true);
return true; return true;
} }
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) protected void onActivityResult(int requestCode, int resultCode, Intent data)
{ {
Log.d("GalleryActivity", "onActivityResult(" + requestCode + "," + resultCode + "," + data); Log.d("GalleryActivity", "onActivityResult(" + requestCode + "," + resultCode + "," + data);
if (requestCode == RC_SETTINGS)
{
File InstantSaveDir = new File(NativeExports.SettingsLoadString(SettingsID.Directory_InstantSave.getValue()));
final File GameSaveDir = new File(InstantSaveDir,NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue()));
StartGameMenu(GameSaveDir, true);
return;
}
// Check which request we're responding to // Check which request we're responding to
if (requestCode == GAME_DIR_REQUEST_CODE) if (requestCode == GAME_DIR_REQUEST_CODE)
{ {
@ -621,7 +630,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
Bundle extras = data.getExtras(); Bundle extras = data.getExtras();
String searchPath = extras.getString( ScanRomsActivity.GAME_DIR_PATH ); String searchPath = extras.getString( ScanRomsActivity.GAME_DIR_PATH );
boolean searchRecursively = extras.getBoolean( ScanRomsActivity.GAME_DIR_RECURSIVELY ); boolean searchRecursively = extras.getBoolean( ScanRomsActivity.GAME_DIR_RECURSIVELY );
if (searchPath != null) if (searchPath != null)
{ {
NativeExports.RefreshRomDir(searchPath, searchRecursively); NativeExports.RefreshRomDir(searchPath, searchRecursively);
@ -629,7 +638,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
} }
} }
// Pass on the activity result to the helper for handling // Pass on the activity result to the helper for handling
if (mIabHelper != null && !mIabHelper.handleActivityResult(requestCode, resultCode, data)) if (mIabHelper != null && !mIabHelper.handleActivityResult(requestCode, resultCode, data))
{ {
// not handled, so handle it ourselves (here's where you'd // not handled, so handle it ourselves (here's where you'd
// perform any handling of activity results not related to in-app // perform any handling of activity results not related to in-app
@ -639,21 +648,21 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
} }
void refreshGrid( ) void refreshGrid( )
{ {
List<GalleryItem> items; List<GalleryItem> items;
items = new ArrayList<GalleryItem>(); items = new ArrayList<GalleryItem>();
if (mRecentItems.size() > 0) if (mRecentItems.size() > 0)
{ {
items.add( new GalleryItem( this, getString( R.string.galleryRecentlyPlayed ) ) ); items.add( new GalleryItem( this, getString( R.string.galleryRecentlyPlayed ) ) );
items.addAll( mRecentItems ); items.addAll( mRecentItems );
items.add( new GalleryItem( this, getString( R.string.galleryLibrary ) ) ); items.add( new GalleryItem( this, getString( R.string.galleryLibrary ) ) );
} }
items.addAll( mGalleryItems ); items.addAll( mGalleryItems );
mGridView.setAdapter( new GalleryItem.Adapter( this, items ) ); mGridView.setAdapter( new GalleryItem.Adapter( this, items ) );
// Allow the headings to take up the entire width of the layout // Allow the headings to take up the entire width of the layout
final List<GalleryItem> finalItems = items; final List<GalleryItem> finalItems = items;
GridLayoutManager layoutManager = new GridLayoutManager( this, galleryColumns ); GridLayoutManager layoutManager = new GridLayoutManager( this, galleryColumns );
@ -665,29 +674,29 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
// Headings will take up every span (column) in the grid // Headings will take up every span (column) in the grid
if( finalItems.get( position ).isHeading ) if( finalItems.get( position ).isHeading )
return galleryColumns; return galleryColumns;
// Games will fit in a single column // Games will fit in a single column
return 1; return 1;
} }
} ); } );
mGridView.setLayoutManager( layoutManager ); mGridView.setLayoutManager( layoutManager );
} }
@Override @Override
protected void onResume() protected void onResume()
{ {
super.onResume(); super.onResume();
refreshViews(); refreshViews();
} }
@TargetApi( 11 ) @TargetApi( 11 )
private void refreshViews() private void refreshViews()
{ {
// Refresh the gallery // Refresh the gallery
refreshGrid(); refreshGrid();
} }
@Override @Override
public boolean onKeyDown( int keyCode, KeyEvent event ) public boolean onKeyDown( int keyCode, KeyEvent event )
{ {
@ -705,9 +714,9 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
} }
return super.onKeyDown( keyCode, event ); return super.onKeyDown( keyCode, event );
} }
@Override @Override
public void onBackPressed() public void onBackPressed()
{ {
if( mDrawerLayout.isDrawerOpen( GravityCompat.START ) ) if( mDrawerLayout.isDrawerOpen( GravityCompat.START ) )
{ {
@ -718,7 +727,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
moveTaskToBack(true); moveTaskToBack(true);
} }
} }
public void launchGameActivity() public void launchGameActivity()
{ {
// Launch the game activity // Launch the game activity
@ -727,23 +736,23 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
Intent intent = isXperiaPlay ? new Intent( this, GameActivityXperiaPlay.class ) : new Intent( this, GameActivity.class ); Intent intent = isXperiaPlay ? new Intent( this, GameActivityXperiaPlay.class ) : new Intent( this, GameActivity.class );
this.startActivity( intent ); this.startActivity( intent );
} }
public static void RomListReset () public static void RomListReset ()
{ {
mGalleryItems = new ArrayList<GalleryItem>(); mGalleryItems = new ArrayList<GalleryItem>();
if (mActiveGalleryActivity != null && mActiveGalleryActivity.mProgress != null) if (mActiveGalleryActivity != null && mActiveGalleryActivity.mProgress != null)
{ {
Handler h = new Handler(Looper.getMainLooper()); Handler h = new Handler(Looper.getMainLooper());
h.post(new Runnable() h.post(new Runnable()
{ {
public void run() public void run()
{ {
mActiveGalleryActivity.mProgress.show(); mActiveGalleryActivity.mProgress.show();
} }
}); });
} }
} }
public static void RomListAddItem (String FullFileName, String FileName, String GoodName, int TextColor) public static void RomListAddItem (String FullFileName, String FileName, String GoodName, int TextColor)
{ {
GalleryItem item = new GalleryItem( mActiveGalleryActivity, GoodName, FileName, FullFileName, TextColor ); GalleryItem item = new GalleryItem( mActiveGalleryActivity, GoodName, FileName, FullFileName, TextColor );
@ -755,7 +764,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
final String ProgressSubText = new String(FullFileName); final String ProgressSubText = new String(FullFileName);
final String ProgressMessage = new String("Added " + GoodName); final String ProgressMessage = new String("Added " + GoodName);
h.post(new Runnable() h.post(new Runnable()
{ {
public void run() public void run()
{ {
@ -770,9 +779,9 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
public static void RomListLoadDone() public static void RomListLoadDone()
{ {
mRecentItems = new ArrayList<GalleryItem>(); mRecentItems = new ArrayList<GalleryItem>();
Log.d("GalleryActivity","File_RecentGameFileCount = " + NativeExports.UISettingsLoadDword(UISettingID.File_RecentGameFileCount.getValue())); Log.d("GalleryActivity","File_RecentGameFileCount = " + NativeExports.UISettingsLoadDword(UISettingID.File_RecentGameFileCount.getValue()));
for (int i = 0, n = NativeExports.UISettingsLoadDword(UISettingID.File_RecentGameFileCount.getValue()); i < n; i++) for (int i = 0, n = NativeExports.UISettingsLoadDword(UISettingID.File_RecentGameFileCount.getValue()); i < n; i++)
{ {
String RecentFile = NativeExports.UISettingsLoadStringIndex(UISettingID.File_RecentGameFileIndex.getValue(), i); String RecentFile = NativeExports.UISettingsLoadStringIndex(UISettingID.File_RecentGameFileIndex.getValue(), i);
@ -793,7 +802,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
if (mActiveGalleryActivity != null && mActiveGalleryActivity.mProgress != null) if (mActiveGalleryActivity != null && mActiveGalleryActivity.mProgress != null)
{ {
Handler h = new Handler(Looper.getMainLooper()); Handler h = new Handler(Looper.getMainLooper());
h.post(new Runnable() h.post(new Runnable()
{ {
public void run() public void run()
{ {

View File

@ -36,17 +36,17 @@ public class GalleryItem
public final int textColor; public final int textColor;
public final Context context; public final Context context;
public final boolean isHeading; public final boolean isHeading;
public GalleryItem( Context context, String goodName, String fileName, String romPath, int textColor ) public GalleryItem( Context context, String goodName, String fileName, String romPath, int textColor )
{ {
this.goodName = goodName; this.goodName = goodName;
this.fileName = fileName; this.fileName = fileName;
this.context = context; this.context = context;
this.textColor = textColor; this.textColor = textColor;
this.isHeading = false; this.isHeading = false;
this.romFile = TextUtils.isEmpty( romPath ) ? null : new File( romPath ); this.romFile = TextUtils.isEmpty( romPath ) ? null : new File( romPath );
} }
public GalleryItem( Context context, String headingName ) public GalleryItem( Context context, String headingName )
{ {
this.goodName = headingName; this.goodName = headingName;
@ -56,7 +56,7 @@ public class GalleryItem
this.romFile = null; this.romFile = null;
this.textColor = 0; this.textColor = 0;
} }
@Override @Override
public String toString() public String toString()
{ {
@ -73,7 +73,7 @@ public class GalleryItem
return "unknown file"; return "unknown file";
} }
} }
public static class NameComparator implements Comparator<GalleryItem> public static class NameComparator implements Comparator<GalleryItem>
{ {
@Override @Override
@ -82,13 +82,13 @@ public class GalleryItem
return item1.toString().compareToIgnoreCase( item2.toString() ); return item1.toString().compareToIgnoreCase( item2.toString() );
} }
} }
public static class ViewHolder extends RecyclerView.ViewHolder implements OnClickListener, public static class ViewHolder extends RecyclerView.ViewHolder implements OnClickListener,
OnLongClickListener OnLongClickListener
{ {
public GalleryItem item; public GalleryItem item;
private Context mContext; private Context mContext;
public ViewHolder( Context context, View view ) public ViewHolder( Context context, View view )
{ {
super( view ); super( view );
@ -96,13 +96,13 @@ public class GalleryItem
view.setOnClickListener( this ); view.setOnClickListener( this );
view.setOnLongClickListener( this ); view.setOnLongClickListener( this );
} }
@Override @Override
public String toString() public String toString()
{ {
return item.toString(); return item.toString();
} }
@Override @Override
public void onClick( View view ) public void onClick( View view )
{ {
@ -112,7 +112,7 @@ public class GalleryItem
activity.onGalleryItemClick( item ); activity.onGalleryItemClick( item );
} }
} }
@Override @Override
public boolean onLongClick( View view ) public boolean onLongClick( View view )
{ {
@ -124,52 +124,52 @@ public class GalleryItem
return false; return false;
} }
} }
public static class Adapter extends RecyclerView.Adapter<ViewHolder> public static class Adapter extends RecyclerView.Adapter<ViewHolder>
{ {
private final Context mContext; private final Context mContext;
private final List<GalleryItem> mObjects; private final List<GalleryItem> mObjects;
public Adapter( Context context, List<GalleryItem> objects ) public Adapter( Context context, List<GalleryItem> objects )
{ {
mContext = context; mContext = context;
mObjects = objects; mObjects = objects;
} }
@Override @Override
public int getItemCount() public int getItemCount()
{ {
return mObjects.size(); return mObjects.size();
} }
@Override @Override
public long getItemId( int position ) public long getItemId( int position )
{ {
return 0; return 0;
} }
@Override @Override
public int getItemViewType( int position ) public int getItemViewType( int position )
{ {
return mObjects.get( position ).isHeading ? 1 : 0; return mObjects.get( position ).isHeading ? 1 : 0;
} }
public void onBindViewHolder( ViewHolder holder, int position ) public void onBindViewHolder( ViewHolder holder, int position )
{ {
// Called by RecyclerView to display the data at the specified position. // Called by RecyclerView to display the data at the specified position.
View view = holder.itemView; View view = holder.itemView;
GalleryItem item = mObjects.get( position ); GalleryItem item = mObjects.get( position );
holder.item = item; holder.item = item;
if( item != null ) if( item != null )
{ {
TextView tv1 = (TextView) view.findViewById( R.id.text1 ); TextView tv1 = (TextView) view.findViewById( R.id.text1 );
tv1.setText( item.toString() ); tv1.setText( item.toString() );
tv1.setTextColor(Color.rgb((item.textColor >> 16) & 0xff,(item.textColor >> 8) & 0xff,item.textColor & 0xff)); tv1.setTextColor(Color.rgb((item.textColor >> 16) & 0xff,(item.textColor >> 8) & 0xff,item.textColor & 0xff));
LinearLayout linearLayout = (LinearLayout) view.findViewById( R.id.galleryItem ); LinearLayout linearLayout = (LinearLayout) view.findViewById( R.id.galleryItem );
GalleryActivity activity = (GalleryActivity) item.context; GalleryActivity activity = (GalleryActivity) item.context;
if( item.isHeading ) if( item.isHeading )
{ {
view.setClickable( false ); view.setClickable( false );
@ -192,7 +192,7 @@ public class GalleryItem
layout.getLayoutParams().width = activity.galleryWidth; layout.getLayoutParams().width = activity.galleryWidth;
} }
} }
public ViewHolder onCreateViewHolder( ViewGroup parent, int viewType ) public ViewHolder onCreateViewHolder( ViewGroup parent, int viewType )
{ {
LayoutInflater inflater = (LayoutInflater) mContext LayoutInflater inflater = (LayoutInflater) mContext