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