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