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.DeviceProfile.OnDeviceProfileChangeListener; 24 import com.android.launcher3.InvariantDeviceProfile; 25 import com.android.launcher3.views.ActivityContext; 26 import com.android.launcher3.views.BaseDragLayer; 27 28 import java.util.ArrayList; 29 import java.util.List; 30 31 /** 32 * {@link ContextWrapper} with internal Launcher interface for testing 33 */ 34 public class ActivityContextWrapper extends ContextThemeWrapper implements ActivityContext { 35 36 private final List<OnDeviceProfileChangeListener> mDpChangeListeners = new ArrayList<>(); 37 38 private final DeviceProfile mProfile; 39 private final MyDragLayer mMyDragLayer; 40 ActivityContextWrapper(Context base)41 public ActivityContextWrapper(Context base) { 42 super(base, android.R.style.Theme_DeviceDefault); 43 mProfile = InvariantDeviceProfile.INSTANCE.get(base).getDeviceProfile(base).copy(base); 44 mMyDragLayer = new MyDragLayer(this); 45 } 46 47 @Override getDragLayer()48 public BaseDragLayer getDragLayer() { 49 return mMyDragLayer; 50 } 51 52 @Override getOnDeviceProfileChangeListeners()53 public List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners() { 54 return mDpChangeListeners; 55 } 56 57 @Override getDeviceProfile()58 public DeviceProfile getDeviceProfile() { 59 return mProfile; 60 } 61 62 private static class MyDragLayer extends BaseDragLayer<ActivityContextWrapper> { 63 MyDragLayer(Context context)64 MyDragLayer(Context context) { 65 super(context, null, 1); 66 } 67 68 @Override recreateControllers()69 public void recreateControllers() { 70 mControllers = new TouchController[0]; 71 } 72 } 73 } 74