blob: e48640c9385c1f46e80bef2f83b10b730851d880 [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
Sunny Goyalfa401a12015-04-10 13:45:42 -070024import com.android.launcher3.R;
Kenny Guyf07af7b2014-07-31 11:39:16 +010025import com.android.launcher3.compat.UserHandleCompat;
26
Winson Chung61fa4192011-06-12 15:15:29 -070027public class InfoDropTarget extends ButtonDropTarget {
Winson Chung4c98d922011-05-31 16:50:48 -070028
Winson Chung4c98d922011-05-31 16:50:48 -070029 public InfoDropTarget(Context context, AttributeSet attrs) {
30 this(context, attrs, 0);
31 }
32
33 public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
34 super(context, attrs, defStyle);
35 }
36
37 @Override
38 protected void onFinishInflate() {
39 super.onFinishInflate();
Winson Chung4c98d922011-05-31 16:50:48 -070040 // Get the hover color
Sunny Goyalfa401a12015-04-10 13:45:42 -070041 mHoverColor = getResources().getColor(R.color.info_target_hover_tint);
Adam Cohen18bbc6a2014-06-03 21:43:24 -070042
Sunny Goyalfa401a12015-04-10 13:45:42 -070043 setDrawable(R.drawable.info_target_selector);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080044 }
45
46 public static void startDetailsActivityForInfo(Object info, Launcher launcher) {
Winson Chung4c98d922011-05-31 16:50:48 -070047 ComponentName componentName = null;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080048 if (info instanceof AppInfo) {
49 componentName = ((AppInfo) info).componentName;
50 } else if (info instanceof ShortcutInfo) {
51 componentName = ((ShortcutInfo) info).intent.getComponent();
52 } else if (info instanceof PendingAddItemInfo) {
53 componentName = ((PendingAddItemInfo) info).componentName;
Winson Chung4c98d922011-05-31 16:50:48 -070054 }
Kenny Guyf07af7b2014-07-31 11:39:16 +010055 final UserHandleCompat user;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080056 if (info instanceof ItemInfo) {
57 user = ((ItemInfo) info).user;
Kenny Guyf07af7b2014-07-31 11:39:16 +010058 } else {
59 user = UserHandleCompat.myUserHandle();
60 }
61
Winson Chung4c98d922011-05-31 16:50:48 -070062 if (componentName != null) {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080063 launcher.startApplicationDetailsActivity(componentName, user);
Winson Chung4c98d922011-05-31 16:50:48 -070064 }
Winson Chung4c98d922011-05-31 16:50:48 -070065 }
66
67 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -070068 protected boolean supportsDrop(DragSource source, Object info) {
69 return source.supportsAppInfoDropTarget() &&
70 Settings.Global.getInt(getContext().getContentResolver(),
71 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1;
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}