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.screenshotShelfUi2;
22 
23 import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 
25 import android.content.Context;
26 import android.hardware.display.DisplayManager;
27 import android.view.Display;
28 import android.view.LayoutInflater;
29 
30 import com.android.systemui.clipboardoverlay.ClipboardOverlayView;
31 import com.android.systemui.res.R;
32 import com.android.systemui.settings.DisplayTracker;
33 
34 import dagger.Module;
35 import dagger.Provides;
36 
37 import java.lang.annotation.Documented;
38 import java.lang.annotation.Retention;
39 
40 import javax.inject.Qualifier;
41 
42 /** Module for {@link com.android.systemui.clipboardoverlay}. */
43 @Module
44 public interface ClipboardOverlayModule {
45 
46     /**
47      *
48      */
49     @Provides
50     @OverlayWindowContext
provideWindowContext(DisplayManager displayManager, DisplayTracker displayTracker, Context context)51     static Context provideWindowContext(DisplayManager displayManager,
52             DisplayTracker displayTracker, Context context) {
53         Display display = displayManager.getDisplay(displayTracker.getDefaultDisplayId());
54         return context.createWindowContext(display, TYPE_SCREENSHOT, null);
55     }
56 
57     /**
58      *
59      */
60     @Provides
provideClipboardOverlayView(@verlayWindowContext Context context)61     static ClipboardOverlayView provideClipboardOverlayView(@OverlayWindowContext Context context) {
62         if (screenshotShelfUi2()) {
63             return (ClipboardOverlayView) LayoutInflater.from(context).inflate(
64                     R.layout.clipboard_overlay2, null);
65         } else {
66             return (ClipboardOverlayView) LayoutInflater.from(context).inflate(
67                     R.layout.clipboard_overlay, null);
68         }
69     }
70 
71     @Qualifier
72     @Documented
73     @Retention(RUNTIME)
74     @interface OverlayWindowContext {
75     }
76 }
77