Java Code Examples for android.graphics.Bitmap#createHardwareBitmap()

The following examples show how to use android.graphics.Bitmap#createHardwareBitmap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WallpaperController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Take a screenshot of the wallpaper if it's visible.
 *
 * @return Bitmap of the wallpaper
 */
Bitmap screenshotWallpaperLocked() {
    if (!mService.mPolicy.isScreenOn()) {
        if (DEBUG_SCREENSHOT) {
            Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
        }
        return null;
    }

    final WindowState wallpaperWindowState = getTopVisibleWallpaper();
    if (wallpaperWindowState == null) {
        if (DEBUG_SCREENSHOT) {
            Slog.i(TAG_WM, "No visible wallpaper to screenshot");
        }
        return null;
    }

    final Rect bounds = wallpaperWindowState.getBounds();
    bounds.offsetTo(0, 0);

    GraphicBuffer wallpaperBuffer = SurfaceControl.captureLayers(
            wallpaperWindowState.getSurfaceControl().getHandle(), bounds, 1 /* frameScale */);

    if (wallpaperBuffer == null) {
        Slog.w(TAG_WM, "Failed to screenshot wallpaper");
        return null;
    }
    return Bitmap.createHardwareBitmap(wallpaperBuffer);
}
 
Example 2
Source File: ActivityOptions.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/** @hide */
public ActivityOptions(Bundle opts) {
    // If the remote side sent us bad parcelables, they won't get the
    // results they want, which is their loss.
    opts.setDefusable(true);

    mPackageName = opts.getString(KEY_PACKAGE_NAME);
    try {
        mUsageTimeReport = opts.getParcelable(KEY_USAGE_TIME_REPORT);
    } catch (RuntimeException e) {
        Slog.w(TAG, e);
    }
    mLaunchBounds = opts.getParcelable(KEY_LAUNCH_BOUNDS);
    mAnimationType = opts.getInt(KEY_ANIM_TYPE);
    switch (mAnimationType) {
        case ANIM_CUSTOM:
            mCustomEnterResId = opts.getInt(KEY_ANIM_ENTER_RES_ID, 0);
            mCustomExitResId = opts.getInt(KEY_ANIM_EXIT_RES_ID, 0);
            mAnimationStartedListener = IRemoteCallback.Stub.asInterface(
                    opts.getBinder(KEY_ANIM_START_LISTENER));
            break;

        case ANIM_CUSTOM_IN_PLACE:
            mCustomInPlaceResId = opts.getInt(KEY_ANIM_IN_PLACE_RES_ID, 0);
            break;

        case ANIM_SCALE_UP:
        case ANIM_CLIP_REVEAL:
            mStartX = opts.getInt(KEY_ANIM_START_X, 0);
            mStartY = opts.getInt(KEY_ANIM_START_Y, 0);
            mWidth = opts.getInt(KEY_ANIM_WIDTH, 0);
            mHeight = opts.getInt(KEY_ANIM_HEIGHT, 0);
            break;

        case ANIM_THUMBNAIL_SCALE_UP:
        case ANIM_THUMBNAIL_SCALE_DOWN:
        case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
        case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
            // Unpackage the GraphicBuffer from the parceled thumbnail
            final GraphicBuffer buffer = opts.getParcelable(KEY_ANIM_THUMBNAIL);
            if (buffer != null) {
                mThumbnail = Bitmap.createHardwareBitmap(buffer);
            }
            mStartX = opts.getInt(KEY_ANIM_START_X, 0);
            mStartY = opts.getInt(KEY_ANIM_START_Y, 0);
            mWidth = opts.getInt(KEY_ANIM_WIDTH, 0);
            mHeight = opts.getInt(KEY_ANIM_HEIGHT, 0);
            mAnimationStartedListener = IRemoteCallback.Stub.asInterface(
                    opts.getBinder(KEY_ANIM_START_LISTENER));
            break;

        case ANIM_SCENE_TRANSITION:
            mTransitionReceiver = opts.getParcelable(KEY_TRANSITION_COMPLETE_LISTENER);
            mIsReturning = opts.getBoolean(KEY_TRANSITION_IS_RETURNING, false);
            mSharedElementNames = opts.getStringArrayList(KEY_TRANSITION_SHARED_ELEMENTS);
            mResultData = opts.getParcelable(KEY_RESULT_DATA);
            mResultCode = opts.getInt(KEY_RESULT_CODE);
            mExitCoordinatorIndex = opts.getInt(KEY_EXIT_COORDINATOR_INDEX);
            break;
    }
    mLockTaskMode = opts.getBoolean(KEY_LOCK_TASK_MODE, false);
    mLaunchDisplayId = opts.getInt(KEY_LAUNCH_DISPLAY_ID, INVALID_DISPLAY);
    mLaunchWindowingMode = opts.getInt(KEY_LAUNCH_WINDOWING_MODE, WINDOWING_MODE_UNDEFINED);
    mLaunchActivityType = opts.getInt(KEY_LAUNCH_ACTIVITY_TYPE, ACTIVITY_TYPE_UNDEFINED);
    mLaunchTaskId = opts.getInt(KEY_LAUNCH_TASK_ID, -1);
    mTaskOverlay = opts.getBoolean(KEY_TASK_OVERLAY, false);
    mTaskOverlayCanResume = opts.getBoolean(KEY_TASK_OVERLAY_CAN_RESUME, false);
    mAvoidMoveToFront = opts.getBoolean(KEY_AVOID_MOVE_TO_FRONT, false);
    mSplitScreenCreateMode = opts.getInt(KEY_SPLIT_SCREEN_CREATE_MODE,
            SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT);
    mDisallowEnterPictureInPictureWhileLaunching = opts.getBoolean(
            KEY_DISALLOW_ENTER_PICTURE_IN_PICTURE_WHILE_LAUNCHING, false);
    if (opts.containsKey(KEY_ANIM_SPECS)) {
        Parcelable[] specs = opts.getParcelableArray(KEY_ANIM_SPECS);
        mAnimSpecs = new AppTransitionAnimationSpec[specs.length];
        for (int i = specs.length - 1; i >= 0; i--) {
            mAnimSpecs[i] = (AppTransitionAnimationSpec) specs[i];
        }
    }
    if (opts.containsKey(KEY_ANIMATION_FINISHED_LISTENER)) {
        mAnimationFinishedListener = IRemoteCallback.Stub.asInterface(
                opts.getBinder(KEY_ANIMATION_FINISHED_LISTENER));
    }
    mRotationAnimationHint = opts.getInt(KEY_ROTATION_ANIMATION_HINT);
    mAppVerificationBundle = opts.getBundle(KEY_INSTANT_APP_VERIFICATION_BUNDLE);
    if (opts.containsKey(KEY_SPECS_FUTURE)) {
        mSpecsFuture = IAppTransitionAnimationSpecsFuture.Stub.asInterface(opts.getBinder(
                KEY_SPECS_FUTURE));
    }
    mRemoteAnimationAdapter = opts.getParcelable(KEY_REMOTE_ANIMATION_ADAPTER);
}