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 {
|
||||
release {
|
||||
minifyEnabled false
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.reicast.emulator;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
@ -22,24 +20,23 @@ import android.widget.Toast;
|
|||
import com.reicast.emulator.config.Config;
|
||||
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.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
public class AboutFragment extends Fragment {
|
||||
|
||||
String buildId = "";
|
||||
|
@ -61,8 +58,7 @@ public class AboutFragment extends Fragment {
|
|||
try {
|
||||
InputStream file = getResources().getAssets().open("build");
|
||||
if (file != null) {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(file));
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(file));
|
||||
buildId = reader.readLine();
|
||||
file.close();
|
||||
}
|
||||
|
@ -75,8 +71,7 @@ public class AboutFragment extends Fragment {
|
|||
.getPackageInfo(getActivity().getPackageName(), 0).versionName;
|
||||
int versionCode = getActivity().getPackageManager()
|
||||
.getPackageInfo(getActivity().getPackageName(), 0).versionCode;
|
||||
TextView version = (TextView) getView().findViewById(
|
||||
R.id.revision_text);
|
||||
TextView version = (TextView) getView().findViewById(R.id.revision_text);
|
||||
String revision = getString(R.string.revision_text,
|
||||
versionName, String.valueOf(versionCode));
|
||||
if (!buildId.equals("")) {
|
||||
|
@ -125,21 +120,15 @@ public class AboutFragment extends Fragment {
|
|||
JSONObject commitArray = jsonObject.getJSONObject("commit");
|
||||
|
||||
String date = commitArray.getJSONObject("committer")
|
||||
.getString("date").replace("T", " ")
|
||||
.replace("Z", "");
|
||||
String author = commitArray.getJSONObject("author")
|
||||
.getString("name");
|
||||
String committer = commitArray.getJSONObject("committer")
|
||||
.getString("name");
|
||||
.getString("date").replace("T", " ").replace("Z", "");
|
||||
String author = commitArray.getJSONObject("author").getString("name");
|
||||
String committer = commitArray.getJSONObject("committer").getString("name");
|
||||
|
||||
String avatar = null;
|
||||
if (!jsonObject.getString("committer").equals("null")) {
|
||||
avatar = jsonObject.getJSONObject("committer")
|
||||
.getString("avatar_url");
|
||||
committer = committer
|
||||
+ " ("
|
||||
+ jsonObject.getJSONObject("committer")
|
||||
.getString("login") + ")";
|
||||
avatar = jsonObject.getJSONObject("committer").getString("avatar_url");
|
||||
committer = committer + " (" + jsonObject
|
||||
.getJSONObject("committer").getString("login") + ")";
|
||||
if (avatar.equals("null")) {
|
||||
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";
|
||||
}
|
||||
if (!jsonObject.getString("author").equals("null")) {
|
||||
author = author
|
||||
+ " ("
|
||||
+ jsonObject.getJSONObject("author").getString(
|
||||
"login") + ")";
|
||||
author = author + " (" + jsonObject.getJSONObject(
|
||||
"author").getString("login") + ")";
|
||||
}
|
||||
String sha = jsonObject.getString("sha");
|
||||
String curl = jsonObject
|
||||
.getString("url")
|
||||
.replace("https://api.github.com/repos",
|
||||
"https://github.com")
|
||||
String curl = jsonObject.getString("url")
|
||||
.replace("https://api.github.com/repos", "https://github.com")
|
||||
.replace("commits", "commit");
|
||||
|
||||
String title = "No commit heading attached";
|
||||
|
@ -164,11 +149,9 @@ public class AboutFragment extends Fragment {
|
|||
|
||||
if (commitArray.getString("message").contains("\n\n")) {
|
||||
String fullOutput = commitArray.getString("message");
|
||||
title = fullOutput.substring(0,
|
||||
fullOutput.indexOf("\n\n"));
|
||||
title = fullOutput.substring(0, fullOutput.indexOf("\n\n"));
|
||||
message = fullOutput.substring(
|
||||
fullOutput.indexOf("\n\n") + 1,
|
||||
fullOutput.length());
|
||||
fullOutput.indexOf("\n\n") + 1, fullOutput.length());
|
||||
} else {
|
||||
title = commitArray.getString("message");
|
||||
}
|
||||
|
@ -232,32 +215,23 @@ public class AboutFragment extends Fragment {
|
|||
|
||||
}
|
||||
|
||||
private JSONArray getContent(String urlString)
|
||||
throws IOException, JSONException {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
HttpClient client = new DefaultHttpClient();
|
||||
HttpGet httpGet = new HttpGet(urlString);
|
||||
try {
|
||||
HttpResponse response = client.execute(httpGet);
|
||||
StatusLine statusLine = response.getStatusLine();
|
||||
int statusCode = statusLine.getStatusCode();
|
||||
if (statusCode == 200) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
InputStream content = entity.getContent();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(content));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
private JSONArray getContent(String urlString) throws IOException, JSONException {
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setDoInput(true);
|
||||
int responseCode = conn.getResponseCode();
|
||||
|
||||
if (responseCode != HttpsURLConnection.HTTP_OK) {
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
return new JSONArray(result.toString());
|
||||
}
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new JSONArray(builder.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import android.net.NetworkInfo;
|
|||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.StrictMode;
|
||||
import android.os.Vibrator;
|
||||
import android.view.View;
|
||||
import android.view.View.OnLongClickListener;
|
||||
|
@ -23,12 +22,6 @@ import android.widget.TextView;
|
|||
import com.reicast.emulator.FileBrowser.OnItemSelectedListener;
|
||||
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.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -37,6 +30,7 @@ import org.xml.sax.InputSource;
|
|||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -44,6 +38,7 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.io.StringReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
|
@ -67,8 +62,8 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
|||
private String gameId;
|
||||
private String game_details;
|
||||
|
||||
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=";
|
||||
private String game_index = "http://thegamesdb.net/api/GetGamesList.php?platform=sega+dreamcast&name=";
|
||||
private String game_id = "http://thegamesdb.net/api/GetGame.php?platform=sega+dreamcast&id=";
|
||||
|
||||
public XMLParser(File game, int index, SharedPreferences mPrefs) {
|
||||
this.mPrefs = mPrefs;
|
||||
|
@ -87,71 +82,13 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
|||
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
|
||||
protected String doInBackground(String... params) {
|
||||
String filename = game_name = params[0];
|
||||
if (isNetworkAvailable() && mPrefs.getBoolean(Config.pref_gamedetails, false)) {
|
||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
||||
HttpPost httpPost;
|
||||
String xmlUrl = "";
|
||||
if (gameId != null) {
|
||||
httpPost = new HttpPost(game_id + gameId);
|
||||
xmlUrl = game_id + gameId;
|
||||
} else {
|
||||
filename = filename.substring(0, filename.lastIndexOf("."));
|
||||
try {
|
||||
|
@ -159,15 +96,23 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
|||
} catch (UnsupportedEncodingException e) {
|
||||
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) {
|
||||
|
||||
|
@ -199,7 +144,8 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
|||
boxart = (Element) images.getElementsByTagName("boxart").item(0);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -337,4 +283,67 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
|
|||
}
|
||||
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;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.StrictMode;
|
||||
|
||||
import com.reicast.emulator.config.Config;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
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.BufferedInputStream;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
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.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
|
||||
|
@ -40,22 +35,21 @@ public class UploadLogs extends AsyncTask<String, Integer, Object> {
|
|||
private String logUrl;
|
||||
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) {
|
||||
this.mContext = mContext;
|
||||
this.currentTime = currentTime;
|
||||
}
|
||||
|
||||
private void RedirectSubmission(Header[] headers, String content) {
|
||||
UploadLogs mUploadLogs = new UploadLogs(mContext,
|
||||
currentTime);
|
||||
mUploadLogs.setPostUrl(headers[headers.length - 1]
|
||||
.getValue());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
mUploadLogs.executeOnExecutor(
|
||||
AsyncTask.THREAD_POOL_EXECUTOR, content);
|
||||
} else {
|
||||
mUploadLogs.execute(content);
|
||||
}
|
||||
private void RedirectSubmission(String header, String content) {
|
||||
UploadLogs mUploadLogs = new UploadLogs(mContext, currentTime);
|
||||
mUploadLogs.setPostUrl(header);
|
||||
mUploadLogs.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, content);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,67 +67,88 @@ public class UploadLogs extends AsyncTask<String, Integer, Object> {
|
|||
if (logUrl == null || logUrl.equals(null)) {
|
||||
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
|
||||
protected Object doInBackground(String... params) {
|
||||
HttpClient client = new DefaultHttpClient();
|
||||
HttpPost post = new HttpPost(logUrl);
|
||||
HttpURLConnection conn = null;
|
||||
try {
|
||||
ArrayList<NameValuePair> mPairs = new ArrayList<NameValuePair>();
|
||||
mPairs.add(new BasicNameValuePair("name", currentTime));
|
||||
mPairs.add(new BasicNameValuePair("issue", params[0]));
|
||||
post.setEntity(new UrlEncodedFormEntity(mPairs));
|
||||
HttpResponse getResponse = client.execute(post);
|
||||
final int statusCode = getResponse.getStatusLine().getStatusCode();
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
Header[] headers = getResponse.getHeaders("Location");
|
||||
if (headers != null && headers.length != 0) {
|
||||
RedirectSubmission(headers, params[0]);
|
||||
conn = (HttpURLConnection) new URL(logUrl).openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
|
||||
ArrayList<AbstractMap.SimpleEntry> mPairs = new ArrayList<>();
|
||||
mPairs.add(new AbstractMap.SimpleEntry("name", currentTime));
|
||||
mPairs.add(new AbstractMap.SimpleEntry("issue", 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 {
|
||||
return null;
|
||||
}
|
||||
} 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) {
|
||||
e.printStackTrace();
|
||||
post.abort();
|
||||
if (conn != null) conn.disconnect();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
post.abort();
|
||||
if (conn != null) conn.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
post.abort();
|
||||
if (conn != null) conn.disconnect();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onPostExecute(Object response) {
|
||||
if (response != null && !response.equals(null)) {
|
||||
String logLink = Config.report_url + currentTime + ".txt";
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mContext
|
||||
.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
android.content.ClipData clip = android.content.ClipData
|
||||
.newPlainText("logcat", logLink);
|
||||
android.content.ClipData clip = android.content.ClipData.newPlainText("logcat", logLink);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
} else {
|
||||
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));
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Config.git_issues));
|
||||
mContext.startActivity(browserIntent);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue