diff --git a/Android/src/emu/project64/GalleryActivity.java b/Android/src/emu/project64/GalleryActivity.java index 296980b2b..e215f98c3 100644 --- a/Android/src/emu/project64/GalleryActivity.java +++ b/Android/src/emu/project64/GalleryActivity.java @@ -66,7 +66,7 @@ import android.widget.ListAdapter; import android.widget.TextView; public class GalleryActivity extends AppCompatActivity implements IabBroadcastListener -{ +{ //Progress dialog for ROM scan private ProgressDialog mProgress = null; @@ -81,24 +81,25 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi public int galleryMaxWidth; public int galleryHalfSpacing; public int galleryColumns = 2; - + // Misc. private static List mGalleryItems = new ArrayList(); private static List mRecentItems = new ArrayList(); private static GalleryActivity mActiveGalleryActivity = null; - + // The IAB helper object IabHelper mIabHelper; - private boolean mHasSaveSupport = false; - + private boolean mHasSaveSupport = false; + // Provides purchase notification while this app is running IabBroadcastReceiver mBroadcastReceiver; - + public static final int GAME_DIR_REQUEST_CODE = 1; static final String SKU_SAVESUPPORT = "save_support"; // (arbitrary) request code for the purchase flow static final int RC_REQUEST = 10001; + static final int RC_SETTINGS = 10002; @Override 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 // happen anyhow in onResume(), so we don't really need to do much here. super.onNewIntent( intent ); - + // Only remember the last intent used setIntent( intent ); } - + @Override protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); mActiveGalleryActivity = this; - + 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). - mIabHelper.enableDebugLogging(true); + mIabHelper.enableDebugLogging(true); Log.d("GalleryActivity", "Starting setup."); mIabHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { - public void onIabSetupFinished(IabResult result) + public void onIabSetupFinished(IabResult result) { Log.d("GalleryActivity", "onIabSetupFinished."); - if (!result.isSuccess()) + if (!result.isSuccess()) { // Oh noes, there was a problem. 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. Log.d("GalleryActivity", "Setup successful. Querying inventory."); - try + try { mIabHelper.queryInventoryAsync(mGotInventoryListener); } - catch (IabAsyncInProgressException e) + catch (IabAsyncInProgressException e) { //complain("Error querying inventory. Another async operation in progress."); } } }); - + // Lay out the content setContentView( R.layout.gallery_activity ); mGridView = (RecyclerView) findViewById( R.id.gridview ); 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(); refreshGrid(); - + // Update the grid layout galleryMaxWidth = (int) getResources().getDimension( R.dimen.galleryImageWidth ); galleryHalfSpacing = (int) getResources().getDimension( R.dimen.galleryHalfSpacing ); - + DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics( metrics ); - + int width = metrics.widthPixels - galleryHalfSpacing * 2; galleryColumns = (int) Math.ceil( width * 1.0 / ( galleryMaxWidth + galleryHalfSpacing * 2 ) ); galleryWidth = width / galleryColumns - galleryHalfSpacing * 2; - + GridLayoutManager layoutManager = (GridLayoutManager) mGridView.getLayoutManager(); layoutManager.setSpanCount( galleryColumns ); - + // Add the toolbar to the activity (which supports the fancy menu/arrow animation) Toolbar toolbar = (Toolbar) findViewById( R.id.toolbar ); toolbar.setTitle( R.string.app_name ); setSupportActionBar( toolbar ); - + // Configure the navigation drawer mDrawerLayout = (DrawerLayout) findViewById( R.id.drawerLayout ); mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, toolbar, 0, 0 ); mDrawerLayout.setDrawerListener( mDrawerToggle ); - + // Configure the list in the navigation drawer mDrawerList = (MenuListView) findViewById( R.id.drawerNavigation ); mDrawerList.setMenuResource( R.menu.gallery_drawer ); @@ -216,9 +217,9 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi } } ); } - + // Enables or disables the "please wait" screen. - void setWaitScreen(boolean set) + void setWaitScreen(boolean 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 - 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."); @@ -260,14 +261,14 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi { mHasSaveSupport = true; } - + 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); // if we were disposed of in the meantime, quit. @@ -280,10 +281,10 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi setWaitScreen(false); return; } - + Log.d("GalleryActivity", "Purchase successful."); - if (purchase.getSku().equals(SKU_SAVESUPPORT)) + if (purchase.getSku().equals(SKU_SAVESUPPORT)) { // bought the premium upgrade! 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); 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 Log.d("GalleryActivity", "Received broadcast notification. Querying inventory."); - try + try { mIabHelper.queryInventoryAsync(mGotInventoryListener); } - catch (IabAsyncInProgressException e) + catch (IabAsyncInProgressException e) { //complain("Error querying inventory. Another async operation in progress."); } @@ -323,22 +324,22 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi super.onPostCreate( savedInstanceState ); mDrawerToggle.syncState(); } - + @Override public void onConfigurationChanged( Configuration newConfig ) { super.onConfigurationChanged( newConfig ); mDrawerToggle.onConfigurationChanged( newConfig ); } - + @Override public boolean onCreateOptionsMenu( Menu menu ) { getMenuInflater().inflate( R.menu.gallery_activity, menu ); - + return super.onCreateOptionsMenu( menu ); } - + @Override public boolean onOptionsItemSelected( MenuItem item ) { @@ -368,28 +369,28 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi return super.onOptionsItemSelected( item ); } } - + private boolean HasAutoSave(File GameSaveDir) { - if (!GameSaveDir.exists() || !GameSaveDir.isDirectory()) + if (!GameSaveDir.exists() || !GameSaveDir.isDirectory()) { return false; } - + File[] fList = GameSaveDir.listFiles(); for (File file : fList) { String extension = ""; int i = file.getName().lastIndexOf('.'); - if (i > 0) + if (i > 0) { extension = file.getName().substring(i+1); } if (extension.equals("zip")) { i = file.getName().lastIndexOf('.', i - 1); - if (i > 0) + if (i > 0) { extension = file.getName().substring(i+1); } @@ -420,7 +421,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi return text; } } - + ListmenuItemLst = new ArrayList(); if (mHasSaveSupport) { @@ -430,22 +431,22 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi else { 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)); if (ShowSettings && !NativeExports.SettingsLoadBool(SettingsID.UserInterface_BasicMode.getValue())) { menuItemLst.add(new Item("Settings", R.drawable.ic_sliders)); } - + Item[] itemsDynamic = new Item[menuItemLst .size()]; - itemsDynamic = menuItemLst.toArray(itemsDynamic); - + itemsDynamic = menuItemLst.toArray(itemsDynamic); + final Item[] items = itemsDynamic; final File SaveDir = GameSaveDir; ListAdapter adapter = new ArrayAdapter( 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 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); } - } + } //Put the image on the TextView tv.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null); @@ -478,13 +479,13 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi } @Override - public boolean areAllItemsEnabled() + public boolean areAllItemsEnabled() { return true; } @Override - public boolean isEnabled(int position) + public boolean isEnabled(int position) { if (position == 1 && HasAutoSave(SaveDir) == false) { @@ -495,7 +496,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi return false; } return true; - } + } }; final Context finalContext = this; @@ -505,7 +506,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi GameMenu.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int item) + public void onClick(DialogInterface dialog, int item) { if ((item == 0 || item == 1) && !mHasSaveSupport) { @@ -513,19 +514,19 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi ResetPrompt .setTitle(getText(R.string.GetSaveSupport_title)) .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); //Purchase save support - try + try { String payload = NativeExports.appVersion(); mIabHelper.launchPurchaseFlow(finalActivity, SKU_SAVESUPPORT, RC_REQUEST, mPurchaseFinishedListener, payload); } - catch (IabAsyncInProgressException e) - { + catch (IabAsyncInProgressException e) + { setWaitScreen(false); } } @@ -536,23 +537,23 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi } if (item == 0) { - launchGameActivity(); + launchGameActivity(); } else if (item == 1) { NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0); - NativeExports.ExternalEvent(SystemEvent.SysEvent_LoadMachineState.getValue()); + NativeExports.ExternalEvent(SystemEvent.SysEvent_LoadMachineState.getValue()); launchGameActivity(); } - else if (item == 2) + else if (item == 2) { AlertDialog.Builder ResetPrompt = new AlertDialog.Builder(finalContext); ResetPrompt .setTitle(getText(R.string.confirmResetGame_title)) .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(); for(String s: entries) @@ -566,11 +567,11 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi }) .setNegativeButton(android.R.string.cancel, this) .show(); - } - else if (item == 3) + } + else if (item == 3) { 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())); if (GameSaveDir.exists() && !mHasSaveSupport) { - StartGameMenu(GameSaveDir, false); + StartGameMenu(GameSaveDir, false); } else { if (HasAutoSave(GameSaveDir)) { 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 ) { NativeExports.LoadGame(item.romFile.getAbsolutePath()); @@ -606,12 +607,20 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi StartGameMenu(GameSaveDir, true); return true; } - + @Override protected void onActivityResult(int requestCode, int resultCode, Intent 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 if (requestCode == GAME_DIR_REQUEST_CODE) { @@ -621,7 +630,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi Bundle extras = data.getExtras(); String searchPath = extras.getString( ScanRomsActivity.GAME_DIR_PATH ); boolean searchRecursively = extras.getBoolean( ScanRomsActivity.GAME_DIR_RECURSIVELY ); - + if (searchPath != null) { 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 - 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 // perform any handling of activity results not related to in-app @@ -639,21 +648,21 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi } void refreshGrid( ) - { + { List items; items = new ArrayList(); - + if (mRecentItems.size() > 0) { items.add( new GalleryItem( this, getString( R.string.galleryRecentlyPlayed ) ) ); items.addAll( mRecentItems ); - + items.add( new GalleryItem( this, getString( R.string.galleryLibrary ) ) ); } items.addAll( mGalleryItems ); - + mGridView.setAdapter( new GalleryItem.Adapter( this, items ) ); - + // Allow the headings to take up the entire width of the layout final List finalItems = items; 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 if( finalItems.get( position ).isHeading ) return galleryColumns; - + // Games will fit in a single column return 1; } } ); - + mGridView.setLayoutManager( layoutManager ); } - + @Override protected void onResume() { super.onResume(); refreshViews(); } - + @TargetApi( 11 ) private void refreshViews() { // Refresh the gallery refreshGrid(); } - + @Override public boolean onKeyDown( int keyCode, KeyEvent event ) { @@ -705,9 +714,9 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi } return super.onKeyDown( keyCode, event ); } - + @Override - public void onBackPressed() + public void onBackPressed() { if( mDrawerLayout.isDrawerOpen( GravityCompat.START ) ) { @@ -718,7 +727,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi moveTaskToBack(true); } } - + public void launchGameActivity() { // 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 ); this.startActivity( intent ); } - + public static void RomListReset () { mGalleryItems = new ArrayList(); if (mActiveGalleryActivity != null && mActiveGalleryActivity.mProgress != null) { Handler h = new Handler(Looper.getMainLooper()); - h.post(new Runnable() + h.post(new Runnable() { public void run() { - mActiveGalleryActivity.mProgress.show(); + mActiveGalleryActivity.mProgress.show(); } }); } } - + public static void RomListAddItem (String FullFileName, String FileName, String GoodName, int 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 ProgressMessage = new String("Added " + GoodName); - h.post(new Runnable() + h.post(new Runnable() { public void run() { @@ -770,9 +779,9 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi public static void RomListLoadDone() { mRecentItems = new ArrayList(); - + 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++) { 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) { Handler h = new Handler(Looper.getMainLooper()); - h.post(new Runnable() + h.post(new Runnable() { public void run() { diff --git a/Android/src/emu/project64/GalleryItem.java b/Android/src/emu/project64/GalleryItem.java index c2f85a942..dc6e1836b 100644 --- a/Android/src/emu/project64/GalleryItem.java +++ b/Android/src/emu/project64/GalleryItem.java @@ -36,17 +36,17 @@ public class GalleryItem public final int textColor; public final Context context; public final boolean isHeading; - + public GalleryItem( Context context, String goodName, String fileName, String romPath, int textColor ) { this.goodName = goodName; this.fileName = fileName; - this.context = context; + this.context = context; this.textColor = textColor; this.isHeading = false; this.romFile = TextUtils.isEmpty( romPath ) ? null : new File( romPath ); } - + public GalleryItem( Context context, String headingName ) { this.goodName = headingName; @@ -56,7 +56,7 @@ public class GalleryItem this.romFile = null; this.textColor = 0; } - + @Override public String toString() { @@ -73,7 +73,7 @@ public class GalleryItem return "unknown file"; } } - + public static class NameComparator implements Comparator { @Override @@ -82,13 +82,13 @@ public class GalleryItem return item1.toString().compareToIgnoreCase( item2.toString() ); } } - + public static class ViewHolder extends RecyclerView.ViewHolder implements OnClickListener, - OnLongClickListener + OnLongClickListener { public GalleryItem item; private Context mContext; - + public ViewHolder( Context context, View view ) { super( view ); @@ -96,13 +96,13 @@ public class GalleryItem view.setOnClickListener( this ); view.setOnLongClickListener( this ); } - + @Override public String toString() { return item.toString(); } - + @Override public void onClick( View view ) { @@ -112,7 +112,7 @@ public class GalleryItem activity.onGalleryItemClick( item ); } } - + @Override public boolean onLongClick( View view ) { @@ -124,52 +124,52 @@ public class GalleryItem return false; } } - + public static class Adapter extends RecyclerView.Adapter { private final Context mContext; private final List mObjects; - + public Adapter( Context context, List objects ) { mContext = context; mObjects = objects; } - + @Override public int getItemCount() { return mObjects.size(); } - + @Override public long getItemId( int position ) { return 0; } - + @Override public int getItemViewType( int position ) { return mObjects.get( position ).isHeading ? 1 : 0; } - + public void onBindViewHolder( ViewHolder holder, int position ) { // Called by RecyclerView to display the data at the specified position. View view = holder.itemView; GalleryItem item = mObjects.get( position ); holder.item = item; - + if( item != null ) - { + { TextView tv1 = (TextView) view.findViewById( R.id.text1 ); tv1.setText( item.toString() ); tv1.setTextColor(Color.rgb((item.textColor >> 16) & 0xff,(item.textColor >> 8) & 0xff,item.textColor & 0xff)); - + LinearLayout linearLayout = (LinearLayout) view.findViewById( R.id.galleryItem ); GalleryActivity activity = (GalleryActivity) item.context; - + if( item.isHeading ) { view.setClickable( false ); @@ -192,7 +192,7 @@ public class GalleryItem layout.getLayoutParams().width = activity.galleryWidth; } } - + public ViewHolder onCreateViewHolder( ViewGroup parent, int viewType ) { LayoutInflater inflater = (LayoutInflater) mContext