mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-20 11:18:21 +00:00
Using custom threadpool executor instead of the one defined in AsyncTask
Change-Id: I8fe95d932c5de14c74f0576bfc3d1f641d12b448
This commit is contained in:
@@ -13,7 +13,6 @@ import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -90,7 +89,7 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
|
||||
}.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
LauncherAppState app = LauncherAppState.getInstanceNoCreate();
|
||||
|
||||
@@ -94,7 +94,7 @@ public class DeleteDropTarget extends ButtonDropTarget {
|
||||
appWidgetHost.deleteAppWidgetId(widget.appWidgetId);
|
||||
return null;
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -4735,7 +4735,7 @@ public class Launcher extends Activity
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
|
||||
}.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,10 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -105,6 +109,18 @@ public final class Utilities {
|
||||
public static final boolean ATLEAST_JB_MR2 =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
|
||||
|
||||
// These values are same as that in {@link AsyncTask}.
|
||||
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
|
||||
private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
|
||||
private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
|
||||
private static final int KEEP_ALIVE = 1;
|
||||
/**
|
||||
* An {@link Executor} to be used with async task with no limit on the queue size.
|
||||
*/
|
||||
public static final Executor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
|
||||
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
|
||||
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
|
||||
|
||||
// To turn on these properties, type
|
||||
// adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
|
||||
private static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
|
||||
|
||||
@@ -43,25 +43,12 @@ import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class WidgetPreviewLoader {
|
||||
|
||||
private static final String TAG = "WidgetPreviewLoader";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
// These values are same as that in {@link AsyncTask}.
|
||||
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
|
||||
private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
|
||||
private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
|
||||
private static final int KEEP_ALIVE = 1;
|
||||
private static final Executor PREVIEW_LOAD_EXECUTOR = new ThreadPoolExecutor(
|
||||
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
|
||||
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
|
||||
|
||||
private static final float WIDGET_PREVIEW_ICON_PADDING_PERCENTAGE = 0.25f;
|
||||
|
||||
private final HashMap<String, long[]> mPackageVersions = new HashMap<>();
|
||||
@@ -109,7 +96,7 @@ public class WidgetPreviewLoader {
|
||||
WidgetCacheKey key = getObjectKey(o, size);
|
||||
|
||||
PreviewLoadTask task = new PreviewLoadTask(key, o, previewWidth, previewHeight, caller);
|
||||
task.executeOnExecutor(PREVIEW_LOAD_EXECUTOR);
|
||||
task.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
|
||||
return new PreviewLoadRequest(task);
|
||||
}
|
||||
|
||||
|
||||
@@ -1326,7 +1326,7 @@ public class Workspace extends PagedView
|
||||
mLauncher.overrideWallpaperDimensions());
|
||||
return null;
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
|
||||
}.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
protected void snapToPage(int whichPage, Runnable r) {
|
||||
|
||||
Reference in New Issue
Block a user