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