[Android] Folder Browser a fragment as well. Removes the menu item for selected path, because it was just a confusing mechanic anyway. People just tap on the ISO in the browser anyway.

This commit is contained in:
Ryan Houdek 2013-07-16 06:58:51 -05:00
parent aa1fc077b4
commit bd6218685f
2 changed files with 75 additions and 82 deletions

View File

@ -1,32 +1,30 @@
package org.dolphinemu.dolphinemu; package org.dolphinemu.dolphinemu;
import android.app.Activity; import android.app.Activity;
import android.app.ListActivity; import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.view.Menu; import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class FolderBrowser extends ListActivity { public class FolderBrowser extends Fragment {
private Activity m_activity;
private FolderBrowserAdapter adapter; private FolderBrowserAdapter adapter;
private ListView mDrawerList;
private View rootView;
private static File currentDir = null; private static File currentDir = null;
// Populates the FolderView with the given currDir's contents. // Populates the FolderView with the given currDir's contents.
private void Fill(File currDir) private void Fill(File currDir)
{ {
this.setTitle("Current Dir: " + currDir.getName()); m_activity.setTitle("Current Dir: " + currDir.getName());
File[] dirs = currDir.listFiles(); File[] dirs = currDir.listFiles();
List<GameListItem>dir = new ArrayList<GameListItem>(); List<GameListItem>dir = new ArrayList<GameListItem>();
List<GameListItem>fls = new ArrayList<GameListItem>(); List<GameListItem>fls = new ArrayList<GameListItem>();
@ -46,17 +44,17 @@ public class FolderBrowser extends ListActivity {
{ {
if(entry.isDirectory()) if(entry.isDirectory())
{ {
dir.add(new GameListItem(getApplicationContext(), entryName,"Folder",entry.getAbsolutePath(), true)); dir.add(new GameListItem(m_activity, entryName,"Folder",entry.getAbsolutePath(), true));
} }
else else
{ {
if (validExts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.')))) if (validExts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.'))))
{ {
fls.add(new GameListItem(getApplicationContext(), entryName,"File Size: "+entry.length(),entry.getAbsolutePath(), true)); fls.add(new GameListItem(m_activity, entryName,"File Size: "+entry.length(),entry.getAbsolutePath(), true));
} }
else if (archiveExts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.')))) else if (archiveExts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.'))))
{ {
fls.add(new GameListItem(getApplicationContext(), entryName,"File Size: "+entry.length(),entry.getAbsolutePath(), false)); fls.add(new GameListItem(m_activity, entryName,"File Size: "+entry.length(),entry.getAbsolutePath(), false));
} }
} }
} }
@ -72,17 +70,33 @@ public class FolderBrowser extends ListActivity {
// Check for a parent directory to the one we're currently in. // Check for a parent directory to the one we're currently in.
if (!currDir.getPath().equalsIgnoreCase("/")) if (!currDir.getPath().equalsIgnoreCase("/"))
dir.add(0, new GameListItem(getApplicationContext(), "..", "Parent Directory", currDir.getParent(), true)); dir.add(0, new GameListItem(m_activity, "..", "Parent Directory", currDir.getParent(), true));
adapter = new FolderBrowserAdapter(this,R.layout.folderbrowser,dir); adapter = new FolderBrowserAdapter(m_activity, R.layout.folderbrowser, dir);
this.setListAdapter(adapter); mDrawerList = (ListView) rootView.findViewById(R.id.gamelist);
mDrawerList.setAdapter(adapter);
mDrawerList.setOnItemClickListener(mMenuItemClickListener);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
if(currentDir == null)
currentDir = new File(Environment.getExternalStorageDirectory().getPath());
rootView = inflater.inflate(R.layout.gamelist_listview, container, false);
Fill(currentDir);
return mDrawerList;
} }
@Override private AdapterView.OnItemClickListener mMenuItemClickListener = new AdapterView.OnItemClickListener()
protected void onListItemClick(ListView l, View v, int position, long id) { {
super.onListItemClick(l, v, position, id); public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
GameListItem o = adapter.getItem(position); GameListItem o = adapter.getItem(position);
if(o.getData().equalsIgnoreCase("folder") || o.getData().equalsIgnoreCase("parent directory")){ if(o.getData().equalsIgnoreCase("folder") || o.getData().equalsIgnoreCase("parent directory"))
{
currentDir = new File(o.getPath()); currentDir = new File(o.getPath());
Fill(currentDir); Fill(currentDir);
} }
@ -90,34 +104,31 @@ public class FolderBrowser extends ListActivity {
if (o.isValid()) if (o.isValid())
FolderSelected(); FolderSelected();
else else
Toast.makeText(this, "Can not use compressed file types.", Toast.LENGTH_LONG).show(); Toast.makeText(m_activity, "Can not use compressed file types.", Toast.LENGTH_LONG).show();
} }
};
@Override @Override
public void onCreate(Bundle savedInstanceState) public void onAttach(Activity activity) {
{ super.onAttach(activity);
super.onCreate(savedInstanceState);
if(currentDir == null) // This makes sure that the container activity has implemented
currentDir = new File(Environment.getExternalStorageDirectory().getPath()); // the callback interface. If not, it throws an exception
Fill(currentDir); try {
m_activity = activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnGameListZeroListener");
} }
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
menu.add("Add current folder");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
FolderSelected();
return true;
} }
private void FolderSelected() private void FolderSelected()
{ {
Intent intent = new Intent(); String Directories = NativeLibrary.GetConfig("Dolphin.ini", "General", "GCMPathes", "0");
intent.putExtra("Select", currentDir.getPath()); int intDirectories = Integer.parseInt(Directories);
setResult(Activity.RESULT_OK, intent); Directories = Integer.toString(intDirectories + 1);
this.finish(); NativeLibrary.SetConfig("Dolphin.ini", "General", "GCMPathes", Directories);
NativeLibrary.SetConfig("Dolphin.ini", "General", "GCMPath" + Integer.toString(intDirectories), currentDir.getPath());
((GameListActivity)m_activity).SwitchPage(0);
} }
} }

View File

@ -3,7 +3,6 @@ package org.dolphinemu.dolphinemu;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
@ -95,12 +94,16 @@ public class GameListActivity extends Activity
FragmentManager fragmentManager = getFragmentManager(); FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit(); fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
} }
private void SwitchPage(int toPage) public void SwitchPage(int toPage)
{ {
if (mCurFragmentNum == toPage) if (mCurFragmentNum == toPage)
return; return;
switch (mCurFragmentNum) switch (mCurFragmentNum)
{ {
// Folder browser
case 1:
recreateFragment();
break;
// Settings // Settings
case 2: case 2:
{ {
@ -160,7 +163,6 @@ public class GameListActivity extends Activity
} }
break; break;
case 0: // Game List case 0: // Game List
case 1: // Folder browser
case 4: // About case 4: // About
/* Do Nothing */ /* Do Nothing */
break; break;
@ -176,9 +178,13 @@ public class GameListActivity extends Activity
} }
break; break;
case 1: case 1:
{
Toast.makeText(mMe, "Loading up the browser", Toast.LENGTH_SHORT).show(); Toast.makeText(mMe, "Loading up the browser", Toast.LENGTH_SHORT).show();
Intent ListIntent = new Intent(mMe, FolderBrowser.class); mCurFragmentNum = 1;
startActivityForResult(ListIntent, 1); mCurFragment = new FolderBrowser();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
}
break; break;
case 2: case 2:
{ {
@ -220,30 +226,6 @@ public class GameListActivity extends Activity
SwitchPage(o.getID()); SwitchPage(o.getID());
} }
}; };
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode)
{
// Browse
case 1:
if (resultCode == Activity.RESULT_OK)
{
String FileName = data.getStringExtra("Select");
Toast.makeText(this, "Folder Selected: " + FileName, Toast.LENGTH_SHORT).show();
String Directories = NativeLibrary.GetConfig("Dolphin.ini", "General", "GCMPathes", "0");
int intDirectories = Integer.parseInt(Directories);
Directories = Integer.toString(intDirectories + 1);
NativeLibrary.SetConfig("Dolphin.ini", "General", "GCMPathes", Directories);
NativeLibrary.SetConfig("Dolphin.ini", "General", "GCMPath" + Integer.toString(intDirectories), FileName);
recreateFragment();
}
break;
}
}
/** /**
* When using the ActionBarDrawerToggle, you must call it during * When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()... * onPostCreate() and onConfigurationChanged()...