Merge pull request #440 from LoungeKatt/master
Add game information to launch process
This commit is contained in:
commit
a937428115
|
@ -11,6 +11,7 @@
|
|||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<uses-feature
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:text="Something Wrong?"
|
||||
android:text="@string/disk_loading"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textSize="18dp" />
|
||||
</LinearLayout>
|
||||
|
|
|
@ -78,6 +78,41 @@
|
|||
android:text="Browse" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="6dp"
|
||||
android:stretchColumns="*" >
|
||||
|
||||
<TableRow
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/details_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.5"
|
||||
android:ems="10"
|
||||
android:gravity="center_vertical|left"
|
||||
android:text="@string/select_details" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<de.ankri.views.Switch
|
||||
android:id="@+id/details_option"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="true" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
<string name="optimization_opts">Optimization and Debugging Options</string>
|
||||
<string name="experimental_opts">Experimental (May cause widespread panic)</string>
|
||||
<string name="select_details">Enable Game Details</string>
|
||||
<string name="select_native">Enable Native Interface</string>
|
||||
<string name="select_dynarec">Dynarec Options</string>
|
||||
<string name="select_unstable">Unstable Optimisations</string>
|
||||
|
@ -42,6 +43,10 @@
|
|||
|
||||
<string name="games_listing">Game List</string>
|
||||
|
||||
<string name="game_details">Game Info - %1$s</string>
|
||||
<string name="info_unavailable">Game Info Unavailable</string>
|
||||
<string name="disk_loading">Loading Disk Info</string>
|
||||
|
||||
<string name="report_issue">Previous Crash Detected</string>
|
||||
<string name="bios_config">Configuration failed!</string>
|
||||
|
||||
|
|
|
@ -17,7 +17,9 @@ import java.util.Locale;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
@ -200,7 +202,7 @@ public class FileBrowser extends Fragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<File> games) {
|
||||
protected void onPostExecute(List<File> items) {
|
||||
final LinearLayout list = (LinearLayout) parentActivity.findViewById(R.id.game_list);
|
||||
if (list != null) {
|
||||
list.removeAllViews();
|
||||
|
@ -208,9 +210,9 @@ public class FileBrowser extends Fragment {
|
|||
|
||||
String heading = parentActivity.getString(R.string.games_listing);
|
||||
createListHeader(heading, list, true);
|
||||
if (games != null && !games.isEmpty()) {
|
||||
for (final File game : games) {
|
||||
createListItem(list, game);
|
||||
if (items != null && !items.isEmpty()) {
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
createListItem(list, items.get(i), i);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(parentActivity, R.string.config_game, Toast.LENGTH_LONG).show();
|
||||
|
@ -284,22 +286,13 @@ public class FileBrowser extends Fragment {
|
|||
|
||||
}
|
||||
|
||||
private void createListItem(LinearLayout list, final File game) {
|
||||
final String name = game.getName();
|
||||
final String nameLower = name.toLowerCase(Locale.getDefault());
|
||||
private void createListItem(LinearLayout list, final File game, final int index) {
|
||||
final View childview = parentActivity.getLayoutInflater().inflate(
|
||||
R.layout.app_list_item, null, false);
|
||||
|
||||
((TextView) childview.findViewById(R.id.item_name)).setText(name);
|
||||
|
||||
((ImageView) childview.findViewById(R.id.item_icon))
|
||||
.setImageResource(game.isDirectory() ? R.drawable.open_folder
|
||||
: nameLower.endsWith(".gdi") ? R.drawable.gdi
|
||||
: nameLower.endsWith(".cdi") ? R.drawable.cdi
|
||||
: nameLower.endsWith(".chd") ? R.drawable.chd
|
||||
: R.drawable.disk_unknown);
|
||||
|
||||
childview.setTag(name);
|
||||
|
||||
final XMLParser xmlParser = new XMLParser(game, index);
|
||||
xmlParser.setViewParent(parentActivity, childview);
|
||||
xmlParser.execute(game.getName());
|
||||
|
||||
orig_bg = childview.getBackground();
|
||||
|
||||
|
@ -309,9 +302,36 @@ public class FileBrowser extends Fragment {
|
|||
new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
vib.vibrate(50);
|
||||
mCallback.onGameSelected(game != null ? Uri
|
||||
.fromFile(game) : Uri.EMPTY);
|
||||
vib.vibrate(250);
|
||||
if (mPrefs.getBoolean(Config.pref_gamedetails, true)) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
||||
builder.setCancelable(true);
|
||||
builder.setTitle(getString(R.string.game_details,
|
||||
xmlParser.getGameTitle()));
|
||||
builder.setMessage(xmlParser.game_details.get(index));
|
||||
builder.setIcon(xmlParser.getGameIcon());
|
||||
builder.setPositiveButton("Close",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
return;
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton("Launch",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
mCallback.onGameSelected(game != null ? Uri
|
||||
.fromFile(game) : Uri.EMPTY);
|
||||
vib.vibrate(250);
|
||||
return;
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
} else {
|
||||
mCallback.onGameSelected(game != null ? Uri
|
||||
.fromFile(game) : Uri.EMPTY);
|
||||
vib.vibrate(250);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -325,7 +345,6 @@ public class FileBrowser extends Fragment {
|
|||
|| arg1.getActionMasked() == MotionEvent.ACTION_UP) {
|
||||
view.setBackgroundDrawable(orig_bg);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ public class GL2JNIActivity extends Activity {
|
|||
if (pad.custom[playerNum] || pad.compat[playerNum]) {
|
||||
pad.joystick[playerNum] = prefs.getBoolean(Gamepad.pref_js_separate + id, false);
|
||||
} else {
|
||||
pad.joystick[playerNum] = false;
|
||||
pad.joystick[playerNum] = true;
|
||||
}
|
||||
if (InputDevice.getDevice(joy).getName()
|
||||
.contains(Gamepad.controllers_gamekey)) {
|
||||
|
|
|
@ -166,7 +166,7 @@ public class GL2JNINative extends NativeActivity {
|
|||
if (pad.custom[playerNum] || pad.compat[playerNum]) {
|
||||
pad.joystick[playerNum] = prefs.getBoolean(Gamepad.pref_js_separate + id, false);
|
||||
} else {
|
||||
pad.joystick[playerNum] = false;
|
||||
pad.joystick[playerNum] = true;
|
||||
}
|
||||
if (InputDevice.getDevice(joy).getName()
|
||||
.contains(Gamepad.controllers_gamekey)) {
|
||||
|
|
|
@ -0,0 +1,245 @@
|
|||
package com.reicast.emulator;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.StrictMode;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class XMLParser extends AsyncTask<String, Integer, String> {
|
||||
|
||||
private File game;
|
||||
private int index;
|
||||
private View childview;
|
||||
private Context mContext;
|
||||
private String game_name;
|
||||
private Drawable game_icon;
|
||||
|
||||
private static final String game_index = "http://thegamesdb.net/api/GetGame.php?platform=sega+dreamcast&name=";
|
||||
public SparseArray<String> game_details = new SparseArray<String>();
|
||||
public SparseArray<Bitmap> game_preview = new SparseArray<Bitmap>();
|
||||
|
||||
public XMLParser(File game, int index) {
|
||||
this.game = game;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public void setViewParent(Context mContext, View childview) {
|
||||
this.mContext = mContext;
|
||||
this.childview = childview;
|
||||
}
|
||||
|
||||
protected void onPreExecute() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
|
||||
.permitAll().build();
|
||||
StrictMode.setThreadPolicy(policy);
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap decodeBitmapIcon(String filename) throws IOException {
|
||||
URL updateURL = new URL(filename);
|
||||
URLConnection conn1 = updateURL.openConnection();
|
||||
InputStream im = conn1.getInputStream();
|
||||
BufferedInputStream bis = new BufferedInputStream(im, 512);
|
||||
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(bis, null, options);
|
||||
|
||||
int heightRatio = (int) Math.ceil(options.outHeight / (float) 72);
|
||||
int widthRatio = (int) Math.ceil(options.outWidth / (float) 72);
|
||||
|
||||
if (heightRatio > 1 || widthRatio > 1) {
|
||||
if (heightRatio > widthRatio) {
|
||||
options.inSampleSize = heightRatio;
|
||||
} else {
|
||||
options.inSampleSize = widthRatio;
|
||||
}
|
||||
}
|
||||
|
||||
options.inJustDecodeBounds = false;
|
||||
bis.close();
|
||||
im.close();
|
||||
conn1 = updateURL.openConnection();
|
||||
im = conn1.getInputStream();
|
||||
bis = new BufferedInputStream(im, 512);
|
||||
bitmap = BitmapFactory.decodeStream(bis, null, options);
|
||||
|
||||
bis.close();
|
||||
im.close();
|
||||
bis = null;
|
||||
im = null;
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
if (isNetworkAvailable()) {
|
||||
String filename = game_name = params[0];
|
||||
if (params[0].contains("[")) {
|
||||
filename = params[0].substring(0, params[0].lastIndexOf("["));
|
||||
} else {
|
||||
filename = params[0].substring(0, params[0].lastIndexOf("."));
|
||||
}
|
||||
filename = filename.replace(" ", "+").replace("_", "+");
|
||||
if (filename.endsWith("+")) {
|
||||
filename = filename.substring(0, filename.length() - 1);
|
||||
}
|
||||
try {
|
||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
||||
HttpPost httpPost = new HttpPost(game_index + filename);
|
||||
|
||||
HttpResponse httpResponse = httpClient.execute(httpPost);
|
||||
HttpEntity httpEntity = httpResponse.getEntity();
|
||||
return EntityUtils.toString(httpEntity);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
|
||||
} catch (ClientProtocolException e) {
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String gameData) {
|
||||
if (gameData != null) {
|
||||
Document doc = getDomElement(gameData);
|
||||
if (doc != null && doc.getElementsByTagName("Game") != null) {
|
||||
Element root = (Element) doc.getElementsByTagName("Game").item(
|
||||
0);
|
||||
game_name = getValue(root, "GameTitle");
|
||||
String details = getValue(root, "Overview");
|
||||
game_details.put(index, details);
|
||||
Element boxart = (Element) root.getElementsByTagName("Images")
|
||||
.item(0);
|
||||
String image = "http://thegamesdb.net/banners/"
|
||||
+ getValue(boxart, "boxart");
|
||||
try {
|
||||
game_preview.put(index, decodeBitmapIcon(image));
|
||||
game_icon = new BitmapDrawable(decodeBitmapIcon(image));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
game_details.put(index, mContext.getString(R.string.info_unavailable));
|
||||
final String nameLower = game.getName().toLowerCase(Locale.getDefault());
|
||||
game_icon = mContext.getResources().getDrawable(
|
||||
game.isDirectory() ? R.drawable.open_folder : nameLower
|
||||
.endsWith(".gdi") ? R.drawable.gdi : nameLower
|
||||
.endsWith(".cdi") ? R.drawable.cdi : nameLower
|
||||
.endsWith(".chd") ? R.drawable.chd
|
||||
: R.drawable.disk_unknown);
|
||||
|
||||
}
|
||||
|
||||
((TextView) childview.findViewById(R.id.item_name)).setText(game_name);
|
||||
|
||||
((ImageView) childview.findViewById(R.id.item_icon))
|
||||
.setImageDrawable(game_icon);
|
||||
|
||||
childview.setTag(game_name);
|
||||
}
|
||||
|
||||
private boolean isNetworkAvailable() {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) mContext
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo activeNetworkInfo = connectivityManager
|
||||
.getActiveNetworkInfo();
|
||||
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
|
||||
}
|
||||
|
||||
public Drawable getGameIcon() {
|
||||
return game_icon;
|
||||
}
|
||||
|
||||
public String getGameTitle() {
|
||||
return game_name;
|
||||
}
|
||||
|
||||
public Document getDomElement(String xml) {
|
||||
Document doc = null;
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
try {
|
||||
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
|
||||
InputSource is = new InputSource();
|
||||
is.setCharacterStream(new StringReader(xml));
|
||||
doc = db.parse(is);
|
||||
|
||||
} catch (ParserConfigurationException e) {
|
||||
|
||||
return null;
|
||||
} catch (SAXException e) {
|
||||
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
public String getValue(Element item, String str) {
|
||||
NodeList n = item.getElementsByTagName(str);
|
||||
return this.getElementValue(n.item(0));
|
||||
}
|
||||
|
||||
public final String getElementValue(Node elem) {
|
||||
Node child;
|
||||
if (elem != null) {
|
||||
if (elem.hasChildNodes()) {
|
||||
for (child = elem.getFirstChild(); child != null; child = child
|
||||
.getNextSibling()) {
|
||||
if (child.getNodeType() == Node.TEXT_NODE) {
|
||||
return child.getNodeValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ public class Config {
|
|||
public static final String pref_home = "home_directory";
|
||||
public static final String pref_games = "game_directory";
|
||||
|
||||
public static final String pref_gamedetails = "game_details";
|
||||
public static final String pref_nativeact = "enable_native";
|
||||
public static final String pref_dynarecopt = "dynarec_opt";
|
||||
public static final String pref_unstable = "unstable_opt";
|
||||
|
|
|
@ -14,11 +14,15 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.reicast.emulator.R;
|
||||
|
||||
import de.ankri.views.Switch;
|
||||
|
||||
public class OptionsFragment extends Fragment {
|
||||
|
||||
private Button mainBrowse;
|
||||
|
@ -99,6 +103,18 @@ public class OptionsFragment extends Fragment {
|
|||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
});
|
||||
|
||||
OnCheckedChangeListener details_options = new OnCheckedChangeListener() {
|
||||
|
||||
public void onCheckedChanged(CompoundButton buttonView,
|
||||
boolean isChecked) {
|
||||
mPrefs.edit().putBoolean(Config.pref_gamedetails, isChecked).commit();
|
||||
}
|
||||
};
|
||||
Switch details_opt = (Switch) getView().findViewById(
|
||||
R.id.details_option);
|
||||
details_opt.setChecked(mPrefs.getBoolean(Config.pref_gamedetails, true));
|
||||
details_opt.setOnCheckedChangeListener(details_options);
|
||||
|
||||
gameBrowse = (Button) getView().findViewById(R.id.browse_game_path);
|
||||
|
||||
|
|
Loading…
Reference in New Issue