blob: fb50dfbbb5ac6ccc4dadfed6c92f8d3136f947c1 [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
Sunny Goyal7f920b82018-06-27 15:47:49 -070026import com.android.launcher3.util.ResourceBasedOverride;
27
Jon Miranda54441f52018-01-24 15:38:25 -080028/**
29 * Manages the opening and closing app transitions from Launcher.
30 */
Sunny Goyal7f920b82018-06-27 15:47:49 -070031public class LauncherAppTransitionManager implements ResourceBasedOverride {
Jon Miranda54441f52018-01-24 15:38:25 -080032
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080033 public static LauncherAppTransitionManager newInstance(Context context) {
Sunny Goyal7f920b82018-06-27 15:47:49 -070034 return Overrides.getObject(LauncherAppTransitionManager.class,
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080035 context, R.string.app_transition_manager_class);
36 }
37
Jon Miranda73c27ec2018-05-16 18:06:23 -070038 public ActivityOptions getActivityLaunchOptions(Launcher launcher, View v) {
Sunny Goyal8c48d8b2019-01-25 15:10:18 -080039 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();
Jon Miranda54441f52018-01-24 15:38:25 -080050 }
Jon Miranda54441f52018-01-24 15:38:25 -080051 }
Sunny Goyal8c48d8b2019-01-25 15:10:18 -080052 return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
Jon Miranda54441f52018-01-24 15:38:25 -080053 }
Jon Miranda54441f52018-01-24 15:38:25 -080054}