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

Commit 04fba96b authored by Daniel Sandler's avatar Daniel Sandler Committed by Android (Google) Code Review
Browse files

Merge "Animate transitions between notification & settings panels." into honeycomb

parents c8219299 14db0bc0
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -61,8 +61,6 @@
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal|bottom"
                    android:animateLayoutChanges="true"
                    android:animationCache="false"
                    android:orientation="vertical"
                    android:clickable="true"
                    android:focusable="true"
+53 −45
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.tablet;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
@@ -32,10 +33,10 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.android.systemui.R;
@@ -100,7 +101,6 @@ public class NotificationPanel extends RelativeLayout implements StatusBarPanel,
        } else {
            mShowing = show;
            setVisibility(show ? View.VISIBLE : View.GONE);
            mChoreo.jumpTo(show);
        }
    }

@@ -117,50 +117,74 @@ public class NotificationPanel extends RelativeLayout implements StatusBarPanel,
        super.onVisibilityChanged(v, vis);
        // when we hide, put back the notifications
        if (!isShown()) {
            switchToNotificationMode();
            if (mSettingsView != null) removeSettingsView();
            mNotificationScroller.setVisibility(View.VISIBLE);
            mNotificationScroller.setAlpha(1f);
            mNotificationScroller.scrollTo(0, 0);
            updatePanelModeButtons();
        }
    }

    /**
     * We need to be aligned at the bottom.  LinearLayout can't do this, so instead,
     * let LinearLayout do all the hard work, and then shift everything down to the bottom.
     */
    /*
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);

        mChoreo.setPanelHeight(mContentParent.getHeight());
        if (DEBUG) Slog.d(TAG, String.format("PANEL: onLayout: (%d, %d, %d, %d)", l, t, r, b));
    }

    @Override
    public void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        
        if (DEBUG) {
            Slog.d(TAG, String.format("PANEL: onSizeChanged: (%d -> %d, %d -> %d)",
                        oldw, w, oldh, h));
        }
    }
    */

    public void onClick(View v) {
        if (v == mModeToggle) {
            swapPanels();
        }
    }

    final static int PANEL_FADE_DURATION = 150;

    public void swapPanels() {
        final View toShow, toHide;
        if (mSettingsView == null) {
                switchToSettingsMode();
            addSettingsView();
            toShow = mSettingsView;
            toHide = mNotificationScroller;
        } else {
                switchToNotificationMode();
            toShow = mNotificationScroller;
            toHide = mSettingsView;
        }
        Animator a = ObjectAnimator.ofFloat(toHide, "alpha", 1f, 0f)
                .setDuration(PANEL_FADE_DURATION);
        a.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator _a) {
                toHide.setVisibility(View.GONE);
                toShow.setVisibility(View.VISIBLE);
                ObjectAnimator.ofFloat(toShow, "alpha", 0f, 1f)
                        .setDuration(PANEL_FADE_DURATION)
                        .start();
                if (toHide == mSettingsView) {
                    removeSettingsView();
                }
                updatePanelModeButtons();
            }

    public void switchToSettingsMode() {
        removeSettingsView();
        addSettingsView();
        mSettingsButton.setVisibility(View.INVISIBLE);
        mNotificationScroller.setVisibility(View.GONE);
        mNotificationButton.setVisibility(View.VISIBLE);
        });
        a.start();
    }
 
    public void switchToNotificationMode() {
        removeSettingsView();
        mSettingsButton.setVisibility(View.VISIBLE);
        mNotificationScroller.setVisibility(View.VISIBLE);
        mNotificationButton.setVisibility(View.INVISIBLE);
    public void updatePanelModeButtons() {
        final boolean settingsVisible = (mSettingsView != null);
        mSettingsButton.setVisibility(!settingsVisible ? View.VISIBLE : View.INVISIBLE);
        mNotificationButton.setVisibility(settingsVisible ? View.VISIBLE : View.INVISIBLE);
    }

    public boolean isInContentArea(int x, int y) {
@@ -179,9 +203,11 @@ public class NotificationPanel extends RelativeLayout implements StatusBarPanel,
        }
    }

    // NB: it will be invisible until you show it
    void addSettingsView() {
        LayoutInflater infl = LayoutInflater.from(getContext());
        mSettingsView = infl.inflate(R.layout.status_bar_settings_view, mContentFrame, false);
        mSettingsView.setVisibility(View.GONE);
        mContentFrame.addView(mSettingsView);
    }

@@ -191,8 +217,8 @@ public class NotificationPanel extends RelativeLayout implements StatusBarPanel,
        AnimatorSet mContentAnim;

        // should group this into a multi-property animation
        final int OPEN_DURATION = 250;
        final int CLOSE_DURATION = 250;
        final static int OPEN_DURATION = 136;
        final static int CLOSE_DURATION = 250;

        // the panel will start to appear this many px from the end
        final int HYPERSPACE_OFFRAMP = 100;
@@ -257,24 +283,6 @@ public class NotificationPanel extends RelativeLayout implements StatusBarPanel,
            mVisible = appearing;
        }

        void jumpTo(boolean appearing) {
            mContentParent.setTranslationY(appearing ? 0 : mPanelHeight);
        }

        public void setPanelHeight(int h) {
            if (DEBUG) Slog.d(TAG, "panelHeight=" + h);
            mPanelHeight = h;
            if (mPanelHeight == 0) {
                // fully closed, no animation necessary
            } else if (mVisible) {
                if (DEBUG) {
                    Slog.d(TAG, "panelHeight not zero but trying to open; scheduling an anim"
                            + " to open fully");
                }
                startAnimation(true);
            }
        }

        public void onAnimationCancel(Animator animation) {
            if (DEBUG) Slog.d(TAG, "onAnimationCancel");
            // force this to zero so we close the window