[Android] Initial skeleton for the core manager. Not functional yet.

This commit is contained in:
Lioncash 2013-10-30 00:55:41 -04:00
parent e51cecbff4
commit 8453002ee0
10 changed files with 398 additions and 0 deletions

View File

@ -38,6 +38,7 @@
<activity android:name="com.retroarch.browser.diractivities.StateDirActivity"/>
<activity android:name="com.retroarch.browser.diractivities.SystemDirActivity"/>
<activity android:name="com.retroarch.browser.preferences.fragments.PreferenceActivity" android:theme="@style/Theme.AppCompat" />
<activity android:name="com.retroarch.browser.coremanager.CoreManagerActivity" android:theme="@style/Theme.AppCompat"/>
<activity android:name="com.retroarch.browser.RetroActivity" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<meta-data android:name="android.app.lib_name" android:value="retroarch-activity" />

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="3dp">
<ImageView
android:id="@+id/CoreManagerListItemIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"/>
<TextView
android:id="@+id/CoreManagerListItemSubTitle"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_toRightOf="@id/CoreManagerListItemIcon"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"/>
<TextView
android:id="@+id/CoreManagerListItemTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/CoreManagerListItemIcon"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_above="@id/CoreManagerListItemSubTitle"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:textStyle="bold" />
</RelativeLayout>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>

View File

@ -0,0 +1,5 @@
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/coreviewer_viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -16,6 +16,7 @@
<string name="load_core">Load Core</string>
<string name="load_game">Load Game</string>
<string name="load_game_history">Load Game (History)</string>
<string name="manage_cores">Manage Cores</string>
<string name="settings">Settings</string>
<string name="help">Help</string>
<string name="about">About</string>
@ -23,6 +24,10 @@
<!-- Core Selection Class -->
<string name="select_libretro_core">Select Libretro core</string>
<!-- Core Manager -->
<string name="installed_cores">Installed Cores</string>
<string name="downloadable_cores">Downloadable Cores</string>
<!-- Display Refresh Rate Test Class -->
<string name="refresh_rate_calibration">Refresh rate calibration</string>
<string name="touch_screen_with_fingers">Touch the screen with your fingers for more accurate measurements.</string>
@ -148,6 +153,8 @@
<!-- General Settings -->
<string name="general_options">General</string>
<string name="core_management">Core Management</string>
<string name="manage_cores">Manage Cores</string>
<string name="config_style">Configuration style</string>
<string name="global_config">Global configuration</string>
<string name="global_config_desc">Enable global settings for all cores. Leave disabled if you want per-core settings.</string>

View File

@ -1,6 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Core Management -->
<PreferenceCategory android:title="@string/core_management">
<Preference
android:title="@string/manage_cores">
<intent
android:targetClass="com.retroarch.browser.coremanager.CoreManagerActivity"
android:targetPackage="com.retroarch"/>
</Preference>
</PreferenceCategory>
<!-- Configuration Style -->
<PreferenceCategory android:title="@string/config_style" >
<CheckBoxPreference

View File

@ -0,0 +1,129 @@
package com.retroarch.browser.coremanager;
import com.retroarch.R;
import com.retroarch.browser.coremanager.fragments.DownloadableCoresFragment;
import com.retroarch.browser.coremanager.fragments.InstalledCoresFragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.Tab;
import android.support.v7.app.ActionBar.TabListener;
import android.support.v7.app.ActionBarActivity;
/**
* Activity which provides the base for viewing installed cores,
* as well as the ability to download other cores.
*/
public final class CoreManagerActivity extends ActionBarActivity implements TabListener
{
// ViewPager for the fragments
private ViewPager viewPager;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set the ViewPager
setContentView(R.layout.coremanager_viewpager);
viewPager = (ViewPager) findViewById(R.id.coreviewer_viewPager);
// Set the ViewPager adapter.
final ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
// Initialize the ActionBar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.addTab(actionBar.newTab().setText(R.string.installed_cores).setTabListener(this));
actionBar.addTab(actionBar.newTab().setText(R.string.downloadable_cores).setTabListener(this));
// 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.
viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
{
@Override
public void onPageSelected(int position)
{
actionBar.setSelectedNavigationItem(position);
}
});
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft)
{
// Switch to the fragment indicated by the tab's position.
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft)
{
// Do nothing. Not used.
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft)
{
// Do nothing. Not used.
}
// Adapter for the CoreView ViewPager class.
private final class ViewPagerAdapter extends FragmentPagerAdapter
{
/**
* Constructor
*
* @param fm The {@link FragmentManager} for this adapter.
*/
public ViewPagerAdapter(FragmentManager fm)
{
super(fm);
}
@Override
public Fragment getItem(int position)
{
switch (position)
{
case 0:
return new InstalledCoresFragment();
case 1:
return new DownloadableCoresFragment();
default: // Should never happen.
return null;
}
}
@Override
public int getCount()
{
return 2;
}
@Override
public CharSequence getPageTitle(int position)
{
switch (position)
{
case 0:
return getString(R.string.installed_cores);
case 1:
return getString(R.string.downloadable_cores);
default: // Should never happen.
return null;
}
}
}
}

View File

@ -0,0 +1,69 @@
package com.retroarch.browser.coremanager;
import java.io.File;
/**
* Represents a list item within the CoreManager fragments.
*/
public final class CoreManagerListItem
{
private final String name;
private final String subtitle;
private final String path;
private final File underlyingFile;
/**
* Constructor
*
* @param name The name of the core represented by this CoreManagerListItem.
* @param subtitle The subtitle description of the core represented by this CoreManagerListItem.
* @param path The path to the core represented by this CoreManagerListItem.
*/
public CoreManagerListItem(String name, String subtitle, String path)
{
this.name = name;
this.subtitle = subtitle;
this.path = path;
this.underlyingFile = new File(path);
}
/**
* Gets the name of the core represented by this CoreManagerListItem.
*
* @return the name of the core represented by this CoreManagerListItem.
*/
public String getName()
{
return name;
}
/**
* Gets the subtitle description of the core represented by this CoreManagerListItem.
*
* @return the subtitle description of the core represented by this CoreManagerListItem.
*/
public String getSubtitle()
{
return subtitle;
}
/**
* Gets the path to the core represented by this CoreManagerListItem.
*
* @return the path to the core represented by this CoreManagerListItem.
*/
public String getPath()
{
return path;
}
/**
* Gets the underlying {@link File} instance to the core represented by this CoreManagerListItem.
*
* @return the underlying {@link File} instance to the core represented by this CoreManagerListItem.
*/
public File getUnderlyingFile()
{
return underlyingFile;
}
}

View File

@ -0,0 +1,12 @@
package com.retroarch.browser.coremanager.fragments;
import android.support.v4.app.ListFragment;
/**
* {@link ListFragment} that is responsible for showing
* cores that are able to be downloaded or are not installed..
*/
public final class DownloadableCoresFragment extends ListFragment
{
}

View File

@ -0,0 +1,115 @@
package com.retroarch.browser.coremanager.fragments;
import java.util.ArrayList;
import java.util.List;
import com.retroarch.R;
import com.retroarch.browser.coremanager.CoreManagerListItem;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
/**
* {@link ListFragment} that displays all of the currently installed cores
*/
public final class InstalledCoresFragment extends ListFragment
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// List which will contain all of the items for the list.
List<CoreManagerListItem> items = new ArrayList<CoreManagerListItem>();
// TODO: Populate list adapter.
// Set the list adapter.
final InstalledCoresAdapter adapter = new InstalledCoresAdapter(getActivity(), R.layout.coremanager_list_item, items);
setListAdapter(adapter);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Inflate the layout for this ListFragment.
View parentView = inflater.inflate(R.layout.coremanager_listview_layout, container, false);
return parentView.findViewById(android.R.id.list);
}
/**
* The {@link ArrayAdapter} that backs this InstalledCoresFragment.
*/
private final class InstalledCoresAdapter extends ArrayAdapter<CoreManagerListItem>
{
private final Context context;
private final int resourceId;
private final List<CoreManagerListItem> items;
/**
* Constructor
*
* @param context The current {@link Context}.
* @param resourceId The resource ID for a layout file containing a layout to use when instantiating views.
* @param objects The items to represent in the {@link ListView}.
*/
public InstalledCoresAdapter(Context context, int resourceId, List<CoreManagerListItem> items)
{
super(context, resourceId, items);
this.context = context;
this.resourceId = resourceId;
this.items = items;
}
@Override
public CoreManagerListItem getItem(int i)
{
return items.get(i);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
LayoutInflater vi = LayoutInflater.from(context);
convertView = vi.inflate(resourceId, parent, false);
}
final CoreManagerListItem item = items.get(position);
if (item != null)
{
TextView title = (TextView) convertView.findViewById(R.id.CoreManagerListItemTitle);
TextView subtitle = (TextView) convertView.findViewById(R.id.CoreManagerListItemSubTitle);
ImageView icon = (ImageView) convertView.findViewById(R.id.CoreManagerListItemIcon);
if (title != null)
{
title.setText(item.getName());
}
if (subtitle != null)
{
subtitle.setText(item.getSubtitle());
}
if (icon != null)
{
// TODO: Set core icon.
}
}
return convertView;
}
}
}