Merge "Adding a generic method to initiate overridable objects" into ub-launcher3-master
This commit is contained in:
commit
1d896b011d
8 files changed
+32
-72
No files matched your search
@@ -66,7 +66,7 @@ public class AllAppsList {
|
||||
* If the app is already in the list, doesn't add it.
|
||||
*/
|
||||
public void add(AppInfo info) {
|
||||
if (mAppFilter != null && !mAppFilter.shouldShowApp(info.componentName)) {
|
||||
if (!mAppFilter.shouldShowApp(info.componentName)) {
|
||||
return;
|
||||
}
|
||||
if (findActivity(data, info.componentName, info.user)) {
|
||||
|
||||
@@ -1,35 +1,10 @@
|
||||
package com.android.launcher3;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
public abstract class AppFilter {
|
||||
public class AppFilter {
|
||||
|
||||
private static final boolean DBG = false;
|
||||
private static final String TAG = "AppFilter";
|
||||
|
||||
public abstract boolean shouldShowApp(ComponentName app);
|
||||
|
||||
public static AppFilter loadByName(String className) {
|
||||
if (TextUtils.isEmpty(className)) return null;
|
||||
if (DBG) Log.d(TAG, "Loading AppFilter: " + className);
|
||||
try {
|
||||
Class<?> cls = Class.forName(className);
|
||||
return (AppFilter) cls.newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.e(TAG, "Bad AppFilter class", e);
|
||||
return null;
|
||||
} catch (InstantiationException e) {
|
||||
Log.e(TAG, "Bad AppFilter class", e);
|
||||
return null;
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.e(TAG, "Bad AppFilter class", e);
|
||||
return null;
|
||||
} catch (ClassCastException e) {
|
||||
Log.e(TAG, "Bad AppFilter class", e);
|
||||
return null;
|
||||
}
|
||||
public boolean shouldShowApp(ComponentName app) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -123,9 +123,8 @@ public class IconCache {
|
||||
mLowResCanvas = new Canvas();
|
||||
mLowResPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
|
||||
|
||||
mIconProvider = IconProvider.loadByName(context.getString(R.string.icon_provider_class),
|
||||
context);
|
||||
|
||||
mIconProvider = Utilities.getOverrideObject(
|
||||
IconProvider.class, context, R.string.icon_provider_class);
|
||||
mWorkerHandler = new Handler(LauncherModel.getWorkerLooper());
|
||||
|
||||
mActivityBgColor = context.getResources().getColor(R.color.quantum_panel_bg_color);
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package com.android.launcher3;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.launcher3.compat.LauncherActivityInfoCompat;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Locale;
|
||||
|
||||
public class IconProvider {
|
||||
@@ -21,19 +17,6 @@ public class IconProvider {
|
||||
updateSystemStateString();
|
||||
}
|
||||
|
||||
public static IconProvider loadByName(String className, Context context) {
|
||||
if (TextUtils.isEmpty(className)) return new IconProvider();
|
||||
if (DBG) Log.d(TAG, "Loading IconProvider: " + className);
|
||||
try {
|
||||
Class<?> cls = Class.forName(className);
|
||||
return (IconProvider) cls.getDeclaredConstructor(Context.class).newInstance(context);
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
|
||||
| ClassCastException | NoSuchMethodException | InvocationTargetException e) {
|
||||
Log.e(TAG, "Bad IconProvider class", e);
|
||||
return new IconProvider();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateSystemStateString() {
|
||||
mSystemState = Locale.getDefault().toString();
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ public class LauncherAppState {
|
||||
|
||||
public static final boolean PROFILE_STARTUP = ProviderConfig.IS_DOGFOOD_BUILD;
|
||||
|
||||
private final AppFilter mAppFilter;
|
||||
@Thunk final LauncherModel mModel;
|
||||
private final IconCache mIconCache;
|
||||
private final WidgetPreviewLoader mWidgetCache;
|
||||
@@ -96,8 +95,8 @@ public class LauncherAppState {
|
||||
mIconCache = new IconCache(sContext, mInvariantDeviceProfile);
|
||||
mWidgetCache = new WidgetPreviewLoader(sContext, mIconCache);
|
||||
|
||||
mAppFilter = AppFilter.loadByName(sContext.getString(R.string.app_filter_class));
|
||||
mModel = new LauncherModel(this, mIconCache, mAppFilter);
|
||||
mModel = new LauncherModel(this, mIconCache,
|
||||
Utilities.getOverrideObject(AppFilter.class, sContext, R.string.app_filter_class));
|
||||
|
||||
LauncherAppsCompat.getInstance(sContext).addOnAppsChangedCallback(mModel);
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ import com.android.launcher3.config.ProviderConfig;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
@@ -655,4 +656,23 @@ public final class Utilities {
|
||||
return e.getCause() instanceof TransactionTooLargeException
|
||||
|| e.getCause() instanceof DeadObjectException;
|
||||
}
|
||||
|
||||
public static <T> T getOverrideObject(Class<T> clazz, Context context, int resId) {
|
||||
String className = context.getString(resId);
|
||||
if (!TextUtils.isEmpty(className)) {
|
||||
try {
|
||||
Class<?> cls = Class.forName(className);
|
||||
return (T) cls.getDeclaredConstructor(Context.class).newInstance(context);
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
|
||||
| ClassCastException | NoSuchMethodException | InvocationTargetException e) {
|
||||
Log.e(TAG, "Bad overriden class", e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return clazz.newInstance();
|
||||
} catch (InstantiationException|IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,11 @@ package com.android.launcher3.graphics;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.launcher3.FastBitmapDrawable;
|
||||
import com.android.launcher3.ItemInfo;
|
||||
import com.android.launcher3.R;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import com.android.launcher3.Utilities;
|
||||
|
||||
/**
|
||||
* Factory for creating new drawables.
|
||||
@@ -37,27 +35,13 @@ public class DrawableFactory {
|
||||
public static DrawableFactory get(Context context) {
|
||||
synchronized (LOCK) {
|
||||
if (sInstance == null) {
|
||||
context = context.getApplicationContext();
|
||||
sInstance = loadByName(context.getString(R.string.drawable_factory_class), context);
|
||||
sInstance = Utilities.getOverrideObject(DrawableFactory.class,
|
||||
context.getApplicationContext(), R.string.drawable_factory_class);
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
}
|
||||
|
||||
public static DrawableFactory loadByName(String className, Context context) {
|
||||
if (!TextUtils.isEmpty(className)) {
|
||||
try {
|
||||
Class<?> cls = Class.forName(className);
|
||||
return (DrawableFactory)
|
||||
cls.getDeclaredConstructor(Context.class).newInstance(context);
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
|
||||
| ClassCastException | NoSuchMethodException | InvocationTargetException e) {
|
||||
return new DrawableFactory();
|
||||
}
|
||||
}
|
||||
return new DrawableFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a FastBitmapDrawable with the icon.
|
||||
*/
|
||||
|
||||
@@ -117,7 +117,7 @@ public class WidgetsModel {
|
||||
}
|
||||
}
|
||||
|
||||
if (mAppFilter != null && !mAppFilter.shouldShowApp(item.componentName)) {
|
||||
if (!mAppFilter.shouldShowApp(item.componentName)) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, String.format("%s is filtered and not added to the widget tray.",
|
||||
item.componentName));
|
||||
|
||||
Reference in new issue
Block a user