Search in sources :

Example 1 with Thunk

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;
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Thunk(com.android.launcher3.util.Thunk)

Example 2 with Thunk

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();
    }
}
Also used : PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) Thunk(com.android.launcher3.util.Thunk)

Example 3 with Thunk

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);
}
Also used : ContentValues(android.content.ContentValues) Thunk(com.android.launcher3.util.Thunk)

Example 4 with Thunk

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;
}
Also used : SQLException(android.database.SQLException) BitmapFactory(android.graphics.BitmapFactory) Cursor(android.database.Cursor) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) SQLException(android.database.SQLException) ExecutionException(java.util.concurrent.ExecutionException) Thunk(com.android.launcher3.util.Thunk)

Example 5 with Thunk

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);
                    }
                }
            });
        }
    }
}
Also used : StateManager(com.android.launcher3.statemanager.StateManager) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) QsbContainerView(com.android.launcher3.qsb.QsbContainerView) OptionsPopupView(com.android.launcher3.views.OptionsPopupView) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) ImageView(android.widget.ImageView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) FloatingSurfaceView(com.android.launcher3.views.FloatingSurfaceView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) ScrimView(com.android.launcher3.views.ScrimView) PendingRequestArgs(com.android.launcher3.util.PendingRequestArgs) Thunk(com.android.launcher3.util.Thunk)

Aggregations

Thunk (com.android.launcher3.util.Thunk)5 AppWidgetHostView (android.appwidget.AppWidgetHostView)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)2 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)2 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)2 ContentValues (android.content.ContentValues)1 PackageInfo (android.content.pm.PackageInfo)1 Cursor (android.database.Cursor)1 SQLException (android.database.SQLException)1 BitmapFactory (android.graphics.BitmapFactory)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 AllAppsContainerView (com.android.launcher3.allapps.AllAppsContainerView)1 DragView (com.android.launcher3.dragndrop.DragView)1 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)1 QsbContainerView (com.android.launcher3.qsb.QsbContainerView)1 StateManager (com.android.launcher3.statemanager.StateManager)1 PendingRequestArgs (com.android.launcher3.util.PendingRequestArgs)1 FloatingSurfaceView (com.android.launcher3.views.FloatingSurfaceView)1 OptionsPopupView (com.android.launcher3.views.OptionsPopupView)1