blob: b4a144526e755500d5de80ce5e9c28b3c19f6f70 [file] [log] [blame]
Winson Chung4c98d922011-05-31 16:50:48 -07001/*
2 * Copyright (C) 2011 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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Winson Chung4c98d922011-05-31 16:50:48 -070018
19import android.content.ComponentName;
20import android.content.Context;
Winson Chung4c98d922011-05-31 16:50:48 -070021import android.util.AttributeSet;
Winson Chung4c98d922011-05-31 16:50:48 -070022
Winson Chung61fa4192011-06-12 15:15:29 -070023public class InfoDropTarget extends ButtonDropTarget {
Winson Chung4c98d922011-05-31 16:50:48 -070024
Winson Chung4c98d922011-05-31 16:50:48 -070025 public InfoDropTarget(Context context, AttributeSet attrs) {
26 this(context, attrs, 0);
27 }
28
29 public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
30 super(context, attrs, defStyle);
31 }
32
33 @Override
34 protected void onFinishInflate() {
35 super.onFinishInflate();
Winson Chung4c98d922011-05-31 16:50:48 -070036 // Get the hover color
Sunny Goyalfa401a12015-04-10 13:45:42 -070037 mHoverColor = getResources().getColor(R.color.info_target_hover_tint);
Adam Cohen18bbc6a2014-06-03 21:43:24 -070038
Sunny Goyal40b626b2015-06-04 22:40:14 -070039 setDrawable(R.drawable.ic_info_launcher);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080040 }
41
Sunny Goyalaa8ef112015-06-12 20:04:41 -070042 public static void startDetailsActivityForInfo(ItemInfo info, Launcher launcher) {
Winson Chung4c98d922011-05-31 16:50:48 -070043 ComponentName componentName = null;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080044 if (info instanceof AppInfo) {
45 componentName = ((AppInfo) info).componentName;
46 } else if (info instanceof ShortcutInfo) {
47 componentName = ((ShortcutInfo) info).intent.getComponent();
48 } else if (info instanceof PendingAddItemInfo) {
49 componentName = ((PendingAddItemInfo) info).componentName;
Winson Chung4c98d922011-05-31 16:50:48 -070050 }
51 if (componentName != null) {
Sunny Goyalaa8ef112015-06-12 20:04:41 -070052 launcher.startApplicationDetailsActivity(componentName, info.user);
Winson Chung4c98d922011-05-31 16:50:48 -070053 }
Winson Chung4c98d922011-05-31 16:50:48 -070054 }
55
56 @Override
Sunny Goyalaa8ef112015-06-12 20:04:41 -070057 protected boolean supportsDrop(DragSource source, ItemInfo info) {
Sunny Goyal1a70cef2015-04-22 11:29:51 -070058 return source.supportsAppInfoDropTarget() && supportsDrop(getContext(), info);
59 }
60
Sunny Goyalaa8ef112015-06-12 20:04:41 -070061 public static boolean supportsDrop(Context context, ItemInfo info) {
Sunny Goyald7da55f2015-06-12 12:25:45 -070062 return info instanceof AppInfo || info instanceof PendingAddItemInfo;
Winson Chung4c98d922011-05-31 16:50:48 -070063 }
64
65 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -070066 void completeDrop(DragObject d) {
67 startDetailsActivityForInfo(d.dragInfo, mLauncher);
Winson Chung4c98d922011-05-31 16:50:48 -070068 }
69}