blob: 0f139fa983e97f340d9ac6148077c9d21f3ad2fd [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
Sunny Goyal70660032015-05-14 00:07:08 -070019import android.annotation.TargetApi;
Winson Chung4c98d922011-05-31 16:50:48 -070020import android.content.ComponentName;
21import android.content.Context;
Sunny Goyal70660032015-05-14 00:07:08 -070022import android.os.Build;
Sunny Goyalfa401a12015-04-10 13:45:42 -070023import android.provider.Settings;
Winson Chung4c98d922011-05-31 16:50:48 -070024import android.util.AttributeSet;
Winson Chung4c98d922011-05-31 16:50:48 -070025
Kenny Guyf07af7b2014-07-31 11:39:16 +010026import com.android.launcher3.compat.UserHandleCompat;
27
Winson Chung61fa4192011-06-12 15:15:29 -070028public class InfoDropTarget extends ButtonDropTarget {
Winson Chung4c98d922011-05-31 16:50:48 -070029
Winson Chung4c98d922011-05-31 16:50:48 -070030 public InfoDropTarget(Context context, AttributeSet attrs) {
31 this(context, attrs, 0);
32 }
33
34 public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
35 super(context, attrs, defStyle);
36 }
37
38 @Override
39 protected void onFinishInflate() {
40 super.onFinishInflate();
Winson Chung4c98d922011-05-31 16:50:48 -070041 // Get the hover color
Sunny Goyalfa401a12015-04-10 13:45:42 -070042 mHoverColor = getResources().getColor(R.color.info_target_hover_tint);
Adam Cohen18bbc6a2014-06-03 21:43:24 -070043
Sunny Goyal3a644ed2015-05-21 10:28:02 -070044 setDrawable(R.drawable.ic_launcher_info_normal);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080045 }
46
47 public static void startDetailsActivityForInfo(Object info, Launcher launcher) {
Winson Chung4c98d922011-05-31 16:50:48 -070048 ComponentName componentName = null;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080049 if (info instanceof AppInfo) {
50 componentName = ((AppInfo) info).componentName;
51 } else if (info instanceof ShortcutInfo) {
52 componentName = ((ShortcutInfo) info).intent.getComponent();
53 } else if (info instanceof PendingAddItemInfo) {
54 componentName = ((PendingAddItemInfo) info).componentName;
Winson Chung4c98d922011-05-31 16:50:48 -070055 }
Kenny Guyf07af7b2014-07-31 11:39:16 +010056 final UserHandleCompat user;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080057 if (info instanceof ItemInfo) {
58 user = ((ItemInfo) info).user;
Kenny Guyf07af7b2014-07-31 11:39:16 +010059 } else {
60 user = UserHandleCompat.myUserHandle();
61 }
62
Winson Chung4c98d922011-05-31 16:50:48 -070063 if (componentName != null) {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080064 launcher.startApplicationDetailsActivity(componentName, user);
Winson Chung4c98d922011-05-31 16:50:48 -070065 }
Winson Chung4c98d922011-05-31 16:50:48 -070066 }
67
68 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -070069 protected boolean supportsDrop(DragSource source, Object info) {
Sunny Goyal1a70cef2015-04-22 11:29:51 -070070 return source.supportsAppInfoDropTarget() && supportsDrop(getContext(), info);
71 }
72
Sunny Goyal70660032015-05-14 00:07:08 -070073 @SuppressWarnings("deprecation")
74 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Sunny Goyal1a70cef2015-04-22 11:29:51 -070075 public static boolean supportsDrop(Context context, Object info) {
Sunny Goyal70660032015-05-14 00:07:08 -070076 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
77 return (Settings.Global.getInt(context.getContentResolver(),
78 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1) &&
79 (info instanceof AppInfo || info instanceof PendingAddItemInfo);
80 } else {
81 return (Settings.Secure.getInt(context.getContentResolver(),
82 Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1) &&
83 (info instanceof AppInfo || info instanceof PendingAddItemInfo);
84 }
Winson Chung4c98d922011-05-31 16:50:48 -070085 }
86
87 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -070088 void completeDrop(DragObject d) {
89 startDetailsActivityForInfo(d.dragInfo, mLauncher);
Winson Chung4c98d922011-05-31 16:50:48 -070090 }
91}