File browser 'BOOT BIOS' now optional. Can set to also display 'SELECT CURRENT FOLDER' instead using fragment arguments. Starting the emu is now handled by the fragment container instead of the FileBrowser class. Class passes cd image URI to fragment callback when image is selected. Likewise, 'SELECT CURRENT FOLDER' will pass the CWD as a URI to another callback in the fragment container. This is in preparation for re-using the file browser for the options activity.
This commit is contained in:
parent
e190f6cf3a
commit
614fe19d20
|
@ -37,10 +37,39 @@ public class FileBrowser extends Fragment {
|
|||
Vibrator vib;
|
||||
Drawable orig_bg;
|
||||
Activity parentActivity;
|
||||
|
||||
boolean ImgBrowse;
|
||||
OnItemSelectedListener mCallback;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Bundle b = getArguments();
|
||||
if(b!=null)
|
||||
ImgBrowse = b.getBoolean("ImgBrowse", true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Container Activity must implement this interface
|
||||
public interface OnItemSelectedListener {
|
||||
public void onGameSelected(Uri uri);
|
||||
public void onFolderSelected(Uri uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
||||
// This makes sure that the container activity has implemented
|
||||
// the callback interface. If not, it throws an exception
|
||||
try {
|
||||
mCallback = (OnItemSelectedListener) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(activity.toString()
|
||||
+ " must implement OnItemSelectedListener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
|
@ -206,7 +235,9 @@ public class FileBrowser extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
void navigate(File root_sd)
|
||||
|
||||
|
||||
void navigate(final File root_sd)
|
||||
{
|
||||
LinearLayout v = (LinearLayout)parentActivity.findViewById(R.id.game_list);
|
||||
v.removeAllViews();
|
||||
|
@ -233,14 +264,22 @@ public class FileBrowser extends Fragment {
|
|||
|
||||
for (int i=0;i<list.size();i++)
|
||||
{
|
||||
if (list.get(i)!=null && list.get(i).isFile())
|
||||
if (!list.get(i).getName().toLowerCase().endsWith(".gdi") && !list.get(i).getName().toLowerCase().endsWith(".cdi") && !list.get(i).getName().toLowerCase().endsWith(".chd"))
|
||||
if(ImgBrowse){
|
||||
if (list.get(i)!=null && list.get(i).isFile())
|
||||
if (!list.get(i).getName().toLowerCase().endsWith(".gdi") && !list.get(i).getName().toLowerCase().endsWith(".cdi") && !list.get(i).getName().toLowerCase().endsWith(".chd"))
|
||||
continue;
|
||||
}else{
|
||||
if (list.get(i)!=null && !list.get(i).isDirectory())
|
||||
continue;
|
||||
|
||||
}
|
||||
View childview=parentActivity.getLayoutInflater().inflate(R.layout.app_list_item, null, false);
|
||||
|
||||
if (list.get(i)==null)
|
||||
((TextView)childview.findViewById(R.id.item_name)).setText("BOOT BIOS");
|
||||
if (list.get(i)==null){
|
||||
if(ImgBrowse==true)
|
||||
((TextView)childview.findViewById(R.id.item_name)).setText("BOOT BIOS");
|
||||
if(ImgBrowse==false)
|
||||
((TextView)childview.findViewById(R.id.item_name)).setText("SELECT CURRENT FOLDER");
|
||||
}
|
||||
else if (list.get(i)==parent)
|
||||
((TextView)childview.findViewById(R.id.item_name)).setText("..");
|
||||
else
|
||||
|
@ -270,17 +309,23 @@ public class FileBrowser extends Fragment {
|
|||
{
|
||||
navigate(f);
|
||||
vib.vibrate(50);
|
||||
}else if(f == null && !ImgBrowse){
|
||||
vib.vibrate(50);
|
||||
|
||||
mCallback.onFolderSelected(Uri.fromFile(new File(root_sd.getAbsolutePath())));
|
||||
vib.vibrate(250);
|
||||
}
|
||||
else
|
||||
{
|
||||
vib.vibrate(50);
|
||||
Intent inte = new Intent(Intent.ACTION_VIEW,f!=null? Uri.fromFile(f):Uri.EMPTY,parentActivity.getBaseContext(),GL2JNIActivity.class);
|
||||
FileBrowser.this.startActivity(inte);
|
||||
mCallback.onGameSelected(Uri.fromFile(f));
|
||||
//Intent inte = new Intent(Intent.ACTION_VIEW,f!=null? Uri.fromFile(f):Uri.EMPTY,parentActivity.getBaseContext(),GL2JNIActivity.class);
|
||||
//FileBrowser.this.startActivity(inte);
|
||||
vib.vibrate(250);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
childview.findViewById(R.id.childview).setOnTouchListener(
|
||||
new OnTouchListener() {
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package com.reicast.emulator;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.Menu;
|
||||
|
||||
public class MainActivity extends FragmentActivity {
|
||||
public class MainActivity extends FragmentActivity implements
|
||||
FileBrowser.OnItemSelectedListener{
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -24,7 +27,9 @@ public class MainActivity extends FragmentActivity {
|
|||
|
||||
// Create a new Fragment to be placed in the activity layout
|
||||
FileBrowser firstFragment = new FileBrowser();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean("ImgBrowse", false);
|
||||
firstFragment.setArguments(args);
|
||||
// In case this activity was started with special instructions from
|
||||
// an
|
||||
// Intent, pass the Intent's extras to the fragment as arguments
|
||||
|
@ -37,6 +42,15 @@ public class MainActivity extends FragmentActivity {
|
|||
|
||||
}
|
||||
|
||||
public void onGameSelected(Uri uri){
|
||||
Intent inte = new Intent(Intent.ACTION_VIEW,uri,getBaseContext(),GL2JNIActivity.class);
|
||||
startActivity(inte);
|
||||
}
|
||||
|
||||
public void onFolderSelected(Uri uri){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
|
Loading…
Reference in New Issue