Home | History | Annotate | Download | only in launcher3
      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 
     17 package com.android.launcher3;
     18 
     19 import android.content.ComponentName;
     20 import android.content.Context;
     21 import android.util.AttributeSet;
     22 
     23 import com.android.launcher3.compat.UserHandleCompat;
     24 
     25 public class InfoDropTarget extends ButtonDropTarget {
     26 
     27     public InfoDropTarget(Context context, AttributeSet attrs) {
     28         this(context, attrs, 0);
     29     }
     30 
     31     public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
     32         super(context, attrs, defStyle);
     33     }
     34 
     35     @Override
     36     protected void onFinishInflate() {
     37         super.onFinishInflate();
     38         // Get the hover color
     39         mHoverColor = getResources().getColor(R.color.info_target_hover_tint);
     40 
     41         setDrawable(R.drawable.ic_info_launcher);
     42     }
     43 
     44     public static void startDetailsActivityForInfo(Object info, Launcher launcher) {
     45         ComponentName componentName = null;
     46         if (info instanceof AppInfo) {
     47             componentName = ((AppInfo) info).componentName;
     48         } else if (info instanceof ShortcutInfo) {
     49             componentName = ((ShortcutInfo) info).intent.getComponent();
     50         } else if (info instanceof PendingAddItemInfo) {
     51             componentName = ((PendingAddItemInfo) info).componentName;
     52         }
     53         final UserHandleCompat user;
     54         if (info instanceof ItemInfo) {
     55             user = ((ItemInfo) info).user;
     56         } else {
     57             user = UserHandleCompat.myUserHandle();
     58         }
     59 
     60         if (componentName != null) {
     61             launcher.startApplicationDetailsActivity(componentName, user);
     62         }
     63     }
     64 
     65     @Override
     66     protected boolean supportsDrop(DragSource source, Object info) {
     67         return source.supportsAppInfoDropTarget() && supportsDrop(getContext(), info);
     68     }
     69 
     70     public static boolean supportsDrop(Context context, Object info) {
     71         return info instanceof AppInfo || info instanceof PendingAddItemInfo;
     72     }
     73 
     74     @Override
     75     void completeDrop(DragObject d) {
     76         startDetailsActivityForInfo(d.dragInfo, mLauncher);
     77     }
     78 }
     79