• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 package com.android.launcher3.views;
17 
18 import android.content.Context;
19 import android.content.ContextWrapper;
20 import android.view.ContextThemeWrapper;
21 import android.view.View.AccessibilityDelegate;
22 
23 import com.android.launcher3.DeviceProfile;
24 import com.android.launcher3.dot.DotInfo;
25 import com.android.launcher3.model.data.ItemInfo;
26 
27 /**
28  * An interface to be used along with a context for various activities in Launcher. This allows a
29  * generic class to depend on Context subclass instead of an Activity.
30  */
31 public interface ActivityContext {
32 
finishAutoCancelActionMode()33     default boolean finishAutoCancelActionMode() {
34         return false;
35     }
36 
getDotInfoForItem(ItemInfo info)37     default DotInfo getDotInfoForItem(ItemInfo info) {
38         return null;
39     }
40 
41     /**
42      * For items with tree hierarchy, notifies the activity to invalidate the parent when a root
43      * is invalidated
44      * @param info info associated with a root node.
45      */
invalidateParent(ItemInfo info)46     default void invalidateParent(ItemInfo info) { }
47 
getAccessibilityDelegate()48     default AccessibilityDelegate getAccessibilityDelegate() {
49         return null;
50     }
51 
52     /**
53      * The root view to support drag-and-drop and popup support.
54      */
getDragLayer()55     BaseDragLayer getDragLayer();
56 
getDeviceProfile()57     DeviceProfile getDeviceProfile();
58 
lookupContext(Context context)59     static ActivityContext lookupContext(Context context) {
60         if (context instanceof ActivityContext) {
61             return (ActivityContext) context;
62         } else if (context instanceof ContextThemeWrapper) {
63             return lookupContext(((ContextWrapper) context).getBaseContext());
64         } else {
65             throw new IllegalArgumentException("Cannot find ActivityContext in parent tree");
66         }
67     }
68 }
69