Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3dec0819 authored by Filip Gruszczynski's avatar Filip Gruszczynski
Browse files

Remaining APIs for freeform window caption.

The APIs are:
* setting a listener for the area of the caption where we display
control buttons; this is intended for apps that overlay the caption on
their content, so they don't display the content in that area and clash
with the buttons;
* specifying the color pallete of controls in the caption; by default we
try to infer the best color from the theme (dark buttons for light theme
and vice versa), but in case we get it wrong, we allow the developer to
overwrite it;
* specifying the caption background during the resizing; by default we
try to infer a good color from the theme, but in case we do it wrong, we
allow the developer to overwrite this.

The CL also includes merging of layouts decor_caption_dark and
decor_caption_light into a single one. Not only it reduces code
duplication, but also is necessary for allowing adjustment of the
controls color pallete after the layout was created.

Bug: 25486369
Bug: 25818398

Change-Id: Ib87fe849b07df341893ec7873982bf7ab932f6d5
parent 6f775a8d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -41844,6 +41844,7 @@ package android.view {
    method public abstract void setContentView(int);
    method public abstract void setContentView(android.view.View);
    method public abstract void setContentView(android.view.View, android.view.ViewGroup.LayoutParams);
    method public abstract void setDecorCaptionShade(int);
    method protected void setDefaultWindowFormat(int);
    method public void setDimAmount(float);
    method public void setElevation(float);
@@ -41864,6 +41865,8 @@ package android.view {
    method public void setMediaController(android.media.session.MediaController);
    method public abstract void setNavigationBarColor(int);
    method public void setReenterTransition(android.transition.Transition);
    method public abstract void setResizingCaptionDrawable(android.graphics.drawable.Drawable);
    method public final void setRestrictedCaptionAreaListener(android.view.Window.RestrictedCaptionAreaListener);
    method public void setReturnTransition(android.transition.Transition);
    method public void setSharedElementEnterTransition(android.transition.Transition);
    method public void setSharedElementExitTransition(android.transition.Transition);
@@ -41892,6 +41895,9 @@ package android.view {
    method public abstract void takeKeyEvents(boolean);
    method public abstract void takeSurface(android.view.SurfaceHolder.Callback2);
    method public abstract void togglePanel(int, android.view.KeyEvent);
    field public static final int DECOR_CAPTION_SHADE_AUTO = 0; // 0x0
    field public static final int DECOR_CAPTION_SHADE_DARK = 2; // 0x2
    field public static final int DECOR_CAPTION_SHADE_LIGHT = 1; // 0x1
    field protected static final deprecated int DEFAULT_FEATURES = 65; // 0x41
    field public static final int FEATURE_ACTION_BAR = 8; // 0x8
    field public static final int FEATURE_ACTION_BAR_OVERLAY = 9; // 0x9
@@ -41946,6 +41952,10 @@ package android.view {
    method public abstract android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback, int);
  }
  public static abstract interface Window.RestrictedCaptionAreaListener {
    method public abstract void onRestrictedCaptionAreaChanged(android.graphics.Rect);
  }
  public final class WindowAnimationFrameStats extends android.view.FrameStats implements android.os.Parcelable {
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
+10 −0
Original line number Diff line number Diff line
@@ -44177,6 +44177,7 @@ package android.view {
    method public abstract void setContentView(int);
    method public abstract void setContentView(android.view.View);
    method public abstract void setContentView(android.view.View, android.view.ViewGroup.LayoutParams);
    method public abstract void setDecorCaptionShade(int);
    method protected void setDefaultWindowFormat(int);
    method public void setDimAmount(float);
    method public void setDisableWallpaperTouchEvents(boolean);
@@ -44198,6 +44199,8 @@ package android.view {
    method public void setMediaController(android.media.session.MediaController);
    method public abstract void setNavigationBarColor(int);
    method public void setReenterTransition(android.transition.Transition);
    method public abstract void setResizingCaptionDrawable(android.graphics.drawable.Drawable);
    method public final void setRestrictedCaptionAreaListener(android.view.Window.RestrictedCaptionAreaListener);
    method public void setReturnTransition(android.transition.Transition);
    method public void setSharedElementEnterTransition(android.transition.Transition);
    method public void setSharedElementExitTransition(android.transition.Transition);
@@ -44226,6 +44229,9 @@ package android.view {
    method public abstract void takeKeyEvents(boolean);
    method public abstract void takeSurface(android.view.SurfaceHolder.Callback2);
    method public abstract void togglePanel(int, android.view.KeyEvent);
    field public static final int DECOR_CAPTION_SHADE_AUTO = 0; // 0x0
    field public static final int DECOR_CAPTION_SHADE_DARK = 2; // 0x2
    field public static final int DECOR_CAPTION_SHADE_LIGHT = 1; // 0x1
    field protected static final deprecated int DEFAULT_FEATURES = 65; // 0x41
    field public static final int FEATURE_ACTION_BAR = 8; // 0x8
    field public static final int FEATURE_ACTION_BAR_OVERLAY = 9; // 0x9
@@ -44280,6 +44286,10 @@ package android.view {
    method public abstract android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback, int);
  }
  public static abstract interface Window.RestrictedCaptionAreaListener {
    method public abstract void onRestrictedCaptionAreaChanged(android.graphics.Rect);
  }
  public final class WindowAnimationFrameStats extends android.view.FrameStats implements android.os.Parcelable {
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
+10 −0
Original line number Diff line number Diff line
@@ -41846,6 +41846,7 @@ package android.view {
    method public abstract void setContentView(int);
    method public abstract void setContentView(android.view.View);
    method public abstract void setContentView(android.view.View, android.view.ViewGroup.LayoutParams);
    method public abstract void setDecorCaptionShade(int);
    method protected void setDefaultWindowFormat(int);
    method public void setDimAmount(float);
    method public void setElevation(float);
@@ -41866,6 +41867,8 @@ package android.view {
    method public void setMediaController(android.media.session.MediaController);
    method public abstract void setNavigationBarColor(int);
    method public void setReenterTransition(android.transition.Transition);
    method public abstract void setResizingCaptionDrawable(android.graphics.drawable.Drawable);
    method public final void setRestrictedCaptionAreaListener(android.view.Window.RestrictedCaptionAreaListener);
    method public void setReturnTransition(android.transition.Transition);
    method public void setSharedElementEnterTransition(android.transition.Transition);
    method public void setSharedElementExitTransition(android.transition.Transition);
@@ -41894,6 +41897,9 @@ package android.view {
    method public abstract void takeKeyEvents(boolean);
    method public abstract void takeSurface(android.view.SurfaceHolder.Callback2);
    method public abstract void togglePanel(int, android.view.KeyEvent);
    field public static final int DECOR_CAPTION_SHADE_AUTO = 0; // 0x0
    field public static final int DECOR_CAPTION_SHADE_DARK = 2; // 0x2
    field public static final int DECOR_CAPTION_SHADE_LIGHT = 1; // 0x1
    field protected static final deprecated int DEFAULT_FEATURES = 65; // 0x41
    field public static final int FEATURE_ACTION_BAR = 8; // 0x8
    field public static final int FEATURE_ACTION_BAR_OVERLAY = 9; // 0x9
@@ -41948,6 +41954,10 @@ package android.view {
    method public abstract android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback, int);
  }
  public static abstract interface Window.RestrictedCaptionAreaListener {
    method public abstract void onRestrictedCaptionAreaChanged(android.graphics.Rect);
  }
  public final class WindowAnimationFrameStats extends android.view.FrameStats implements android.os.Parcelable {
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
+65 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.media.session.MediaController;
import android.net.Uri;
@@ -247,12 +248,30 @@ public abstract class Window {

    private static final String PROPERTY_HARDWARE_UI = "persist.sys.ui.hw";

    /**
     * Flag for letting the theme drive the color of the window caption controls. Use with
     * {@link #setDecorCaptionShade(int)}. This is the default value.
     */
    public static final int DECOR_CAPTION_SHADE_AUTO = 0;
    /**
     * Flag for setting light-color controls on the window caption. Use with
     * {@link #setDecorCaptionShade(int)}.
     */
    public static final int DECOR_CAPTION_SHADE_LIGHT = 1;
    /**
     * Flag for setting dark-color controls on the window caption. Use with
     * {@link #setDecorCaptionShade(int)}.
     */
    public static final int DECOR_CAPTION_SHADE_DARK = 2;

    private final Context mContext;

    private TypedArray mWindowStyle;
    private Callback mCallback;
    private OnWindowDismissedCallback mOnWindowDismissedCallback;
    private WindowControllerCallback mWindowControllerCallback;
    private RestrictedCaptionAreaListener mRestrictedCaptionAreaListener;
    private Rect mRestrictedCaptionAreaRect;
    private WindowManager mWindowManager;
    private IBinder mAppToken;
    private String mAppName;
@@ -565,6 +584,18 @@ public abstract class Window {
        int getWindowStackId() throws RemoteException;
    }

    /**
     * Callback for clients that want to be aware of where caption draws content.
     */
    public interface RestrictedCaptionAreaListener {
        /**
         * Called when the area where caption draws content changes.
         *
         * @param rect The area where caption content is positioned, relative to the top view.
         */
        void onRestrictedCaptionAreaChanged(Rect rect);
    }

    public Window(Context context) {
        mContext = context;
        mFeatures = mLocalFeatures = getDefaultFeatures(context);
@@ -777,6 +808,16 @@ public abstract class Window {
        return mWindowControllerCallback;
    }

    /**
     * Set a callback for changes of area where caption will draw its content.
     *
     * @param listener Callback that will be called when the area changes.
     */
    public final void setRestrictedCaptionAreaListener(RestrictedCaptionAreaListener listener) {
        mRestrictedCaptionAreaListener = listener;
        mRestrictedCaptionAreaRect = listener != null ? new Rect() : null;
    }

    /**
     * Take ownership of this window's surface.  The window's view hierarchy
     * will no longer draw into the surface, though it will otherwise continue
@@ -2040,5 +2081,29 @@ public abstract class Window {
        return mOverlayWithDecorCaption;
    }

    /** @hide */
    public void notifyRestrictedCaptionAreaCallback(int left, int top, int right, int bottom) {
        if (mRestrictedCaptionAreaListener != null) {
            mRestrictedCaptionAreaRect.set(left, top, right, bottom);
            mRestrictedCaptionAreaListener.onRestrictedCaptionAreaChanged(
                    mRestrictedCaptionAreaRect);
        }
    }

    /**
     * Set what color should the caption controls be. By default the system will try to determine
     * the color from the theme. You can overwrite this by using {@link #DECOR_CAPTION_SHADE_DARK}
     * or {@link #DECOR_CAPTION_SHADE_DARK}.
     */
    public abstract void setDecorCaptionShade(int decorCaptionShade);

    /**
     * Set the drawable that is drawn underneath the caption during the resizing.
     *
     * During the resizing the caption might not be drawn fast enough to match the new dimensions.
     * There is a second caption drawn underneath it that will be fast enough. By default the
     * caption is constructed from the theme. You can provide a drawable, that will be drawn instead
     * to better match your application.
     */
    public abstract void setResizingCaptionDrawable(Drawable drawable);
}
+14 −5
Original line number Diff line number Diff line
@@ -63,17 +63,18 @@ public class BackdropFrameRenderer extends Thread implements Choreographer.Frame
    private boolean mReportNextDraw;

    private Drawable mCaptionBackgroundDrawable;
    private Drawable mUserCaptionBackgroundDrawable;
    private Drawable mResizingBackgroundDrawable;
    private ColorDrawable mStatusBarColor;

    public BackdropFrameRenderer(DecorView decorView, ThreadedRenderer renderer, Rect initialBounds,
            Drawable resizingBackgroundDrawable, Drawable captionBackgroundDrawable,
            int statusBarColor) {
            Drawable userCaptionBackgroundDrawable, int statusBarColor) {
        setName("ResizeFrame");

        mRenderer = renderer;
        onResourcesLoaded(decorView, resizingBackgroundDrawable, captionBackgroundDrawable,
                statusBarColor);
                userCaptionBackgroundDrawable, statusBarColor);

        // Create a render node for the content and frame backdrop
        // which can be resized independently from the content.
@@ -92,10 +93,12 @@ public class BackdropFrameRenderer extends Thread implements Choreographer.Frame
    }

    void onResourcesLoaded(DecorView decorView, Drawable resizingBackgroundDrawable,
            Drawable captionBackgroundDrawableDrawable, int statusBarColor) {
            Drawable captionBackgroundDrawableDrawable, Drawable userCaptionBackgroundDrawable,
            int statusBarColor) {
        mDecorView = decorView;
        mResizingBackgroundDrawable = resizingBackgroundDrawable;
        mCaptionBackgroundDrawable = captionBackgroundDrawableDrawable;
        mUserCaptionBackgroundDrawable = userCaptionBackgroundDrawable;
        if (statusBarColor != 0) {
            mStatusBarColor = new ColorDrawable(statusBarColor);
            addSystemBarNodeIfNeeded();
@@ -281,8 +284,10 @@ public class BackdropFrameRenderer extends Thread implements Choreographer.Frame

        // Draw the caption and content backdrops in to our render node.
        DisplayListCanvas canvas = mFrameAndBackdropNode.start(width, height);
        mCaptionBackgroundDrawable.setBounds(0, 0, left + width, top + mLastCaptionHeight);
        mCaptionBackgroundDrawable.draw(canvas);
        final Drawable drawable = mUserCaptionBackgroundDrawable != null
                ? mUserCaptionBackgroundDrawable : mCaptionBackgroundDrawable;
        drawable.setBounds(0, 0, left + width, top + mLastCaptionHeight);
        drawable.draw(canvas);

        // The backdrop: clear everything with the background. Clipping is done elsewhere.
        mResizingBackgroundDrawable.setBounds(0, mLastCaptionHeight, left + width, top + height);
@@ -324,4 +329,8 @@ public class BackdropFrameRenderer extends Thread implements Choreographer.Frame
            mChoreographer.postFrameCallback(this);
        }
    }

    void setUserCaptionBackgroundDrawable(Drawable userCaptionBackgroundDrawable) {
        mUserCaptionBackgroundDrawable = userCaptionBackgroundDrawable;
    }
}
Loading