[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:
parent
aa1fc077b4
commit
bd6218685f
|
@ -1,32 +1,30 @@
|
|||
package org.dolphinemu.dolphinemu;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ListActivity;
|
||||
import android.content.Intent;
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class FolderBrowser extends ListActivity {
|
||||
public class FolderBrowser extends Fragment {
|
||||
private Activity m_activity;
|
||||
private FolderBrowserAdapter adapter;
|
||||
private ListView mDrawerList;
|
||||
private View rootView;
|
||||
private static File currentDir = null;
|
||||
|
||||
// Populates the FolderView with the given currDir's contents.
|
||||
private void Fill(File currDir)
|
||||
{
|
||||
this.setTitle("Current Dir: " + currDir.getName());
|
||||
m_activity.setTitle("Current Dir: " + currDir.getName());
|
||||
File[] dirs = currDir.listFiles();
|
||||
List<GameListItem>dir = new ArrayList<GameListItem>();
|
||||
List<GameListItem>fls = new ArrayList<GameListItem>();
|
||||
|
@ -46,17 +44,17 @@ public class FolderBrowser extends ListActivity {
|
|||
{
|
||||
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
|
||||
{
|
||||
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('.'))))
|
||||
{
|
||||
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,52 +70,65 @@ public class FolderBrowser extends ListActivity {
|
|||
|
||||
// Check for a parent directory to the one we're currently in.
|
||||
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);
|
||||
this.setListAdapter(adapter);
|
||||
adapter = new FolderBrowserAdapter(m_activity, R.layout.folderbrowser, dir);
|
||||
mDrawerList = (ListView) rootView.findViewById(R.id.gamelist);
|
||||
mDrawerList.setAdapter(adapter);
|
||||
mDrawerList.setOnItemClickListener(mMenuItemClickListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
GameListItem o = adapter.getItem(position);
|
||||
if(o.getData().equalsIgnoreCase("folder") || o.getData().equalsIgnoreCase("parent directory")){
|
||||
currentDir = new File(o.getPath());
|
||||
Fill(currentDir);
|
||||
}
|
||||
else
|
||||
if (o.isValid())
|
||||
FolderSelected();
|
||||
else
|
||||
Toast.makeText(this, "Can not use compressed file types.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if(currentDir == null)
|
||||
currentDir = new File(Environment.getExternalStorageDirectory().getPath());
|
||||
|
||||
rootView = inflater.inflate(R.layout.gamelist_listview, container, false);
|
||||
|
||||
Fill(currentDir);
|
||||
return mDrawerList;
|
||||
}
|
||||
|
||||
private AdapterView.OnItemClickListener mMenuItemClickListener = new AdapterView.OnItemClickListener()
|
||||
{
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
GameListItem o = adapter.getItem(position);
|
||||
if(o.getData().equalsIgnoreCase("folder") || o.getData().equalsIgnoreCase("parent directory"))
|
||||
{
|
||||
currentDir = new File(o.getPath());
|
||||
Fill(currentDir);
|
||||
}
|
||||
else
|
||||
if (o.isValid())
|
||||
FolderSelected();
|
||||
else
|
||||
Toast.makeText(m_activity, "Can not use compressed file types.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
};
|
||||
|
||||
@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 {
|
||||
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()
|
||||
{
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("Select", currentDir.getPath());
|
||||
setResult(Activity.RESULT_OK, intent);
|
||||
this.finish();
|
||||
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), currentDir.getPath());
|
||||
|
||||
((GameListActivity)m_activity).SwitchPage(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.dolphinemu.dolphinemu;
|
|||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
|
@ -95,12 +94,16 @@ public class GameListActivity extends Activity
|
|||
FragmentManager fragmentManager = getFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
|
||||
}
|
||||
private void SwitchPage(int toPage)
|
||||
public void SwitchPage(int toPage)
|
||||
{
|
||||
if (mCurFragmentNum == toPage)
|
||||
return;
|
||||
switch (mCurFragmentNum)
|
||||
{
|
||||
// Folder browser
|
||||
case 1:
|
||||
recreateFragment();
|
||||
break;
|
||||
// Settings
|
||||
case 2:
|
||||
{
|
||||
|
@ -160,7 +163,6 @@ public class GameListActivity extends Activity
|
|||
}
|
||||
break;
|
||||
case 0: // Game List
|
||||
case 1: // Folder browser
|
||||
case 4: // About
|
||||
/* Do Nothing */
|
||||
break;
|
||||
|
@ -176,10 +178,14 @@ public class GameListActivity extends Activity
|
|||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
Toast.makeText(mMe, "Loading up the browser", Toast.LENGTH_SHORT).show();
|
||||
Intent ListIntent = new Intent(mMe, FolderBrowser.class);
|
||||
startActivityForResult(ListIntent, 1);
|
||||
break;
|
||||
mCurFragmentNum = 1;
|
||||
mCurFragment = new FolderBrowser();
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
Toast.makeText(mMe, "Loading up settings", Toast.LENGTH_SHORT).show();
|
||||
|
@ -220,30 +226,6 @@ public class GameListActivity extends Activity
|
|||
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
|
||||
* onPostCreate() and onConfigurationChanged()...
|
||||
|
|
Loading…
Reference in New Issue