Expand Up @@ -7,117 +7,116 @@
*/
public final class FolderBrowserItem implements Comparable<FolderBrowserItem>
{
private final String name;
private final String subtitle;
private final String path;
private final boolean isValid;
private final File underlyingFile;

/**
* Constructor
*
* @param name The name of the file/folder represented by this item.
* @param subtitle The subtitle of this FolderBrowserItem to display.
* @param path The path of the file/folder represented by this item.
* @param isValid Whether or not this item represents a file type that can be handled.
*/
public FolderBrowserItem(String name, String subtitle, String path, boolean isValid)
{
this.name = name;
this.subtitle = subtitle;
this.path = path;
this.isValid = isValid;
this.underlyingFile = new File(path);
}

/**
* Constructor. Initializes a FolderBrowserItem with an empty subtitle.
*
* @param ctx Context this FolderBrowserItem is being used in.
* @param name The name of the file/folder represented by this item.
* @param path The path of the file/folder represented by this item.
* @param isValid Whether or not this item represents a file type that can be handled.
*/
public FolderBrowserItem(String name, String path, boolean isValid)
{
this.name = name;
this.subtitle = "";
this.path = path;
this.isValid = isValid;
this.underlyingFile = new File(path);
}

/**
* Gets the name of the file/folder represented by this FolderBrowserItem.
*
* @return the name of the file/folder represented by this FolderBrowserItem.
*/
public String getName()
{
return name;
}

/**
* Gets the subtitle text of this FolderBrowserItem.
*
* @return the subtitle text of this FolderBrowserItem.
*/
public String getSubtitle()
{
return subtitle;
}

/**
* Gets the path of the file/folder represented by this FolderBrowserItem.
*
* @return the path of the file/folder represented by this FolderBrowserItem.
*/
public String getPath()
{
return path;
}

/**
* Gets whether or not the file represented
* by this FolderBrowserItem is supported
* and can be handled correctly.
*
* @return whether or not the file represented
* by this FolderBrowserItem is supported
* and can be handled correctly.
*/
public boolean isValid()
{
return isValid;
}

/**
* Gets the {@link File} representation of the underlying file/folder
* represented by this FolderBrowserItem.
*
* @return the {@link File} representation of the underlying file/folder
* represented by this FolderBrowserItem.
*/
public File getUnderlyingFile()
{
return underlyingFile;
}

/**
* Gets whether or not this FolderBrowserItem represents a directory.
*
* @return true if this FolderBrowserItem represents a directory, false otherwise.
*/
public boolean isDirectory()
{
return underlyingFile.isDirectory();
}

public int compareTo(FolderBrowserItem other)
{
if(this.name != null)
return this.name.toLowerCase().compareTo(other.getName().toLowerCase());
else
throw new IllegalArgumentException();
}
private final String name;
private final String subtitle;
private final String path;
private final boolean isValid;
private final File underlyingFile;

/**
* Constructor
*
* @param name The name of the file/folder represented by this item.
* @param subtitle The subtitle of this FolderBrowserItem to display.
* @param path The path of the file/folder represented by this item.
* @param isValid Whether or not this item represents a file type that can be handled.
*/
public FolderBrowserItem(String name, String subtitle, String path, boolean isValid)
{
this.name = name;
this.subtitle = subtitle;
this.path = path;
this.isValid = isValid;
this.underlyingFile = new File(path);
}

/**
* Constructor. Initializes a FolderBrowserItem with an empty subtitle.
*
* @param name The name of the file/folder represented by this item.
* @param path The path of the file/folder represented by this item.
* @param isValid Whether or not this item represents a file type that can be handled.
*/
public FolderBrowserItem(String name, String path, boolean isValid)
{
this.name = name;
this.subtitle = "";
this.path = path;
this.isValid = isValid;
this.underlyingFile = new File(path);
}

/**
* Gets the name of the file/folder represented by this FolderBrowserItem.
*
* @return the name of the file/folder represented by this FolderBrowserItem.
*/
public String getName()
{
return name;
}

/**
* Gets the subtitle text of this FolderBrowserItem.
*
* @return the subtitle text of this FolderBrowserItem.
*/
public String getSubtitle()
{
return subtitle;
}

/**
* Gets the path of the file/folder represented by this FolderBrowserItem.
*
* @return the path of the file/folder represented by this FolderBrowserItem.
*/
public String getPath()
{
return path;
}

/**
* Gets whether or not the file represented
* by this FolderBrowserItem is supported
* and can be handled correctly.
*
* @return whether or not the file represented
* by this FolderBrowserItem is supported
* and can be handled correctly.
*/
public boolean isValid()
{
return isValid;
}

/**
* Gets the {@link File} representation of the underlying file/folder
* represented by this FolderBrowserItem.
*
* @return the {@link File} representation of the underlying file/folder
* represented by this FolderBrowserItem.
*/
public File getUnderlyingFile()
{
return underlyingFile;
}

/**
* Gets whether or not this FolderBrowserItem represents a directory.
*
* @return true if this FolderBrowserItem represents a directory, false otherwise.
*/
public boolean isDirectory()
{
return underlyingFile.isDirectory();
}

public int compareTo(FolderBrowserItem other)
{
if(this.name != null)
return this.name.toLowerCase().compareTo(other.getName().toLowerCase());
else
throw new IllegalArgumentException();
}
}
Expand Up @@ -99,19 +99,19 @@ private void recreateFragment()
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
}

public void SwitchPage(int toPage)
{
if (mCurFragmentNum == toPage)
return;

switch (mCurFragmentNum)
{
// Folder browser
case 1:
recreateFragment();
break;

case 3: // Gamepad settings
{
InputConfigAdapter adapter = ((InputConfigFragment)mCurFragment).getAdapter();
Expand All @@ -127,14 +127,14 @@ public void SwitchPage(int toPage)
}
}
break;

case 0: // Game List
case 2: // Settings
case 4: // About
/* Do Nothing */
/* Do Nothing */
break;
}

switch(toPage)
{
case 0:
Expand All @@ -145,7 +145,7 @@ public void SwitchPage(int toPage)
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
}
break;

case 1:
{
mCurFragmentNum = 1;
Expand All @@ -154,14 +154,14 @@ public void SwitchPage(int toPage)
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
}
break;

case 2:
{
{
Intent intent = new Intent(this, PrefsActivity.class);
startActivity(intent);
}
break;

case 3:
{
mCurFragmentNum = 3;
Expand All @@ -170,7 +170,7 @@ public void SwitchPage(int toPage)
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
}
break;

case 4:
{
mCurFragmentNum = 4;
Expand All @@ -179,12 +179,12 @@ public void SwitchPage(int toPage)
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
}
break;

default:
break;
}
}

private AdapterView.OnItemClickListener mMenuItemClickListener = new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
Expand Down Expand Up @@ -231,7 +231,7 @@ public boolean onOptionsItemSelected(MenuItem item)
{
return true;
}

return super.onOptionsItemSelected(item);
}

Expand All @@ -245,7 +245,7 @@ public void onBackPressed()
public boolean onMotionEvent(MotionEvent event);
public boolean onKeyEvent(KeyEvent event);
}

// Gets move(triggers, joystick) events
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event)
Expand All @@ -255,10 +255,10 @@ public boolean dispatchGenericMotionEvent(MotionEvent event)
if (((OnGameConfigListener)mCurFragment).onMotionEvent(event))
return true;
}

return super.dispatchGenericMotionEvent(event);
}

// Gets button presses
@Override
public boolean dispatchKeyEvent(KeyEvent event)
Expand All @@ -268,8 +268,7 @@ public boolean dispatchKeyEvent(KeyEvent event)
if (((OnGameConfigListener)mCurFragment).onKeyEvent(event))
return true;
}

return super.dispatchKeyEvent(event);
}

}
Expand Up @@ -14,55 +14,55 @@

public final class GameListAdapter extends ArrayAdapter<GameListItem>
{
private final Context c;
private final int id;
private final List<GameListItem>items;
private final Context c;
private final int id;
private final List<GameListItem>items;

public GameListAdapter(Context context, int textViewResourceId, List<GameListItem> objects)
{
super(context, textViewResourceId, objects);
c = context;
id = textViewResourceId;
items = objects;
}
public GameListAdapter(Context context, int textViewResourceId, List<GameListItem> objects)
{
super(context, textViewResourceId, objects);
c = context;
id = textViewResourceId;
items = objects;
}

public GameListItem getItem(int i)
{
return items.get(i);
}
public GameListItem getItem(int i)
{
return items.get(i);
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(id, parent, false);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(id, parent, false);
}

final GameListItem item = items.get(position);
if (item != null)
{
TextView title = (TextView) v.findViewById(R.id.GameItemTitle);
TextView subtitle = (TextView) v.findViewById(R.id.GameItemSubText);
ImageView icon = (ImageView) v.findViewById(R.id.GameItemIcon);
final GameListItem item = items.get(position);
if (item != null)
{
TextView title = (TextView) v.findViewById(R.id.GameItemTitle);
TextView subtitle = (TextView) v.findViewById(R.id.GameItemSubText);
ImageView icon = (ImageView) v.findViewById(R.id.GameItemIcon);

if(title != null)
title.setText(item.getName());
if(subtitle != null)
subtitle.setText(item.getData());
if(icon != null)
{
icon.setImageBitmap(item.getImage());
icon.getLayoutParams().width = (int) ((860 / c.getResources().getDisplayMetrics().density) + 0.5);
icon.getLayoutParams().height = (int)((340 / c.getResources().getDisplayMetrics().density) + 0.5);
}
}
return v;
}
if (title != null)
title.setText(item.getName());

if (subtitle != null)
subtitle.setText(item.getData());

if (icon != null)
{
icon.setImageBitmap(item.getImage());
icon.getLayoutParams().width = (int) ((860 / c.getResources().getDisplayMetrics().density) + 0.5);
icon.getLayoutParams().height = (int)((340 / c.getResources().getDisplayMetrics().density) + 0.5);
}
}

return v;
}
}

Expand Up @@ -43,7 +43,7 @@ public GameListFragment()
{
// Empty constructor required for fragment subclasses
}

private void Fill()
{
List<GameListItem> fls = new ArrayList<GameListItem>();
Expand All @@ -60,39 +60,39 @@ private void Fill()
File[] dirs = currentDir.listFiles();
try
{
for(File entry : dirs)
for (File entry : dirs)
{
String entryName = entry.getName();

if (entryName.charAt(0) != '.')
{
if(!entry.isDirectory())
if (!entry.isDirectory())
{
if (exts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.'))))
fls.add(new GameListItem(mMe.getApplicationContext(), entryName, getString(R.string.file_size)+entry.length(),entry.getAbsolutePath(), true));
}
}
}
}
catch(Exception ignored)
catch (Exception ignored)
{
}
}
Collections.sort(fls);

// Remove any duplicate items from the list.
// We don't need to index these in the game list more than once.
//
// This works by comparing the paths of items in the file list for equality,
// so there should be no worries about accidentally removing a valid game.
for (int i = 0; i < fls.size(); i++)
{
int indexNext = i+1;
if (indexNext < fls.size() && fls.get(indexNext).getPath().contains(fls.get(i).getPath()))
{
fls.remove(indexNext);
}
int indexNext = i+1;

if (indexNext < fls.size() && fls.get(indexNext).getPath().contains(fls.get(i).getPath()))
{
fls.remove(indexNext);
}
}

mGameAdapter = new GameListAdapter(mMe, R.layout.gamelist_layout, fls);
Expand All @@ -112,19 +112,19 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

return mMainList;
}

private AdapterView.OnItemClickListener mGameItemClickListener = new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
GameListItem o = mGameAdapter.getItem(position);
if(!(o.getData().equalsIgnoreCase(getString(R.string.folder))||o.getData().equalsIgnoreCase(getString(R.string.parent_directory))))
if (!(o.getData().equalsIgnoreCase(getString(R.string.folder))||o.getData().equalsIgnoreCase(getString(R.string.parent_directory))))
{
onFileClick(o.getPath());
}
}
};

private void onFileClick(String o)
{
Toast.makeText(mMe, getString(R.string.file_clicked) + o, Toast.LENGTH_SHORT).show();
Expand All @@ -134,7 +134,7 @@ private void onFileClick(String o)
mMe.setResult(Activity.RESULT_OK, intent);
mMe.finish();
}

@Override
public void onAttach(Activity activity)
{
Expand Down
Expand Up @@ -12,27 +12,27 @@

public final class GameListItem implements Comparable<GameListItem>
{
private String name;
private final String data;
private final String path;
private final boolean isValid;
private Bitmap image;
private String name;
private final String data;
private final String path;
private final boolean isValid;
private Bitmap image;

public GameListItem(Context ctx, String name, String data, String path, boolean isValid)
{
this.name = name;
this.data = data;
this.path = path;
this.isValid = isValid;
File file = new File(path);
if (!file.isDirectory() && !path.equals(""))
{
int[] Banner = NativeLibrary.GetBanner(path);
if (Banner[0] == 0)
{
try
{
public GameListItem(Context ctx, String name, String data, String path, boolean isValid)
{
this.name = name;
this.data = data;
this.path = path;
this.isValid = isValid;

File file = new File(path);
if (!file.isDirectory() && !path.equals(""))
{
int[] Banner = NativeLibrary.GetBanner(path);
if (Banner[0] == 0)
{
try
{
// Open the no banner icon.
InputStream noBannerPath = ctx.getAssets().open("NoBanner.png");

Expand All @@ -42,53 +42,52 @@ public GameListItem(Context ctx, String name, String data, String path, boolean
// Scale the bitmap to match other banners.
image = Bitmap.createScaledBitmap(image, 96, 32, false);
}
catch (IOException e)
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

}
else
{
image = Bitmap.createBitmap(Banner, 96, 32, Bitmap.Config.ARGB_8888);
}

this.name = NativeLibrary.GetTitle(path);
}
}

public String getName()
{
return name;
}

public String getData()
{
return data;
}

public String getPath()
{
return path;
}

public Bitmap getImage()
{
return image;
}

}
else
{
image = Bitmap.createBitmap(Banner, 96, 32, Bitmap.Config.ARGB_8888);
}

this.name = NativeLibrary.GetTitle(path);
}
}

public String getName()
{
return name;
}

public String getData()
{
return data;
}

public String getPath()
{
return path;
}

public Bitmap getImage()
{
return image;
}

public boolean isValid()
{
return isValid;
}
public int compareTo(GameListItem o)
{
if(this.name != null)
return this.name.toLowerCase().compareTo(o.getName().toLowerCase());
else
throw new IllegalArgumentException();
}

public int compareTo(GameListItem o)
{
if (this.name != null)
return this.name.toLowerCase().compareTo(o.getName().toLowerCase());
else
throw new IllegalArgumentException();
}
}

Expand Up @@ -34,7 +34,7 @@ public InputConfigItem getItem(int i)
{
return items.get(i);
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
Expand All @@ -44,20 +44,20 @@ public View getView(int position, View convertView, ViewGroup parent)
LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(id, parent, false);
}

final InputConfigItem item = items.get(position);
if (item != null)
{
TextView title = (TextView) v.findViewById(R.id.FolderTitle);
TextView subtitle = (TextView) v.findViewById(R.id.FolderSubTitle);

if(title != null)
title.setText(item.getName());
if(subtitle != null)
subtitle.setText(item.getBind());
if (title != null)
title.setText(item.getName());

if (subtitle != null)
subtitle.setText(item.getBind());
}

return v;
}
}
Expand Up @@ -35,7 +35,7 @@ static public String getInputDesc(InputDevice input)
{
if (input == null)
return "null"; // Happens when the inputdevice is from an unknown source

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
{
return input.getDescriptor();
Expand All @@ -44,13 +44,14 @@ static public String getInputDesc(InputDevice input)
{
List<InputDevice.MotionRange> motions = input.getMotionRanges();
String fakeid = "";

for (InputDevice.MotionRange range : motions)
fakeid += range.getAxis();

return fakeid;
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
Expand Down Expand Up @@ -84,7 +85,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mDrawerList.setOnItemClickListener(mMenuItemClickListener);
return mDrawerList;
}

private AdapterView.OnItemClickListener mMenuItemClickListener = new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
Expand All @@ -107,16 +108,16 @@ private void AssignBind(String bind)
o.setBind(bind);
adapter.insert(o, configPosition);
}

public InputConfigAdapter getAdapter()
{
return adapter;
}

// Called from GameListActivity
public boolean onMotionEvent(MotionEvent event)
{
if (((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0))
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)
return false;

InputDevice input = event.getDevice();
Expand All @@ -131,7 +132,7 @@ public boolean onMotionEvent(MotionEvent event)
{
m_values.add(event.getAxisValue(range.getAxis()));
}

firstEvent = false;
}
else
Expand All @@ -155,7 +156,7 @@ else if (m_values.get(a) < (event.getAxisValue(range.getAxis()) - 0.5f))
}
return true;
}

public boolean onKeyEvent(KeyEvent event)
{
Log.w("InputConfigFragment", "Got Event " + event.getAction());
Expand Down
Expand Up @@ -41,7 +41,7 @@ public InputConfigItem(String name, String config, String defaultBind)

/**
* Constructor that creates an InputConfigItem
* that has a default binding of "None"
* that has a default binding of "None".
*
* @param name Name of the input config item.
* @param config Name of the key in the configuration file that this control modifies.
Expand All @@ -50,7 +50,7 @@ public InputConfigItem(String name, String config)
{
Init(name, config, "None");
}

/**
* Gets the name of this InputConfigItem.
*
Expand All @@ -60,7 +60,7 @@ public String getName()
{
return m_name;
}

/**
* Gets the config key this InputConfigItem modifies.
*
Expand All @@ -70,17 +70,17 @@ public String getConfig()
{
return m_Config;
}

/**
* Gets the currently set binding of this InputConfigItem
* Gets the currently set binding of this InputConfigItem.
*
* @return the currently set binding of this InputConfigItem
*/
public String getBind()
{
return m_bind;
}

/**
* Sets a new binding for this InputConfigItem.
*
Expand All @@ -93,7 +93,7 @@ public void setBind(String bind)

public int compareTo(InputConfigItem o)
{
if(this.m_name != null)
if (this.m_name != null)
return this.m_name.toLowerCase().compareTo(o.getName().toLowerCase());
else
throw new IllegalArgumentException();
Expand Down
Expand Up @@ -19,62 +19,62 @@
*/
public final class CPUSettingsFragment extends PreferenceFragment
{
private Activity m_activity;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
private Activity m_activity;

// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.cpu_prefs);
final ListPreference cpuCores = (ListPreference) findPreference("cpuCorePref");
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

//
// Set valid emulation cores depending on the CPU architecture
// that the Android device is running on.
//
if (Build.CPU_ABI.contains("x86"))
{
cpuCores.setEntries(R.array.emuCoreEntriesX86);
cpuCores.setEntryValues(R.array.emuCoreValuesX86);
}
else if (Build.CPU_ABI.contains("arm"))
{
cpuCores.setEntries(R.array.emuCoreEntriesARM);
cpuCores.setEntryValues(R.array.emuCoreValuesARM);
}
else
{
cpuCores.setEntries(R.array.emuCoreEntriesOther);
cpuCores.setEntryValues(R.array.emuCoreValuesOther);
}
}

@Override
public void onAttach(Activity activity)
{
super.onAttach(activity);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.cpu_prefs);

// 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());
}
}

@Override
public void onDestroy()
{
super.onDestroy();

// When this fragment is destroyed, force the settings to be saved to the ini file.
UserPreferences.SaveConfigToDolphinIni(m_activity);
}
final ListPreference cpuCores = (ListPreference) findPreference("cpuCorePref");

//
// Set valid emulation cores depending on the CPU architecture
// that the Android device is running on.
//
if (Build.CPU_ABI.contains("x86"))
{
cpuCores.setEntries(R.array.emuCoreEntriesX86);
cpuCores.setEntryValues(R.array.emuCoreValuesX86);
}
else if (Build.CPU_ABI.contains("arm"))
{
cpuCores.setEntries(R.array.emuCoreEntriesARM);
cpuCores.setEntryValues(R.array.emuCoreValuesARM);
}
else
{
cpuCores.setEntries(R.array.emuCoreEntriesOther);
cpuCores.setEntryValues(R.array.emuCoreValuesOther);
}
}

@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());
}
}

@Override
public void onDestroy()
{
super.onDestroy();

// When this fragment is destroyed, force the settings to be saved to the ini file.
UserPreferences.SaveConfigToDolphinIni(m_activity);
}
}
244 changes: 125 additions & 119 deletions Source/Android/src/org/dolphinemu/dolphinemu/settings/PrefsActivity.java
Expand Up @@ -7,6 +7,7 @@
package org.dolphinemu.dolphinemu.settings;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.inputconfig.InputConfigFragment;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
Expand All @@ -24,123 +25,128 @@
*/
public final class PrefsActivity extends Activity implements ActionBar.TabListener
{
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide org.dolphinemu.dolphinemu.settings for each of the
* sections. We use a {@link android.support.v4.app.FragmentPagerAdapter} derivative, which will
* keep every loaded fragment in memory. If this becomes too memory intensive, it may be best to
* switch to a {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
SectionsPagerAdapter mSectionsPagerAdapter;

/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.prefs_viewpager);

// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);

// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
{
@Override
public void onPageSelected(int position)
{
actionBar.setSelectedNavigationItem(position);
}
} );

// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
actionBar.addTab(actionBar.newTab().setText(R.string.cpu_settings).setTabListener(this));
actionBar.addTab(actionBar.newTab().setText(R.string.video_settings).setTabListener(this));

}

public void onTabReselected(Tab arg0, FragmentTransaction arg1)
{
// Do nothing.
}

public void onTabSelected(Tab tab, FragmentTransaction ft)
{
// When the given tab is selected, switch to the corresponding page in the ViewPager.
mViewPager.setCurrentItem(tab.getPosition());
}

public void onTabUnselected(Tab tab, FragmentTransaction ft)
{
// Do nothing.
}

/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to one of the
* sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter
{

public SectionsPagerAdapter(FragmentManager fm)
{
super(fm);
}

@Override
public Fragment getItem(int position)
{
switch(position)
{
case 0:
return new CPUSettingsFragment();

case 1:
return new VideoSettingsFragment();

default: // Should never happen.
return null;
}
}

@Override
public int getCount()
{
// Show total pages.
return 2;
}

@Override
public CharSequence getPageTitle(int position)
{
switch(position)
{
case 0:
return getString(R.string.cpu_settings).toUpperCase();

case 1:
return getString(R.string.video_settings).toUpperCase();

default: // Should never happen.
return null;
}
}
}
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide org.dolphinemu.dolphinemu.settings for each of the
* sections. We use a {@link android.support.v4.app.FragmentPagerAdapter} derivative, which will
* keep every loaded fragment in memory. If this becomes too memory intensive, it may be best to
* switch to a {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
SectionsPagerAdapter mSectionsPagerAdapter;

/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.prefs_viewpager);

// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);

// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
{
@Override
public void onPageSelected(int position)
{
actionBar.setSelectedNavigationItem(position);
}
} );

// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
actionBar.addTab(actionBar.newTab().setText(R.string.cpu_settings).setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("Input Settings").setTabListener(this));
actionBar.addTab(actionBar.newTab().setText(R.string.video_settings).setTabListener(this));
}

public void onTabReselected(Tab arg0, FragmentTransaction arg1)
{
// Do nothing.
}

public void onTabSelected(Tab tab, FragmentTransaction ft)
{
// When the given tab is selected, switch to the corresponding page in the ViewPager.
mViewPager.setCurrentItem(tab.getPosition());
}

public void onTabUnselected(Tab tab, FragmentTransaction ft)
{
// Do nothing.
}

/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to one of the
* sections/tabs/pages.
*/
public final class SectionsPagerAdapter extends FragmentPagerAdapter
{
public SectionsPagerAdapter(FragmentManager fm)
{
super(fm);
}

@Override
public Fragment getItem(int position)
{
switch(position)
{
case 0:
return new CPUSettingsFragment();

case 1:
return new InputConfigFragment();

case 2:
return new VideoSettingsFragment();

default: // Should never happen.
return null;
}
}

@Override
public int getCount()
{
// Show total pages.
return 3;
}

@Override
public CharSequence getPageTitle(int position)
{
switch(position)
{
case 0:
return getString(R.string.cpu_settings).toUpperCase();

case 1:
return "Input Settings";//getString(R.string)

case 2:
return getString(R.string.video_settings).toUpperCase();

default: // Should never happen.
return null;
}
}
}
}

Large diffs are not rendered by default.

Expand Up @@ -25,177 +25,177 @@
*/
public final class VideoSettingsFragment extends PreferenceFragment
{
private Activity m_activity;

static public class VersionCheck
{
EGL10 mEGL;
EGLDisplay mEGLDisplay;
EGLConfig[] mEGLConfigs;
EGLConfig mEGLConfig;
EGLContext mEGLContext;
EGLSurface mEGLSurface;
GL10 mGL;

String mThreadOwner;

public VersionCheck()
{
int[] version = new int[2];
int[] attribList = new int[] {
EGL10.EGL_WIDTH, 1,
EGL10.EGL_HEIGHT, 1,
EGL10.EGL_RENDERABLE_TYPE, 4,
EGL10.EGL_NONE
};
int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
int[] ctx_attribs = new int[] {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL10.EGL_NONE
};

// No error checking performed, minimum required code to elucidate logic
mEGL = (EGL10) EGLContext.getEGL();
mEGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
mEGL.eglInitialize(mEGLDisplay, version);
mEGLConfig = chooseConfig(); // Choosing a config is a little more complicated
mEGLContext = mEGL.eglCreateContext(mEGLDisplay, mEGLConfig, EGL10.EGL_NO_CONTEXT, ctx_attribs);
mEGLSurface = mEGL.eglCreatePbufferSurface(mEGLDisplay, mEGLConfig, attribList);
mEGL.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);
mGL = (GL10) mEGLContext.getGL();

// Record thread owner of OpenGL context
mThreadOwner = Thread.currentThread().getName();
}

public String getVersion()
{
return mGL.glGetString(GL10.GL_VERSION);
}

public String getVendor()
{
return mGL.glGetString(GL10.GL_VENDOR);
}
public String getRenderer()
{
return mGL.glGetString(GL10.GL_RENDERER);
}
private EGLConfig chooseConfig()
{
int[] attribList = new int[] {
EGL10.EGL_DEPTH_SIZE, 0,
EGL10.EGL_STENCIL_SIZE, 0,
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_NONE
};

// No error checking performed, minimum required code to elucidate logic
// Expand on this logic to be more selective in choosing a configuration
int[] numConfig = new int[1];
mEGL.eglChooseConfig(mEGLDisplay, attribList, null, 0, numConfig);
int configSize = numConfig[0];
mEGLConfigs = new EGLConfig[configSize];
mEGL.eglChooseConfig(mEGLDisplay, attribList, mEGLConfigs, configSize, numConfig);

return mEGLConfigs[0]; // Best match is probably the first configuration
}
}
static public boolean SupportsGLES3()
{
VersionCheck mbuffer = new VersionCheck();
String m_GLVersion = mbuffer.getVersion();
String m_GLVendor = mbuffer.getVendor();
String m_GLRenderer = mbuffer.getRenderer();

boolean mSupportsGLES3 = false;

// Check for OpenGL ES 3 support (General case).
if (m_GLVersion != null && (m_GLVersion.contains("OpenGL ES 3.0") || m_GLVersion.equals("OpenGL ES 3.0")))
mSupportsGLES3 = true;
// Checking for OpenGL ES 3 support for certain Qualcomm devices.
if (!mSupportsGLES3 && m_GLVendor != null && m_GLVendor.equals("Qualcomm"))
{
if (m_GLRenderer.contains("Adreno (TM) 3"))
{
int mVStart = m_GLVersion.indexOf("V@") + 2;
int mVEnd = 0;
float mVersion;
for (int a = mVStart; a < m_GLVersion.length(); ++a)
{
if (m_GLVersion.charAt(a) == ' ')
{
mVEnd = a;
break;
}
}
mVersion = Float.parseFloat(m_GLVersion.substring(mVStart, mVEnd));

if (mVersion >= 14.0f)
mSupportsGLES3 = true;
}
}
return mSupportsGLES3;
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.video_prefs);

//
// Setting valid video backends.
//
final ListPreference videoBackends = (ListPreference) findPreference("gpuPref");
final boolean deviceSupportsGLES3 = SupportsGLES3();

if (deviceSupportsGLES3)
{
videoBackends.setEntries(R.array.videoBackendEntriesGLES3);
videoBackends.setEntryValues(R.array.videoBackendValuesGLES3);
}
else
{
videoBackends.setEntries(R.array.videoBackendEntriesNoGLES3);
videoBackends.setEntryValues(R.array.videoBackendValuesNoGLES3);
}
}

@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());
}
}
@Override
public void onDestroy()
{
super.onDestroy();
// When the fragment is done being used, save the settings to the Dolphin ini file.
UserPreferences.SaveConfigToDolphinIni(m_activity);
}
private Activity m_activity;

public static class VersionCheck
{
EGL10 mEGL;
EGLDisplay mEGLDisplay;
EGLConfig[] mEGLConfigs;
EGLConfig mEGLConfig;
EGLContext mEGLContext;
EGLSurface mEGLSurface;
GL10 mGL;

String mThreadOwner;

public VersionCheck()
{
int[] version = new int[2];
int[] attribList = new int[] {
EGL10.EGL_WIDTH, 1,
EGL10.EGL_HEIGHT, 1,
EGL10.EGL_RENDERABLE_TYPE, 4,
EGL10.EGL_NONE
};
int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
int[] ctx_attribs = new int[] {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL10.EGL_NONE
};

// No error checking performed, minimum required code to elucidate logic
mEGL = (EGL10) EGLContext.getEGL();
mEGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
mEGL.eglInitialize(mEGLDisplay, version);
mEGLConfig = chooseConfig(); // Choosing a config is a little more complicated
mEGLContext = mEGL.eglCreateContext(mEGLDisplay, mEGLConfig, EGL10.EGL_NO_CONTEXT, ctx_attribs);
mEGLSurface = mEGL.eglCreatePbufferSurface(mEGLDisplay, mEGLConfig, attribList);
mEGL.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);
mGL = (GL10) mEGLContext.getGL();

// Record thread owner of OpenGL context
mThreadOwner = Thread.currentThread().getName();
}

public String getVersion()
{
return mGL.glGetString(GL10.GL_VERSION);
}

public String getVendor()
{
return mGL.glGetString(GL10.GL_VENDOR);
}

public String getRenderer()
{
return mGL.glGetString(GL10.GL_RENDERER);
}

private EGLConfig chooseConfig()
{
int[] attribList = new int[] {
EGL10.EGL_DEPTH_SIZE, 0,
EGL10.EGL_STENCIL_SIZE, 0,
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_NONE
};

// No error checking performed, minimum required code to elucidate logic
// Expand on this logic to be more selective in choosing a configuration
int[] numConfig = new int[1];
mEGL.eglChooseConfig(mEGLDisplay, attribList, null, 0, numConfig);
int configSize = numConfig[0];
mEGLConfigs = new EGLConfig[configSize];
mEGL.eglChooseConfig(mEGLDisplay, attribList, mEGLConfigs, configSize, numConfig);

return mEGLConfigs[0]; // Best match is probably the first configuration
}
}

public static boolean SupportsGLES3()
{
VersionCheck mbuffer = new VersionCheck();
String m_GLVersion = mbuffer.getVersion();
String m_GLVendor = mbuffer.getVendor();
String m_GLRenderer = mbuffer.getRenderer();

boolean mSupportsGLES3 = false;

// Check for OpenGL ES 3 support (General case).
if (m_GLVersion != null && (m_GLVersion.contains("OpenGL ES 3.0") || m_GLVersion.equals("OpenGL ES 3.0")))
mSupportsGLES3 = true;

// Checking for OpenGL ES 3 support for certain Qualcomm devices.
if (!mSupportsGLES3 && m_GLVendor != null && m_GLVendor.equals("Qualcomm"))
{
if (m_GLRenderer.contains("Adreno (TM) 3"))
{
int mVStart = m_GLVersion.indexOf("V@") + 2;
int mVEnd = 0;
float mVersion;

for (int a = mVStart; a < m_GLVersion.length(); ++a)
{
if (m_GLVersion.charAt(a) == ' ')
{
mVEnd = a;
break;
}
}

mVersion = Float.parseFloat(m_GLVersion.substring(mVStart, mVEnd));

if (mVersion >= 14.0f)
mSupportsGLES3 = true;
}
}
return mSupportsGLES3;
}

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.video_prefs);

//
// Setting valid video backends.
//
final ListPreference videoBackends = (ListPreference) findPreference("gpuPref");
final boolean deviceSupportsGLES3 = SupportsGLES3();

if (deviceSupportsGLES3)
{
videoBackends.setEntries(R.array.videoBackendEntriesGLES3);
videoBackends.setEntryValues(R.array.videoBackendValuesGLES3);
}
else
{
videoBackends.setEntries(R.array.videoBackendEntriesNoGLES3);
videoBackends.setEntryValues(R.array.videoBackendValuesNoGLES3);
}
}

@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());
}
}

@Override
public void onDestroy()
{
super.onDestroy();

// When the fragment is done being used, save the settings to the Dolphin ini file.
UserPreferences.SaveConfigToDolphinIni(m_activity);
}
}
Expand Up @@ -16,40 +16,40 @@ public final class SideMenuAdapter extends ArrayAdapter<SideMenuItem>
private final Context c;
private final int id;
private final List<SideMenuItem>items;

public SideMenuAdapter(Context context, int textViewResourceId, List<SideMenuItem> objects)
{
super(context, textViewResourceId, objects);
c = context;
id = textViewResourceId;
items = objects;
}

public SideMenuItem getItem(int i)
{
return items.get(i);
return items.get(i);
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(id, null);
}
final SideMenuItem item = items.get(position);
if (item != null)
{
TextView title = (TextView) v.findViewById(R.id.SideMenuTitle);
if(title != null)
title.setText(item.getName());
}
return v;
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(id, null);
}

final SideMenuItem item = items.get(position);
if (item != null)
{
TextView title = (TextView) v.findViewById(R.id.SideMenuTitle);

if (title != null)
title.setText(item.getName());
}

return v;
}
}

Expand Up @@ -12,47 +12,47 @@
*/
public final class SideMenuItem implements Comparable<SideMenuItem>
{
private final String m_name;
private final int m_id;

/**
* Constructor
*
* @param name The name of the SideMenuItem.
* @param id ID number of this specific SideMenuItem.
*/
public SideMenuItem(String name, int id)
{
m_name = name;
m_id = id;
}
/**
* Gets the name of this SideMenuItem.
*
* @return the name of this SideMenuItem.
*/
public String getName()
{
return m_name;
}
/**
* Gets the ID of this SideMenuItem.
*
* @return the ID of this SideMenuItem.
*/
public int getID()
{
return m_id;
}
public int compareTo(SideMenuItem o)
{
if(this.m_name != null)
return this.m_name.toLowerCase().compareTo(o.getName().toLowerCase());
else
throw new IllegalArgumentException();
}
private final String m_name;
private final int m_id;

/**
* Constructor
*
* @param name The name of the SideMenuItem.
* @param id ID number of this specific SideMenuItem.
*/
public SideMenuItem(String name, int id)
{
m_name = name;
m_id = id;
}

/**
* Gets the name of this SideMenuItem.
*
* @return the name of this SideMenuItem.
*/
public String getName()
{
return m_name;
}

/**
* Gets the ID of this SideMenuItem.
*
* @return the ID of this SideMenuItem.
*/
public int getID()
{
return m_id;
}

public int compareTo(SideMenuItem o)
{
if (this.m_name != null)
return this.m_name.toLowerCase().compareTo(o.getName().toLowerCase());
else
throw new IllegalArgumentException();
}
}