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

Unverified Commit bedde671 authored by Kyrylo Mikos's avatar Kyrylo Mikos Committed by Michael Bestas
Browse files

SystemUI: change back button to hide ime button with rotate animation.

Squashed in: "SystemUI: fix incorrectly sized nav bar icons"
(Change-Id: I90c533a10830c641e657f48ee6f8407d4c67c830)

Change-Id: Ia9a7716a6797d0442670451e59857d44b579b5f6
parent 5531836c
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -10,6 +10,11 @@
  public void setGlowScale(float);
}

-keep class com.android.systemui.statusbar.policy.BackButtonDrawable {
  public float getRotation();
  public void setRotation(float);
}

-keep class com.android.systemui.statusbar.car.CarStatusBar
-keep class com.android.systemui.statusbar.phone.PhoneStatusBar
-keep class com.android.systemui.statusbar.tv.TvStatusBar
+33 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import java.util.ArrayList;
 * Dispatches common view calls to multiple views.  This is used to handle
 * multiples of the same nav bar icon appearing.
 */
public class ButtonDispatcher {
public class ButtonDispatcher implements Drawable.Callback {

    private final ArrayList<View> mViews = new ArrayList<>();

@@ -74,6 +74,7 @@ public class ButtonDispatcher {
            ((ButtonInterface) view).setImageResource(mImageResource);
        } else if (mImageDrawable != null) {
            ((ButtonInterface) view).setImageDrawable(mImageDrawable);
            updateDrawable();
        }
    }

@@ -96,6 +97,7 @@ public class ButtonDispatcher {
        for (int i = 0; i < N; i++) {
            ((ButtonInterface) mViews.get(i)).setImageDrawable(mImageDrawable);
        }
        updateDrawable();
    }

    public void setImageResource(int resource) {
@@ -186,6 +188,36 @@ public class ButtonDispatcher {
        }
    }

    private void updateDrawable() {
        mImageDrawable.setCallback(this);
        // one of our buttons will always be visible
        mImageDrawable.setVisible(true, false);
    }

    @Override
    public void invalidateDrawable(Drawable who) {
        final int N = mViews.size();
        for (int i = 0; i < N; i++) {
            mViews.get(i).invalidateDrawable(who);
        }
    }

    @Override
    public void scheduleDrawable(Drawable who, Runnable what, long when) {
        final int N = mViews.size();
        for (int i = 0; i < N; i++) {
            mViews.get(i).scheduleDrawable(who, what, when);
        }
    }

    @Override
    public void unscheduleDrawable(Drawable who, Runnable what) {
        final int N = mViews.size();
        for (int i = 0; i < N; i++) {
            mViews.get(i).unscheduleDrawable(who, what);
        }
    }

    /**
     * Interface for button actions.
     */
+9 −19
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.widget.LinearLayout;
import com.android.systemui.R;
import com.android.systemui.RecentsComponent;
import com.android.systemui.stackdivider.Divider;
import com.android.systemui.statusbar.policy.BackButtonDrawable;
import com.android.systemui.statusbar.policy.DeadZone;
import com.android.systemui.tuner.TunerService;

@@ -80,9 +81,8 @@ public class NavigationBarView extends LinearLayout implements TunerService.Tuna
    int mDisabledFlags = 0;
    int mNavigationIconHints = 0;

    private Drawable mBackIcon, mBackLandIcon, mBackAltIcon, mBackAltLandIcon;
    private Drawable mBackCarModeIcon, mBackLandCarModeIcon;
    private Drawable mBackAltCarModeIcon, mBackAltLandCarModeIcon;
    private BackButtonDrawable mBackIcon, mBackLandIcon;
    private BackButtonDrawable mBackCarModeIcon, mBackLandCarModeIcon;
    private Drawable mHomeDefaultIcon, mHomeCarModeIcon;
    private Drawable mRecentIcon;
    private Drawable mDockedIcon;
@@ -292,10 +292,9 @@ public class NavigationBarView extends LinearLayout implements TunerService.Tuna
    public ViewGroup getDpadView() { return (ViewGroup) getCurrentView().findViewById(R.id.dpad_group); }

    private void updateCarModeIcons(Context ctx) {
        mBackCarModeIcon = ctx.getDrawable(R.drawable.ic_sysbar_back_carmode);
        mBackCarModeIcon = new BackButtonDrawable(
                ctx.getDrawable(R.drawable.ic_sysbar_back_carmode));
        mBackLandCarModeIcon = mBackCarModeIcon;
        mBackAltCarModeIcon = ctx.getDrawable(R.drawable.ic_sysbar_back_ime_carmode);
        mBackAltLandCarModeIcon = mBackAltCarModeIcon;
        mHomeCarModeIcon = ctx.getDrawable(R.drawable.ic_sysbar_home_carmode);
    }

@@ -305,10 +304,8 @@ public class NavigationBarView extends LinearLayout implements TunerService.Tuna
            mDockedIcon = ctx.getDrawable(R.drawable.ic_sysbar_docked);
        }
        if (oldConfig.densityDpi != newConfig.densityDpi) {
            mBackIcon = ctx.getDrawable(R.drawable.ic_sysbar_back);
            mBackIcon = new BackButtonDrawable(ctx.getDrawable(R.drawable.ic_sysbar_back));
            mBackLandIcon = mBackIcon;
            mBackAltIcon = ctx.getDrawable(R.drawable.ic_sysbar_back_ime);
            mBackAltLandIcon = mBackAltIcon;

            mHomeDefaultIcon = ctx.getDrawable(R.drawable.ic_sysbar_home);
            mRecentIcon = ctx.getDrawable(R.drawable.ic_sysbar_recent);
@@ -338,13 +335,7 @@ public class NavigationBarView extends LinearLayout implements TunerService.Tuna
        setNavigationIconHints(hints, false);
    }

    private Drawable getBackIconWithAlt(boolean carMode, boolean landscape) {
        return landscape
                ? carMode ? mBackAltLandCarModeIcon : mBackAltLandIcon
                : carMode ? mBackAltCarModeIcon : mBackAltIcon;
    }

    private Drawable getBackIcon(boolean carMode, boolean landscape) {
    private BackButtonDrawable getBackIcon(boolean carMode, boolean landscape) {
        return landscape
                ? carMode ? mBackLandCarModeIcon : mBackLandIcon
                : carMode ? mBackCarModeIcon : mBackIcon;
@@ -367,9 +358,8 @@ public class NavigationBarView extends LinearLayout implements TunerService.Tuna
        // We have to replace or restore the back and home button icons when exiting or entering
        // carmode, respectively. Recents are not available in CarMode in nav bar so change
        // to recent icon is not required.
        Drawable backIcon = (backAlt)
                ? getBackIconWithAlt(mUseCarModeUi, mVertical)
                : getBackIcon(mUseCarModeUi, mVertical);
        BackButtonDrawable backIcon = getBackIcon(mUseCarModeUi, mVertical);
        backIcon.setImeVisible(backAlt);

        getBackButton().setImageDrawable(backIcon);

+86 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The CyanogenMod 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.systemui.statusbar.policy;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.app.ActivityManager;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.DrawableWrapper;

public class BackButtonDrawable extends DrawableWrapper {
    private float mRotation;
    private Animator mCurrentAnimator;

    private static final int ANIMATION_DURATION = 200;

    public BackButtonDrawable(Drawable wrappedDrawable) {
        super(wrappedDrawable);
    }

    @Override
    public void draw(Canvas canvas) {
        final Rect bounds = getBounds();
        final int boundsCenterX = bounds.width() / 2;
        final int boundsCenterY = bounds.height() / 2;

        canvas.save();
        canvas.translate(boundsCenterX, boundsCenterY);
        canvas.rotate(mRotation);
        canvas.translate(-boundsCenterX, -boundsCenterY);

        super.draw(canvas);
        canvas.restore();
    }

    @Override
    public void setAlpha(int alpha) {
        super.setAlpha(alpha);
        if (mCurrentAnimator != null) {
            mCurrentAnimator.end();
        }
    }

    public void setRotation(float rotation) {
        mRotation = rotation;
        invalidateSelf();
    }

    public float getRotation() {
        return mRotation;
    }

    public void setImeVisible(boolean ime) {
        if (mCurrentAnimator != null) {
            mCurrentAnimator.cancel();
        }

        final float nextRotation = ime ? -90 : 0;
        if (mRotation == nextRotation) {
            return;
        }

        if (isVisible() && ActivityManager.isHighEndGfx()) {
            mCurrentAnimator = ObjectAnimator.ofFloat(this, "rotation", nextRotation)
                    .setDuration(ANIMATION_DURATION);
            mCurrentAnimator.start();
        } else {
            setRotation(nextRotation);
        }
    }
}