1 /*
2  * Copyright (C) 2021 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.util;
17 
18 import android.content.Context;
19 import android.content.ContextWrapper;
20 import android.view.ContextThemeWrapper;
21 
22 import com.android.launcher3.DeviceProfile;
23 import com.android.launcher3.InvariantDeviceProfile;
24 import com.android.launcher3.views.ActivityContext;
25 import com.android.launcher3.views.BaseDragLayer;
26 
27 /**
28  * {@link ContextWrapper} with internal Launcher interface for testing
29  */
30 public class ActivityContextWrapper extends ContextThemeWrapper implements ActivityContext {
31 
32     private final DeviceProfile mProfile;
33     private final MyDragLayer mMyDragLayer;
34 
ActivityContextWrapper(Context base)35     public ActivityContextWrapper(Context base) {
36         super(base, android.R.style.Theme_DeviceDefault);
37         mProfile = InvariantDeviceProfile.INSTANCE.get(base).getDeviceProfile(base).copy(base);
38         mMyDragLayer = new MyDragLayer(this);
39     }
40 
41     @Override
getDragLayer()42     public BaseDragLayer getDragLayer() {
43         return mMyDragLayer;
44     }
45 
46     @Override
getDeviceProfile()47     public DeviceProfile getDeviceProfile() {
48         return mProfile;
49     }
50 
51     private static class MyDragLayer extends BaseDragLayer<ActivityContextWrapper> {
52 
MyDragLayer(Context context)53         MyDragLayer(Context context) {
54             super(context, null, 1);
55         }
56 
57         @Override
recreateControllers()58         public void recreateControllers() {
59             mControllers = new TouchController[0];
60         }
61     }
62 }
63