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

Commit 236bcc3a authored by Adam Powell's avatar Adam Powell Committed by Android (Google) Code Review
Browse files

Merge "Action bar refactoring, round 1"

parents 5575def8 4369e7d0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ public class WindowDecorActionBar extends ActionBar implements

    private void init(View decor) {
        mOverlayLayout = (ActionBarOverlayLayout) decor.findViewById(
                com.android.internal.R.id.action_bar_overlay_layout);
                com.android.internal.R.id.decor_content_parent);
        if (mOverlayLayout != null) {
            mOverlayLayout.setActionBarVisibilityCallback(this);
        }
+185 −3
Original line number Diff line number Diff line
@@ -19,26 +19,34 @@ package com.android.internal.widget;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.IntProperty;
import android.util.Log;
import android.util.Property;
import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.view.Window;
import android.view.WindowInsets;
import android.widget.OverScroller;
import com.android.internal.view.menu.MenuPresenter;

/**
 * Special layout for the containing of an overlay action bar (and its
 * content) to correctly handle fitting system windows when the content
 * has request that its layout ignore them.
 */
public class ActionBarOverlayLayout extends ViewGroup {
public class ActionBarOverlayLayout extends ViewGroup implements DecorContentParent {
    private static final String TAG = "ActionBarOverlayLayout";

    private int mActionBarHeight;
@@ -47,7 +55,7 @@ public class ActionBarOverlayLayout extends ViewGroup {

    // The main UI elements that we handle the layout of.
    private View mContent;
    private View mActionBarBottom;
    private ActionBarContainer mActionBarBottom;
    private ActionBarContainer mActionBarTop;

    // Some interior UI elements.
@@ -556,7 +564,8 @@ public class ActionBarOverlayLayout extends ViewGroup {
            mActionBarTop = (ActionBarContainer) findViewById(
                    com.android.internal.R.id.action_bar_container);
            mActionBarView = (ActionBarView) findViewById(com.android.internal.R.id.action_bar);
            mActionBarBottom = findViewById(com.android.internal.R.id.split_action_bar);
            mActionBarBottom = (ActionBarContainer) findViewById(
                    com.android.internal.R.id.split_action_bar);
        }
    }

@@ -629,6 +638,179 @@ public class ActionBarOverlayLayout extends ViewGroup {
        return finalY > mActionBarTop.getHeight();
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (super.dispatchKeyEvent(event)) {
            return true;
        }

        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            final int action = event.getAction();

            // Collapse any expanded action views.
            if (mActionBarView != null && mActionBarView.hasExpandedActionView()) {
                if (action == KeyEvent.ACTION_UP) {
                    mActionBarView.collapseActionView();
                }
                return true;
            }
        }

        return false;
    }

    @Override
    public void setWindowCallback(Window.Callback cb) {
        pullChildren();
        mActionBarView.setWindowCallback(cb);
    }

    @Override
    public void setWindowTitle(CharSequence title) {
        pullChildren();
        mActionBarView.setWindowTitle(title);
    }

    @Override
    public CharSequence getTitle() {
        pullChildren();
        return mActionBarView.getTitle();
    }

    @Override
    public void initFeature(int windowFeature) {
        pullChildren();
        switch (windowFeature) {
            case Window.FEATURE_PROGRESS:
                mActionBarView.initProgress();
                break;
            case Window.FEATURE_INDETERMINATE_PROGRESS:
                mActionBarView.initIndeterminateProgress();
                break;
            case Window.FEATURE_ACTION_BAR_OVERLAY:
                setOverlayMode(true);
                break;
        }
    }

    @Override
    public void setUiOptions(int uiOptions) {
        boolean splitActionBar = false;
        final boolean splitWhenNarrow =
                (uiOptions & ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW) != 0;
        if (splitWhenNarrow) {
            splitActionBar = getContext().getResources().getBoolean(
                    com.android.internal.R.bool.split_action_bar_is_narrow);
        }
        if (splitActionBar) {
            pullChildren();
            if (mActionBarBottom != null) {
                mActionBarView.setSplitView(mActionBarBottom);
                mActionBarView.setSplitActionBar(splitActionBar);
                mActionBarView.setSplitWhenNarrow(splitWhenNarrow);

                final ActionBarContextView cab = (ActionBarContextView) findViewById(
                        com.android.internal.R.id.action_context_bar);
                cab.setSplitView(mActionBarBottom);
                cab.setSplitActionBar(splitActionBar);
                cab.setSplitWhenNarrow(splitWhenNarrow);
            } else if (splitActionBar) {
                Log.e(TAG, "Requested split action bar with " +
                        "incompatible window decor! Ignoring request.");
            }
        }
    }

    @Override
    public boolean hasIcon() {
        pullChildren();
        return mActionBarView.hasIcon();
    }

    @Override
    public boolean hasLogo() {
        pullChildren();
        return mActionBarView.hasLogo();
    }

    @Override
    public void setIcon(int resId) {
        pullChildren();
        mActionBarView.setIcon(resId);
    }

    @Override
    public void setIcon(Drawable d) {
        pullChildren();
        mActionBarView.setIcon(d);
    }

    @Override
    public void setLogo(int resId) {
        pullChildren();
        mActionBarView.setLogo(resId);
    }

    @Override
    public boolean canShowOverflowMenu() {
        pullChildren();
        return mActionBarView.isOverflowReserved() && mActionBarView.getVisibility() == VISIBLE;
    }

    @Override
    public boolean isOverflowMenuShowing() {
        pullChildren();
        return mActionBarView.isOverflowMenuShowing();
    }

    @Override
    public boolean isOverflowMenuShowPending() {
        pullChildren();
        return mActionBarView.isOverflowMenuShowPending();
    }

    @Override
    public boolean showOverflowMenu() {
        pullChildren();
        return mActionBarView.showOverflowMenu();
    }

    @Override
    public boolean hideOverflowMenu() {
        pullChildren();
        return mActionBarView.hideOverflowMenu();
    }

    @Override
    public void setMenuPrepared() {
        pullChildren();
        mActionBarView.setMenuPrepared();
    }

    @Override
    public void setMenu(Menu menu, MenuPresenter.Callback cb) {
        pullChildren();
        mActionBarView.setMenu(menu, cb);
    }

    @Override
    public void saveToolbarHierarchyState(SparseArray<Parcelable> toolbarStates) {
        pullChildren();
        mActionBarView.saveHierarchyState(toolbarStates);
    }

    @Override
    public void restoreToolbarHierarchyState(SparseArray<Parcelable> toolbarStates) {
        pullChildren();
        mActionBarView.restoreHierarchyState(toolbarStates);
    }

    @Override
    public void dismissPopups() {
        pullChildren();
        mActionBarView.dismissPopupMenus();
    }

    public static class LayoutParams extends MarginLayoutParams {
        public LayoutParams(Context c, AttributeSet attrs) {
            super(c, attrs);
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.android.internal.widget;

import android.graphics.drawable.Drawable;
import android.os.Parcelable;
import android.util.SparseArray;
import android.view.Menu;
import android.view.Window;
import com.android.internal.view.menu.MenuPresenter;

/**
 * Implemented by the top-level decor layout for a window. DecorContentParent offers
 * entry points for a number of title/window decor features.
 */
public interface DecorContentParent {
    void setWindowCallback(Window.Callback cb);
    void setWindowTitle(CharSequence title);
    CharSequence getTitle();
    void initFeature(int windowFeature);
    void setUiOptions(int uiOptions);
    boolean hasIcon();
    boolean hasLogo();
    void setIcon(int resId);
    void setIcon(Drawable d);
    void setLogo(int resId);
    boolean canShowOverflowMenu();
    boolean isOverflowMenuShowing();
    boolean isOverflowMenuShowPending();
    boolean showOverflowMenu();
    boolean hideOverflowMenu();
    void setMenuPrepared();
    void setMenu(Menu menu, MenuPresenter.Callback cb);
    void saveToolbarHierarchyState(SparseArray<Parcelable> toolbarStates);
    void restoreToolbarHierarchyState(SparseArray<Parcelable> toolbarStates);
    void dismissPopups();

}
+0 −51
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!--
This is an optimized layout for a screen with
the Action Bar enabled overlaying application content.
-->

<com.android.internal.widget.ActionBarOverlayLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/action_bar_overlay_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:splitMotionEvents="false">
    <FrameLayout android:id="@android:id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <com.android.internal.widget.ActionBarContainer
        android:id="@+id/action_bar_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        style="?android:attr/actionBarStyle"
        android:viewName="android:action_bar"
        android:gravity="top">
        <com.android.internal.widget.ActionBarView
            android:id="@+id/action_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="?android:attr/actionBarStyle" />
        <com.android.internal.widget.ActionBarContextView
            android:id="@+id/action_context_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone"
            style="?android:attr/actionModeStyle" />
    </com.android.internal.widget.ActionBarContainer>
</com.android.internal.widget.ActionBarOverlayLayout>
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ This is an optimized layout for a screen with the Action Bar enabled.

<com.android.internal.widget.ActionBarOverlayLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/action_bar_overlay_layout"
    android:id="@+id/decor_content_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:splitMotionEvents="false"
Loading