blob: d93cdcc1ba2605b0c583b3caf332c62042f5374b [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
Kenny Guyf07af7b2014-07-31 11:39:16 +010023import com.android.launcher3.compat.UserHandleCompat;
24
Winson Chung61fa4192011-06-12 15:15:29 -070025public class InfoDropTarget extends ButtonDropTarget {
Winson Chung4c98d922011-05-31 16:50:48 -070026
Winson Chung4c98d922011-05-31 16:50:48 -070027 public InfoDropTarget(Context context, AttributeSet attrs) {
28 this(context, attrs, 0);
29 }
30
31 public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
32 super(context, attrs, defStyle);
33 }
34
35 @Override
36 protected void onFinishInflate() {
37 super.onFinishInflate();
Winson Chung4c98d922011-05-31 16:50:48 -070038 // Get the hover color
Sunny Goyalfa401a12015-04-10 13:45:42 -070039 mHoverColor = getResources().getColor(R.color.info_target_hover_tint);
Adam Cohen18bbc6a2014-06-03 21:43:24 -070040
Sunny Goyal40b626b2015-06-04 22:40:14 -070041 setDrawable(R.drawable.ic_info_launcher);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080042 }
43
44 public static void startDetailsActivityForInfo(Object info, Launcher launcher) {
Winson Chung4c98d922011-05-31 16:50:48 -070045 ComponentName componentName = null;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080046 if (info instanceof AppInfo) {
47 componentName = ((AppInfo) info).componentName;
48 } else if (info instanceof ShortcutInfo) {
49 componentName = ((ShortcutInfo) info).intent.getComponent();
50 } else if (info instanceof PendingAddItemInfo) {
51 componentName = ((PendingAddItemInfo) info).componentName;
Winson Chung4c98d922011-05-31 16:50:48 -070052 }
Kenny Guyf07af7b2014-07-31 11:39:16 +010053 final UserHandleCompat user;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080054 if (info instanceof ItemInfo) {
55 user = ((ItemInfo) info).user;
Kenny Guyf07af7b2014-07-31 11:39:16 +010056 } else {
57 user = UserHandleCompat.myUserHandle();
58 }
59
Winson Chung4c98d922011-05-31 16:50:48 -070060 if (componentName != null) {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080061 launcher.startApplicationDetailsActivity(componentName, user);
Winson Chung4c98d922011-05-31 16:50:48 -070062 }
Winson Chung4c98d922011-05-31 16:50:48 -070063 }
64
65 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -070066 protected boolean supportsDrop(DragSource source, Object info) {
Sunny Goyal1a70cef2015-04-22 11:29:51 -070067 return source.supportsAppInfoDropTarget() && supportsDrop(getContext(), info);
68 }
69
70 public static boolean supportsDrop(Context context, Object info) {
Sunny Goyald7da55f2015-06-12 12:25:45 -070071 return info instanceof AppInfo || info instanceof PendingAddItemInfo;
Winson Chung4c98d922011-05-31 16:50:48 -070072 }
73
74 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -070075 void completeDrop(DragObject d) {
76 startDetailsActivityForInfo(d.dragInfo, mLauncher);
Winson Chung4c98d922011-05-31 16:50:48 -070077 }
78}