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; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 22 | |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 23 | public class InfoDropTarget extends ButtonDropTarget { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 24 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 25 | public InfoDropTarget(Context context, AttributeSet attrs) { |
| 26 | this(context, attrs, 0); |
| 27 | } |
| 28 | |
| 29 | public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) { |
| 30 | super(context, attrs, defStyle); |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | protected void onFinishInflate() { |
| 35 | super.onFinishInflate(); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 36 | // Get the hover color |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 37 | mHoverColor = getResources().getColor(R.color.info_target_hover_tint); |
Adam Cohen | 18bbc6a | 2014-06-03 21:43:24 -0700 | [diff] [blame] | 38 | |
Sunny Goyal | 40b626b | 2015-06-04 22:40:14 -0700 | [diff] [blame] | 39 | setDrawable(R.drawable.ic_info_launcher); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 40 | } |
| 41 | |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 42 | public static void startDetailsActivityForInfo(ItemInfo info, Launcher launcher) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 43 | ComponentName componentName = null; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 44 | if (info instanceof AppInfo) { |
| 45 | componentName = ((AppInfo) info).componentName; |
| 46 | } else if (info instanceof ShortcutInfo) { |
| 47 | componentName = ((ShortcutInfo) info).intent.getComponent(); |
| 48 | } else if (info instanceof PendingAddItemInfo) { |
| 49 | componentName = ((PendingAddItemInfo) info).componentName; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 50 | } |
| 51 | if (componentName != null) { |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 52 | launcher.startApplicationDetailsActivity(componentName, info.user); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 53 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 57 | protected boolean supportsDrop(DragSource source, ItemInfo info) { |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 58 | return source.supportsAppInfoDropTarget() && supportsDrop(getContext(), info); |
| 59 | } |
| 60 | |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 61 | public static boolean supportsDrop(Context context, ItemInfo info) { |
Sunny Goyal | d7da55f | 2015-06-12 12:25:45 -0700 | [diff] [blame] | 62 | return info instanceof AppInfo || info instanceof PendingAddItemInfo; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 66 | void completeDrop(DragObject d) { |
| 67 | startDetailsActivityForInfo(d.dragInfo, mLauncher); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 68 | } |
| 69 | } |