• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.scroll;
18 
19 import android.graphics.Rect;
20 
21 import com.android.systemui.dagger.SysUISingleton;
22 
23 import java.util.concurrent.atomic.AtomicReference;
24 
25 import javax.inject.Inject;
26 
27 /**
28  * LongScreenshotData holds on to 1 LongScreenshot reference and 1 TransitionDestination
29  * reference, to facilitate indirect in-process passing.
30  */
31 @SysUISingleton
32 public class LongScreenshotData {
33     private final AtomicReference<ScrollCaptureController.LongScreenshot> mLongScreenshot;
34     private final AtomicReference<TransitionDestination>
35             mTransitionDestinationCallback;
36 
37     public interface TransitionDestination {
38         /**
39          * Allows the long screenshot activity to call back with a destination location (the bounds
40          * on screen of the destination for the transitioning view) and a Runnable to be run once
41          * the transition animation is complete.
42          */
setTransitionDestination(Rect transitionDestination, Runnable onTransitionEnd)43         void setTransitionDestination(Rect transitionDestination, Runnable onTransitionEnd);
44     }
45 
46     @Inject
LongScreenshotData()47     public LongScreenshotData() {
48         mLongScreenshot = new AtomicReference<>();
49         mTransitionDestinationCallback = new AtomicReference<>();
50     }
51 
52     /**
53      * Set the holder's stored LongScreenshot.
54      */
setLongScreenshot(ScrollCaptureController.LongScreenshot longScreenshot)55     public void setLongScreenshot(ScrollCaptureController.LongScreenshot longScreenshot) {
56         mLongScreenshot.set(longScreenshot);
57     }
58 
59     /**
60      * @return true if the holder has a non-null LongScreenshot.
61      */
hasLongScreenshot()62     public boolean hasLongScreenshot() {
63         return mLongScreenshot.get() != null;
64     }
65 
66     /**
67      * Return the current stored LongScreenshot, clear the holder's storage.
68      */
takeLongScreenshot()69     public ScrollCaptureController.LongScreenshot takeLongScreenshot() {
70         return mLongScreenshot.getAndSet(null);
71     }
72 
73     /**
74      * Set the holder's TransitionDestination callback.
75      */
setTransitionDestinationCallback(TransitionDestination destination)76     public void setTransitionDestinationCallback(TransitionDestination destination) {
77         mTransitionDestinationCallback.set(destination);
78     }
79 
80     /**
81      * Return the current TransitionDestination callback and clear.
82      */
takeTransitionDestinationCallback()83     public TransitionDestination takeTransitionDestinationCallback() {
84         return mTransitionDestinationCallback.getAndSet(null);
85     }
86 }
87