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 | |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 19 | import android.annotation.TargetApi; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
| 21 | import android.content.Context; |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 22 | import android.os.Build; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 23 | import android.provider.Settings; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 24 | import android.util.AttributeSet; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 25 | |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 26 | import com.android.launcher3.compat.UserHandleCompat; |
| 27 | |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 28 | public class InfoDropTarget extends ButtonDropTarget { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 29 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 30 | 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 Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 41 | // Get the hover color |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 42 | mHoverColor = getResources().getColor(R.color.info_target_hover_tint); |
Adam Cohen | 18bbc6a | 2014-06-03 21:43:24 -0700 | [diff] [blame] | 43 | |
Sunny Goyal | 40b626b | 2015-06-04 22:40:14 -0700 | [diff] [blame] | 44 | setDrawable(R.drawable.ic_info_launcher); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | public static void startDetailsActivityForInfo(Object info, Launcher launcher) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 48 | ComponentName componentName = null; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 49 | 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 Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 55 | } |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 56 | final UserHandleCompat user; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 57 | if (info instanceof ItemInfo) { |
| 58 | user = ((ItemInfo) info).user; |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 59 | } else { |
| 60 | user = UserHandleCompat.myUserHandle(); |
| 61 | } |
| 62 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 63 | if (componentName != null) { |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 64 | launcher.startApplicationDetailsActivity(componentName, user); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 65 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 69 | protected boolean supportsDrop(DragSource source, Object info) { |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 70 | return source.supportsAppInfoDropTarget() && supportsDrop(getContext(), info); |
| 71 | } |
| 72 | |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 73 | @SuppressWarnings("deprecation") |
| 74 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 75 | public static boolean supportsDrop(Context context, Object info) { |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 76 | 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 Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 88 | void completeDrop(DragObject d) { |
| 89 | startDetailsActivityForInfo(d.dragInfo, mLauncher); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 90 | } |
| 91 | } |