blob: f1ff48da30e224eb04a8b6f9acf67014e50070a7 [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;
Sunny Goyalfa401a12015-04-10 13:45:42 -070021import android.provider.Settings;
Winson Chung4c98d922011-05-31 16:50:48 -070022import android.util.AttributeSet;
Winson Chung4c98d922011-05-31 16:50:48 -070023
Kenny Guyf07af7b2014-07-31 11:39:16 +010024import com.android.launcher3.compat.UserHandleCompat;
25
Winson Chung61fa4192011-06-12 15:15:29 -070026public class InfoDropTarget extends ButtonDropTarget {
Winson Chung4c98d922011-05-31 16:50:48 -070027
Winson Chung4c98d922011-05-31 16:50:48 -070028 public InfoDropTarget(Context context, AttributeSet attrs) {
29 this(context, attrs, 0);
30 }
31
32 public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
33 super(context, attrs, defStyle);
34 }
35
36 @Override
37 protected void onFinishInflate() {
38 super.onFinishInflate();
Winson Chung4c98d922011-05-31 16:50:48 -070039 // Get the hover color
Sunny Goyalfa401a12015-04-10 13:45:42 -070040 mHoverColor = getResources().getColor(R.color.info_target_hover_tint);
Adam Cohen18bbc6a2014-06-03 21:43:24 -070041
Sunny Goyalfa401a12015-04-10 13:45:42 -070042 setDrawable(R.drawable.info_target_selector);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080043 }
44
45 public static void startDetailsActivityForInfo(Object info, Launcher launcher) {
Winson Chung4c98d922011-05-31 16:50:48 -070046 ComponentName componentName = null;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080047 if (info instanceof AppInfo) {
48 componentName = ((AppInfo) info).componentName;
49 } else if (info instanceof ShortcutInfo) {
50 componentName = ((ShortcutInfo) info).intent.getComponent();
51 } else if (info instanceof PendingAddItemInfo) {
52 componentName = ((PendingAddItemInfo) info).componentName;
Winson Chung4c98d922011-05-31 16:50:48 -070053 }
Kenny Guyf07af7b2014-07-31 11:39:16 +010054 final UserHandleCompat user;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080055 if (info instanceof ItemInfo) {
56 user = ((ItemInfo) info).user;
Kenny Guyf07af7b2014-07-31 11:39:16 +010057 } else {
58 user = UserHandleCompat.myUserHandle();
59 }
60
Winson Chung4c98d922011-05-31 16:50:48 -070061 if (componentName != null) {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080062 launcher.startApplicationDetailsActivity(componentName, user);
Winson Chung4c98d922011-05-31 16:50:48 -070063 }
Winson Chung4c98d922011-05-31 16:50:48 -070064 }
65
66 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -070067 protected boolean supportsDrop(DragSource source, Object info) {
Sunny Goyal1a70cef2015-04-22 11:29:51 -070068 return source.supportsAppInfoDropTarget() && supportsDrop(getContext(), info);
69 }
70
71 public static boolean supportsDrop(Context context, Object info) {
72 return (Settings.Global.getInt(context.getContentResolver(),
73 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1) &&
74 (info instanceof AppInfo || info instanceof PendingAddItemInfo);
Winson Chung4c98d922011-05-31 16:50:48 -070075 }
76
77 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -070078 void completeDrop(DragObject d) {
79 startDetailsActivityForInfo(d.dragInfo, mLauncher);
Winson Chung4c98d922011-05-31 16:50:48 -070080 }
81}