use of com.android.launcher3.util.Thunk in project android_packages_apps_Launcher3 by crdroidandroid.
the class DatabaseWidgetPreviewLoader method getPackageVersion.
/**
* @return an array of containing versionCode and lastUpdatedTime for the package.
*/
@Thunk
long[] getPackageVersion(String packageName) {
synchronized (mPackageVersions) {
long[] versions = mPackageVersions.get(packageName);
if (versions == null) {
versions = new long[2];
try {
PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
versions[0] = info.versionCode;
versions[1] = info.lastUpdateTime;
} catch (NameNotFoundException e) {
Log.e(TAG, "PackageInfo not found", e);
}
mPackageVersions.put(packageName, versions);
}
return versions;
}
}
use of com.android.launcher3.util.Thunk in project android_packages_apps_Launcher3 by crdroidandroid.
the class Launcher method completeTwoStageWidgetDrop.
@Thunk
void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
Runnable onCompleteRunnable = null;
int animationType = 0;
AppWidgetHostView boundWidget = null;
if (resultCode == RESULT_OK) {
animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, requestArgs.getWidgetHandler().getProviderInfo(this));
boundWidget = layout;
onCompleteRunnable = new Runnable() {
@Override
public void run() {
completeAddAppWidget(appWidgetId, requestArgs, layout, null);
mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
}
};
} else if (resultCode == RESULT_CANCELED) {
mAppWidgetHost.deleteAppWidgetId(appWidgetId);
animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
}
if (mDragLayer.getAnimatedView() != null) {
mWorkspace.animateWidgetDrop(requestArgs, cellLayout, (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, animationType, boundWidget, true);
} else if (onCompleteRunnable != null) {
// The animated view may be null in the case of a rotation during widget configuration
onCompleteRunnable.run();
}
}
use of com.android.launcher3.util.Thunk in project android_packages_apps_Launcher3 by crdroidandroid.
the class DatabaseWidgetPreviewLoader method writeToDb.
@Thunk
void writeToDb(WidgetCacheKey key, long[] versions, Bitmap preview) {
ContentValues values = new ContentValues();
values.put(CacheDb.COLUMN_COMPONENT, key.componentName.flattenToShortString());
values.put(CacheDb.COLUMN_USER, mUserCache.getSerialNumberForUser(key.user));
values.put(CacheDb.COLUMN_SIZE, key.mSize);
values.put(CacheDb.COLUMN_PACKAGE, key.componentName.getPackageName());
values.put(CacheDb.COLUMN_VERSION, versions[0]);
values.put(CacheDb.COLUMN_LAST_UPDATED, versions[1]);
values.put(CacheDb.COLUMN_PREVIEW_BITMAP, GraphicsUtils.flattenBitmap(preview));
mDb.insertOrReplace(values);
}
use of com.android.launcher3.util.Thunk in project android_packages_apps_Launcher3 by crdroidandroid.
the class DatabaseWidgetPreviewLoader method readFromDb.
/**
* Reads the preview bitmap from the DB or null if the preview is not in the DB.
*/
@Thunk
Bitmap readFromDb(WidgetCacheKey key, Bitmap recycle, PreviewLoadTask loadTask) {
Cursor cursor = null;
try {
cursor = mDb.query(new String[] { CacheDb.COLUMN_PREVIEW_BITMAP }, CacheDb.COLUMN_COMPONENT + " = ? AND " + CacheDb.COLUMN_USER + " = ? AND " + CacheDb.COLUMN_SIZE + " = ?", new String[] { key.componentName.flattenToShortString(), Long.toString(mUserCache.getSerialNumberForUser(key.user)), key.mSize });
// If cancelled, skip getting the blob and decoding it into a bitmap
if (loadTask.isCancelled()) {
return null;
}
if (cursor.moveToNext()) {
byte[] blob = cursor.getBlob(0);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inBitmap = recycle;
try {
if (!loadTask.isCancelled()) {
return BitmapFactory.decodeByteArray(blob, 0, blob.length, opts);
}
} catch (Exception e) {
return null;
}
}
} catch (SQLException e) {
Log.w(TAG, "Error loading preview from DB", e);
} finally {
if (cursor != null) {
cursor.close();
}
}
return null;
}
use of com.android.launcher3.util.Thunk in project android_packages_apps_Launcher3 by crdroidandroid.
the class Launcher method completeAddAppWidget.
/**
* Add a widget to the workspace.
*
* @param appWidgetId The app widget id
*/
@Thunk
void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo, AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
if (appWidgetInfo == null) {
appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
}
if (hostView == null) {
// Perform actual inflation because we're live
hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
}
LauncherAppWidgetInfo launcherInfo;
launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider, appWidgetInfo, hostView);
launcherInfo.spanX = itemInfo.spanX;
launcherInfo.spanY = itemInfo.spanY;
launcherInfo.minSpanX = itemInfo.minSpanX;
launcherInfo.minSpanY = itemInfo.minSpanY;
launcherInfo.user = appWidgetInfo.getProfile();
if (itemInfo instanceof PendingAddWidgetInfo) {
launcherInfo.sourceContainer = ((PendingAddWidgetInfo) itemInfo).sourceContainer;
} else if (itemInfo instanceof PendingRequestArgs) {
launcherInfo.sourceContainer = ((PendingRequestArgs) itemInfo).getWidgetSourceContainer();
}
getModelWriter().addItemToDatabase(launcherInfo, itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
hostView.setVisibility(View.VISIBLE);
prepareAppWidget(hostView, launcherInfo);
mWorkspace.addInScreen(hostView, launcherInfo);
announceForAccessibility(R.string.item_added_to_workspace);
// Show the widget resize frame.
if (hostView instanceof LauncherAppWidgetHostView) {
final LauncherAppWidgetHostView launcherHostView = (LauncherAppWidgetHostView) hostView;
CellLayout cellLayout = getCellLayout(launcherInfo.container, launcherInfo.screenId);
if (mStateManager.getState() == NORMAL) {
// Show resize frame once the widget layout is drawn.
View.OnLayoutChangeListener onLayoutChangeListener = new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
AppWidgetResizeFrame.showForWidget(launcherHostView, cellLayout);
launcherHostView.removeOnLayoutChangeListener(this);
}
};
launcherHostView.addOnLayoutChangeListener(onLayoutChangeListener);
// There is a small chance that the layout was already drawn before the layout
// change listener was registered, which means that the resize frame wouldn't be
// shown. Directly call requestLayout to force a layout change.
launcherHostView.requestLayout();
} else {
mStateManager.addStateListener(new StateManager.StateListener<LauncherState>() {
@Override
public void onStateTransitionComplete(LauncherState finalState) {
if (mPrevLauncherState == SPRING_LOADED && finalState == NORMAL) {
AppWidgetResizeFrame.showForWidget(launcherHostView, cellLayout);
mStateManager.removeStateListener(this);
}
}
});
}
}
}
Aggregations