blob: 04f9b3affae4b236da5cfb595e2759cb6f984cb1 [file] [log] [blame]
Jon Miranda54441f52018-01-24 15:38:25 -08001/*
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;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080021import android.content.Context;
Jon Miranda54441f52018-01-24 15:38:25 -080022import android.graphics.Rect;
23import android.graphics.drawable.Drawable;
Jon Miranda54441f52018-01-24 15:38:25 -080024import android.view.View;
25
26/**
27 * Manages the opening and closing app transitions from Launcher.
28 */
29public class LauncherAppTransitionManager {
30
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080031 public static LauncherAppTransitionManager newInstance(Context context) {
32 return Utilities.getOverrideObject(LauncherAppTransitionManager.class,
33 context, R.string.app_transition_manager_class);
34 }
35
Tony Wickham005df0b2018-02-13 11:28:12 -080036 public ActivityOptions getDefaultActivityLaunchOptions(Launcher launcher, View v) {
Jon Miranda54441f52018-01-24 15:38:25 -080037 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 }
Tony Wickham005df0b2018-02-13 11:28:12 -080051 return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
Jon Miranda54441f52018-01-24 15:38:25 -080052 } 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,
Tony Wickham005df0b2018-02-13 11:28:12 -080057 R.anim.no_anim);
Jon Miranda54441f52018-01-24 15:38:25 -080058 }
59 return null;
60 }
61
Tony Wickham005df0b2018-02-13 11:28:12 -080062 public ActivityOptions getActivityLaunchOptions(Launcher launcher, View v) {
Jon Miranda54441f52018-01-24 15:38:25 -080063 return getDefaultActivityLaunchOptions(launcher, v);
64 }
Jon Miranda54441f52018-01-24 15:38:25 -080065}