Update Apache dependency to non-legacy
Apache-compliant log upload functionality (non-legacy) Apache-compliant xml parsing functionality (non-legacy) Apache-compliant image url functionality (non-legacy) Apache-compliant changelog functionality (non-legacy) Remove apache legacy library dependency (deprecated)
This commit is contained in:
parent
0f45296ea4
commit
159e9fe0ad
|
@ -18,8 +18,6 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useLibrary 'org.apache.http.legacy'
|
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package com.reicast.emulator;
|
package com.reicast.emulator;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
@ -22,24 +20,23 @@ import android.widget.Toast;
|
||||||
import com.reicast.emulator.config.Config;
|
import com.reicast.emulator.config.Config;
|
||||||
import com.reicast.emulator.debug.GitAdapter;
|
import com.reicast.emulator.debug.GitAdapter;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.StatusLine;
|
|
||||||
import org.apache.http.client.ClientProtocolException;
|
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
|
||||||
public class AboutFragment extends Fragment {
|
public class AboutFragment extends Fragment {
|
||||||
|
|
||||||
String buildId = "";
|
String buildId = "";
|
||||||
|
@ -61,8 +58,7 @@ public class AboutFragment extends Fragment {
|
||||||
try {
|
try {
|
||||||
InputStream file = getResources().getAssets().open("build");
|
InputStream file = getResources().getAssets().open("build");
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
BufferedReader reader = new BufferedReader(
|
BufferedReader reader = new BufferedReader(new InputStreamReader(file));
|
||||||
new InputStreamReader(file));
|
|
||||||
buildId = reader.readLine();
|
buildId = reader.readLine();
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
@ -75,8 +71,7 @@ public class AboutFragment extends Fragment {
|
||||||
.getPackageInfo(getActivity().getPackageName(), 0).versionName;
|
.getPackageInfo(getActivity().getPackageName(), 0).versionName;
|
||||||
int versionCode = getActivity().getPackageManager()
|
int versionCode = getActivity().getPackageManager()
|
||||||
.getPackageInfo(getActivity().getPackageName(), 0).versionCode;
|
.getPackageInfo(getActivity().getPackageName(), 0).versionCode;
|
||||||
TextView version = (TextView) getView().findViewById(
|
TextView version = (TextView) getView().findViewById(R.id.revision_text);
|
||||||
R.id.revision_text);
|
|
||||||
String revision = getString(R.string.revision_text,
|
String revision = getString(R.string.revision_text,
|
||||||
versionName, String.valueOf(versionCode));
|
versionName, String.valueOf(versionCode));
|
||||||
if (!buildId.equals("")) {
|
if (!buildId.equals("")) {
|
||||||
|
@ -125,21 +120,15 @@ public class AboutFragment extends Fragment {
|
||||||
JSONObject commitArray = jsonObject.getJSONObject("commit");
|
JSONObject commitArray = jsonObject.getJSONObject("commit");
|
||||||
|
|
||||||
String date = commitArray.getJSONObject("committer")
|
String date = commitArray.getJSONObject("committer")
|
||||||
.getString("date").replace("T", " ")
|
.getString("date").replace("T", " ").replace("Z", "");
|
||||||
.replace("Z", "");
|
String author = commitArray.getJSONObject("author").getString("name");
|
||||||
String author = commitArray.getJSONObject("author")
|
String committer = commitArray.getJSONObject("committer").getString("name");
|
||||||
.getString("name");
|
|
||||||
String committer = commitArray.getJSONObject("committer")
|
|
||||||
.getString("name");
|
|
||||||
|
|
||||||
String avatar = null;
|
String avatar = null;
|
||||||
if (!jsonObject.getString("committer").equals("null")) {
|
if (!jsonObject.getString("committer").equals("null")) {
|
||||||
avatar = jsonObject.getJSONObject("committer")
|
avatar = jsonObject.getJSONObject("committer").getString("avatar_url");
|
||||||
.getString("avatar_url");
|
committer = committer + " (" + jsonObject
|
||||||
committer = committer
|
.getJSONObject("committer").getString("login") + ")";
|
||||||
+ " ("
|
|
||||||
+ jsonObject.getJSONObject("committer")
|
|
||||||
.getString("login") + ")";
|
|
||||||
if (avatar.equals("null")) {
|
if (avatar.equals("null")) {
|
||||||
avatar = "https://github.com/apple-touch-icon-144.png";
|
avatar = "https://github.com/apple-touch-icon-144.png";
|
||||||
}
|
}
|
||||||
|
@ -147,16 +136,12 @@ public class AboutFragment extends Fragment {
|
||||||
avatar = "https://github.com/apple-touch-icon-144.png";
|
avatar = "https://github.com/apple-touch-icon-144.png";
|
||||||
}
|
}
|
||||||
if (!jsonObject.getString("author").equals("null")) {
|
if (!jsonObject.getString("author").equals("null")) {
|
||||||
author = author
|
author = author + " (" + jsonObject.getJSONObject(
|
||||||
+ " ("
|
"author").getString("login") + ")";
|
||||||
+ jsonObject.getJSONObject("author").getString(
|
|
||||||
"login") + ")";
|
|
||||||
}
|
}
|
||||||
String sha = jsonObject.getString("sha");
|
String sha = jsonObject.getString("sha");
|
||||||
String curl = jsonObject
|
String curl = jsonObject.getString("url")
|
||||||
.getString("url")
|
.replace("https://api.github.com/repos", "https://github.com")
|
||||||
.replace("https://api.github.com/repos",
|
|
||||||
"https://github.com")
|
|
||||||
.replace("commits", "commit");
|
.replace("commits", "commit");
|
||||||
|
|
||||||
String title = "No commit heading attached";
|
String title = "No commit heading attached";
|
||||||
|
@ -164,11 +149,9 @@ public class AboutFragment extends Fragment {
|
||||||
|
|
||||||
if (commitArray.getString("message").contains("\n\n")) {
|
if (commitArray.getString("message").contains("\n\n")) {
|
||||||
String fullOutput = commitArray.getString("message");
|
String fullOutput = commitArray.getString("message");
|
||||||
title = fullOutput.substring(0,
|
title = fullOutput.substring(0, fullOutput.indexOf("\n\n"));
|
||||||
fullOutput.indexOf("\n\n"));
|
|
||||||
message = fullOutput.substring(
|
message = fullOutput.substring(
|
||||||
fullOutput.indexOf("\n\n") + 1,
|
fullOutput.indexOf("\n\n") + 1, fullOutput.length());
|
||||||
fullOutput.length());
|
|
||||||
} else {
|
} else {
|
||||||
title = commitArray.getString("message");
|
title = commitArray.getString("message");
|
||||||
}
|
}
|
||||||
|
@ -232,32 +215,23 @@ public class AboutFragment extends Fragment {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONArray getContent(String urlString)
|
private JSONArray getContent(String urlString) throws IOException, JSONException {
|
||||||
throws IOException, JSONException {
|
HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
|
||||||
StringBuilder builder = new StringBuilder();
|
conn.setRequestMethod("GET");
|
||||||
HttpClient client = new DefaultHttpClient();
|
conn.setDoInput(true);
|
||||||
HttpGet httpGet = new HttpGet(urlString);
|
int responseCode = conn.getResponseCode();
|
||||||
try {
|
|
||||||
HttpResponse response = client.execute(httpGet);
|
if (responseCode != HttpsURLConnection.HTTP_OK) {
|
||||||
StatusLine statusLine = response.getStatusLine();
|
InputStream is = new BufferedInputStream(conn.getInputStream());
|
||||||
int statusCode = statusLine.getStatusCode();
|
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||||
if (statusCode == 200) {
|
byte[] buffer = new byte[1024];
|
||||||
HttpEntity entity = response.getEntity();
|
int length;
|
||||||
InputStream content = entity.getContent();
|
while ((length = is.read(buffer)) != -1) {
|
||||||
BufferedReader reader = new BufferedReader(
|
result.write(buffer, 0, length);
|
||||||
new InputStreamReader(content));
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
builder.append(line);
|
|
||||||
}
|
}
|
||||||
} else {
|
return new JSONArray(result.toString());
|
||||||
}
|
}
|
||||||
} catch (ClientProtocolException e) {
|
return null;
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return new JSONArray(builder.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.StrictMode;
|
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnLongClickListener;
|
import android.view.View.OnLongClickListener;
|
||||||
|
@ -23,12 +22,6 @@ import android.widget.TextView;
|
||||||
import com.reicast.emulator.FileBrowser.OnItemSelectedListener;
|
import com.reicast.emulator.FileBrowser.OnItemSelectedListener;
|
||||||
import com.reicast.emulator.config.Config;
|
import com.reicast.emulator.config.Config;
|
||||||
|
|
||||||
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.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
@ -37,6 +30,7 @@ import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -44,6 +38,7 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
@ -67,8 +62,8 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
||||||
private String gameId;
|
private String gameId;
|
||||||
private String game_details;
|
private String game_details;
|
||||||
|
|
||||||
private static final String game_index = "http://thegamesdb.net/api/GetGamesList.php?platform=sega+dreamcast&name=";
|
private 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=";
|
private String game_id = "http://thegamesdb.net/api/GetGame.php?platform=sega+dreamcast&id=";
|
||||||
|
|
||||||
public XMLParser(File game, int index, SharedPreferences mPrefs) {
|
public XMLParser(File game, int index, SharedPreferences mPrefs) {
|
||||||
this.mPrefs = mPrefs;
|
this.mPrefs = mPrefs;
|
||||||
|
@ -87,71 +82,13 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
||||||
initializeDefaults();
|
initializeDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(String... params) {
|
protected String doInBackground(String... params) {
|
||||||
String filename = game_name = params[0];
|
String filename = game_name = params[0];
|
||||||
if (isNetworkAvailable() && mPrefs.getBoolean(Config.pref_gamedetails, false)) {
|
if (isNetworkAvailable() && mPrefs.getBoolean(Config.pref_gamedetails, false)) {
|
||||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
String xmlUrl = "";
|
||||||
HttpPost httpPost;
|
|
||||||
if (gameId != null) {
|
if (gameId != null) {
|
||||||
httpPost = new HttpPost(game_id + gameId);
|
xmlUrl = game_id + gameId;
|
||||||
} else {
|
} else {
|
||||||
filename = filename.substring(0, filename.lastIndexOf("."));
|
filename = filename.substring(0, filename.lastIndexOf("."));
|
||||||
try {
|
try {
|
||||||
|
@ -159,15 +96,23 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
filename = filename.replace(" ", "+");
|
filename = filename.replace(" ", "+");
|
||||||
}
|
}
|
||||||
httpPost = new HttpPost(game_index + filename);
|
xmlUrl = game_index + filename;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
HttpResponse httpResponse = httpClient.execute(httpPost);
|
|
||||||
HttpEntity httpEntity = httpResponse.getEntity();
|
|
||||||
return EntityUtils.toString(httpEntity);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
|
|
||||||
} catch (ClientProtocolException e) {
|
try {
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) new URL(xmlUrl).openConnection();
|
||||||
|
conn.setRequestMethod("POST");
|
||||||
|
conn.setDoInput(true);
|
||||||
|
|
||||||
|
InputStream is = new BufferedInputStream(conn.getInputStream());
|
||||||
|
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int length;
|
||||||
|
while ((length = is.read(buffer)) != -1) {
|
||||||
|
result.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
@ -199,7 +144,8 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
||||||
boxart = (Element) images.getElementsByTagName("boxart").item(0);
|
boxart = (Element) images.getElementsByTagName("boxart").item(0);
|
||||||
}
|
}
|
||||||
if (boxart != null) {
|
if (boxart != null) {
|
||||||
coverart = decodeBitmapIcon("http://thegamesdb.net/banners/" + getElementValue(boxart));
|
(new decodeBitmapIcon()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
||||||
|
"http://thegamesdb.net/banners/" + getElementValue(boxart));
|
||||||
game_icon = new BitmapDrawable(coverart);
|
game_icon = new BitmapDrawable(coverart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -337,4 +283,67 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class decodeBitmapIcon extends AsyncTask<String, Integer, Bitmap> {
|
||||||
|
@Override
|
||||||
|
protected Bitmap doInBackground(String... params) {
|
||||||
|
try {
|
||||||
|
String index = params[0].substring(params[0].lastIndexOf("/") + 1, params[0].lastIndexOf("."));
|
||||||
|
File file = new File(mContext.getExternalFilesDir(null) + "/images", index + ".png");
|
||||||
|
if (file.exists()) {
|
||||||
|
return BitmapFactory.decodeFile(file.getAbsolutePath());
|
||||||
|
} else {
|
||||||
|
URL updateURL = new URL(params[0]);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Bitmap gameImage) {
|
||||||
|
coverart = gameImage;
|
||||||
|
game_icon = new BitmapDrawable(gameImage);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,38 +1,33 @@
|
||||||
package com.reicast.emulator.debug;
|
package com.reicast.emulator.debug;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.StrictMode;
|
|
||||||
|
|
||||||
import com.reicast.emulator.config.Config;
|
import com.reicast.emulator.config.Config;
|
||||||
|
|
||||||
import org.apache.http.Header;
|
import java.io.BufferedInputStream;
|
||||||
import org.apache.http.HttpResponse;
|
import java.io.BufferedWriter;
|
||||||
import org.apache.http.HttpStatus;
|
import java.io.ByteArrayOutputStream;
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.AbstractMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload the specialized logcat to reicast issues
|
* Upload the specialized logcat to reicast issues
|
||||||
*
|
|
||||||
* @param mContext
|
|
||||||
* The context this method will be executed from
|
|
||||||
* @param currentTime
|
|
||||||
* The system time at which the log was made
|
|
||||||
*/
|
*/
|
||||||
public class UploadLogs extends AsyncTask<String, Integer, Object> {
|
public class UploadLogs extends AsyncTask<String, Integer, Object> {
|
||||||
|
|
||||||
|
@ -40,22 +35,21 @@ public class UploadLogs extends AsyncTask<String, Integer, Object> {
|
||||||
private String logUrl;
|
private String logUrl;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mContext
|
||||||
|
* The context this method will be executed from
|
||||||
|
* @param currentTime
|
||||||
|
* The system time at which the log was made
|
||||||
|
*/
|
||||||
public UploadLogs(Context mContext, String currentTime) {
|
public UploadLogs(Context mContext, String currentTime) {
|
||||||
this.mContext = mContext;
|
this.mContext = mContext;
|
||||||
this.currentTime = currentTime;
|
this.currentTime = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RedirectSubmission(Header[] headers, String content) {
|
private void RedirectSubmission(String header, String content) {
|
||||||
UploadLogs mUploadLogs = new UploadLogs(mContext,
|
UploadLogs mUploadLogs = new UploadLogs(mContext, currentTime);
|
||||||
currentTime);
|
mUploadLogs.setPostUrl(header);
|
||||||
mUploadLogs.setPostUrl(headers[headers.length - 1]
|
mUploadLogs.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, content);
|
||||||
.getValue());
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
||||||
mUploadLogs.executeOnExecutor(
|
|
||||||
AsyncTask.THREAD_POOL_EXECUTOR, content);
|
|
||||||
} else {
|
|
||||||
mUploadLogs.execute(content);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,67 +67,88 @@ public class UploadLogs extends AsyncTask<String, Integer, Object> {
|
||||||
if (logUrl == null || logUrl.equals(null)) {
|
if (logUrl == null || logUrl.equals(null)) {
|
||||||
logUrl = Config.log_url;
|
logUrl = Config.log_url;
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
|
||||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
|
|
||||||
.permitAll().build();
|
|
||||||
StrictMode.setThreadPolicy(policy);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
private String getQuery(List<AbstractMap.SimpleEntry> params)
|
||||||
|
throws UnsupportedEncodingException {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
boolean first = true;
|
||||||
|
|
||||||
|
for (AbstractMap.SimpleEntry pair : params) {
|
||||||
|
if (first)
|
||||||
|
first = false;
|
||||||
|
else
|
||||||
|
result.append("&");
|
||||||
|
|
||||||
|
result.append(URLEncoder.encode((String) pair.getKey(), "UTF-8"));
|
||||||
|
result.append("=");
|
||||||
|
result.append(URLEncoder.encode((String) pair.getValue(), "UTF-8"));
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object doInBackground(String... params) {
|
protected Object doInBackground(String... params) {
|
||||||
HttpClient client = new DefaultHttpClient();
|
HttpURLConnection conn = null;
|
||||||
HttpPost post = new HttpPost(logUrl);
|
|
||||||
try {
|
try {
|
||||||
ArrayList<NameValuePair> mPairs = new ArrayList<NameValuePair>();
|
conn = (HttpURLConnection) new URL(logUrl).openConnection();
|
||||||
mPairs.add(new BasicNameValuePair("name", currentTime));
|
conn.setRequestMethod("POST");
|
||||||
mPairs.add(new BasicNameValuePair("issue", params[0]));
|
conn.setDoInput(true);
|
||||||
post.setEntity(new UrlEncodedFormEntity(mPairs));
|
conn.setDoOutput(true);
|
||||||
HttpResponse getResponse = client.execute(post);
|
|
||||||
final int statusCode = getResponse.getStatusLine().getStatusCode();
|
ArrayList<AbstractMap.SimpleEntry> mPairs = new ArrayList<>();
|
||||||
if (statusCode != HttpStatus.SC_OK) {
|
mPairs.add(new AbstractMap.SimpleEntry("name", currentTime));
|
||||||
Header[] headers = getResponse.getHeaders("Location");
|
mPairs.add(new AbstractMap.SimpleEntry("issue", params[0]));
|
||||||
if (headers != null && headers.length != 0) {
|
|
||||||
RedirectSubmission(headers, params[0]);
|
OutputStream os = conn.getOutputStream();
|
||||||
|
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
|
||||||
|
writer.write(getQuery(mPairs));
|
||||||
|
writer.flush();
|
||||||
|
writer.close();
|
||||||
|
os.close();
|
||||||
|
|
||||||
|
int responseCode=conn.getResponseCode();
|
||||||
|
|
||||||
|
if (responseCode != HttpsURLConnection.HTTP_OK) {
|
||||||
|
String header = conn.getHeaderField("Location");
|
||||||
|
if (header != null && header.length() != 0) {
|
||||||
|
RedirectSubmission(header, params[0]);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return EntityUtils.toString(getResponse.getEntity());
|
InputStream is = new BufferedInputStream(conn.getInputStream());
|
||||||
|
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int length;
|
||||||
|
while ((length = is.read(buffer)) != -1) {
|
||||||
|
result.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
return result.toString("UTF-8");
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
post.abort();
|
if (conn != null) conn.disconnect();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
post.abort();
|
if (conn != null) conn.disconnect();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
post.abort();
|
if (conn != null) conn.disconnect();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Object response) {
|
protected void onPostExecute(Object response) {
|
||||||
if (response != null && !response.equals(null)) {
|
if (response != null && !response.equals(null)) {
|
||||||
String logLink = Config.report_url + currentTime + ".txt";
|
String logLink = Config.report_url + currentTime + ".txt";
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
||||||
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mContext
|
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mContext
|
||||||
.getSystemService(Context.CLIPBOARD_SERVICE);
|
.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
android.content.ClipData clip = android.content.ClipData
|
android.content.ClipData clip = android.content.ClipData.newPlainText("logcat", logLink);
|
||||||
.newPlainText("logcat", logLink);
|
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
} else {
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Config.git_issues));
|
||||||
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) mContext
|
|
||||||
.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
clipboard.setText(logLink);
|
|
||||||
}
|
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
|
|
||||||
Uri.parse(Config.git_issues));
|
|
||||||
mContext.startActivity(browserIntent);
|
mContext.startActivity(browserIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue