• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.systemui.screenshot;
18 
19 import com.android.systemui.dagger.SysUISingleton;
20 
21 import java.util.concurrent.atomic.AtomicReference;
22 
23 import javax.inject.Inject;
24 
25 /**
26  * LongScreenshotData holds on to 1 LongScreenshot reference and 1 TransitionDestination
27  * reference, to facilitate indirect in-process passing.
28  */
29 @SysUISingleton
30 public class LongScreenshotData {
31     private final AtomicReference<ScrollCaptureController.LongScreenshot> mLongScreenshot;
32     private final AtomicReference<ScreenshotController.TransitionDestination>
33             mTransitionDestinationCallback;
34 
35     @Inject
LongScreenshotData()36     public LongScreenshotData() {
37         mLongScreenshot = new AtomicReference<>();
38         mTransitionDestinationCallback = new AtomicReference<>();
39     }
40 
41     /**
42      * Set the holder's stored LongScreenshot.
43      */
setLongScreenshot(ScrollCaptureController.LongScreenshot longScreenshot)44     public void setLongScreenshot(ScrollCaptureController.LongScreenshot longScreenshot) {
45         mLongScreenshot.set(longScreenshot);
46     }
47 
48     /**
49      * @return true if the holder has a non-null LongScreenshot.
50      */
hasLongScreenshot()51     public boolean hasLongScreenshot() {
52         return mLongScreenshot.get() != null;
53     }
54 
55     /**
56      * Return the current stored LongScreenshot, clear the holder's storage.
57      */
takeLongScreenshot()58     public ScrollCaptureController.LongScreenshot takeLongScreenshot() {
59         return mLongScreenshot.getAndSet(null);
60     }
61 
62     /**
63      * Set the holder's TransitionDestination callback.
64      */
setTransitionDestinationCallback( ScreenshotController.TransitionDestination destination)65     public void setTransitionDestinationCallback(
66             ScreenshotController.TransitionDestination destination) {
67         mTransitionDestinationCallback.set(destination);
68     }
69 
70     /**
71      * Return the current TransitionDestination callback and clear.
72      */
takeTransitionDestinationCallback()73     public ScreenshotController.TransitionDestination takeTransitionDestinationCallback() {
74         return mTransitionDestinationCallback.getAndSet(null);
75     }
76 }
77