Submit a local test of the git-based build update downloads
This commit is contained in:
parent
3bb036741b
commit
256347d947
|
@ -91,7 +91,6 @@ import android.widget.ListView;
|
|||
import android.widget.SlidingDrawer;
|
||||
import android.widget.SlidingDrawer.OnDrawerOpenListener;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.reicast.emulator.config.Config;
|
||||
import com.reicast.emulator.debug.GitAdapter;
|
||||
|
|
|
@ -64,6 +64,7 @@ import android.app.Activity;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.Build;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -85,11 +86,12 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
|||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.reicast.emulator.MainActivity;
|
||||
import com.reicast.emulator.R;
|
||||
|
||||
public class GitAdapter extends BaseAdapter {
|
||||
|
||||
private Activity activity;
|
||||
private static Activity activity;
|
||||
private ArrayList<HashMap<String, String>> data;
|
||||
private LayoutInflater inflater = null;
|
||||
private DisplayImageOptions options;
|
||||
|
@ -168,7 +170,15 @@ public class GitAdapter extends BaseAdapter {
|
|||
return vi;
|
||||
}
|
||||
|
||||
public static void displayCommit(String title, String message, String url,
|
||||
private static void callGithubVerification(String sha) {
|
||||
String hash = sha.substring(0, 7);
|
||||
Intent github = new Intent("com.reicast.emulator.debug.GitHash");
|
||||
github.setAction("reicast.emulator.GITHUB");
|
||||
github.putExtra("hashtag", hash);
|
||||
activity.startActivity(github);
|
||||
}
|
||||
|
||||
public static void displayCommit(final String title, String message, String url,
|
||||
Context context) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setCancelable(true);
|
||||
|
@ -186,6 +196,16 @@ public class GitAdapter extends BaseAdapter {
|
|||
return;
|
||||
}
|
||||
});
|
||||
if (MainActivity.debugUser) {
|
||||
builder.setNegativeButton("Download",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
callGithubVerification(title);
|
||||
dialog.dismiss();
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
builder.create().show();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
android:minSdkVersion="8"
|
||||
android:targetSdkVersion="18" />
|
||||
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_LOGS" />
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
|
@ -31,6 +34,15 @@
|
|||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".GitHash"
|
||||
android:excludeFromRecents="true"
|
||||
android:theme="@style/Theme.PanelTheme" >
|
||||
<intent-filter>
|
||||
<action android:name="reicast.emulator.GITHUB" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<receiver
|
||||
android:name=".GcmBroadcastReceiver"
|
||||
android:permission="com.google.android.c2dm.permission.SEND" >
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?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="fill_parent"
|
||||
android:padding="5dp" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/status_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_marginRight="5dp" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_toRightOf="@id/status_icon" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/status_text"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginBottom="5dp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/status_progress"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/status_text"
|
||||
android:indeterminate="false"
|
||||
android:indeterminateOnly="false"
|
||||
android:progressDrawable="@android:drawable/progress_horizontal" />
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
|
@ -3,6 +3,7 @@ package com.reicast.emulator.debug;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
|
@ -44,6 +45,7 @@ import android.content.DialogInterface;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.Resources;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -57,12 +59,10 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
@ -178,6 +178,20 @@ public class Debug extends Activity {
|
|||
generateErrorLog();
|
||||
}
|
||||
});
|
||||
try {
|
||||
Resources res = getPackageManager().getResourcesForApplication("com.reicast.emulator");
|
||||
InputStream file = res.getAssets().open("build");
|
||||
if (file != null) {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(file));
|
||||
Log.d("reicast-debug", "Hash: " + reader.readLine());
|
||||
file.close();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void generateErrorLog() {
|
||||
|
|
|
@ -0,0 +1,187 @@
|
|||
package com.reicast.emulator.debug;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class GitHash extends Activity {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mContext = this.getApplicationContext();
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
String hash = extras.getString("hashtag");
|
||||
NetworkHandler mDownload = new NetworkHandler(mContext);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
mDownload.executeOnExecutor(
|
||||
AsyncTask.THREAD_POOL_EXECUTOR, hash);
|
||||
} else {
|
||||
mDownload.execute(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class NetworkHandler extends AsyncTask<String, Integer, File> {
|
||||
|
||||
private Context mContext;
|
||||
private NotificationManager mNM;
|
||||
private Notification notification;
|
||||
private int progress = 0;
|
||||
private String hash;
|
||||
|
||||
short timestamp = (short) System.currentTimeMillis();
|
||||
|
||||
NetworkHandler(Context mContext) {
|
||||
this.mContext = mContext;
|
||||
mNM = (NotificationManager) mContext
|
||||
.getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File doInBackground(String... paths) {
|
||||
String apk = "reicast-emulator-" + paths[0] + ".apk";
|
||||
String file = "http://twisted.dyndns.tv:3194/ReicastBot/compiled/" + apk;
|
||||
File SDCard = mContext.getExternalCacheDir();
|
||||
File apkFile = new File(SDCard, apk);
|
||||
try {
|
||||
URL url = new URL(file);
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) url
|
||||
.openConnection();
|
||||
HttpURLConnection.setFollowRedirects(true);
|
||||
urlConnection.setRequestMethod("GET");
|
||||
urlConnection.setDoOutput(true);
|
||||
urlConnection.connect();
|
||||
FileOutputStream fileOutput = new FileOutputStream(apkFile);
|
||||
InputStream inputStream = urlConnection.getInputStream();
|
||||
int totalSize = urlConnection.getContentLength();
|
||||
int downloadedSize = 0;
|
||||
byte[] buffer = new byte[1024];
|
||||
int bufferLength = 0;
|
||||
int priorProgress = 0;
|
||||
while ((bufferLength = inputStream.read(buffer)) > 0) {
|
||||
downloadedSize += bufferLength;
|
||||
int currentSize = (int) (downloadedSize * 100 / totalSize);
|
||||
if (currentSize > priorProgress) {
|
||||
priorProgress = (int) (downloadedSize * 100 / totalSize);
|
||||
publishProgress(currentSize);
|
||||
}
|
||||
fileOutput.write(buffer, 0, bufferLength);
|
||||
}
|
||||
fileOutput.close();
|
||||
inputStream.close();
|
||||
return apkFile.getAbsoluteFile();
|
||||
} catch (MalformedURLException e) {
|
||||
Log.d(Debug.APP_TAG, "MalformedURLException: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
Log.d(Debug.APP_TAG, "IOException: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
Log.d(Debug.APP_TAG, "Exception: " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... progress) {
|
||||
notification.contentView.setProgressBar(R.id.status_progress, 100,
|
||||
progress[0], false);
|
||||
mNM.notify(timestamp, notification);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
Intent intent = new Intent(mContext, GitHash.class);
|
||||
final PendingIntent pendingIntent = PendingIntent.getActivity(
|
||||
mContext.getApplicationContext(), 0, intent, 0);
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(
|
||||
mContext.getApplicationContext());
|
||||
builder.setContentTitle("reicast " + hash)
|
||||
.setSmallIcon(R.drawable.ic_launcher)
|
||||
.setAutoCancel(false).setOngoing(true)
|
||||
.setPriority(Notification.PRIORITY_HIGH);
|
||||
notification = builder.build();
|
||||
notification.flags |= Notification.FLAG_NO_CLEAR;
|
||||
notification.contentView = new RemoteViews(mContext
|
||||
.getApplicationContext().getPackageName(),
|
||||
R.layout.download_prog);
|
||||
notification.contentIntent = pendingIntent;
|
||||
notification.contentView.setImageViewResource(R.id.status_icon,
|
||||
R.drawable.ic_launcher);
|
||||
notification.contentView.setTextViewText(R.id.status_text, "Downloading " + hash + "...");
|
||||
notification.contentView.setProgressBar(R.id.status_progress, 100,
|
||||
progress, false);
|
||||
mNM.notify(timestamp, notification);
|
||||
// Use a resourceId as an unique identifier
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(File download) {
|
||||
mNM.cancel(timestamp);
|
||||
if (download != null) {
|
||||
System.gc();
|
||||
Intent installIntent;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
|
||||
installIntent.setData(Uri.fromFile(download));
|
||||
installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE,
|
||||
true);
|
||||
installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
|
||||
installIntent.putExtra(Intent.EXTRA_ALLOW_REPLACE, true);
|
||||
installIntent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME,
|
||||
getApplicationInfo().packageName);
|
||||
} else {
|
||||
installIntent = new Intent(Intent.ACTION_VIEW);
|
||||
installIntent.setDataAndType(Uri.fromFile(download),
|
||||
"application/vnd.android.package-archive");
|
||||
}
|
||||
startActivityForResult(installIntent, 0);
|
||||
} else {
|
||||
Toast.makeText(mContext, "Download Unavailable!", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue