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

Commit 42334050 authored by Tony Mak's avatar Tony Mak
Browse files

Add peek to work tab animation

Only the tab is moved, the RV does not.

Fix: 71748023

Change-Id: I99216e9072df03104dd0644f3909e8b49e07faf0
parent 383b7fa0
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -607,6 +607,12 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource,
        return mHeader != null && mHeader.getVisibility() == View.VISIBLE;
    }

    public void onScrollUpEnd() {
        if (mUsingTabs) {
            ((PersonalWorkSlidingTabStrip) findViewById(R.id.tabs)).peekWorkTabIfNecessary();
        }
    }

    public class AdapterHolder {
        public static final int MAIN = 0;
        public static final int WORK = 1;
+1 −0
Original line number Diff line number Diff line
@@ -216,6 +216,7 @@ public class AllAppsTransitionController
        } else if (Float.compare(mProgress, 0f) == 0) {
            mHotseat.setVisibility(View.INVISIBLE);
            mAppsView.setVisibility(View.VISIBLE);
            mAppsView.onScrollUpEnd();
        } else {
            mAppsView.setVisibility(View.VISIBLE);
            mHotseat.setVisibility(View.VISIBLE);
+38 −1
Original line number Diff line number Diff line
@@ -15,7 +15,9 @@
 */
package com.android.launcher3.allapps;

import android.animation.ValueAnimator;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.NonNull;
@@ -25,17 +27,27 @@ import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.util.Themes;

/**
 * Supports two indicator colors, dedicated for personal and work tabs.
 */
public class PersonalWorkSlidingTabStrip extends LinearLayout {
    private static final int POSITION_PERSONAL = 0;
    private static final int POSITION_WORK = 1;
    private static final int PEEK_DURATION = 1000;
    private static final float PEAK_OFFSET = 0.4f;

    private static final String KEY_SHOWED_PEEK_WORK_TAB = "showed_peek_work_tab";

    private final Paint mPersonalTabIndicatorPaint;
    private final Paint mWorkTabIndicatorPaint;
    private final Paint mDividerPaint;
    private final SharedPreferences mSharedPreferences;

    private int mSelectedIndicatorHeight;
    private int mIndicatorLeft = -1;
@@ -64,7 +76,10 @@ public class PersonalWorkSlidingTabStrip extends LinearLayout {

        mDividerPaint = new Paint();
        mDividerPaint.setColor(Themes.getAttrColor(context, android.R.attr.colorControlHighlight));
        mDividerPaint.setStrokeWidth(getResources().getDimensionPixelSize(R.dimen.all_apps_divider_height));
        mDividerPaint.setStrokeWidth(
                getResources().getDimensionPixelSize(R.dimen.all_apps_divider_height));

        mSharedPreferences = Launcher.getLauncher(getContext()).getSharedPrefs();
    }

    public void updateIndicatorPosition(int position, float positionOffset) {
@@ -141,4 +156,26 @@ public class PersonalWorkSlidingTabStrip extends LinearLayout {
        boolean isPersonal = mIsRtl ^ firstHalf;
        return isPersonal ? mPersonalTabIndicatorPaint : mWorkTabIndicatorPaint;
    }

    public void peekWorkTabIfNecessary() {
        if (mSharedPreferences.getBoolean(KEY_SHOWED_PEEK_WORK_TAB, false)) {
            return;
        }
        if (mIndicatorPosition != POSITION_PERSONAL) {
            return;
        }
        peekWorkTab();
        mSharedPreferences.edit().putBoolean(KEY_SHOWED_PEEK_WORK_TAB, true).apply();
    }

    private void peekWorkTab() {
        final boolean isRtl = Utilities.isRtl(getResources());
        ValueAnimator animator = ValueAnimator.ofFloat(0, isRtl ? 1 - PEAK_OFFSET : PEAK_OFFSET, 0);
        animator.setDuration(PEEK_DURATION);
        animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
        animator.addUpdateListener(
                animation -> updateIndicatorPosition(mIndicatorPosition,
                        (float) animation.getAnimatedValue()));
        animator.start();
    }
}