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

Commit 6c41953d authored by Kyrylo Mikos's avatar Kyrylo Mikos Committed by Gerrit Code Review
Browse files

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

Change-Id: Ia9a7716a6797d0442670451e59857d44b579b5f6
parent b01b0892
Loading
Loading
Loading
Loading
+123 −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.phone;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.app.ActivityManager;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.FloatProperty;
import android.util.Property;

public class BackButtonDrawable extends Drawable {
    private final Drawable mWrappedDrawable;
    private float mRotation;
    private Animator mCurrentAnimator;

    private static final int ANIMATION_DURATION = 200;
    public static final Property<BackButtonDrawable, Float> ROTATION
            = new FloatProperty<BackButtonDrawable>("rotation") {
        @Override
        public void setValue(BackButtonDrawable object, float value) {
            object.setRotation(value);
        }

        @Override
        public Float get(BackButtonDrawable object) {
            return object.getRotation();
        }
    };

    public BackButtonDrawable(Drawable wrappedDrawable) {
        mWrappedDrawable = wrappedDrawable;
    }

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

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

        mWrappedDrawable.draw(canvas);
    }

    @Override
    public void setBounds(Rect bounds) {
        mWrappedDrawable.setBounds(bounds);
    }

    @Override
    public void setBounds(int left, int top, int right, int bottom) {
        mWrappedDrawable.setBounds(left, top, right, bottom);
    }

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

    @Override
    public int getAlpha() {
        return mWrappedDrawable.getAlpha();
    }

    @Override
    public void setColorFilter(ColorFilter cf) {
    }

    @Override
    public int getOpacity() {
        return mWrappedDrawable.getOpacity();
    }

    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);
        }
    }
}
+7 −8
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public class NavigationBarView extends LinearLayout {
    int mDisabledFlags = 0;
    int mNavigationIconHints = 0;

    private Drawable mBackIcon, mBackLandIcon, mBackAltIcon, mBackAltLandIcon;
    private BackButtonDrawable mBackIcon, mBackLandIcon;
    private Drawable mRecentIcon;
    private Drawable mRecentLandIcon;

@@ -267,10 +267,8 @@ public class NavigationBarView extends LinearLayout {
    }

    private void getIcons(Resources res) {
        mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back);
        mBackLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_land);
        mBackAltIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);
        mBackAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);
        mBackIcon = new BackButtonDrawable(res.getDrawable(R.drawable.ic_sysbar_back));
        mBackLandIcon = new BackButtonDrawable(res.getDrawable(R.drawable.ic_sysbar_back_land));
        mRecentIcon = res.getDrawable(R.drawable.ic_sysbar_recent);
        mRecentLandIcon = res.getDrawable(R.drawable.ic_sysbar_recent_land);
    }
@@ -305,9 +303,10 @@ public class NavigationBarView extends LinearLayout {

        mNavigationIconHints = hints;

        ((ImageView)getBackButton()).setImageDrawable(backAlt
                ? (mVertical ? mBackAltLandIcon : mBackAltIcon)
                : (mVertical ? mBackLandIcon : mBackIcon));
        ((ImageView)getBackButton()).setImageDrawable(null);
        ((ImageView)getBackButton()).setImageDrawable(mVertical ? mBackLandIcon : mBackIcon);
        mBackLandIcon.setImeVisible(backAlt);
        mBackIcon.setImeVisible(backAlt);

        ((ImageView)getRecentsButton()).setImageDrawable(mVertical ? mRecentLandIcon : mRecentIcon);