1 /* 2 * Copyright (C) 2022 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.systemui.clipboardoverlay.dagger; 18 19 import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT; 20 21 import static com.android.systemui.Flags.clipboardOverlayMultiuser; 22 import static com.android.systemui.shared.Flags.usePreferredImageEditor; 23 24 import static java.lang.annotation.RetentionPolicy.RUNTIME; 25 26 import android.content.Context; 27 import android.hardware.display.DisplayManager; 28 import android.view.Display; 29 import android.view.LayoutInflater; 30 import android.view.WindowManager; 31 32 import com.android.systemui.clipboardoverlay.ActionIntentCreator; 33 import com.android.systemui.clipboardoverlay.ClipboardOverlayView; 34 import com.android.systemui.clipboardoverlay.DefaultIntentCreator; 35 import com.android.systemui.clipboardoverlay.IntentCreator; 36 import com.android.systemui.res.R; 37 import com.android.systemui.settings.DisplayTracker; 38 import com.android.systemui.settings.UserTracker; 39 import com.android.systemui.utils.windowmanager.WindowManagerProvider; 40 41 import dagger.Lazy; 42 import dagger.Module; 43 import dagger.Provides; 44 45 import java.lang.annotation.Documented; 46 import java.lang.annotation.Retention; 47 48 import javax.inject.Qualifier; 49 50 /** Module for {@link com.android.systemui.clipboardoverlay}. */ 51 @Module 52 public interface ClipboardOverlayModule { 53 54 /** 55 * 56 */ 57 @Provides 58 @OverlayWindowContext provideWindowContext(DisplayManager displayManager, DisplayTracker displayTracker, Context context, UserTracker userTracker)59 static Context provideWindowContext(DisplayManager displayManager, 60 DisplayTracker displayTracker, Context context, UserTracker userTracker) { 61 Display display = displayManager.getDisplay(displayTracker.getDefaultDisplayId()); 62 if (clipboardOverlayMultiuser()) { 63 return userTracker.getUserContext().createWindowContext(display, TYPE_SCREENSHOT, null); 64 } else { 65 return context.createWindowContext(display, TYPE_SCREENSHOT, null); 66 } 67 } 68 69 /** 70 * 71 */ 72 @Provides provideClipboardOverlayView( @verlayWindowContext Context overlayContext, Context context)73 static ClipboardOverlayView provideClipboardOverlayView( 74 @OverlayWindowContext Context overlayContext, Context context) { 75 if (clipboardOverlayMultiuser()) { 76 return (ClipboardOverlayView) LayoutInflater.from(context).inflate( 77 R.layout.clipboard_overlay, null); 78 } else { 79 return (ClipboardOverlayView) LayoutInflater.from(overlayContext).inflate( 80 R.layout.clipboard_overlay, null); 81 } 82 } 83 84 /** 85 * 86 */ 87 @Provides 88 @OverlayWindowContext provideWindowManager(@verlayWindowContext Context context, WindowManagerProvider windowManagerProvider)89 static WindowManager provideWindowManager(@OverlayWindowContext Context context, 90 WindowManagerProvider windowManagerProvider) { 91 return windowManagerProvider.getWindowManager(context); 92 } 93 94 @Provides provideIntentCreator( Lazy<DefaultIntentCreator> defaultIntentCreator, Lazy<ActionIntentCreator> actionIntentCreator)95 static IntentCreator provideIntentCreator( 96 Lazy<DefaultIntentCreator> defaultIntentCreator, 97 Lazy<ActionIntentCreator> actionIntentCreator) { 98 if (usePreferredImageEditor()) { 99 return actionIntentCreator.get(); 100 } else { 101 return defaultIntentCreator.get(); 102 } 103 } 104 105 @Qualifier 106 @Documented 107 @Retention(RUNTIME) 108 @interface OverlayWindowContext { 109 } 110 } 111