Merge pull request #704 from AbandonedCart/loungekatt
XMLParser and GLES 3 cleanup
This commit is contained in:
commit
a3f66be3ce
|
@ -28,7 +28,6 @@ import android.graphics.Typeface;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Vibrator;
|
||||
|
@ -38,7 +37,6 @@ import android.view.LayoutInflater;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnLongClickListener;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
@ -370,8 +368,8 @@ public class FileBrowser extends Fragment {
|
|||
final View childview = parentActivity.getLayoutInflater().inflate(
|
||||
R.layout.app_list_item, null, false);
|
||||
|
||||
final XMLParser xmlParser = new XMLParser(game, index, mPrefs);
|
||||
xmlParser.setViewParent(parentActivity, childview);
|
||||
XMLParser xmlParser = new XMLParser(game, index, mPrefs);
|
||||
xmlParser.setViewParent(parentActivity, childview, mCallback);
|
||||
orig_bg = childview.getBackground();
|
||||
|
||||
childview.findViewById(R.id.childview).setOnClickListener(
|
||||
|
@ -398,40 +396,6 @@ public class FileBrowser extends Fragment {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (mPrefs.getBoolean(Config.pref_gamedetails, false) && isGame) {
|
||||
childview.findViewById(R.id.childview).setOnLongClickListener(
|
||||
new OnLongClickListener() {
|
||||
public boolean onLongClick(View view) {
|
||||
vib.vibrate(50);
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
||||
builder.setCancelable(true);
|
||||
builder.setTitle(getString(R.string.game_details,
|
||||
xmlParser.getGameTitle()));
|
||||
builder.setMessage(xmlParser.getGameDetails());
|
||||
builder.setIcon(xmlParser.getGameIcon());
|
||||
builder.setNegativeButton("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();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
childview.findViewById(R.id.childview).setOnTouchListener(
|
||||
new OnTouchListener() {
|
||||
|
|
|
@ -2,12 +2,15 @@ package com.reicast.emulator;
|
|||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StringReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
|
@ -27,9 +30,9 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.reicast.emulator.config.Config;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
@ -37,27 +40,35 @@ import android.graphics.drawable.BitmapDrawable;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.StrictMode;
|
||||
import android.util.SparseArray;
|
||||
import android.os.Vibrator;
|
||||
import android.view.View;
|
||||
import android.view.View.OnLongClickListener;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.reicast.emulator.FileBrowser.OnItemSelectedListener;
|
||||
import com.reicast.emulator.config.Config;
|
||||
|
||||
public class XMLParser extends AsyncTask<String, Integer, String> {
|
||||
|
||||
private SharedPreferences mPrefs;
|
||||
private File game;
|
||||
private int index;
|
||||
private View childview;
|
||||
private OnItemSelectedListener mCallback;
|
||||
private Context mContext;
|
||||
private String game_name;
|
||||
private Bitmap coverart;
|
||||
private Drawable game_icon;
|
||||
private String gameId;
|
||||
private String game_details;
|
||||
|
||||
private static final String game_index = "http://thegamesdb.net/api/GetGame.php?platform=sega+dreamcast&name=";
|
||||
private SparseArray<String> game_details = new SparseArray<String>();
|
||||
private SparseArray<Bitmap> game_preview = new SparseArray<Bitmap>();
|
||||
private static final String game_index = "http://thegamesdb.net/api/GetGamesList.php?platform=sega+dreamcast&name=";
|
||||
private static final String game_id = "http://thegamesdb.net/api/GetGame.php?platform=sega+dreamcast&id=";
|
||||
|
||||
public XMLParser(File game, int index, SharedPreferences mPrefs) {
|
||||
this.mPrefs = mPrefs;
|
||||
|
@ -65,9 +76,15 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
|||
this.index = index;
|
||||
}
|
||||
|
||||
public void setViewParent(Context mContext, View childview) {
|
||||
public void setViewParent(Context mContext, View childview, OnItemSelectedListener mCallback) {
|
||||
this.mContext = mContext;
|
||||
this.childview = childview;
|
||||
this.mCallback = mCallback;
|
||||
}
|
||||
|
||||
public void setGameID(String id) {
|
||||
this.gameId = id;
|
||||
initializeDefaults();
|
||||
}
|
||||
|
||||
protected void onPreExecute() {
|
||||
|
@ -79,63 +96,72 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
|||
}
|
||||
|
||||
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;
|
||||
String index = filename.substring(filename.lastIndexOf("/") + 1, filename.lastIndexOf("."));
|
||||
File file = new File(mContext.getExternalFilesDir(null) + "/images", index + ".png");
|
||||
if (file.exists()) {
|
||||
return BitmapFactory.decodeFile(file.getAbsolutePath());
|
||||
} else {
|
||||
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;
|
||||
OutputStream fOut = null;
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdir();
|
||||
}
|
||||
try {
|
||||
fOut = new FileOutputStream(file, false);
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
|
||||
fOut.flush();
|
||||
fOut.close();
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
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) {
|
||||
String filename = game_name = params[0];
|
||||
if (isNetworkAvailable() && mPrefs.getBoolean(Config.pref_gamedetails, false)) {
|
||||
if (filename.startsWith("[")) {
|
||||
filename = filename.substring(filename.indexOf("]") + 1, filename.length());
|
||||
}
|
||||
if (filename.contains("[")) {
|
||||
filename = filename.substring(0, filename.indexOf("["));
|
||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
||||
HttpPost httpPost;
|
||||
if (gameId != null) {
|
||||
httpPost = new HttpPost(game_id + gameId);
|
||||
} else {
|
||||
filename = filename.substring(0, filename.lastIndexOf("."));
|
||||
}
|
||||
filename = filename.replace("_", " ").replace(":", " ");
|
||||
filename = filename.replaceAll("[^\\p{Alpha}\\p{Digit}]+"," ");
|
||||
filename = filename.replace(" ", " ").replace(" ", "+");
|
||||
if (filename.endsWith("+")) {
|
||||
filename = filename.substring(0, filename.length() - 1);
|
||||
try {
|
||||
filename = URLEncoder.encode(filename, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
filename = filename.replace(" ", "+");
|
||||
}
|
||||
httpPost = new HttpPost(game_index + filename);
|
||||
}
|
||||
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);
|
||||
|
@ -157,37 +183,76 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
|||
Document doc = getDomElement(gameData);
|
||||
if (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 images = (Element) root.getElementsByTagName("Images").item(0);
|
||||
Element boxart = (Element) images.getElementsByTagName("boxart").item(1);
|
||||
String image = "http://thegamesdb.net/banners/" + getElementValue(boxart);
|
||||
game_preview.put(index, decodeBitmapIcon(image));
|
||||
game_icon = new BitmapDrawable(decodeBitmapIcon(image));
|
||||
} else {
|
||||
initializeDefaults();
|
||||
if (gameId == null) {
|
||||
XMLParser xmlParser = new XMLParser(game, index, mPrefs);
|
||||
xmlParser.setViewParent(mContext, childview, mCallback);
|
||||
xmlParser.setGameID(getValue(root, "id"));
|
||||
xmlParser.execute(game_name);
|
||||
} else {
|
||||
game_name = getValue(root, "GameTitle");
|
||||
game_details = getValue(root, "Overview");
|
||||
Element images = (Element) root.getElementsByTagName("Images").item(0);
|
||||
Element boxart = null;
|
||||
if (images.getElementsByTagName("boxart").getLength() > 1) {
|
||||
boxart = (Element) images.getElementsByTagName("boxart").item(1);
|
||||
} else if (images.getElementsByTagName("boxart").getLength() == 1) {
|
||||
boxart = (Element) images.getElementsByTagName("boxart").item(0);
|
||||
}
|
||||
if (boxart != null) {
|
||||
coverart = decodeBitmapIcon("http://thegamesdb.net/banners/" + getElementValue(boxart));
|
||||
game_icon = new BitmapDrawable(coverart);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
initializeDefaults();
|
||||
|
||||
}
|
||||
} else {
|
||||
initializeDefaults();
|
||||
}
|
||||
|
||||
((TextView) childview.findViewById(R.id.item_name)).setText(game_name);
|
||||
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
((ImageView) childview.findViewById(R.id.item_icon))
|
||||
.setImageDrawable(game_icon);
|
||||
((ImageView) childview.findViewById(R.id.item_icon)).setImageDrawable(game_icon);
|
||||
} else {
|
||||
((ImageView) childview.findViewById(R.id.item_icon)).setImageBitmap(coverart);
|
||||
}
|
||||
|
||||
if (mPrefs.getBoolean(Config.pref_gamedetails, false)) {
|
||||
childview.findViewById(R.id.childview).setOnLongClickListener(
|
||||
new OnLongClickListener() {
|
||||
public boolean onLongClick(View view) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||
builder.setCancelable(true);
|
||||
builder.setTitle(mContext.getString(R.string.game_details, game_name));
|
||||
builder.setMessage(game_details);
|
||||
builder.setIcon(game_icon);
|
||||
builder.setNegativeButton("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);
|
||||
((Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(250);
|
||||
return;
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
childview.setTag(game_name);
|
||||
}
|
||||
|
||||
private void initializeDefaults() {
|
||||
game_details.put(index,
|
||||
mContext.getString(R.string.info_unavailable));
|
||||
game_details = mContext.getString(R.string.info_unavailable);
|
||||
final String nameLower = game.getName().toLowerCase(
|
||||
Locale.getDefault());
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
|
@ -216,17 +281,17 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
|||
public Drawable getGameIcon() {
|
||||
return game_icon;
|
||||
}
|
||||
|
||||
public Bitmap getGameCover() {
|
||||
return coverart;
|
||||
}
|
||||
|
||||
public String getGameTitle() {
|
||||
return game_name;
|
||||
}
|
||||
|
||||
public String getGameDetails() {
|
||||
return game_details.get(index);
|
||||
}
|
||||
|
||||
public Bitmap getGamePreview() {
|
||||
return game_preview.get(index);
|
||||
return game_details;
|
||||
}
|
||||
|
||||
public Document getDomElement(String xml) {
|
||||
|
|
|
@ -170,6 +170,14 @@ public class OptionsFragment extends Fragment {
|
|||
public void onCheckedChanged(CompoundButton buttonView,
|
||||
boolean isChecked) {
|
||||
mPrefs.edit().putBoolean(Config.pref_gamedetails, isChecked).commit();
|
||||
if (!isChecked) {
|
||||
File dir = new File(getActivity().getExternalFilesDir(null), "images");
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isDirectory()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Switch details_opt = (Switch) getView().findViewById(
|
||||
|
|
|
@ -26,14 +26,20 @@ public class GLCFactory6 {
|
|||
private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
|
||||
|
||||
public EGLContext createContext(EGL10 egl,EGLDisplay display,EGLConfig eglConfig)
|
||||
{
|
||||
int[] attrList = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE };
|
||||
{
|
||||
EGLContext context = EGL10.EGL_NO_CONTEXT;
|
||||
for ( int clientVersion = 3; clientVersion >= 2; clientVersion-- ) {
|
||||
int[] attrList = { EGL_CONTEXT_CLIENT_VERSION, clientVersion, EGL14.EGL_NONE };
|
||||
|
||||
LOGI("Creating OpenGL ES X context");
|
||||
LOGI("Creating OpenGL ES " + clientVersion + " context");
|
||||
|
||||
checkEglError("Before eglCreateContext",egl);
|
||||
EGLContext context = egl.eglCreateContext(display,eglConfig,EGL10.EGL_NO_CONTEXT,attrList);
|
||||
checkEglError("After eglCreateContext",egl);
|
||||
checkEglError("Before eglCreateContext",egl);
|
||||
context = egl.eglCreateContext(display,eglConfig,EGL10.EGL_NO_CONTEXT,attrList);
|
||||
checkEglError("After eglCreateContext",egl);
|
||||
if (context != EGL10.EGL_NO_CONTEXT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(context);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue