Search in sources :

Example 21 with LayoutParams

use of android.view.WindowManager.LayoutParams in project platform_frameworks_base by android.

the class WindowStateAnimator method tryChangeFormatInPlaceLocked.

/**
     * Try to change the pixel format without recreating the surface. This
     * will be common in the case of changing from PixelFormat.OPAQUE to
     * PixelFormat.TRANSLUCENT in the hardware-accelerated case as both
     * requested formats resolve to the same underlying SurfaceControl format
     * @return True if format was succesfully changed, false otherwise
     */
boolean tryChangeFormatInPlaceLocked() {
    if (mSurfaceController == null) {
        return false;
    }
    final LayoutParams attrs = mWin.getAttrs();
    final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
    final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
    if (format == mSurfaceFormat) {
        setOpaqueLocked(!PixelFormat.formatHasAlpha(attrs.format));
        return true;
    }
    return false;
}
Also used : LayoutParams(android.view.WindowManager.LayoutParams) Point(android.graphics.Point)

Example 22 with LayoutParams

use of android.view.WindowManager.LayoutParams in project android_frameworks_base by ParanoidAndroid.

the class ZoomButtonsController method createContainer.

private FrameLayout createContainer() {
    LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    // Controls are positioned BOTTOM | CENTER with respect to the owner view.
    lp.gravity = Gravity.TOP | Gravity.START;
    lp.flags = LayoutParams.FLAG_NOT_TOUCHABLE | LayoutParams.FLAG_NOT_FOCUSABLE | LayoutParams.FLAG_LAYOUT_NO_LIMITS | LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    lp.height = LayoutParams.WRAP_CONTENT;
    lp.width = LayoutParams.MATCH_PARENT;
    lp.type = LayoutParams.TYPE_APPLICATION_PANEL;
    lp.format = PixelFormat.TRANSLUCENT;
    lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons;
    mContainerLayoutParams = lp;
    FrameLayout container = new Container(mContext);
    container.setLayoutParams(lp);
    container.setMeasureAllChildren(true);
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(com.android.internal.R.layout.zoom_container, container);
    mControls = (ZoomControls) container.findViewById(com.android.internal.R.id.zoomControls);
    mControls.setOnZoomInClickListener(new OnClickListener() {

        public void onClick(View v) {
            dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT);
            if (mCallback != null)
                mCallback.onZoom(true);
        }
    });
    mControls.setOnZoomOutClickListener(new OnClickListener() {

        public void onClick(View v) {
            dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT);
            if (mCallback != null)
                mCallback.onZoom(false);
        }
    });
    return container;
}
Also used : LayoutParams(android.view.WindowManager.LayoutParams) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) View(android.view.View)

Example 23 with LayoutParams

use of android.view.WindowManager.LayoutParams in project android_frameworks_base by ParanoidAndroid.

the class WindowManagerService method handleAppTransitionReadyLocked.

/**
     * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method.
     * @param windows List of windows on default display.
     * @return bitmap indicating if another pass through layout must be made.
     */
public int handleAppTransitionReadyLocked(WindowList windows) {
    int changes = 0;
    int i;
    int NN = mOpeningApps.size();
    boolean goodToGo = true;
    if (DEBUG_APP_TRANSITIONS)
        Slog.v(TAG, "Checking " + NN + " opening apps (frozen=" + mDisplayFrozen + " timeout=" + mAppTransition.isTimeout() + ")...");
    if (!mDisplayFrozen && !mAppTransition.isTimeout()) {
        // we'll unfreeze the display when everyone is ready.
        for (i = 0; i < NN && goodToGo; i++) {
            AppWindowToken wtoken = mOpeningApps.get(i);
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "Check opening app=" + wtoken + ": allDrawn=" + wtoken.allDrawn + " startingDisplayed=" + wtoken.startingDisplayed + " startingMoved=" + wtoken.startingMoved);
            if (!wtoken.allDrawn && !wtoken.startingDisplayed && !wtoken.startingMoved) {
                goodToGo = false;
            }
        }
    }
    if (goodToGo) {
        if (DEBUG_APP_TRANSITIONS)
            Slog.v(TAG, "**** GOOD TO GO");
        int transit = mAppTransition.getAppTransition();
        if (mSkipAppTransitionAnimation) {
            transit = AppTransition.TRANSIT_UNSET;
        }
        mAppTransition.goodToGo();
        mStartingIconInTransition = false;
        mSkipAppTransitionAnimation = false;
        mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
        rebuildAppWindowListLocked();
        // if wallpaper is animating in or out set oldWallpaper to null else to wallpaper
        WindowState oldWallpaper = mWallpaperTarget != null && mWallpaperTarget.mWinAnimator.isAnimating() && !mWallpaperTarget.mWinAnimator.isDummyAnimation() ? null : mWallpaperTarget;
        mInnerFields.mWallpaperMayChange = false;
        // The top-most window will supply the layout params,
        // and we will determine it below.
        LayoutParams animLp = null;
        int bestAnimLayer = -1;
        boolean fullscreenAnim = false;
        if (DEBUG_APP_TRANSITIONS)
            Slog.v(TAG, "New wallpaper target=" + mWallpaperTarget + ", oldWallpaper=" + oldWallpaper + ", lower target=" + mLowerWallpaperTarget + ", upper target=" + mUpperWallpaperTarget);
        boolean openingAppHasWallpaper = false;
        boolean closingAppHasWallpaper = false;
        final AppWindowToken lowerWallpaperAppToken;
        final AppWindowToken upperWallpaperAppToken;
        if (mLowerWallpaperTarget == null) {
            lowerWallpaperAppToken = upperWallpaperAppToken = null;
        } else {
            lowerWallpaperAppToken = mLowerWallpaperTarget.mAppToken;
            upperWallpaperAppToken = mUpperWallpaperTarget.mAppToken;
        }
        // Do a first pass through the tokens for two
        // things:
        // (1) Determine if both the closing and opening
        // app token sets are wallpaper targets, in which
        // case special animations are needed
        // (since the wallpaper needs to stay static
        // behind them).
        // (2) Find the layout params of the top-most
        // application window in the tokens, which is
        // what will control the animation theme.
        final int NC = mClosingApps.size();
        NN = NC + mOpeningApps.size();
        for (i = 0; i < NN; i++) {
            final AppWindowToken wtoken;
            if (i < NC) {
                wtoken = mClosingApps.get(i);
                if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
                    closingAppHasWallpaper = true;
                }
            } else {
                wtoken = mOpeningApps.get(i - NC);
                if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
                    openingAppHasWallpaper = true;
                }
            }
            if (wtoken.appFullscreen) {
                WindowState ws = wtoken.findMainWindow();
                if (ws != null) {
                    animLp = ws.mAttrs;
                    bestAnimLayer = ws.mLayer;
                    fullscreenAnim = true;
                }
            } else if (!fullscreenAnim) {
                WindowState ws = wtoken.findMainWindow();
                if (ws != null) {
                    if (ws.mLayer > bestAnimLayer) {
                        animLp = ws.mAttrs;
                        bestAnimLayer = ws.mLayer;
                    }
                }
            }
        }
        if (closingAppHasWallpaper && openingAppHasWallpaper) {
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "Wallpaper animation!");
            switch(transit) {
                case AppTransition.TRANSIT_ACTIVITY_OPEN:
                case AppTransition.TRANSIT_TASK_OPEN:
                case AppTransition.TRANSIT_TASK_TO_FRONT:
                    transit = AppTransition.TRANSIT_WALLPAPER_INTRA_OPEN;
                    break;
                case AppTransition.TRANSIT_ACTIVITY_CLOSE:
                case AppTransition.TRANSIT_TASK_CLOSE:
                case AppTransition.TRANSIT_TASK_TO_BACK:
                    transit = AppTransition.TRANSIT_WALLPAPER_INTRA_CLOSE;
                    break;
            }
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "New transit: " + transit);
        } else if ((oldWallpaper != null) && !mOpeningApps.contains(oldWallpaper.mAppToken)) {
            // We are transitioning from an activity with
            // a wallpaper to one without.
            transit = AppTransition.TRANSIT_WALLPAPER_CLOSE;
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "New transit away from wallpaper: " + transit);
        } else if (mWallpaperTarget != null && mWallpaperTarget.isVisibleLw()) {
            // We are transitioning from an activity without
            // a wallpaper to now showing the wallpaper
            transit = AppTransition.TRANSIT_WALLPAPER_OPEN;
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "New transit into wallpaper: " + transit);
        }
        // the lock screen.
        if (!mPolicy.allowAppAnimationsLw()) {
            animLp = null;
        }
        AppWindowToken topOpeningApp = null;
        int topOpeningLayer = 0;
        NN = mOpeningApps.size();
        for (i = 0; i < NN; i++) {
            AppWindowToken wtoken = mOpeningApps.get(i);
            final AppWindowAnimator appAnimator = wtoken.mAppAnimator;
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "Now opening app" + wtoken);
            appAnimator.clearThumbnail();
            wtoken.inPendingTransaction = false;
            appAnimator.animation = null;
            setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
            wtoken.updateReportedVisibilityLocked();
            wtoken.waitingToShow = false;
            appAnimator.mAllAppWinAnimators.clear();
            final int N = wtoken.allAppWindows.size();
            for (int j = 0; j < N; j++) {
                appAnimator.mAllAppWinAnimators.add(wtoken.allAppWindows.get(j).mWinAnimator);
            }
            mAnimator.mAnimating |= appAnimator.showAllWindowsLocked();
            if (animLp != null) {
                int layer = -1;
                for (int j = 0; j < wtoken.windows.size(); j++) {
                    WindowState win = wtoken.windows.get(j);
                    if (win.mWinAnimator.mAnimLayer > layer) {
                        layer = win.mWinAnimator.mAnimLayer;
                    }
                }
                if (topOpeningApp == null || layer > topOpeningLayer) {
                    topOpeningApp = wtoken;
                    topOpeningLayer = layer;
                }
            }
        }
        NN = mClosingApps.size();
        for (i = 0; i < NN; i++) {
            AppWindowToken wtoken = mClosingApps.get(i);
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "Now closing app " + wtoken);
            wtoken.mAppAnimator.clearThumbnail();
            wtoken.inPendingTransaction = false;
            wtoken.mAppAnimator.animation = null;
            setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
            wtoken.updateReportedVisibilityLocked();
            wtoken.waitingToHide = false;
            // Force the allDrawn flag, because we want to start
            // this guy's animations regardless of whether it's
            // gotten drawn.
            wtoken.allDrawn = true;
            wtoken.deferClearAllDrawn = false;
        }
        AppWindowAnimator appAnimator = topOpeningApp == null ? null : topOpeningApp.mAppAnimator;
        Bitmap nextAppTransitionThumbnail = mAppTransition.getNextAppTransitionThumbnail();
        if (nextAppTransitionThumbnail != null && appAnimator != null && appAnimator.animation != null) {
            // This thumbnail animation is very special, we need to have
            // an extra surface with the thumbnail included with the animation.
            Rect dirty = new Rect(0, 0, nextAppTransitionThumbnail.getWidth(), nextAppTransitionThumbnail.getHeight());
            try {
                // TODO(multi-display): support other displays
                final DisplayContent displayContent = getDefaultDisplayContentLocked();
                final Display display = displayContent.getDisplay();
                SurfaceControl surfaceControl = new SurfaceControl(mFxSession, "thumbnail anim", dirty.width(), dirty.height(), PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
                surfaceControl.setLayerStack(display.getLayerStack());
                appAnimator.thumbnail = surfaceControl;
                if (SHOW_TRANSACTIONS)
                    Slog.i(TAG, "  THUMBNAIL " + surfaceControl + ": CREATE");
                Surface drawSurface = new Surface();
                drawSurface.copyFrom(surfaceControl);
                Canvas c = drawSurface.lockCanvas(dirty);
                c.drawBitmap(nextAppTransitionThumbnail, 0, 0, null);
                drawSurface.unlockCanvasAndPost(c);
                drawSurface.release();
                appAnimator.thumbnailLayer = topOpeningLayer;
                DisplayInfo displayInfo = getDefaultDisplayInfoLocked();
                Animation anim = mAppTransition.createThumbnailAnimationLocked(transit, true, true, displayInfo.appWidth, displayInfo.appHeight);
                appAnimator.thumbnailAnimation = anim;
                anim.restrictDuration(MAX_ANIMATION_DURATION);
                anim.scaleCurrentDuration(mTransitionAnimationScale);
                Point p = new Point();
                mAppTransition.getStartingPoint(p);
                appAnimator.thumbnailX = p.x;
                appAnimator.thumbnailY = p.y;
            } catch (SurfaceControl.OutOfResourcesException e) {
                Slog.e(TAG, "Can't allocate thumbnail surface w=" + dirty.width() + " h=" + dirty.height(), e);
                appAnimator.clearThumbnail();
            } catch (Surface.OutOfResourcesException e) {
                Slog.e(TAG, "Can't allocate Canvas surface w=" + dirty.width() + " h=" + dirty.height(), e);
                appAnimator.clearThumbnail();
            }
        }
        mAppTransition.postAnimationCallback();
        mAppTransition.clear();
        mOpeningApps.clear();
        mClosingApps.clear();
        // This has changed the visibility of windows, so perform
        // a new layout to get them all up-to-date.
        changes |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
        getDefaultDisplayContentLocked().layoutNeeded = true;
        // TODO(multidisplay): IMEs are only supported on the default display.
        if (windows == getDefaultWindowListLocked() && !moveInputMethodWindowsIfNeededLocked(true)) {
            assignLayersLocked(windows);
        }
        updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, false);
        mFocusMayChange = false;
    }
    return changes;
}
Also used : Rect(android.graphics.Rect) LayoutParams(android.view.WindowManager.LayoutParams) DisplayInfo(android.view.DisplayInfo) SurfaceControl(android.view.SurfaceControl) Canvas(android.graphics.Canvas) Point(android.graphics.Point) Point(android.graphics.Point) Surface(android.view.Surface) Bitmap(android.graphics.Bitmap) Animation(android.view.animation.Animation) Display(android.view.Display)

Example 24 with LayoutParams

use of android.view.WindowManager.LayoutParams in project platform_frameworks_base by android.

the class PopupWindow method dismiss.

/**
     * Disposes of the popup window. This method can be invoked only after
     * {@link #showAsDropDown(android.view.View)} has been executed. Failing
     * that, calling this method will have no effect.
     *
     * @see #showAsDropDown(android.view.View)
     */
public void dismiss() {
    if (!isShowing() || mIsTransitioningToDismiss) {
        return;
    }
    final PopupDecorView decorView = mDecorView;
    final View contentView = mContentView;
    final ViewGroup contentHolder;
    final ViewParent contentParent = contentView.getParent();
    if (contentParent instanceof ViewGroup) {
        contentHolder = ((ViewGroup) contentParent);
    } else {
        contentHolder = null;
    }
    // Ensure any ongoing or pending transitions are canceled.
    decorView.cancelTransitions();
    mIsShowing = false;
    mIsTransitioningToDismiss = true;
    // This method may be called as part of window detachment, in which
    // case the anchor view (and its root) will still return true from
    // isAttachedToWindow() during execution of this method; however, we
    // can expect the OnAttachStateChangeListener to have been called prior
    // to executing this method, so we can rely on that instead.
    final Transition exitTransition = mExitTransition;
    if (mIsAnchorRootAttached && exitTransition != null && decorView.isLaidOut()) {
        // The decor view is non-interactive and non-IME-focusable during exit transitions.
        final LayoutParams p = (LayoutParams) decorView.getLayoutParams();
        p.flags |= LayoutParams.FLAG_NOT_TOUCHABLE;
        p.flags |= LayoutParams.FLAG_NOT_FOCUSABLE;
        p.flags &= ~LayoutParams.FLAG_ALT_FOCUSABLE_IM;
        mWindowManager.updateViewLayout(decorView, p);
        // Once we start dismissing the decor view, all state (including
        // the anchor root) needs to be moved to the decor view since we
        // may open another popup while it's busy exiting.
        final View anchorRoot = mAnchorRoot != null ? mAnchorRoot.get() : null;
        final Rect epicenter = getTransitionEpicenter();
        exitTransition.setEpicenterCallback(new EpicenterCallback() {

            @Override
            public Rect onGetEpicenter(Transition transition) {
                return epicenter;
            }
        });
        decorView.startExitTransition(exitTransition, anchorRoot, new TransitionListenerAdapter() {

            @Override
            public void onTransitionEnd(Transition transition) {
                dismissImmediate(decorView, contentHolder, contentView);
            }
        });
    } else {
        dismissImmediate(decorView, contentHolder, contentView);
    }
    // Clears the anchor view.
    detachFromAnchor();
    if (mOnDismissListener != null) {
        mOnDismissListener.onDismiss();
    }
}
Also used : Rect(android.graphics.Rect) LayoutParams(android.view.WindowManager.LayoutParams) ViewGroup(android.view.ViewGroup) ViewParent(android.view.ViewParent) EpicenterCallback(android.transition.Transition.EpicenterCallback) Transition(android.transition.Transition) TransitionListenerAdapter(android.transition.Transition.TransitionListenerAdapter) View(android.view.View)

Example 25 with LayoutParams

use of android.view.WindowManager.LayoutParams in project platform_frameworks_base by android.

the class PopupWindow method update.

private void update(View anchor, boolean updateLocation, int xoff, int yoff, int width, int height) {
    if (!isShowing() || mContentView == null) {
        return;
    }
    final WeakReference<View> oldAnchor = mAnchor;
    final int gravity = mAnchoredGravity;
    final boolean needsUpdate = updateLocation && (mAnchorXoff != xoff || mAnchorYoff != yoff);
    if (oldAnchor == null || oldAnchor.get() != anchor || (needsUpdate && !mIsDropdown)) {
        attachToAnchor(anchor, xoff, yoff, gravity);
    } else if (needsUpdate) {
        // No need to register again if this is a DropDown, showAsDropDown already did.
        mAnchorXoff = xoff;
        mAnchorYoff = yoff;
    }
    final LayoutParams p = (LayoutParams) mDecorView.getLayoutParams();
    final int oldGravity = p.gravity;
    final int oldWidth = p.width;
    final int oldHeight = p.height;
    final int oldX = p.x;
    final int oldY = p.y;
    // explicitly specified value (either from setWidth/Height or update).
    if (width < 0) {
        width = mWidth;
    }
    if (height < 0) {
        height = mHeight;
    }
    final boolean aboveAnchor = findDropDownPosition(anchor, p, mAnchorXoff, mAnchorYoff, width, height, gravity);
    updateAboveAnchor(aboveAnchor);
    final boolean paramsChanged = oldGravity != p.gravity || oldX != p.x || oldY != p.y || oldWidth != p.width || oldHeight != p.height;
    // If width and mWidth were both < 0 then we have a MATCH_PARENT/WRAP_CONTENT case.
    // findDropDownPosition will have resolved this to absolute values,
    // but we don't want to update mWidth/mHeight to these absolute values.
    update(p.x, p.y, width < 0 ? width : p.width, height < 0 ? height : p.height, paramsChanged);
}
Also used : LayoutParams(android.view.WindowManager.LayoutParams) View(android.view.View)

Aggregations

LayoutParams (android.view.WindowManager.LayoutParams)46 View (android.view.View)19 Point (android.graphics.Point)10 Rect (android.graphics.Rect)8 OnClickListener (android.view.View.OnClickListener)8 LayoutInflater (android.view.LayoutInflater)7 Transition (android.transition.Transition)5 TransitionListenerAdapter (android.transition.Transition.TransitionListenerAdapter)5 ViewGroup (android.view.ViewGroup)5 ViewParent (android.view.ViewParent)5 WindowManager (android.view.WindowManager)5 Window (android.view.Window)3 Canvas (android.graphics.Canvas)2 Surface (android.view.Surface)2 Animation (android.view.animation.Animation)2 TargetApi (android.annotation.TargetApi)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 EpicenterCallback (android.transition.Transition.EpicenterCallback)1 Display (android.view.Display)1