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
17package com.android.launcher3;
18
19
20import android.app.ActivityOptions;
21import android.content.Context;
22import android.graphics.Rect;
23import android.graphics.drawable.Drawable;
24import android.view.View;
25
26/**
27 * Manages the opening and closing app transitions from Launcher.
28 */
29public class LauncherAppTransitionManager {
30
31    public static LauncherAppTransitionManager newInstance(Context context) {
32        return Utilities.getOverrideObject(LauncherAppTransitionManager.class,
33                context, R.string.app_transition_manager_class);
34    }
35
36    public ActivityOptions getActivityLaunchOptions(Launcher launcher, View v) {
37        if (Utilities.ATLEAST_MARSHMALLOW) {
38            int left = 0, top = 0;
39            int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
40            if (v instanceof BubbleTextView) {
41                // Launch from center of icon, not entire view
42                Drawable icon = ((BubbleTextView) v).getIcon();
43                if (icon != null) {
44                    Rect bounds = icon.getBounds();
45                    left = (width - bounds.width()) / 2;
46                    top = v.getPaddingTop();
47                    width = bounds.width();
48                    height = bounds.height();
49                }
50            }
51            return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
52        } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
53            // On L devices, we use the device default slide-up transition.
54            // On L MR1 devices, we use a custom version of the slide-up transition which
55            // doesn't have the delay present in the device default.
56            return ActivityOptions.makeCustomAnimation(launcher, R.anim.task_open_enter,
57                    R.anim.no_anim);
58        }
59        return null;
60    }
61}
62