mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-25 00:49:47 +00:00
(Android) Remove some more no longer used files
This commit is contained in:
parent
c0a7d10ec0
commit
c06defe102
@ -1,107 +0,0 @@
|
||||
package com.retroarch.browser;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.mainmenu.MainMenuActivity;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
|
||||
/**
|
||||
* {@link ListFragment} subclass that displays the list
|
||||
* of selectable cores for emulating games.
|
||||
*/
|
||||
public final class CoreSelection extends DialogFragment
|
||||
{
|
||||
private IconAdapter<ModuleWrapper> adapter;
|
||||
|
||||
/**
|
||||
* Creates a statically instantiated instance of CoreSelection.
|
||||
*
|
||||
* @return a statically instantiated instance of CoreSelection.
|
||||
*/
|
||||
public static CoreSelection newInstance()
|
||||
{
|
||||
return new CoreSelection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
{
|
||||
// Inflate the ListView we're using.
|
||||
final ListView coreList = (ListView) inflater.inflate(R.layout.line_list, container, false);
|
||||
coreList.setOnItemClickListener(onClickListener);
|
||||
|
||||
// Set the title of the dialog
|
||||
getDialog().setTitle(R.string.select_libretro_core);
|
||||
|
||||
final String cpuInfo = UserPreferences.readCPUInfo();
|
||||
final boolean cpuIsNeon = cpuInfo.contains("neon");
|
||||
|
||||
// Populate the list
|
||||
final List<ModuleWrapper> cores = new ArrayList<ModuleWrapper>();
|
||||
final File[] libs = new File(getActivity().getApplicationInfo().dataDir, "cores").listFiles();
|
||||
for (final File lib : libs) {
|
||||
String libName = lib.getName();
|
||||
|
||||
// Never append a NEON lib if we don't have NEON.
|
||||
if (libName.contains("neon") && !cpuIsNeon)
|
||||
continue;
|
||||
|
||||
// If we have a NEON version with NEON capable CPU,
|
||||
// never append a non-NEON version.
|
||||
if (cpuIsNeon && !libName.contains("neon"))
|
||||
{
|
||||
boolean hasNeonVersion = false;
|
||||
for (final File lib_ : libs)
|
||||
{
|
||||
String otherName = lib_.getName();
|
||||
String baseName = libName.replace(".so", "");
|
||||
if (otherName.contains("neon") && otherName.startsWith(baseName))
|
||||
{
|
||||
hasNeonVersion = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasNeonVersion)
|
||||
continue;
|
||||
}
|
||||
|
||||
cores.add(new ModuleWrapper(getActivity(), lib));
|
||||
}
|
||||
|
||||
// Sort the list of cores alphabetically
|
||||
Collections.sort(cores);
|
||||
|
||||
// Initialize the IconAdapter with the list of cores.
|
||||
adapter = new IconAdapter<ModuleWrapper>(getActivity(), R.layout.line_list_item, cores);
|
||||
coreList.setAdapter(adapter);
|
||||
|
||||
return coreList;
|
||||
}
|
||||
|
||||
private final OnItemClickListener onClickListener = new OnItemClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> listView, View view, int position, long id)
|
||||
{
|
||||
final ModuleWrapper item = adapter.getItem(position);
|
||||
((MainMenuActivity)getActivity()).setModule(item.getUnderlyingFile().getAbsolutePath(), item.getText());
|
||||
UserPreferences.updateConfigFile(getActivity());
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
package com.retroarch.browser;
|
||||
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* {@link Activity} subclass that provides the functionality
|
||||
* for the refresh rate testing for device displays.
|
||||
*/
|
||||
public final class DisplayRefreshRateTest extends Activity {
|
||||
|
||||
private class Renderer implements GLSurfaceView.Renderer {
|
||||
private static final String TAG = "GLESRenderer";
|
||||
private static final double WARMUP_SECONDS = 2.0;
|
||||
private static final double TEST_SECONDS = 10.0;
|
||||
// Test states
|
||||
private static final int STATE_START = 0;
|
||||
private static final int STATE_WARMUP = 1;
|
||||
private static final int STATE_TEST = 2;
|
||||
private static final int STATE_DONE = 3;
|
||||
private static final int STATE_DEAD = 4;
|
||||
private int mState = STATE_START;
|
||||
private double mStartTime = 0.0;
|
||||
private int mNumFrames = 0;
|
||||
|
||||
private Activity activity;
|
||||
|
||||
public Renderer(Activity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
private void setFPSSetting(double fps) {
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(DisplayRefreshRateTest.this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
edit.putString("video_refresh_rate", Double.toString(fps));
|
||||
edit.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawFrame(GL10 gl) {
|
||||
double t = System.nanoTime() * 1.0e-9;
|
||||
switch (mState) {
|
||||
case STATE_START:
|
||||
mStartTime = t;
|
||||
mState = STATE_WARMUP;
|
||||
break;
|
||||
|
||||
case STATE_WARMUP:
|
||||
if ((t - mStartTime) >= WARMUP_SECONDS) {
|
||||
mStartTime = t;
|
||||
mNumFrames = 0;
|
||||
mState = STATE_TEST;
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_TEST:
|
||||
mNumFrames++;
|
||||
double elapsed = t - mStartTime;
|
||||
if (elapsed >= TEST_SECONDS) {
|
||||
double fps = (double)mNumFrames / elapsed;
|
||||
Log.i(TAG, "Measured FPS to: " + fps);
|
||||
setFPSSetting(fps);
|
||||
mState = STATE_DONE;
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_DONE:
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
mState = STATE_DEAD;
|
||||
break;
|
||||
|
||||
case STATE_DEAD:
|
||||
break;
|
||||
}
|
||||
|
||||
float luma = (float)Math.sin((double)mNumFrames * 0.10);
|
||||
luma *= 0.2f;
|
||||
luma += 0.5f;
|
||||
GLES20.glClearColor(luma, luma, luma, 1.0f);
|
||||
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Toast.makeText(this, R.string.touch_screen_with_fingers, Toast.LENGTH_LONG).show();
|
||||
final GLSurfaceView surfaceView = new GLSurfaceView(this);
|
||||
surfaceView.setEGLContextClientVersion(2);
|
||||
surfaceView.setRenderer(new Renderer(this));
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
setTitle(R.string.refresh_rate_calibration);
|
||||
setContentView(surfaceView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
String fps = prefs.getString("video_refresh_rate", "ERROR");
|
||||
Toast.makeText(this, String.format(getString(R.string.refresh_rate_measured_to), fps), Toast.LENGTH_LONG).show();
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
@ -1,346 +0,0 @@
|
||||
package com.retroarch.browser.dirfragment;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.FileWrapper;
|
||||
import com.retroarch.browser.IconAdapter;
|
||||
import com.retroarch.browser.ModuleWrapper;
|
||||
import com.retroarch.browser.mainmenu.MainMenuFragment;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
import com.retroarch.browser.retroactivity.RetroActivityFuture;
|
||||
import com.retroarch.browser.retroactivity.RetroActivityPast;
|
||||
|
||||
/**
|
||||
* {@link DirectoryFragment} that implements core autodetect.
|
||||
* <p>
|
||||
* Basically, how it works is the user selects a file.
|
||||
* Then, we iterate over all the cores and check what their supported extensions are.
|
||||
* Then, if any cores contain the supported extension, they are added to a list and
|
||||
* displayed to the user to choose from.
|
||||
* <p>
|
||||
* The only exception is if only one core matches the extension of the chosen file.
|
||||
* In this case, we just attempt to launch the core with that file directly.
|
||||
*/
|
||||
// TODO: This is ugly as hell. Clean this up sometime.
|
||||
// For example, maybe breaking this out into two fragments
|
||||
// to handle the behavior would be better. One for browsing,
|
||||
// one for handling the list of selectable cores.
|
||||
public final class DetectCoreDirectoryFragment extends DirectoryFragment
|
||||
{
|
||||
private ListView backingListView = null;
|
||||
private boolean inFileBrowser = true;
|
||||
private ArrayList<String> supportedCorePaths = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* Retrieves a new instance of a DetectCoreDirectoryFragment
|
||||
* with a title specified by the given resource ID.
|
||||
*
|
||||
* @param titleResId String resource ID for the title
|
||||
* of this DetectCoreDirectoryFragment.
|
||||
*
|
||||
* @return A new instance of a DetectCoreDirectoryFragment.
|
||||
*/
|
||||
public static DetectCoreDirectoryFragment newInstance(int titleResId)
|
||||
{
|
||||
final DetectCoreDirectoryFragment dFrag = new DetectCoreDirectoryFragment();
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putInt("titleResId", titleResId);
|
||||
dFrag.setArguments(bundle);
|
||||
|
||||
return dFrag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns everything after the last ‘.’ of the given file name or path.
|
||||
*/
|
||||
private static String getFileExt(String filePath)
|
||||
{
|
||||
int i = filePath.lastIndexOf('.');
|
||||
if (i >= 0)
|
||||
return filePath.substring(i+1).toLowerCase();
|
||||
return ""; // No extension
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
{
|
||||
backingListView = (ListView) inflater.inflate(R.layout.line_list, container, false);
|
||||
backingListView.setOnItemClickListener(onItemClickListener);
|
||||
|
||||
// Get whether or not we were in the file browser prior to recreation.
|
||||
if (savedInstanceState != null)
|
||||
{
|
||||
inFileBrowser = savedInstanceState.getBoolean("inFileBrowser");
|
||||
|
||||
if (inFileBrowser)
|
||||
backStack = savedInstanceState.getParcelableArrayList("BACKSTACK");
|
||||
}
|
||||
|
||||
// Set the dialog title.
|
||||
if (inFileBrowser)
|
||||
getDialog().setTitle(getArguments().getInt("titleResId"));
|
||||
else
|
||||
getDialog().setTitle(R.string.multiple_cores_detected);
|
||||
|
||||
// If we're in the file browser, reinitialize the file list adapter.
|
||||
if (savedInstanceState == null || inFileBrowser)
|
||||
{
|
||||
// Setup the list
|
||||
adapter = new IconAdapter<FileWrapper>(getActivity(), R.layout.line_list_item);
|
||||
backingListView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
if (inFileBrowser)
|
||||
{
|
||||
if (backStack == null || backStack.isEmpty())
|
||||
{
|
||||
backStack = new ArrayList<BackStackItem>();
|
||||
String startPath = (startDirectory == null || startDirectory.isEmpty()) ? Environment
|
||||
.getExternalStorageDirectory().getPath() : startDirectory;
|
||||
backStack.add(new BackStackItem(startPath, false));
|
||||
}
|
||||
|
||||
wrapFiles();
|
||||
}
|
||||
else // Rebuild the core adapter.
|
||||
{
|
||||
supportedCorePaths = savedInstanceState.getStringArrayList("coreFilePaths");
|
||||
CoreSelectionAdapter adapter = new CoreSelectionAdapter(getActivity(), android.R.layout.simple_list_item_2);
|
||||
|
||||
for (String path : supportedCorePaths)
|
||||
{
|
||||
ModuleWrapper mw = new ModuleWrapper(getActivity(), path);
|
||||
adapter.add(new CoreItem(mw.getInternalName(), mw.getEmulatedSystemName()));
|
||||
}
|
||||
|
||||
backingListView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
return backingListView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState)
|
||||
{
|
||||
// Save whether or not we're in core selection or the file browser.
|
||||
outState.putBoolean("inFileBrowser", inFileBrowser);
|
||||
|
||||
if (!inFileBrowser)
|
||||
outState.putStringArrayList("coreFilePaths", supportedCorePaths);
|
||||
}
|
||||
|
||||
private File chosenFile = null;
|
||||
private final OnItemClickListener onItemClickListener = new OnItemClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
final FileWrapper item = adapter.getItem(position);
|
||||
|
||||
if (inFileBrowser && item.isParentItem() && backStack.get(backStack.size() - 1).parentIsBack)
|
||||
{
|
||||
backStack.remove(backStack.size() - 1);
|
||||
wrapFiles();
|
||||
return;
|
||||
}
|
||||
|
||||
final File selected = item.isParentItem() ? listedDirectory.getParentFile() : item.getFile();
|
||||
if (inFileBrowser && selected.isDirectory())
|
||||
{
|
||||
Log.d("DirectoryFrag", "Is Directory.");
|
||||
backStack.add(new BackStackItem(selected.getAbsolutePath(), !item.isParentItem()));
|
||||
wrapFiles();
|
||||
return;
|
||||
}
|
||||
else if (inFileBrowser && selected.isFile())
|
||||
{
|
||||
String filePath = selected.getAbsolutePath();
|
||||
chosenFile = selected;
|
||||
|
||||
// Attempt to get the file extension.
|
||||
String fileExt = getFileExt(filePath);
|
||||
|
||||
if (fileExt.equals("zip"))
|
||||
{
|
||||
try
|
||||
{
|
||||
ZipFile zipFile = new ZipFile(chosenFile);
|
||||
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
|
||||
// Try to handle the case of small text files bundles with content.
|
||||
long largestEntry = Long.MIN_VALUE;
|
||||
|
||||
while (entries.hasMoreElements())
|
||||
{
|
||||
ZipEntry zipEntry = entries.nextElement();
|
||||
if (zipEntry.getCompressedSize() >= largestEntry)
|
||||
{
|
||||
largestEntry = zipEntry.getCompressedSize();
|
||||
fileExt = getFileExt(zipEntry.getName());
|
||||
}
|
||||
}
|
||||
|
||||
zipFile.close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Enumerate the cores and check for the extension
|
||||
File coreDir = new File(getActivity().getApplicationInfo().dataDir + File.separator + "cores");
|
||||
File[] coreFiles = coreDir.listFiles();
|
||||
List<ModuleWrapper>supportedCores = new ArrayList<ModuleWrapper>();
|
||||
|
||||
for (File core : coreFiles)
|
||||
{
|
||||
ModuleWrapper mw = new ModuleWrapper(getActivity(), core);
|
||||
|
||||
if (mw.getSupportedExtensions().contains(fileExt))
|
||||
{
|
||||
supportedCores.add(mw);
|
||||
supportedCorePaths.add(mw.getUnderlyingFile().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
// Display a toast if no cores are detected.
|
||||
if (supportedCores.isEmpty())
|
||||
{
|
||||
Toast.makeText(getActivity(), R.string.no_cores_detected, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
// If only one core is supported, launch the content directly.
|
||||
else if (supportedCores.size() == 1)
|
||||
{
|
||||
launchCore(selected.getPath(), supportedCores.get(0).getUnderlyingFile().getPath());
|
||||
}
|
||||
// Otherwise build the list for the user to choose from.
|
||||
else if (supportedCores.size() > 1)
|
||||
{
|
||||
// Not in the file browser any more.
|
||||
inFileBrowser = false;
|
||||
|
||||
// Modify the title to notify of multiple cores.
|
||||
getDialog().setTitle(R.string.multiple_cores_detected);
|
||||
|
||||
// Add all the cores to the adapter and swap it with the one in the ListView.
|
||||
final CoreSelectionAdapter csa = new CoreSelectionAdapter(getActivity(), android.R.layout.simple_list_item_2);
|
||||
|
||||
for (ModuleWrapper core : supportedCores)
|
||||
{
|
||||
csa.add(new CoreItem(core.getInternalName(), core.getEmulatedSystemName()));
|
||||
}
|
||||
|
||||
backingListView.setAdapter(csa);
|
||||
}
|
||||
}
|
||||
else // Selection made
|
||||
{
|
||||
launchCore(chosenFile.getPath(), DetectCoreDirectoryFragment.this.supportedCorePaths.get(position));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void launchCore(String contentPath, String corePath)
|
||||
{
|
||||
Intent retro;
|
||||
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB))
|
||||
retro = new Intent(getActivity(), RetroActivityFuture.class);
|
||||
else
|
||||
retro = new Intent(getActivity(), RetroActivityPast.class);
|
||||
|
||||
UserPreferences.updateConfigFile(getActivity());
|
||||
MainMenuFragment.startRetroActivity(
|
||||
retro,
|
||||
contentPath,
|
||||
corePath,
|
||||
UserPreferences.getDefaultConfigPath(getActivity()),
|
||||
Settings.Secure.getString(getActivity().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD),
|
||||
getActivity().getApplicationInfo().dataDir);
|
||||
startActivity(retro);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
// Used to represent data in the ListView after the user chooses an item.
|
||||
private static final class CoreItem
|
||||
{
|
||||
public final String Title;
|
||||
public final String Subtitle;
|
||||
|
||||
public CoreItem(String title, String subtitle)
|
||||
{
|
||||
this.Title = title;
|
||||
this.Subtitle = subtitle;
|
||||
}
|
||||
}
|
||||
|
||||
// Adapter that the ListView is flipped to after choosing a file to launch.
|
||||
private static final class CoreSelectionAdapter extends ArrayAdapter<CoreItem>
|
||||
{
|
||||
private final int resourceId;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context The current {@link Context}.
|
||||
* @param resourceId The resource ID for a layout file.
|
||||
*/
|
||||
public CoreSelectionAdapter(Context context, int resourceId)
|
||||
{
|
||||
super(context, resourceId);
|
||||
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
if (convertView == null)
|
||||
{
|
||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
convertView = inflater.inflate(resourceId, parent, false);
|
||||
}
|
||||
|
||||
final CoreItem core = getItem(position);
|
||||
if (core != null)
|
||||
{
|
||||
final TextView title = (TextView) convertView.findViewById(android.R.id.text1);
|
||||
final TextView subtitle = (TextView) convertView.findViewById(android.R.id.text2);
|
||||
|
||||
if (title != null)
|
||||
title.setText(core.Title);
|
||||
|
||||
if (subtitle != null)
|
||||
subtitle.setText(core.Subtitle);
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
}
|
@ -83,4 +83,4 @@ public final class MainMenuActivity extends FragmentActivity
|
||||
|
||||
setTitle(savedInstanceState.getCharSequence("title"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,115 +0,0 @@
|
||||
package com.retroarch.browser.preferences;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.preferences.fragments.AudioPreferenceFragment;
|
||||
import com.retroarch.browser.preferences.fragments.GeneralPreferenceFragment;
|
||||
import com.retroarch.browser.preferences.fragments.InputPreferenceFragment;
|
||||
import com.retroarch.browser.preferences.fragments.PathPreferenceFragment;
|
||||
import com.retroarch.browser.preferences.fragments.VideoPreferenceFragment;
|
||||
import com.retroarch.browser.preferences.fragments.util.PreferenceListFragment;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
|
||||
/**
|
||||
* {@link ActionBarActivity} responsible for handling all of the {@link PreferenceListFragment}s.
|
||||
* <p>
|
||||
* This class can be considered the central activity for the settings, as this class
|
||||
* provides the backbone for the {@link ViewPager} that handles all of the fragments being used.
|
||||
*/
|
||||
public final class PreferenceActivity extends ActionBarActivity implements OnSharedPreferenceChangeListener
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Set the ViewPager.
|
||||
setContentView(R.layout.preference_viewpager);
|
||||
|
||||
// Initialize the ViewPager.
|
||||
final ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
|
||||
viewPager.setAdapter(new PreferencesAdapter(getSupportFragmentManager()));
|
||||
|
||||
// Register the preference change listener.
|
||||
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
sPrefs.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
|
||||
{
|
||||
// Update the config file immediately when a preference has changed.
|
||||
UserPreferences.updateConfigFile(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link FragmentPagerAdapter} that will back
|
||||
* the view pager of this {@link PreferenceActivity}.
|
||||
*/
|
||||
private final class PreferencesAdapter extends FragmentPagerAdapter
|
||||
{
|
||||
private final String[] pageTitles = {
|
||||
getString(R.string.general_options),
|
||||
getString(R.string.audio_options),
|
||||
getString(R.string.input_options),
|
||||
getString(R.string.video_options),
|
||||
getString(R.string.path_options)
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param fm the {@link FragmentManager} for this adapter.
|
||||
*/
|
||||
public PreferencesAdapter(FragmentManager fm)
|
||||
{
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int fragmentId)
|
||||
{
|
||||
switch (fragmentId)
|
||||
{
|
||||
case 0:
|
||||
return new GeneralPreferenceFragment();
|
||||
|
||||
case 1:
|
||||
return new AudioPreferenceFragment();
|
||||
|
||||
case 2:
|
||||
return new InputPreferenceFragment();
|
||||
|
||||
case 3:
|
||||
return new VideoPreferenceFragment();
|
||||
|
||||
case 4:
|
||||
return new PathPreferenceFragment();
|
||||
|
||||
default: // Should never happen
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position)
|
||||
{
|
||||
return pageTitles[position];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.retroarch.browser.preferences.fragments;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.preferences.fragments.util.PreferenceListFragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* A {@link PreferenceListFragment} responsible for handling the audio preferences.
|
||||
*/
|
||||
public final class AudioPreferenceFragment extends PreferenceListFragment
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Add audio preferences from the XML.
|
||||
addPreferencesFromResource(R.xml.audio_preferences);
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.retroarch.browser.preferences.fragments;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.preferences.fragments.util.PreferenceListFragment;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
|
||||
/**
|
||||
* A {@link PreferenceListFragment} that handles the general settings.
|
||||
*/
|
||||
public final class GeneralPreferenceFragment extends PreferenceListFragment
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Add general preferences from the XML.
|
||||
addPreferencesFromResource(R.xml.general_preferences);
|
||||
|
||||
// Set a listener for the global configuration checkbox.
|
||||
final CheckBoxPreference usingGlobalConfig = (CheckBoxPreference) findPreference("global_config_enable");
|
||||
usingGlobalConfig.setOnPreferenceClickListener(new OnPreferenceClickListener(){
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference)
|
||||
{
|
||||
UserPreferences.updateConfigFile(getActivity());
|
||||
UserPreferences.readbackConfigFile(getActivity());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package com.retroarch.browser.preferences.fragments;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.dirfragment.DirectoryFragment;
|
||||
import com.retroarch.browser.preferences.fragments.util.PreferenceListFragment;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
import android.provider.Settings;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
/**
|
||||
* A {@link PreferenceListFragment} responsible for handling the input preferences.
|
||||
*/
|
||||
public final class InputPreferenceFragment extends PreferenceListFragment implements OnPreferenceClickListener
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Add input preferences from the XML.
|
||||
addPreferencesFromResource(R.xml.input_preferences);
|
||||
|
||||
// Set preference listeners
|
||||
findPreference("set_ime_pref").setOnPreferenceClickListener(this);
|
||||
findPreference("report_ime_pref").setOnPreferenceClickListener(this);
|
||||
findPreference("inputOverlayDirPref").setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference)
|
||||
{
|
||||
final String prefKey = preference.getKey();
|
||||
|
||||
// Set Input Method preference
|
||||
if (prefKey.equals("set_ime_pref"))
|
||||
{
|
||||
// Show an IME picker so the user can change their set IME.
|
||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showInputMethodPicker();
|
||||
}
|
||||
// Report IME preference
|
||||
else if (prefKey.equals("report_ime_pref"))
|
||||
{
|
||||
final String currentIme = Settings.Secure.getString(getActivity().getContentResolver(),
|
||||
Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
|
||||
AlertDialog.Builder reportImeDialog = new AlertDialog.Builder(getActivity());
|
||||
reportImeDialog.setTitle(R.string.current_ime);
|
||||
reportImeDialog.setMessage(currentIme);
|
||||
reportImeDialog.setNegativeButton(R.string.close, null);
|
||||
reportImeDialog.show();
|
||||
}
|
||||
// Input Overlay selection
|
||||
else if (prefKey.equals("inputOverlayDirPref"))
|
||||
{
|
||||
final DirectoryFragment overlayBrowser = DirectoryFragment.newInstance(R.string.input_overlay_select);
|
||||
File overlayDir = new File(getActivity().getApplicationInfo().dataDir, "overlays");
|
||||
if (overlayDir.exists())
|
||||
overlayBrowser.setStartDirectory(overlayDir.getAbsolutePath());
|
||||
|
||||
overlayBrowser.addAllowedExts(".cfg");
|
||||
overlayBrowser.setPathSettingKey("input_overlay");
|
||||
overlayBrowser.show(getFragmentManager(), "overlayBrowser");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package com.retroarch.browser.preferences.fragments;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.dirfragment.DirectoryFragment;
|
||||
import com.retroarch.browser.preferences.fragments.util.PreferenceListFragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
|
||||
/**
|
||||
* A {@link PreferenceListFragment} that handles the path preferences.
|
||||
*/
|
||||
public final class PathPreferenceFragment extends PreferenceListFragment implements OnPreferenceClickListener
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Add path preferences from the XML.
|
||||
addPreferencesFromResource(R.xml.path_preferences);
|
||||
|
||||
// Set preference click listeners
|
||||
findPreference("romDirPref").setOnPreferenceClickListener(this);
|
||||
findPreference("srmDirPref").setOnPreferenceClickListener(this);
|
||||
findPreference("saveStateDirPref").setOnPreferenceClickListener(this);
|
||||
findPreference("systemDirPref").setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference)
|
||||
{
|
||||
final String prefKey = preference.getKey();
|
||||
|
||||
// Custom ROM directory
|
||||
if (prefKey.equals("romDirPref"))
|
||||
{
|
||||
final DirectoryFragment romDirBrowser = DirectoryFragment.newInstance(R.string.rom_directory_select);
|
||||
romDirBrowser.setPathSettingKey("rgui_browser_directory");
|
||||
romDirBrowser.setIsDirectoryTarget(true);
|
||||
romDirBrowser.show(getFragmentManager(), "romDirBrowser");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package com.retroarch.browser.preferences.fragments;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.preferences.fragments.util.PreferenceListFragment;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* A {@link PreferenceListFragment} responsible for handling the video preferences.
|
||||
*/
|
||||
public final class VideoPreferenceFragment extends PreferenceListFragment implements OnPreferenceClickListener
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Add preferences from the resources
|
||||
addPreferencesFromResource(R.xml.video_preferences);
|
||||
|
||||
// Set preference click listeners
|
||||
findPreference("set_os_reported_ref_rate_pref").setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference)
|
||||
{
|
||||
final String prefKey = preference.getKey();
|
||||
|
||||
// Set OS-reported refresh rate preference.
|
||||
if (prefKey.equals("set_os_reported_ref_rate_pref"))
|
||||
{
|
||||
final WindowManager wm = getActivity().getWindowManager();
|
||||
final Display display = wm.getDefaultDisplay();
|
||||
final double rate = display.getRefreshRate();
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
edit.putString("video_refresh_rate", Double.toString(rate));
|
||||
edit.apply();
|
||||
|
||||
Toast.makeText(getActivity(), String.format(getString(R.string.using_os_reported_refresh_rate), rate), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package com.retroarch.browser.preferences.util;
|
||||
|
||||
import com.retroarch.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public final class SeekbarPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
private float seek_value;
|
||||
private SeekBar bar;
|
||||
private TextView text;
|
||||
private final Context context;
|
||||
|
||||
public SeekbarPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView()
|
||||
{
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(R.layout.seek_dialog, null);
|
||||
this.bar = (SeekBar) view.findViewById(R.id.seekbar_bar);
|
||||
this.text = (TextView) view.findViewById(R.id.seekbar_text);
|
||||
this.seek_value = getPersistedFloat(1.0f);
|
||||
|
||||
// Set initial progress for seek bar and set the listener.
|
||||
int prog = (int) (seek_value * 100);
|
||||
this.bar.setProgress(prog);
|
||||
this.text.setText(prog + "%");
|
||||
this.bar.setOnSeekBarChangeListener(this);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult) {
|
||||
persistFloat(seek_value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
seek_value = (float) progress / 100.0f;
|
||||
text.setText((int) (seek_value * 100) + "%");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user