Merge pull request #31 from ThePlayground/androidui
Pull request - Directory Configuration
This commit is contained in:
commit
b13a806b75
|
@ -18,6 +18,7 @@
|
|||
|
||||
extern "C"
|
||||
{
|
||||
JNIEXPORT void JNICALL Java_com_example_newdc_JNIdc_config(JNIEnv *env,jobject obj,jstring dirName) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_example_newdc_JNIdc_init(JNIEnv *env,jobject obj,jstring fileName) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_example_newdc_JNIdc_run(JNIEnv *env,jobject obj,jobject track) __attribute__((visibility("default")));
|
||||
JNIEXPORT void JNICALL Java_com_example_newdc_JNIdc_stop(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
|
||||
|
@ -127,11 +128,16 @@ void os_SetWindowText(char const *Text)
|
|||
{
|
||||
putinf(Text);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_com_example_newdc_JNIdc_config(JNIEnv *env,jobject obj,jstring dirName)
|
||||
{
|
||||
// Set home directory based on User config
|
||||
const char* D = dirName? env->GetStringUTFChars(dirName,0):0;
|
||||
SetHomeDir(D);
|
||||
printf("Home dir is: '%s'\n",GetPath("/").c_str());
|
||||
env->ReleaseStringUTFChars(dirName,D);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_com_example_newdc_JNIdc_init(JNIEnv *env,jobject obj,jstring fileName)
|
||||
{
|
||||
// Set home directory to SD card
|
||||
SetHomeDir("/sdcard/dc");
|
||||
printf("Home dir is: '%s'\n",GetPath("/").c_str());
|
||||
|
||||
// Get filename string from Java
|
||||
const char* P = fileName? env->GetStringUTFChars(fileName,0):0;
|
||||
|
|
|
@ -6,6 +6,7 @@ public class JNIdc
|
|||
{
|
||||
static { System.loadLibrary("dc"); }
|
||||
|
||||
public static native void config(String dirName);
|
||||
public static native void init(String fileName);
|
||||
public static native void run(Object track);
|
||||
public static native void stop();
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name="com.reicast.emulator.MainActivity"
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/title_activity_main" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -13,7 +13,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1"
|
||||
android:text="System Path(location of dc_boot.bin/dc_flash.bin)" />
|
||||
android:text="@string/system_path" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -53,7 +53,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1"
|
||||
android:text="Default Browser Path" />
|
||||
android:text="@string/browser_path" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -4,5 +4,14 @@
|
|||
<string name="hello_world">Hello world!</string>
|
||||
<string name="menu_settings">Settings</string>
|
||||
<string name="title_activity_main">reicast</string>
|
||||
|
||||
<string name="system_path">System Path (location of dc_boot.bin/dc_flash.bin)</string>
|
||||
<string name="browser_path">Default Browser Path</string>
|
||||
|
||||
<string-array name="images">
|
||||
<item>cdi</item>
|
||||
<item>chd</item>
|
||||
<item>gdi</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
|
@ -0,0 +1,81 @@
|
|||
package com.android.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public void saveArray(String filename, List<String> output_field) {
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(filename);
|
||||
GZIPOutputStream gzos = new GZIPOutputStream(fos);
|
||||
ObjectOutputStream out = new ObjectOutputStream(gzos);
|
||||
out.writeObject(output_field);
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.getStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> loadArray(String filename) {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(filename);
|
||||
GZIPInputStream gzis = new GZIPInputStream(fis);
|
||||
ObjectInputStream in = new ObjectInputStream(gzis);
|
||||
List<String> read_field = (List<String>) in.readObject();
|
||||
in.close();
|
||||
return read_field;
|
||||
} catch (Exception e) {
|
||||
e.getStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public File[] listFilesAsArray(File directory, FilenameFilter[] filter,
|
||||
int recurse) {
|
||||
Collection<File> files = listFiles(directory, filter, recurse);
|
||||
|
||||
File[] arr = new File[files.size()];
|
||||
return files.toArray(arr);
|
||||
}
|
||||
|
||||
public Collection<File> listFiles(File directory, FilenameFilter[] filter,
|
||||
int recurse) {
|
||||
|
||||
Vector<File> files = new Vector<File>();
|
||||
|
||||
File[] entries = directory.listFiles();
|
||||
|
||||
if (entries != null) {
|
||||
for (File entry : entries) {
|
||||
for (FilenameFilter filefilter : filter) {
|
||||
if (filter == null
|
||||
|| filefilter.accept(directory, entry.getName())) {
|
||||
files.add(entry);
|
||||
Log.v("ImageViewFlipper", "Added: " + entry.getName());
|
||||
}
|
||||
}
|
||||
if ((recurse <= -1) || (recurse > 0 && entry.isDirectory())) {
|
||||
recurse--;
|
||||
files.addAll(listFiles(entry, filter, recurse));
|
||||
recurse++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
}
|
|
@ -2,22 +2,33 @@ package com.reicast.emulator;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.io.comparator.CompositeFileComparator;
|
||||
import org.apache.commons.io.comparator.LastModifiedFileComparator;
|
||||
import org.apache.commons.io.comparator.SizeFileComparator;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -31,6 +42,9 @@ import android.widget.LinearLayout;
|
|||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.util.FileUtils;
|
||||
import com.example.newdc.JNIdc;
|
||||
|
||||
public class FileBrowser extends Fragment {
|
||||
|
||||
Vibrator vib;
|
||||
|
@ -39,266 +53,427 @@ public class FileBrowser extends Fragment {
|
|||
boolean ImgBrowse;
|
||||
OnItemSelectedListener mCallback;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Bundle b = getArguments();
|
||||
if(b!=null)
|
||||
ImgBrowse = b.getBoolean("ImgBrowse", true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private SharedPreferences mPrefs;
|
||||
private File sdcard = Environment.getExternalStorageDirectory();
|
||||
private String home_directory = sdcard + "/Dreamcast";
|
||||
|
||||
// Container Activity must implement this interface
|
||||
public interface OnItemSelectedListener {
|
||||
public void onGameSelected(Uri uri);
|
||||
public void onFolderSelected(Uri uri);
|
||||
}
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
home_directory = mPrefs.getString("home_directory", home_directory);
|
||||
|
||||
// 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)
|
||||
{ return inflater.inflate(R.layout.activity_main, container, false); }
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState){
|
||||
//setContentView(R.layout.activity_main);
|
||||
parentActivity = getActivity();
|
||||
try
|
||||
{
|
||||
File file = new File("/sdcard/dc/data/buttons.png");
|
||||
if (!file.exists())
|
||||
{
|
||||
file.createNewFile();
|
||||
OutputStream fo = new FileOutputStream(file);
|
||||
InputStream png=parentActivity.getBaseContext().getAssets().open("buttons.png");
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int len = 0;
|
||||
while ((len = png.read(buffer)) != -1) {
|
||||
fo.write(buffer, 0, len);
|
||||
}
|
||||
fo.close();
|
||||
png.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
|
||||
vib=(Vibrator) parentActivity.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
OnTouchListener viblist=new OnTouchListener() {
|
||||
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (event.getActionMasked()==MotionEvent.ACTION_DOWN)
|
||||
vib.vibrate(50);
|
||||
return false;
|
||||
Bundle b = getArguments();
|
||||
if (b != null) {
|
||||
ImgBrowse = b.getBoolean("ImgBrowse", true);
|
||||
if (b.getString("browse_entry", null) != null) {
|
||||
home_directory = b.getString("browse_entry");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
findViewById(R.id.config).setOnTouchListener(viblist);
|
||||
findViewById(R.id.about).setOnTouchListener(viblist);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
navigate(Environment.getExternalStorageDirectory());
|
||||
}
|
||||
|
||||
File bios = new File("/sdcard/dc/data/dc_boot.bin");
|
||||
File flash = new File("/sdcard/dc/data/dc_flash.bin");
|
||||
// Container Activity must implement this interface
|
||||
public interface OnItemSelectedListener {
|
||||
public void onGameSelected(Uri uri);
|
||||
|
||||
String msg = null;
|
||||
if(!bios.exists())
|
||||
msg = "Bios Missing. Put bios in /sdcard/dc/data/dc_boot.bin";
|
||||
else if (!flash.exists())
|
||||
msg = "Flash Missing. Put bios in /sdcard/dc/data/dc_flash.bin";
|
||||
public void onFolderSelected(Uri uri);
|
||||
}
|
||||
|
||||
if (msg != null ) {
|
||||
vib.vibrate(50);
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
|
||||
parentActivity);
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
||||
// set title
|
||||
alertDialogBuilder.setTitle("Missing files");
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
|
||||
// set dialog message
|
||||
alertDialogBuilder
|
||||
.setMessage(msg)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("Dismiss",new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog,int id) {
|
||||
// if this button is clicked, close
|
||||
// current activity
|
||||
parentActivity.finish();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.activity_main, container, false);
|
||||
}
|
||||
|
||||
// create alert dialog
|
||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
// setContentView(R.layout.activity_main);
|
||||
parentActivity = getActivity();
|
||||
try {
|
||||
File file = new File(home_directory, "data/buttons.png");
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
OutputStream fo = new FileOutputStream(file);
|
||||
InputStream png = parentActivity.getBaseContext().getAssets()
|
||||
.open("buttons.png");
|
||||
|
||||
// show it
|
||||
alertDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
class DirSort implements Comparator<File> {
|
||||
byte[] buffer = new byte[4096];
|
||||
int len = 0;
|
||||
while ((len = png.read(buffer)) != -1) {
|
||||
fo.write(buffer, 0, len);
|
||||
}
|
||||
fo.close();
|
||||
png.close();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
|
||||
// Comparator interface requires defining compare method.
|
||||
public int compare(File filea, File fileb) {
|
||||
|
||||
return ((filea.isFile() ? "a" : "b") + filea.getName().toLowerCase()).compareTo((fileb.isFile() ? "a" : "b")+fileb.getName().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
vib = (Vibrator) parentActivity
|
||||
.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
|
||||
|
||||
void navigate(final File root_sd)
|
||||
{
|
||||
LinearLayout v = (LinearLayout)parentActivity.findViewById(R.id.game_list);
|
||||
v.removeAllViews();
|
||||
|
||||
ArrayList<File> list = new ArrayList<File>();
|
||||
|
||||
((TextView)parentActivity.findViewById(R.id.text_cwd)).setText(root_sd.getAbsolutePath());
|
||||
|
||||
File flist[] = root_sd.listFiles();
|
||||
|
||||
|
||||
File parent=root_sd.getParentFile();
|
||||
|
||||
list.add(null);
|
||||
|
||||
if (parent!=null)
|
||||
list.add(parent);
|
||||
|
||||
Arrays.sort(flist, new DirSort());
|
||||
|
||||
for (int i=0;i<flist.length;i++)
|
||||
list.add(flist[i]);
|
||||
|
||||
|
||||
for (int i=0;i<list.size();i++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
final View childview=parentActivity.getLayoutInflater().inflate(R.layout.app_list_item, null, false);
|
||||
|
||||
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
|
||||
((TextView)childview.findViewById(R.id.item_name)).setText(list.get(i).getName());
|
||||
|
||||
((ImageView)childview.findViewById(R.id.item_icon)).setImageResource(
|
||||
list.get(i)==null ? R.drawable.config :
|
||||
list.get(i).isDirectory() ? R.drawable.open_folder :
|
||||
list.get(i).getName().toLowerCase().endsWith(".gdi") ? R.drawable.gdi :
|
||||
list.get(i).getName().toLowerCase().endsWith(".cdi") ? R.drawable.cdi :
|
||||
list.get(i).getName().toLowerCase().endsWith(".chd") ? R.drawable.chd :
|
||||
R.drawable.disk_unknown);
|
||||
|
||||
childview.setTag(list.get(i));
|
||||
|
||||
orig_bg=childview.getBackground();
|
||||
|
||||
//vw.findViewById(R.id.childview).setBackgroundColor(0xFFFFFFFF);
|
||||
|
||||
/*
|
||||
* OnTouchListener viblist=new OnTouchListener() {
|
||||
*
|
||||
* public boolean onTouch(View v, MotionEvent event) { if
|
||||
* (event.getActionMasked()==MotionEvent.ACTION_DOWN) vib.vibrate(50);
|
||||
* return false; } };
|
||||
*
|
||||
* findViewById(R.id.config).setOnTouchListener(viblist);
|
||||
* findViewById(R.id.about).setOnTouchListener(viblist);
|
||||
*/
|
||||
|
||||
childview.findViewById(R.id.childview).setOnClickListener(
|
||||
new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
File f = (File)view.getTag();
|
||||
|
||||
if (f != null && f.isDirectory())
|
||||
{
|
||||
navigate(f);
|
||||
ScrollView sv = (ScrollView)parentActivity.findViewById(R.id.game_scroller);
|
||||
sv.scrollTo(0,0);
|
||||
vib.vibrate(50);
|
||||
}else if(f == null && !ImgBrowse){
|
||||
vib.vibrate(50);
|
||||
|
||||
mCallback.onFolderSelected(Uri.fromFile(new File(root_sd.getAbsolutePath())));
|
||||
vib.vibrate(250);
|
||||
}
|
||||
else if(ImgBrowse)
|
||||
{
|
||||
vib.vibrate(50);
|
||||
mCallback.onGameSelected(f!=null? Uri.fromFile(f):Uri.EMPTY);
|
||||
//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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!ImgBrowse) {
|
||||
navigate(new File(home_directory));
|
||||
} else {
|
||||
generate(ExternalFiles(sdcard));
|
||||
}
|
||||
|
||||
childview.findViewById(R.id.childview).setOnTouchListener(
|
||||
new OnTouchListener() {
|
||||
File bios = new File(home_directory, "data/dc_boot.bin");
|
||||
File flash = new File(home_directory, "data/dc_flash.bin");
|
||||
|
||||
String msg = null;
|
||||
if (!bios.exists())
|
||||
msg = "BIOS Missing. The Dreamcast BIOS is required for this emulator to work. Place the BIOS file in "
|
||||
+ home_directory + "/data/dc_boot.bin";
|
||||
else if (!flash.exists())
|
||||
msg = "Flash Missing. The Dreamcast Flash is required for this emulator to work. Place the Flash file in "
|
||||
+ home_directory + "/data/dc_flash.bin";
|
||||
|
||||
if (msg != null) {
|
||||
vib.vibrate(50);
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
|
||||
parentActivity);
|
||||
|
||||
// set title
|
||||
alertDialogBuilder.setTitle("You have to provide the BIOS");
|
||||
|
||||
// set dialog message
|
||||
alertDialogBuilder
|
||||
.setMessage(msg)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("Dismiss",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog,
|
||||
int id) {
|
||||
// if this button is clicked, close
|
||||
// current activity
|
||||
parentActivity.finish();
|
||||
}
|
||||
});
|
||||
|
||||
// create alert dialog
|
||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||
|
||||
// show it
|
||||
alertDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
class DirSort implements Comparator<File> {
|
||||
|
||||
// Comparator interface requires defining compare method.
|
||||
public int compare(File filea, File fileb) {
|
||||
|
||||
return ((filea.isFile() ? "a" : "b") + filea.getName().toLowerCase(
|
||||
Locale.getDefault()))
|
||||
.compareTo((fileb.isFile() ? "a" : "b")
|
||||
+ fileb.getName().toLowerCase(Locale.getDefault()));
|
||||
}
|
||||
}
|
||||
|
||||
private List<File> ExternalFiles(File baseDirectory) {
|
||||
// allows the input of a base directory for storage selection
|
||||
final List<File> tFileList = new ArrayList<File>();
|
||||
Resources resources = getResources();
|
||||
// array of valid image file extensions
|
||||
String[] mediaTypes = resources.getStringArray(R.array.images);
|
||||
FilenameFilter[] filter = new FilenameFilter[mediaTypes.length];
|
||||
|
||||
int i = 0;
|
||||
for (final String type : mediaTypes) {
|
||||
filter[i] = new FilenameFilter() {
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
if (dir.getName().startsWith(".") || name.startsWith(".")) {
|
||||
return false;
|
||||
} else {
|
||||
return StringUtils.endsWithIgnoreCase(name, "." + type);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
i++;
|
||||
}
|
||||
|
||||
FileUtils fileUtils = new FileUtils();
|
||||
File[] allMatchingFiles = fileUtils.listFilesAsArray(baseDirectory,
|
||||
filter, -1);
|
||||
for (File mediaFile : allMatchingFiles) {
|
||||
tFileList.add(mediaFile);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
CompositeFileComparator comparator = new CompositeFileComparator(
|
||||
SizeFileComparator.SIZE_REVERSE,
|
||||
LastModifiedFileComparator.LASTMODIFIED_REVERSE);
|
||||
comparator.sort(tFileList);
|
||||
|
||||
return tFileList;
|
||||
}
|
||||
|
||||
void generate(List<File> list) {
|
||||
LinearLayout v = (LinearLayout) parentActivity
|
||||
.findViewById(R.id.game_list);
|
||||
v.removeAllViews();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
final View childview = parentActivity.getLayoutInflater().inflate(
|
||||
R.layout.app_list_item, null, false);
|
||||
|
||||
((TextView) childview.findViewById(R.id.item_name)).setText(list
|
||||
.get(i).getName());
|
||||
|
||||
((ImageView) childview.findViewById(R.id.item_icon))
|
||||
.setImageResource(list.get(i) == null ? R.drawable.config
|
||||
: list.get(i).isDirectory() ? R.drawable.open_folder
|
||||
: list.get(i).getName()
|
||||
.toLowerCase(Locale.getDefault())
|
||||
.endsWith(".gdi") ? R.drawable.gdi
|
||||
: list.get(i)
|
||||
.getName()
|
||||
.toLowerCase(
|
||||
Locale.getDefault())
|
||||
.endsWith(".cdi") ? R.drawable.cdi
|
||||
: list.get(i)
|
||||
.getName()
|
||||
.toLowerCase(
|
||||
Locale.getDefault())
|
||||
.endsWith(".chd") ? R.drawable.chd
|
||||
: R.drawable.disk_unknown);
|
||||
|
||||
childview.setTag(list.get(i));
|
||||
|
||||
orig_bg = childview.getBackground();
|
||||
|
||||
// vw.findViewById(R.id.childview).setBackgroundColor(0xFFFFFFFF);
|
||||
|
||||
childview.findViewById(R.id.childview).setOnClickListener(
|
||||
new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
File f = (File) view.getTag();
|
||||
vib.vibrate(50);
|
||||
mCallback.onGameSelected(f != null ? Uri
|
||||
.fromFile(f) : Uri.EMPTY);
|
||||
// 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() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean onTouch(View view, MotionEvent arg1) {
|
||||
if (arg1.getActionMasked()== MotionEvent.ACTION_DOWN)
|
||||
{
|
||||
if (arg1.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
||||
view.setBackgroundColor(0xFF4F3FFF);
|
||||
}
|
||||
else if (arg1.getActionMasked()== MotionEvent.ACTION_CANCEL ||
|
||||
arg1.getActionMasked()== MotionEvent.ACTION_UP)
|
||||
{
|
||||
} else if (arg1.getActionMasked() == MotionEvent.ACTION_CANCEL
|
||||
|| arg1.getActionMasked() == MotionEvent.ACTION_UP) {
|
||||
view.setBackgroundDrawable(orig_bg);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if (i==0)
|
||||
{
|
||||
FrameLayout sepa= new FrameLayout(parentActivity);
|
||||
sepa.setBackgroundColor(0xFFA0A0A0);
|
||||
sepa.setPadding(0, 0, 0, 1);
|
||||
v.addView(sepa);
|
||||
}
|
||||
v.addView(childview);
|
||||
|
||||
FrameLayout sep= new FrameLayout(parentActivity);
|
||||
sep.setBackgroundColor(0xFFA0A0A0);
|
||||
sep.setPadding(0, 0, 0, 1);
|
||||
v.addView(sep);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (i == 0) {
|
||||
FrameLayout sepa = new FrameLayout(parentActivity);
|
||||
sepa.setBackgroundColor(0xFFA0A0A0);
|
||||
sepa.setPadding(0, 0, 0, 1);
|
||||
v.addView(sepa);
|
||||
}
|
||||
v.addView(childview);
|
||||
|
||||
FrameLayout sep = new FrameLayout(parentActivity);
|
||||
sep.setBackgroundColor(0xFFA0A0A0);
|
||||
sep.setPadding(0, 0, 0, 1);
|
||||
v.addView(sep);
|
||||
}
|
||||
}
|
||||
|
||||
void navigate(final File root_sd) {
|
||||
LinearLayout v = (LinearLayout) parentActivity
|
||||
.findViewById(R.id.game_list);
|
||||
v.removeAllViews();
|
||||
|
||||
ArrayList<File> list = new ArrayList<File>();
|
||||
|
||||
((TextView) parentActivity.findViewById(R.id.text_cwd)).setText(root_sd
|
||||
.getAbsolutePath());
|
||||
|
||||
File flist[] = root_sd.listFiles();
|
||||
|
||||
File parent = root_sd.getParentFile();
|
||||
|
||||
list.add(null);
|
||||
|
||||
if (parent != null)
|
||||
list.add(parent);
|
||||
|
||||
Arrays.sort(flist, new DirSort());
|
||||
|
||||
for (int i = 0; i < flist.length; i++)
|
||||
list.add(flist[i]);
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (ImgBrowse) {
|
||||
if (list.get(i) != null && list.get(i).isFile())
|
||||
if (!list.get(i).getName().toLowerCase(Locale.getDefault())
|
||||
.endsWith(".gdi")
|
||||
&& !list.get(i).getName()
|
||||
.toLowerCase(Locale.getDefault())
|
||||
.endsWith(".cdi")
|
||||
&& !list.get(i).getName()
|
||||
.toLowerCase(Locale.getDefault())
|
||||
.endsWith(".chd"))
|
||||
continue;
|
||||
} else {
|
||||
if (list.get(i) != null && !list.get(i).isDirectory())
|
||||
continue;
|
||||
}
|
||||
final View childview = parentActivity.getLayoutInflater().inflate(
|
||||
R.layout.app_list_item, null, false);
|
||||
|
||||
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
|
||||
((TextView) childview.findViewById(R.id.item_name))
|
||||
.setText(list.get(i).getName());
|
||||
|
||||
((ImageView) childview.findViewById(R.id.item_icon))
|
||||
.setImageResource(list.get(i) == null ? R.drawable.config
|
||||
: list.get(i).isDirectory() ? R.drawable.open_folder
|
||||
: list.get(i).getName()
|
||||
.toLowerCase(Locale.getDefault())
|
||||
.endsWith(".gdi") ? R.drawable.gdi
|
||||
: list.get(i)
|
||||
.getName()
|
||||
.toLowerCase(
|
||||
Locale.getDefault())
|
||||
.endsWith(".cdi") ? R.drawable.cdi
|
||||
: list.get(i)
|
||||
.getName()
|
||||
.toLowerCase(
|
||||
Locale.getDefault())
|
||||
.endsWith(".chd") ? R.drawable.chd
|
||||
: R.drawable.disk_unknown);
|
||||
|
||||
childview.setTag(list.get(i));
|
||||
|
||||
orig_bg = childview.getBackground();
|
||||
|
||||
// vw.findViewById(R.id.childview).setBackgroundColor(0xFFFFFFFF);
|
||||
|
||||
childview.findViewById(R.id.childview).setOnClickListener(
|
||||
new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
File f = (File) view.getTag();
|
||||
|
||||
if (f != null && f.isDirectory()) {
|
||||
navigate(f);
|
||||
ScrollView sv = (ScrollView) parentActivity
|
||||
.findViewById(R.id.game_scroller);
|
||||
sv.scrollTo(0, 0);
|
||||
vib.vibrate(50);
|
||||
} else if (f == null && !ImgBrowse) {
|
||||
vib.vibrate(50);
|
||||
|
||||
mCallback.onFolderSelected(Uri
|
||||
.fromFile(new File(root_sd
|
||||
.getAbsolutePath())));
|
||||
vib.vibrate(250);
|
||||
|
||||
home_directory = root_sd.getAbsolutePath();
|
||||
mPrefs.edit()
|
||||
.putString("home_directory",
|
||||
home_directory).commit();
|
||||
File data_directory = new File(home_directory,
|
||||
"data");
|
||||
if (!data_directory.exists()
|
||||
|| !data_directory.isDirectory()) {
|
||||
data_directory.mkdirs();
|
||||
}
|
||||
JNIdc.config(home_directory);
|
||||
|
||||
} else if (ImgBrowse) {
|
||||
vib.vibrate(50);
|
||||
mCallback.onGameSelected(f != null ? Uri
|
||||
.fromFile(f) : Uri.EMPTY);
|
||||
// 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() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean onTouch(View view, MotionEvent arg1) {
|
||||
if (arg1.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
||||
view.setBackgroundColor(0xFF4F3FFF);
|
||||
} else if (arg1.getActionMasked() == MotionEvent.ACTION_CANCEL
|
||||
|| arg1.getActionMasked() == MotionEvent.ACTION_UP) {
|
||||
view.setBackgroundDrawable(orig_bg);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if (i == 0) {
|
||||
FrameLayout sepa = new FrameLayout(parentActivity);
|
||||
sepa.setBackgroundColor(0xFFA0A0A0);
|
||||
sepa.setPadding(0, 0, 0, 1);
|
||||
v.addView(sepa);
|
||||
}
|
||||
v.addView(childview);
|
||||
|
||||
FrameLayout sep = new FrameLayout(parentActivity);
|
||||
sep.setBackgroundColor(0xFFA0A0A0);
|
||||
sep.setPadding(0, 0, 0, 1);
|
||||
v.addView(sep);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
package com.reicast.emulator;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.example.newdc.JNIdc;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
@ -13,9 +20,15 @@ import android.view.View;
|
|||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnTouchListener;
|
||||
|
||||
import com.example.newdc.JNIdc;
|
||||
|
||||
public class MainActivity extends FragmentActivity implements
|
||||
FileBrowser.OnItemSelectedListener,
|
||||
OptionsFragment.OnClickListener{
|
||||
|
||||
private SharedPreferences mPrefs;
|
||||
private File sdcard = Environment.getExternalStorageDirectory();
|
||||
private String home_directory = sdcard + "/Dreamcast";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -122,6 +135,10 @@ public class MainActivity extends FragmentActivity implements
|
|||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
home_directory = mPrefs.getString("home_directory", home_directory);
|
||||
JNIdc.config(home_directory);
|
||||
|
||||
}
|
||||
|
||||
|
@ -148,14 +165,15 @@ public class MainActivity extends FragmentActivity implements
|
|||
return;
|
||||
}
|
||||
|
||||
public void onMainBrowseSelected(){
|
||||
public void onMainBrowseSelected(String browse_entry){
|
||||
FileBrowser firstFragment = new FileBrowser();
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean("ImgBrowse", false); // specify ImgBrowse option. true = images, false = folders only
|
||||
args.putBoolean("ImgBrowse", false);
|
||||
args.putString("browse_entry", browse_entry);
|
||||
// specify ImgBrowse option. true = images, false = folders only
|
||||
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
|
||||
// an Intent, pass the Intent's extras to the fragment as arguments
|
||||
// firstFragment.setArguments(getIntent().getExtras());
|
||||
|
||||
// Add the fragment to the 'fragment_container' FrameLayout
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package com.reicast.emulator;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.InputDevice;
|
||||
|
@ -11,6 +16,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
public class OptionsFragment extends Fragment{
|
||||
|
@ -19,9 +25,14 @@ public class OptionsFragment extends Fragment{
|
|||
Button mainBrowse;
|
||||
OnClickListener mCallback;
|
||||
|
||||
private SharedPreferences mPrefs;
|
||||
private File sdcard = Environment.getExternalStorageDirectory();
|
||||
private String home_directory = sdcard + "/Dreamcast";
|
||||
private String browse_entry = home_directory;
|
||||
|
||||
// Container Activity must implement this interface
|
||||
public interface OnClickListener {
|
||||
public void onMainBrowseSelected();
|
||||
public void onMainBrowseSelected(String browse_entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,9 +68,18 @@ public class OptionsFragment extends Fragment{
|
|||
|
||||
parentActivity = getActivity();
|
||||
mainBrowse = (Button)getView().findViewById(R.id.browse_main_path);
|
||||
|
||||
final EditText editBrowse = (EditText)getView().findViewById(R.id.main_path);
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
home_directory = mPrefs.getString("home_directory", home_directory);
|
||||
editBrowse.setText(home_directory);
|
||||
|
||||
mainBrowse.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
mCallback.onMainBrowseSelected();
|
||||
if (editBrowse.getText() != null) {
|
||||
browse_entry = editBrowse.getText().toString();
|
||||
}
|
||||
mCallback.onMainBrowseSelected(browse_entry);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue