Home | History | Annotate | Download | only in uioverrides
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.launcher3.uioverrides;
     17 
     18 import android.content.Context;
     19 import android.content.res.Resources;
     20 import android.graphics.Rect;
     21 
     22 import com.android.launcher3.DeviceProfile;
     23 import com.android.launcher3.Launcher;
     24 import com.android.launcher3.R;
     25 import com.android.quickstep.QuickScrubController;
     26 import com.android.quickstep.views.RecentsView;
     27 
     28 /**
     29  * Extension of overview state used for QuickScrub
     30  */
     31 public class FastOverviewState extends OverviewState {
     32 
     33     private static final float MAX_PREVIEW_SCALE_UP = 1.3f;
     34     /**
     35      * Vertical transition of the task previews relative to the full container.
     36      */
     37     public static final float OVERVIEW_TRANSLATION_FACTOR = 0.4f;
     38 
     39     private static final int STATE_FLAGS = FLAG_DISABLE_RESTORE | FLAG_DISABLE_INTERACTION
     40             | FLAG_OVERVIEW_UI | FLAG_HIDE_BACK_BUTTON | FLAG_DISABLE_ACCESSIBILITY;
     41 
     42     public FastOverviewState(int id) {
     43         super(id, QuickScrubController.QUICK_SCRUB_FROM_HOME_START_DURATION, STATE_FLAGS);
     44     }
     45 
     46     @Override
     47     public void onStateTransitionEnd(Launcher launcher) {
     48         super.onStateTransitionEnd(launcher);
     49         RecentsView recentsView = launcher.getOverviewPanel();
     50         recentsView.getQuickScrubController().onFinishedTransitionToQuickScrub();
     51     }
     52 
     53     @Override
     54     public int getVisibleElements(Launcher launcher) {
     55         return NONE;
     56     }
     57 
     58     @Override
     59     public float[] getOverviewScaleAndTranslationYFactor(Launcher launcher) {
     60         RecentsView recentsView = launcher.getOverviewPanel();
     61         recentsView.getTaskSize(sTempRect);
     62 
     63         return new float[] {getOverviewScale(launcher.getDeviceProfile(), sTempRect, launcher),
     64                 OVERVIEW_TRANSLATION_FACTOR};
     65     }
     66 
     67     public static float getOverviewScale(DeviceProfile dp, Rect taskRect, Context context) {
     68         if (dp.isVerticalBarLayout()) {
     69             return 1f;
     70         }
     71 
     72         Resources res = context.getResources();
     73         float usedHeight = taskRect.height() + res.getDimension(R.dimen.task_thumbnail_top_margin);
     74         float usedWidth = taskRect.width() + 2 * (res.getDimension(R.dimen.recents_page_spacing)
     75                 + res.getDimension(R.dimen.quickscrub_adjacent_visible_width));
     76         return Math.min(Math.min(dp.availableHeightPx / usedHeight,
     77                 dp.availableWidthPx / usedWidth), MAX_PREVIEW_SCALE_UP);
     78     }
     79 
     80     @Override
     81     public void onStateDisabled(Launcher launcher) {
     82         super.onStateDisabled(launcher);
     83         launcher.<RecentsView>getOverviewPanel().getQuickScrubController().cancelActiveQuickscrub();
     84     }
     85 }
     86