Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/org/adblockplus/android/updater/UpdaterActivity.java

Issue 8491079: ABP/Android update service (Closed)
Patch Set: Created Oct. 5, 2012, 9:26 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/org/adblockplus/android/updater/UpdaterActivity.java
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/org/adblockplus/android/updater/UpdaterActivity.java
@@ -0,0 +1,83 @@
+package org.adblockplus.android.updater;
+
+import java.io.File;
+
+import org.adblockplus.android.R;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnCancelListener;
+import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.Window;
+
+/**
+ * Prompts user to download update or installs downloaded update.
+ */
+public class UpdaterActivity extends Activity
+{
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+
+ // Prompt user to download update
+ if ("download".equals(getIntent().getAction()))
+ {
+ final Bundle extras = getIntent().getExtras();
+ if (extras == null || extras.getString("url") == null)
+ {
+ finish();
+ return;
+ }
+
+ new AlertDialog.Builder(this).setTitle(R.string.msg_update_available).setMessage(getString(R.string.msg_update_description)).setIcon(android.R.drawable.ic_dialog_info)
+ .setPositiveButton(R.string.ok, new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface arg0, int arg1)
+ {
+ // Start download service
+ startService(new Intent(UpdaterActivity.this, UpdaterService.class).putExtras(extras));
+ finish();
+ }
+ }).setNegativeButton(R.string.cancel, new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which)
+ {
+ finish();
+ }
+ }).setOnCancelListener(new OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog)
+ {
+ finish();
+ }
+ }).create().show();
+ }
+ // Install downloaded update
+ else
+ {
+ String file = getIntent().getStringExtra("path");
+ File updateFile = new File(file);
+ try
+ {
+ Intent installerIntent = new Intent();
+ installerIntent.setAction(Intent.ACTION_VIEW);
+ installerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ installerIntent.setDataAndType(Uri.fromFile(updateFile), "application/vnd.android.package-archive");
+ startActivity(installerIntent);
+ android.os.Process.killProcess(android.os.Process.myPid());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
« no previous file with comments | « src/org/adblockplus/android/updater/AlarmReceiver.java ('k') | src/org/adblockplus/android/updater/UpdaterService.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld