From c715551fbb4636644c7c4969abe25e408ae760b7 Mon Sep 17 00:00:00 2001
From: zhaozihanzzh
Date: Mon, 11 Feb 2019 18:28:22 +0800
Subject: [PATCH] Make it compatible with Android 2.3 This will set
minSdkVersion to 9 and make it work on GingerBread.
---
app/build.gradle | 4 +-
.../com/majeur/materialicons/Adapter.java | 3 +-
.../materialicons/AsyncDataRetriever.java | 56 +-
.../majeur/materialicons/AsyncTaskICS.java | 638 ++++++++++++++++++
.../majeur/materialicons/ExportActivity.java | 79 +--
.../majeur/materialicons/MainActivity.java | 15 +-
.../dirchooser/DirectoryChooserFragment.java | 497 ++++++++++++++
.../res/drawable-hdpi/ic_action_create.png | Bin 0 -> 308 bytes
.../drawable-hdpi/ic_action_create_light.png | Bin 0 -> 289 bytes
.../main/res/drawable-hdpi/navigation_up.png | Bin 0 -> 930 bytes
.../res/drawable-hdpi/navigation_up_light.png | Bin 0 -> 576 bytes
.../main/res/drawable-ldpi/navigation_up.png | Bin 0 -> 583 bytes
.../res/drawable-ldpi/navigation_up_light.png | Bin 0 -> 318 bytes
.../res/drawable-mdpi/ic_action_create.png | Bin 0 -> 183 bytes
.../drawable-mdpi/ic_action_create_light.png | Bin 0 -> 171 bytes
.../main/res/drawable-mdpi/navigation_up.png | Bin 0 -> 507 bytes
.../res/drawable-mdpi/navigation_up_light.png | Bin 0 -> 460 bytes
.../res/drawable-xhdpi/ic_action_create.png | Bin 0 -> 349 bytes
.../drawable-xhdpi/ic_action_create_light.png | Bin 0 -> 645 bytes
.../main/res/drawable-xhdpi/navigation_up.png | Bin 0 -> 2471 bytes
.../drawable-xhdpi/navigation_up_light.png | Bin 0 -> 763 bytes
.../res/drawable-xxhdpi/ic_action_create.png | Bin 0 -> 636 bytes
.../ic_action_create_light.png | Bin 0 -> 636 bytes
.../main/res/drawable/borderless_button.xml | 14 +
.../main/res/layout-v11/activity_export.xml | 193 ++++++
.../main/res/layout-v11/directory_chooser.xml | 121 ++++
app/src/main/res/layout-v11/recycler_item.xml | 55 ++
app/src/main/res/layout/activity_export.xml | 5 +-
app/src/main/res/layout/directory_chooser.xml | 101 +++
.../res/layout/directory_chooser_activity.xml | 9 +
app/src/main/res/layout/list_item.xml | 11 +-
app/src/main/res/layout/recycler_item.xml | 3 +-
app/src/main/res/menu/directory_chooser.xml | 10 +
app/src/main/res/values-de/strings.xml | 15 +
app/src/main/res/values-es/strings.xml | 15 +
app/src/main/res/values-ja/strings.xml | 15 +
app/src/main/res/values-sk/strings.xml | 15 +
app/src/main/res/values-v11/colors.xml | 6 +
app/src/main/res/values/colors.xml | 5 +
app/src/main/res/values/strings.xml | 15 +-
40 files changed, 1794 insertions(+), 106 deletions(-)
create mode 100644 app/src/main/java/com/majeur/materialicons/AsyncTaskICS.java
create mode 100644 app/src/main/java/net/rdrei/android/dirchooser/DirectoryChooserFragment.java
create mode 100644 app/src/main/res/drawable-hdpi/ic_action_create.png
create mode 100644 app/src/main/res/drawable-hdpi/ic_action_create_light.png
create mode 100644 app/src/main/res/drawable-hdpi/navigation_up.png
create mode 100644 app/src/main/res/drawable-hdpi/navigation_up_light.png
create mode 100644 app/src/main/res/drawable-ldpi/navigation_up.png
create mode 100644 app/src/main/res/drawable-ldpi/navigation_up_light.png
create mode 100644 app/src/main/res/drawable-mdpi/ic_action_create.png
create mode 100644 app/src/main/res/drawable-mdpi/ic_action_create_light.png
create mode 100644 app/src/main/res/drawable-mdpi/navigation_up.png
create mode 100644 app/src/main/res/drawable-mdpi/navigation_up_light.png
create mode 100644 app/src/main/res/drawable-xhdpi/ic_action_create.png
create mode 100644 app/src/main/res/drawable-xhdpi/ic_action_create_light.png
create mode 100644 app/src/main/res/drawable-xhdpi/navigation_up.png
create mode 100644 app/src/main/res/drawable-xhdpi/navigation_up_light.png
create mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_create.png
create mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_create_light.png
create mode 100644 app/src/main/res/drawable/borderless_button.xml
create mode 100644 app/src/main/res/layout-v11/activity_export.xml
create mode 100644 app/src/main/res/layout-v11/directory_chooser.xml
create mode 100644 app/src/main/res/layout-v11/recycler_item.xml
create mode 100644 app/src/main/res/layout/directory_chooser.xml
create mode 100644 app/src/main/res/layout/directory_chooser_activity.xml
create mode 100644 app/src/main/res/menu/directory_chooser.xml
create mode 100644 app/src/main/res/values-de/strings.xml
create mode 100644 app/src/main/res/values-es/strings.xml
create mode 100644 app/src/main/res/values-ja/strings.xml
create mode 100644 app/src/main/res/values-sk/strings.xml
create mode 100644 app/src/main/res/values-v11/colors.xml
diff --git a/app/build.gradle b/app/build.gradle
index 25c3721..11f691c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -6,7 +6,7 @@ android {
defaultConfig {
applicationId "com.majeur.materialicons"
- minSdkVersion 14
+ minSdkVersion 9
targetSdkVersion 22
versionCode 3
versionName "1.2"
@@ -25,6 +25,4 @@ dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:cardview-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
- compile 'net.rdrei.android.dirchooser:library:2.1@aar'
- compile 'com.afollestad:material-dialogs:0.7.6.0'
}
diff --git a/app/src/main/java/com/majeur/materialicons/Adapter.java b/app/src/main/java/com/majeur/materialicons/Adapter.java
index 7148dcd..4fb023c 100644
--- a/app/src/main/java/com/majeur/materialicons/Adapter.java
+++ b/app/src/main/java/com/majeur/materialicons/Adapter.java
@@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.List;
+import android.os.*;
public class Adapter extends RecyclerView.Adapter {
@@ -92,7 +93,7 @@ public ViewHolder(View itemView, ItemsClickListener listener) {
view = (CardView) itemView;
titleView = (TextView) itemView.findViewById(R.id.name);
iconView = (SVGView) itemView.findViewById(R.id.icon);
- iconView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
+ if (Build.VERSION.SDK_INT > 10) iconView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
mListener = listener;
diff --git a/app/src/main/java/com/majeur/materialicons/AsyncDataRetriever.java b/app/src/main/java/com/majeur/materialicons/AsyncDataRetriever.java
index b715bbb..38ab6a6 100644
--- a/app/src/main/java/com/majeur/materialicons/AsyncDataRetriever.java
+++ b/app/src/main/java/com/majeur/materialicons/AsyncDataRetriever.java
@@ -1,24 +1,13 @@
package com.majeur.materialicons;
-import android.content.Context;
-import android.content.res.AssetManager;
-import android.os.AsyncTask;
-import android.util.Log;
-import android.widget.Toast;
-
-import com.afollestad.materialdialogs.MaterialDialog;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import android.app.*;
+import android.content.*;
+import android.content.res.*;
+import android.util.*;
+import android.widget.*;
+import java.io.*;
+import java.util.*;
+import org.json.*;
/**
* This class is used to retrieve icons and keep local copies up to date.
@@ -30,7 +19,7 @@
* On the server files are in the same folder, to get download url, we just need the file name, then
* we format it with the "folder" url.
*/
-public class AsyncDataRetriever extends AsyncTask {
+public class AsyncDataRetriever extends AsyncTaskICS {
private static final String TAG = "DataAsyncTask";
@@ -41,7 +30,7 @@ public class AsyncDataRetriever extends AsyncTaskAsyncTask enables proper and easy use of the UI thread. This class allows to
+ * perform background operations and publish results on the UI thread without
+ * having to manipulate threads and/or handlers.
+ *
+ *
An asynchronous task is defined by a computation that runs on a background thread and
+ * whose result is published on the UI thread. An asynchronous task is defined by 3 generic
+ * types, called Params, Progress and Result,
+ * and 4 steps, called onPreExecute, doInBackground,
+ * onProgressUpdate and onPostExecute.
+ *
+ *
+ *
Developer Guides
+ *
For more information about using tasks and threads, read the
+ * Processes and
+ * Threads developer guide.
+ *
+ *
+ *
Usage
+ *
AsyncTask must be subclassed to be used. The subclass will override at least
+ * one method ({@link #doInBackground}), and most often will override a
+ * second one ({@link #onPostExecute}.)
When an asynchronous task is executed, the task goes through 4 steps:
+ *
+ *
{@link #onPreExecute()}, invoked on the UI thread immediately after the task
+ * is executed. This step is normally used to setup the task, for instance by
+ * showing a progress bar in the user interface.
+ *
{@link #doInBackground}, invoked on the background thread
+ * immediately after {@link #onPreExecute()} finishes executing. This step is used
+ * to perform background computation that can take a long time. The parameters
+ * of the asynchronous task are passed to this step. The result of the computation must
+ * be returned by this step and will be passed back to the last step. This step
+ * can also use {@link #publishProgress} to publish one or more units
+ * of progress. These values are published on the UI thread, in the
+ * {@link #onProgressUpdate} step.
+ *
{@link #onProgressUpdate}, invoked on the UI thread after a
+ * call to {@link #publishProgress}. The timing of the execution is
+ * undefined. This method is used to display any form of progress in the user
+ * interface while the background computation is still executing. For instance,
+ * it can be used to animate a progress bar or show logs in a text field.
+ *
{@link #onPostExecute}, invoked on the UI thread after the background
+ * computation finishes. The result of the background computation is passed to
+ * this step as a parameter.
+ *
+ *
+ *
Cancelling a task
+ *
A task can be cancelled at any time by invoking {@link #cancel(boolean)}. Invoking
+ * this method will cause subsequent calls to {@link #isCancelled()} to return true.
+ * After invoking this method, {@link #onCancelled(Object)}, instead of
+ * {@link #onPostExecute(Object)} will be invoked after {@link #doInBackground(Object[])}
+ * returns. To ensure that a task is cancelled as quickly as possible, you should always
+ * check the return value of {@link #isCancelled()} periodically from
+ * {@link #doInBackground(Object[])}, if possible (inside a loop for instance.)
+ *
+ *
Threading rules
+ *
There are a few threading rules that must be followed for this class to
+ * work properly:
+ *
+ *
The task instance must be created on the UI thread.
+ *
{@link #execute} must be invoked on the UI thread.
+ *
Do not call {@link #onPreExecute()}, {@link #onPostExecute},
+ * {@link #doInBackground}, {@link #onProgressUpdate} manually.
+ *
The task can be executed only once (an exception will be thrown if
+ * a second execution is attempted.)
+ *
+ *
+ *
Memory observability
+ *
AsyncTask guarantees that all callback calls are synchronized in such a way that the following
+ * operations are safe without explicit synchronizations.
+ *
+ *
Set member fields in the constructor or {@link #onPreExecute}, and refer to them
+ * in {@link #doInBackground}.
+ *
Set member fields in {@link #doInBackground}, and refer to them in
+ * {@link #onProgressUpdate} and {@link #onPostExecute}.
+ *
+ */
+ public abstract class AsyncTaskICS {
+ private static final String LOG_TAG = "AsyncTask";
+
+ private static final int CORE_POOL_SIZE = 5;
+ private static final int MAXIMUM_POOL_SIZE = 128;
+ private static final int KEEP_ALIVE = 1;
+
+ private static final ThreadFactory sThreadFactory = new ThreadFactory() {
+ private final AtomicInteger mCount = new AtomicInteger(1);
+
+ public Thread newThread(Runnable r) {
+ return new Thread(r, "AsyncTask #" + mCount.getAndIncrement());
+ }
+ };
+
+ private static final BlockingQueue sPoolWorkQueue =
+ new LinkedBlockingQueue(10);
+
+ /**
+ * An {@link Executor} that can be used to execute tasks in parallel.
+ */
+ public static final Executor THREAD_POOL_EXECUTOR
+ = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
+ TimeUnit.SECONDS, sPoolWorkQueue, sThreadFactory);
+
+ /**
+ * An {@link Executor} that executes tasks one at a time in serial
+ * order. This serialization is global to a particular process.
+ */
+ public static final Executor SERIAL_EXECUTOR = new SerialExecutor();
+
+ private static final int MESSAGE_POST_RESULT = 0x1;
+ private static final int MESSAGE_POST_PROGRESS = 0x2;
+
+ private static final InternalHandler sHandler = new InternalHandler();
+
+ private static volatile Executor sDefaultExecutor = SERIAL_EXECUTOR;
+ private final WorkerRunnable mWorker;
+ private final FutureTask mFuture;
+
+ private volatile Status mStatus = Status.PENDING;
+
+ private final AtomicBoolean mTaskInvoked = new AtomicBoolean();
+
+ private static class SerialExecutor implements Executor {
+ final ArrayDeque mTasks = new ArrayDeque();
+ Runnable mActive;
+
+ public synchronized void execute(final Runnable r) {
+ mTasks.offer(new Runnable() {
+ public void run() {
+ try {
+ r.run();
+ } finally {
+ scheduleNext();
+ }
+ }
+ });
+ if (mActive == null) {
+ scheduleNext();
+ }
+ }
+
+ protected synchronized void scheduleNext() {
+ if ((mActive = mTasks.poll()) != null) {
+ THREAD_POOL_EXECUTOR.execute(mActive);
+ }
+ }
+ }
+
+ /**
+ * Indicates the current status of the task. Each status will be set only once
+ * during the lifetime of a task.
+ */
+ public enum Status {
+ /**
+ * Indicates that the task has not been executed yet.
+ */
+ PENDING,
+ /**
+ * Indicates that the task is running.
+ */
+ RUNNING,
+ /**
+ * Indicates that {@link AsyncTask#onPostExecute} has finished.
+ */
+ FINISHED,
+ }
+
+ /** @hide Used to force static handler to be created. */
+ public static void init() {
+ sHandler.getLooper();
+ }
+
+ /** @hide */
+ public static void setDefaultExecutor(Executor exec) {
+ sDefaultExecutor = exec;
+ }
+
+ /**
+ * Creates a new asynchronous task. This constructor must be invoked on the UI thread.
+ */
+ public AsyncTaskICS() {
+ mWorker = new WorkerRunnable() {
+ public Result call() throws Exception {
+ mTaskInvoked.set(true);
+
+ android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
+ return postResult(doInBackground(mParams));
+ }
+ };
+
+ mFuture = new FutureTask(mWorker) {
+ @Override
+ protected void done() {
+ try {
+ final Result result = get();
+
+ postResultIfNotInvoked(result);
+ } catch (InterruptedException e) {
+ android.util.Log.w(LOG_TAG, e);
+ } catch (ExecutionException e) {
+ throw new RuntimeException("An error occured while executing doInBackground()",
+ e.getCause());
+ } catch (CancellationException e) {
+ postResultIfNotInvoked(null);
+ } catch (Throwable t) {
+ throw new RuntimeException("An error occured while executing "
+ + "doInBackground()", t);
+ }
+ }
+ };
+ }
+
+ private void postResultIfNotInvoked(Result result) {
+ final boolean wasTaskInvoked = mTaskInvoked.get();
+ if (!wasTaskInvoked) {
+ postResult(result);
+ }
+ }
+
+ private Result postResult(Result result) {
+ Message message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
+ new AsyncTaskICSResult(this, result));
+ message.sendToTarget();
+ return result;
+ }
+
+ /**
+ * Returns the current status of this task.
+ *
+ * @return The current status.
+ */
+ public final Status getStatus() {
+ return mStatus;
+ }
+
+ /**
+ * Override this method to perform a computation on a background thread. The
+ * specified parameters are the parameters passed to {@link #execute}
+ * by the caller of this task.
+ *
+ * This method can call {@link #publishProgress} to publish updates
+ * on the UI thread.
+ *
+ * @param params The parameters of the task.
+ *
+ * @return A result, defined by the subclass of this task.
+ *
+ * @see #onPreExecute()
+ * @see #onPostExecute
+ * @see #publishProgress
+ */
+ protected abstract Result doInBackground(Params... params);
+
+ /**
+ * Runs on the UI thread before {@link #doInBackground}.
+ *
+ * @see #onPostExecute
+ * @see #doInBackground
+ */
+ protected void onPreExecute() {
+ }
+
+ /**
+ *
Runs on the UI thread after {@link #doInBackground}. The
+ * specified result is the value returned by {@link #doInBackground}.
+ *
+ *
This method won't be invoked if the task was cancelled.
+ *
+ * @param result The result of the operation computed by {@link #doInBackground}.
+ *
+ * @see #onPreExecute
+ * @see #doInBackground
+ * @see #onCancelled(Object)
+ */
+ @SuppressWarnings({"UnusedDeclaration"})
+ protected void onPostExecute(Result result) {
+ }
+
+ /**
+ * Runs on the UI thread after {@link #publishProgress} is invoked.
+ * The specified values are the values passed to {@link #publishProgress}.
+ *
+ * @param values The values indicating progress.
+ *
+ * @see #publishProgress
+ * @see #doInBackground
+ */
+ @SuppressWarnings({"UnusedDeclaration"})
+ protected void onProgressUpdate(Progress... values) {
+ }
+
+ /**
+ *
Runs on the UI thread after {@link #cancel(boolean)} is invoked and
+ * {@link #doInBackground(Object[])} has finished.
+ *
+ *
The default implementation simply invokes {@link #onCancelled()} and
+ * ignores the result. If you write your own implementation, do not call
+ * super.onCancelled(result).
+ *
+ * @param result The result, if any, computed in
+ * {@link #doInBackground(Object[])}, can be null
+ *
+ * @see #cancel(boolean)
+ * @see #isCancelled()
+ */
+ @SuppressWarnings({"UnusedParameters"})
+ protected void onCancelled(Result result) {
+ onCancelled();
+ }
+
+ /**
+ *
Applications should preferably override {@link #onCancelled(Object)}.
+ * This method is invoked by the default implementation of
+ * {@link #onCancelled(Object)}.
+ *
+ *
Runs on the UI thread after {@link #cancel(boolean)} is invoked and
+ * {@link #doInBackground(Object[])} has finished.
+ *
+ * @see #onCancelled(Object)
+ * @see #cancel(boolean)
+ * @see #isCancelled()
+ */
+ protected void onCancelled() {
+ }
+
+ /**
+ * Returns true if this task was cancelled before it completed
+ * normally. If you are calling {@link #cancel(boolean)} on the task,
+ * the value returned by this method should be checked periodically from
+ * {@link #doInBackground(Object[])} to end the task as soon as possible.
+ *
+ * @return true if task was cancelled before it completed
+ *
+ * @see #cancel(boolean)
+ */
+ public final boolean isCancelled() {
+ return mFuture.isCancelled();
+ }
+
+ /**
+ *
Attempts to cancel execution of this task. This attempt will
+ * fail if the task has already completed, already been cancelled,
+ * or could not be cancelled for some other reason. If successful,
+ * and this task has not started when cancel is called,
+ * this task should never run. If the task has already started,
+ * then the mayInterruptIfRunning parameter determines
+ * whether the thread executing this task should be interrupted in
+ * an attempt to stop the task.
+ *
+ *
Calling this method will result in {@link #onCancelled(Object)} being
+ * invoked on the UI thread after {@link #doInBackground(Object[])}
+ * returns. Calling this method guarantees that {@link #onPostExecute(Object)}
+ * is never invoked. After invoking this method, you should check the
+ * value returned by {@link #isCancelled()} periodically from
+ * {@link #doInBackground(Object[])} to finish the task as early as
+ * possible.
+ *
+ * @param mayInterruptIfRunning true if the thread executing this
+ * task should be interrupted; otherwise, in-progress tasks are allowed
+ * to complete.
+ *
+ * @return false if the task could not be cancelled,
+ * typically because it has already completed normally;
+ * true otherwise
+ *
+ * @see #isCancelled()
+ * @see #onCancelled(Object)
+ */
+ public final boolean cancel(boolean mayInterruptIfRunning) {
+ return mFuture.cancel(mayInterruptIfRunning);
+ }
+
+ /**
+ * Waits if necessary for the computation to complete, and then
+ * retrieves its result.
+ *
+ * @return The computed result.
+ *
+ * @throws CancellationException If the computation was cancelled.
+ * @throws ExecutionException If the computation threw an exception.
+ * @throws InterruptedException If the current thread was interrupted
+ * while waiting.
+ */
+ public final Result get() throws InterruptedException, ExecutionException {
+ return mFuture.get();
+ }
+
+ /**
+ * Waits if necessary for at most the given time for the computation
+ * to complete, and then retrieves its result.
+ *
+ * @param timeout Time to wait before cancelling the operation.
+ * @param unit The time unit for the timeout.
+ *
+ * @return The computed result.
+ *
+ * @throws CancellationException If the computation was cancelled.
+ * @throws ExecutionException If the computation threw an exception.
+ * @throws InterruptedException If the current thread was interrupted
+ * while waiting.
+ * @throws TimeoutException If the wait timed out.
+ */
+ public final Result get(long timeout, TimeUnit unit) throws InterruptedException,
+ ExecutionException, TimeoutException {
+ return mFuture.get(timeout, unit);
+ }
+
+ /**
+ * Executes the task with the specified parameters. The task returns
+ * itself (this) so that the caller can keep a reference to it.
+ *
+ *
Note: this function schedules the task on a queue for a single background
+ * thread or pool of threads depending on the platform version. When first
+ * introduced, AsyncTasks were executed serially on a single background thread.
+ * Starting with {@link android.os.Build.VERSION_CODES#DONUT}, this was changed
+ * to a pool of threads allowing multiple tasks to operate in parallel. After
+ * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, it is planned to change this
+ * back to a single thread to avoid common application errors caused
+ * by parallel execution. If you truly want parallel execution, you can use
+ * the {@link #executeOnExecutor} version of this method
+ * with {@link #THREAD_POOL_EXECUTOR}; however, see commentary there for warnings on
+ * its use.
+ *
+ *
This method must be invoked on the UI thread.
+ *
+ * @param params The parameters of the task.
+ *
+ * @return This instance of AsyncTask.
+ *
+ * @throws IllegalStateException If {@link #getStatus()} returns either
+ * {@link AsyncTask.Status#RUNNING} or {@link AsyncTask.Status#FINISHED}.
+ */
+ public final AsyncTaskICS execute(Params... params) {
+ return executeOnExecutor(sDefaultExecutor, params);
+ }
+
+ /**
+ * Executes the task with the specified parameters. The task returns
+ * itself (this) so that the caller can keep a reference to it.
+ *
+ *
This method is typically used with {@link #THREAD_POOL_EXECUTOR} to
+ * allow multiple tasks to run in parallel on a pool of threads managed by
+ * AsyncTask, however you can also use your own {@link Executor} for custom
+ * behavior.
+ *
+ *
Warning: Allowing multiple tasks to run in parallel from
+ * a thread pool is generally not what one wants, because the order
+ * of their operation is not defined. For example, if these tasks are used
+ * to modify any state in common (such as writing a file due to a button click),
+ * there are no guarantees on the order of the modifications.
+ * Without careful work it is possible in rare cases for the newer version
+ * of the data to be over-written by an older one, leading to obscure data
+ * loss and stability issues. Such changes are best
+ * executed in serial; to guarantee such work is serialized regardless of
+ * platform version you can use this function with {@link #SERIAL_EXECUTOR}.
+ *
+ *
This method must be invoked on the UI thread.
+ *
+ * @param exec The executor to use. {@link #THREAD_POOL_EXECUTOR} is available as a
+ * convenient process-wide thread pool for tasks that are loosely coupled.
+ * @param params The parameters of the task.
+ *
+ * @return This instance of AsyncTask.
+ *
+ * @throws IllegalStateException If {@link #getStatus()} returns either
+ * {@link AsyncTask.Status#RUNNING} or {@link AsyncTask.Status#FINISHED}.
+ */
+ public final AsyncTaskICS executeOnExecutor(Executor exec,
+ Params... params) {
+ if (mStatus != Status.PENDING) {
+ switch (mStatus) {
+ case RUNNING:
+ throw new IllegalStateException("Cannot execute task:"
+ + " the task is already running.");
+ case FINISHED:
+ throw new IllegalStateException("Cannot execute task:"
+ + " the task has already been executed "
+ + "(a task can be executed only once)");
+ }
+ }
+
+ mStatus = Status.RUNNING;
+
+ onPreExecute();
+
+ mWorker.mParams = params;
+ exec.execute(mFuture);
+
+ return this;
+ }
+
+ /**
+ * Convenience version of {@link #execute(Object...)} for use with
+ * a simple Runnable object.
+ */
+ public static void execute(Runnable runnable) {
+ sDefaultExecutor.execute(runnable);
+ }
+
+ /**
+ * This method can be invoked from {@link #doInBackground} to
+ * publish updates on the UI thread while the background computation is
+ * still running. Each call to this method will trigger the execution of
+ * {@link #onProgressUpdate} on the UI thread.
+ *
+ * {@link #onProgressUpdate} will note be called if the task has been
+ * canceled.
+ *
+ * @param values The progress values to update the UI with.
+ *
+ * @see #onProgressUpdate
+ * @see #doInBackground
+ */
+ protected final void publishProgress(Progress... values) {
+ if (!isCancelled()) {
+ sHandler.obtainMessage(MESSAGE_POST_PROGRESS,
+ new AsyncTaskICSResult