Merge "Moving some utility classes to icon lib" into ub-launcher3-master
This commit is contained in:
commit
160bfcfede
|
@ -37,6 +37,11 @@ android {
|
|||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.launcher3.graphics;
|
||||
package com.android.launcher3.icons;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.graphics.Bitmap;
|
||||
|
@ -21,14 +21,12 @@ import android.graphics.Canvas;
|
|||
import android.graphics.Picture;
|
||||
import android.os.Build;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
|
||||
/**
|
||||
* Interface representing a bitmap draw operation.
|
||||
*/
|
||||
public interface BitmapRenderer {
|
||||
|
||||
boolean USE_HARDWARE_BITMAP = Utilities.ATLEAST_P;
|
||||
boolean USE_HARDWARE_BITMAP = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P;
|
||||
|
||||
static Bitmap createSoftwareBitmap(int width, int height, BitmapRenderer renderer) {
|
||||
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
@ -29,8 +29,9 @@ public class ComponentKey {
|
|||
private final int mHashCode;
|
||||
|
||||
public ComponentKey(ComponentName componentName, UserHandle user) {
|
||||
Preconditions.assertNotNull(componentName);
|
||||
Preconditions.assertNotNull(user);
|
||||
if (componentName == null || user == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.componentName = componentName;
|
||||
this.user = user;
|
||||
mHashCode = Arrays.hashCode(new Object[] {componentName, user});
|
|
@ -18,8 +18,6 @@ package com.android.launcher3.util;
|
|||
|
||||
import static android.database.sqlite.SQLiteDatabase.NO_LOCALIZED_COLLATORS;
|
||||
|
||||
import static com.android.launcher3.Utilities.ATLEAST_P;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.database.DatabaseErrorHandler;
|
||||
|
@ -27,6 +25,7 @@ import android.database.sqlite.SQLiteDatabase;
|
|||
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||
import android.database.sqlite.SQLiteDatabase.OpenParams;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.os.Build;
|
||||
|
||||
/**
|
||||
* Extension of {@link SQLiteOpenHelper} which avoids creating default locale table by
|
||||
|
@ -34,6 +33,9 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||
*/
|
||||
public abstract class NoLocaleSQLiteHelper extends SQLiteOpenHelper {
|
||||
|
||||
private static final boolean ATLEAST_P =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P;
|
||||
|
||||
public NoLocaleSQLiteHelper(Context context, String name, int version) {
|
||||
super(ATLEAST_P ? context : new NoLocalContext(context), name, null, version);
|
||||
if (ATLEAST_P) {
|
|
@ -9,9 +9,6 @@ import android.database.sqlite.SQLiteFullException;
|
|||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
|
||||
/**
|
||||
* An extension of {@link SQLiteOpenHelper} with utility methods for a single table cache DB.
|
||||
* Any exception during write operations are ignored, and any version change causes a DB reset.
|
||||
|
@ -19,8 +16,7 @@ import com.android.launcher3.config.FeatureFlags;
|
|||
public abstract class SQLiteCacheHelper {
|
||||
private static final String TAG = "SQLiteCacheHelper";
|
||||
|
||||
private static final boolean NO_ICON_CACHE = FeatureFlags.IS_DOGFOOD_BUILD &&
|
||||
Utilities.isPropertyEnabled(LogConfig.MEMORY_ONLY_ICON_CACHE);
|
||||
private static final boolean IN_MEMORY_CACHE = false;
|
||||
|
||||
private final String mTableName;
|
||||
private final MySQLiteOpenHelper mOpenHelper;
|
||||
|
@ -28,7 +24,7 @@ public abstract class SQLiteCacheHelper {
|
|||
private boolean mIgnoreWrites;
|
||||
|
||||
public SQLiteCacheHelper(Context context, String name, int version, String tableName) {
|
||||
if (NO_ICON_CACHE) {
|
||||
if (IN_MEMORY_CACHE) {
|
||||
name = null;
|
||||
}
|
||||
mTableName = tableName;
|
|
@ -36,7 +36,7 @@ import com.android.launcher3.MainThreadExecutor;
|
|||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.folder.PreviewBackground;
|
||||
import com.android.launcher3.graphics.BitmapRenderer;
|
||||
import com.android.launcher3.icons.BitmapRenderer;
|
||||
import com.android.launcher3.util.Preconditions;
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,6 +33,7 @@ import com.android.launcher3.Launcher;
|
|||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.icons.BitmapRenderer;
|
||||
import com.android.launcher3.util.UiThreadHelper;
|
||||
import com.android.launcher3.widget.LauncherAppWidgetHostView;
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import android.os.Build;
|
|||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.icons.BitmapRenderer;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
|
|
@ -36,14 +36,13 @@ import android.graphics.drawable.Drawable;
|
|||
import android.os.Build;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.launcher3.IconProvider;
|
||||
import com.android.launcher3.LauncherModel;
|
||||
import com.android.launcher3.graphics.BitmapRenderer;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.Preconditions;
|
||||
import com.android.launcher3.util.Provider;
|
||||
|
@ -58,7 +57,6 @@ public abstract class BaseIconCache {
|
|||
|
||||
private static final String TAG = "BaseIconCache";
|
||||
private static final boolean DEBUG = false;
|
||||
private static final boolean DEBUG_IGNORE_CACHE = false;
|
||||
|
||||
private static final int INITIAL_ICON_CACHE_CAPACITY = 50;
|
||||
|
||||
|
@ -78,21 +76,24 @@ public abstract class BaseIconCache {
|
|||
|
||||
private final HashMap<ComponentKey, CacheEntry> mCache =
|
||||
new HashMap<>(INITIAL_ICON_CACHE_CAPACITY);
|
||||
final Handler mWorkerHandler;
|
||||
protected final Handler mWorkerHandler;
|
||||
|
||||
protected int mIconDpi;
|
||||
IconDB mIconDb;
|
||||
|
||||
private final String mDbFileName;
|
||||
private final BitmapFactory.Options mDecodeOptions;
|
||||
private final Looper mBgLooper;
|
||||
|
||||
public BaseIconCache(Context context, String dbFileName, int iconDpi, int iconPixelSize) {
|
||||
public BaseIconCache(Context context, String dbFileName, Looper bgLooper,
|
||||
int iconDpi, int iconPixelSize) {
|
||||
mContext = context;
|
||||
mDbFileName = dbFileName;
|
||||
mPackageManager = context.getPackageManager();
|
||||
mBgLooper = bgLooper;
|
||||
|
||||
mIconProvider = IconProvider.newInstance(context);
|
||||
mWorkerHandler = new Handler(LauncherModel.getWorkerLooper());
|
||||
mWorkerHandler = new Handler(mBgLooper);
|
||||
|
||||
if (BitmapRenderer.USE_HARDWARE_BITMAP && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
mDecodeOptions = new BitmapFactory.Options();
|
||||
|
@ -294,7 +295,7 @@ public abstract class BaseIconCache {
|
|||
T object = null;
|
||||
boolean providerFetchedOnce = false;
|
||||
|
||||
if (!getEntryFromDB(cacheKey, entry, useLowResIcon) || DEBUG_IGNORE_CACHE) {
|
||||
if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
|
||||
object = infoProvider.get();
|
||||
providerFetchedOnce = true;
|
||||
|
||||
|
|
|
@ -66,7 +66,8 @@ public class IconCache extends BaseIconCache {
|
|||
private int mPendingIconRequestCount = 0;
|
||||
|
||||
public IconCache(Context context, InvariantDeviceProfile inv) {
|
||||
super(context, LauncherFiles.APP_ICONS_DB, inv.fillResIconDpi, inv.iconBitmapSize);
|
||||
super(context, LauncherFiles.APP_ICONS_DB, LauncherModel.getWorkerLooper(),
|
||||
inv.fillResIconDpi, inv.iconBitmapSize);
|
||||
mComponentWithLabelCachingLogic = new ComponentCachingLogic(context);
|
||||
mLauncherActivityInfoCachingLogic = new LauncherActivtiyCachingLogic(this);
|
||||
mLauncherApps = LauncherAppsCompat.getInstance(mContext);
|
||||
|
|
|
@ -31,7 +31,6 @@ import com.android.launcher3.InvariantDeviceProfile;
|
|||
import com.android.launcher3.ItemInfoWithIcon;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.graphics.BitmapRenderer;
|
||||
import com.android.launcher3.model.PackageItemInfo;
|
||||
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
||||
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
|
||||
|
|
Loading…
Reference in New Issue