Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1 | /* |
| 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 Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 18 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.Context; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 21 | import android.provider.Settings; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 22 | import android.util.AttributeSet; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 23 | |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 24 | import com.android.launcher3.compat.UserHandleCompat; |
| 25 | |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 26 | public class InfoDropTarget extends ButtonDropTarget { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 27 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 28 | 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 Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 39 | // Get the hover color |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 40 | mHoverColor = getResources().getColor(R.color.info_target_hover_tint); |
Adam Cohen | 18bbc6a | 2014-06-03 21:43:24 -0700 | [diff] [blame] | 41 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 42 | setDrawable(R.drawable.info_target_selector); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | public static void startDetailsActivityForInfo(Object info, Launcher launcher) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 46 | ComponentName componentName = null; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 47 | 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 Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 53 | } |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 54 | final UserHandleCompat user; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 55 | if (info instanceof ItemInfo) { |
| 56 | user = ((ItemInfo) info).user; |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 57 | } else { |
| 58 | user = UserHandleCompat.myUserHandle(); |
| 59 | } |
| 60 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 61 | if (componentName != null) { |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 62 | launcher.startApplicationDetailsActivity(componentName, user); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 63 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 67 | protected boolean supportsDrop(DragSource source, Object info) { |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 68 | 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 Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 78 | void completeDrop(DragObject d) { |
| 79 | startDetailsActivityForInfo(d.dragInfo, mLauncher); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 80 | } |
| 81 | } |