This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
Window.java
2808 lines (2550 loc) · 111 KB
/
Window.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.view;
import static android.Manifest.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import static android.Manifest.permission.HIDE_OVERLAY_WINDOWS;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.annotation.IdRes;
import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.StyleRes;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UiContext;
import android.app.WindowConfiguration;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Insets;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.media.session.MediaController;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.transition.Scene;
import android.transition.Transition;
import android.transition.TransitionManager;
import android.util.Pair;
import android.view.View.OnApplyWindowInsetsListener;
import android.view.accessibility.AccessibilityEvent;
import android.window.OnBackInvokedDispatcher;
import java.util.Collections;
import java.util.List;
/**
* Abstract base class for a top-level window look and behavior policy. An
* instance of this class should be used as the top-level view added to the
* window manager. It provides standard UI policies such as a background, title
* area, default key processing, etc.
*
* <p>The framework will instantiate an implementation of this class on behalf of the application.
*/
public abstract class Window {
/** Flag for the "options panel" feature. This is enabled by default. */
public static final int FEATURE_OPTIONS_PANEL = 0;
/** Flag for the "no title" feature, turning off the title at the top
* of the screen. */
public static final int FEATURE_NO_TITLE = 1;
/**
* Flag for the progress indicator feature.
*
* @deprecated No longer supported starting in API 21.
*/
@Deprecated
public static final int FEATURE_PROGRESS = 2;
/** Flag for having an icon on the left side of the title bar */
public static final int FEATURE_LEFT_ICON = 3;
/** Flag for having an icon on the right side of the title bar */
public static final int FEATURE_RIGHT_ICON = 4;
/**
* Flag for indeterminate progress.
*
* @deprecated No longer supported starting in API 21.
*/
@Deprecated
public static final int FEATURE_INDETERMINATE_PROGRESS = 5;
/** Flag for the context menu. This is enabled by default. */
public static final int FEATURE_CONTEXT_MENU = 6;
/** Flag for custom title. You cannot combine this feature with other title features. */
public static final int FEATURE_CUSTOM_TITLE = 7;
/**
* Flag for enabling the Action Bar.
* This is enabled by default for some devices. The Action Bar
* replaces the title bar and provides an alternate location
* for an on-screen menu button on some devices.
*/
public static final int FEATURE_ACTION_BAR = 8;
/**
* Flag for requesting an Action Bar that overlays window content.
* Normally an Action Bar will sit in the space above window content, but if this
* feature is requested along with {@link #FEATURE_ACTION_BAR} it will be layered over
* the window content itself. This is useful if you would like your app to have more control
* over how the Action Bar is displayed, such as letting application content scroll beneath
* an Action Bar with a transparent background or otherwise displaying a transparent/translucent
* Action Bar over application content.
*
* <p>This mode is especially useful with {@link View#SYSTEM_UI_FLAG_FULLSCREEN
* View.SYSTEM_UI_FLAG_FULLSCREEN}, which allows you to seamlessly hide the
* action bar in conjunction with other screen decorations.
*
* <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, when an
* ActionBar is in this mode it will adjust the insets provided to
* {@link View#fitSystemWindows(android.graphics.Rect) View.fitSystemWindows(Rect)}
* to include the content covered by the action bar, so you can do layout within
* that space.
*/
public static final int FEATURE_ACTION_BAR_OVERLAY = 9;
/**
* Flag for specifying the behavior of action modes when an Action Bar is not present.
* If overlay is enabled, the action mode UI will be allowed to cover existing window content.
*/
public static final int FEATURE_ACTION_MODE_OVERLAY = 10;
/**
* Flag for requesting a decoration-free window that is dismissed by swiping from the left.
*
* @deprecated Swipe-to-dismiss isn't functional anymore.
*/
@Deprecated
public static final int FEATURE_SWIPE_TO_DISMISS = 11;
/**
* Flag for requesting that window content changes should be animated using a
* TransitionManager.
*
* <p>The TransitionManager is set using
* {@link #setTransitionManager(android.transition.TransitionManager)}. If none is set,
* a default TransitionManager will be used.</p>
*
* @see #setContentView
*/
public static final int FEATURE_CONTENT_TRANSITIONS = 12;
/**
* Enables Activities to run Activity Transitions either through sending or receiving
* ActivityOptions bundle created with
* {@link android.app.ActivityOptions#makeSceneTransitionAnimation(android.app.Activity,
* android.util.Pair[])} or {@link android.app.ActivityOptions#makeSceneTransitionAnimation(
* android.app.Activity, View, String)}.
*/
public static final int FEATURE_ACTIVITY_TRANSITIONS = 13;
/**
* Max value used as a feature ID
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int FEATURE_MAX = FEATURE_ACTIVITY_TRANSITIONS;
/**
* Flag for setting the progress bar's visibility to VISIBLE.
*
* @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
* supported starting in API 21.
*/
@Deprecated
public static final int PROGRESS_VISIBILITY_ON = -1;
/**
* Flag for setting the progress bar's visibility to GONE.
*
* @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
* supported starting in API 21.
*/
@Deprecated
public static final int PROGRESS_VISIBILITY_OFF = -2;
/**
* Flag for setting the progress bar's indeterminate mode on.
*
* @deprecated {@link #FEATURE_INDETERMINATE_PROGRESS} and related methods
* are no longer supported starting in API 21.
*/
@Deprecated
public static final int PROGRESS_INDETERMINATE_ON = -3;
/**
* Flag for setting the progress bar's indeterminate mode off.
*
* @deprecated {@link #FEATURE_INDETERMINATE_PROGRESS} and related methods
* are no longer supported starting in API 21.
*/
@Deprecated
public static final int PROGRESS_INDETERMINATE_OFF = -4;
/**
* Starting value for the (primary) progress.
*
* @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
* supported starting in API 21.
*/
@Deprecated
public static final int PROGRESS_START = 0;
/**
* Ending value for the (primary) progress.
*
* @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
* supported starting in API 21.
*/
@Deprecated
public static final int PROGRESS_END = 10000;
/**
* Lowest possible value for the secondary progress.
*
* @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
* supported starting in API 21.
*/
@Deprecated
public static final int PROGRESS_SECONDARY_START = 20000;
/**
* Highest possible value for the secondary progress.
*
* @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
* supported starting in API 21.
*/
@Deprecated
public static final int PROGRESS_SECONDARY_END = 30000;
/**
* The transitionName for the status bar background View when a custom background is used.
* @see android.view.Window#setStatusBarColor(int)
*/
public static final String STATUS_BAR_BACKGROUND_TRANSITION_NAME = "android:status:background";
/**
* The transitionName for the navigation bar background View when a custom background is used.
* @see android.view.Window#setNavigationBarColor(int)
*/
public static final String NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME =
"android:navigation:background";
/**
* The default features enabled.
* @deprecated use {@link #getDefaultFeatures(android.content.Context)} instead.
*/
@Deprecated
@SuppressWarnings({"PointlessBitwiseExpression"})
protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) |
(1 << FEATURE_CONTEXT_MENU);
/**
* The ID that the main layout in the XML layout file should have.
*/
public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content;
/**
* Flag for letting the theme drive the color of the window caption controls. Use with
* {@link #setDecorCaptionShade(int)}. This is the default value.
*/
public static final int DECOR_CAPTION_SHADE_AUTO = 0;
/**
* Flag for setting light-color controls on the window caption. Use with
* {@link #setDecorCaptionShade(int)}.
*/
public static final int DECOR_CAPTION_SHADE_LIGHT = 1;
/**
* Flag for setting dark-color controls on the window caption. Use with
* {@link #setDecorCaptionShade(int)}.
*/
public static final int DECOR_CAPTION_SHADE_DARK = 2;
@UnsupportedAppUsage
@UiContext
private final Context mContext;
@UnsupportedAppUsage
private TypedArray mWindowStyle;
@UnsupportedAppUsage
private Callback mCallback;
private OnWindowDismissedCallback mOnWindowDismissedCallback;
private OnWindowSwipeDismissedCallback mOnWindowSwipeDismissedCallback;
private WindowControllerCallback mWindowControllerCallback;
@WindowInsetsController.Appearance
private int mSystemBarAppearance;
private DecorCallback mDecorCallback;
private OnRestrictedCaptionAreaChangedListener mOnRestrictedCaptionAreaChangedListener;
private Rect mRestrictedCaptionAreaRect;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
private WindowManager mWindowManager;
@UnsupportedAppUsage
private IBinder mAppToken;
@UnsupportedAppUsage
private String mAppName;
@UnsupportedAppUsage
private boolean mHardwareAccelerated;
private Window mContainer;
private Window mActiveChild;
private boolean mIsActive = false;
private boolean mHasChildren = false;
private boolean mCloseOnTouchOutside = false;
private boolean mSetCloseOnTouchOutside = false;
private int mForcedWindowFlags = 0;
@UnsupportedAppUsage
private int mFeatures;
@UnsupportedAppUsage
private int mLocalFeatures;
private boolean mHaveWindowFormat = false;
private boolean mHaveDimAmount = false;
private int mDefaultWindowFormat = PixelFormat.OPAQUE;
private boolean mHasSoftInputMode = false;
@UnsupportedAppUsage
private boolean mDestroyed;
private boolean mOverlayWithDecorCaptionEnabled = true;
private boolean mCloseOnSwipeEnabled = false;
// The current window attributes.
@UnsupportedAppUsage
private final WindowManager.LayoutParams mWindowAttributes =
new WindowManager.LayoutParams();
/**
* API from a Window back to its caller. This allows the client to
* intercept key dispatching, panels and menus, etc.
*/
public interface Callback {
/**
* Called to process key events. At the very least your
* implementation must call
* {@link android.view.Window#superDispatchKeyEvent} to do the
* standard key processing.
*
* @param event The key event.
*
* @return boolean Return true if this event was consumed.
*/
public boolean dispatchKeyEvent(KeyEvent event);
/**
* Called to process a key shortcut event.
* At the very least your implementation must call
* {@link android.view.Window#superDispatchKeyShortcutEvent} to do the
* standard key shortcut processing.
*
* @param event The key shortcut event.
* @return True if this event was consumed.
*/
public boolean dispatchKeyShortcutEvent(KeyEvent event);
/**
* Called to process touch screen events. At the very least your
* implementation must call
* {@link android.view.Window#superDispatchTouchEvent} to do the
* standard touch screen processing.
*
* @param event The touch screen event.
*
* @return boolean Return true if this event was consumed.
*/
public boolean dispatchTouchEvent(MotionEvent event);
/**
* Called to process trackball events. At the very least your
* implementation must call
* {@link android.view.Window#superDispatchTrackballEvent} to do the
* standard trackball processing.
*
* @param event The trackball event.
*
* @return boolean Return true if this event was consumed.
*/
public boolean dispatchTrackballEvent(MotionEvent event);
/**
* Called to process generic motion events. At the very least your
* implementation must call
* {@link android.view.Window#superDispatchGenericMotionEvent} to do the
* standard processing.
*
* @param event The generic motion event.
*
* @return boolean Return true if this event was consumed.
*/
public boolean dispatchGenericMotionEvent(MotionEvent event);
/**
* Called to process population of {@link AccessibilityEvent}s.
*
* @param event The event.
*
* @return boolean Return true if event population was completed.
*/
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event);
/**
* Instantiate the view to display in the panel for 'featureId'.
* You can return null, in which case the default content (typically
* a menu) will be created for you.
*
* @param featureId Which panel is being created.
*
* @return view The top-level view to place in the panel.
*
* @see #onPreparePanel
*/
@Nullable
public View onCreatePanelView(int featureId);
/**
* Initialize the contents of the menu for panel 'featureId'. This is
* called if onCreatePanelView() returns null, giving you a standard
* menu in which you can place your items. It is only called once for
* the panel, the first time it is shown.
*
* <p>You can safely hold on to <var>menu</var> (and any items created
* from it), making modifications to it as desired, until the next
* time onCreatePanelMenu() is called for this feature.
*
* @param featureId The panel being created.
* @param menu The menu inside the panel.
*
* @return boolean You must return true for the panel to be displayed;
* if you return false it will not be shown.
*/
boolean onCreatePanelMenu(int featureId, @NonNull Menu menu);
/**
* Prepare a panel to be displayed. This is called right before the
* panel window is shown, every time it is shown.
*
* @param featureId The panel that is being displayed.
* @param view The View that was returned by onCreatePanelView().
* @param menu If onCreatePanelView() returned null, this is the Menu
* being displayed in the panel.
*
* @return boolean You must return true for the panel to be displayed;
* if you return false it will not be shown.
*
* @see #onCreatePanelView
*/
boolean onPreparePanel(int featureId, @Nullable View view, @NonNull Menu menu);
/**
* Called when a panel's menu is opened by the user. This may also be
* called when the menu is changing from one type to another (for
* example, from the icon menu to the expanded menu).
*
* @param featureId The panel that the menu is in.
* @param menu The menu that is opened.
* @return Return true to allow the menu to open, or false to prevent
* the menu from opening.
*/
boolean onMenuOpened(int featureId, @NonNull Menu menu);
/**
* Called when a panel's menu item has been selected by the user.
*
* @param featureId The panel that the menu is in.
* @param item The menu item that was selected.
*
* @return boolean Return true to finish processing of selection, or
* false to perform the normal menu handling (calling its
* Runnable or sending a Message to its target Handler).
*/
boolean onMenuItemSelected(int featureId, @NonNull MenuItem item);
/**
* This is called whenever the current window attributes change.
*
*/
public void onWindowAttributesChanged(WindowManager.LayoutParams attrs);
/**
* This hook is called whenever the content view of the screen changes
* (due to a call to
* {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams)
* Window.setContentView} or
* {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams)
* Window.addContentView}).
*/
public void onContentChanged();
/**
* This hook is called whenever the window focus changes. See
* {@link View#onWindowFocusChanged(boolean)
* View.onWindowFocusChangedNotLocked(boolean)} for more information.
*
* @param hasFocus Whether the window now has focus.
*/
public void onWindowFocusChanged(boolean hasFocus);
/**
* Called when the window has been attached to the window manager.
* See {@link View#onAttachedToWindow() View.onAttachedToWindow()}
* for more information.
*/
public void onAttachedToWindow();
/**
* Called when the window has been detached from the window manager.
* See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()}
* for more information.
*/
public void onDetachedFromWindow();
/**
* Called when a panel is being closed. If another logical subsequent
* panel is being opened (and this panel is being closed to make room for the subsequent
* panel), this method will NOT be called.
*
* @param featureId The panel that is being displayed.
* @param menu If onCreatePanelView() returned null, this is the Menu
* being displayed in the panel.
*/
void onPanelClosed(int featureId, @NonNull Menu menu);
/**
* Called when the user signals the desire to start a search.
*
* @return true if search launched, false if activity refuses (blocks)
*
* @see android.app.Activity#onSearchRequested()
*/
public boolean onSearchRequested();
/**
* Called when the user signals the desire to start a search.
*
* @param searchEvent A {@link SearchEvent} describing the signal to
* start a search.
* @return true if search launched, false if activity refuses (blocks)
*/
public boolean onSearchRequested(SearchEvent searchEvent);
/**
* Called when an action mode is being started for this window. Gives the
* callback an opportunity to handle the action mode in its own unique and
* beautiful way. If this method returns null the system can choose a way
* to present the mode or choose not to start the mode at all. This is equivalent
* to {@link #onWindowStartingActionMode(android.view.ActionMode.Callback, int)}
* with type {@link ActionMode#TYPE_PRIMARY}.
*
* @param callback Callback to control the lifecycle of this action mode
* @return The ActionMode that was started, or null if the system should present it
*/
@Nullable
public ActionMode onWindowStartingActionMode(ActionMode.Callback callback);
/**
* Called when an action mode is being started for this window. Gives the
* callback an opportunity to handle the action mode in its own unique and
* beautiful way. If this method returns null the system can choose a way
* to present the mode or choose not to start the mode at all.
*
* @param callback Callback to control the lifecycle of this action mode
* @param type One of {@link ActionMode#TYPE_PRIMARY} or {@link ActionMode#TYPE_FLOATING}.
* @return The ActionMode that was started, or null if the system should present it
*/
@Nullable
public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type);
/**
* Called when an action mode has been started. The appropriate mode callback
* method will have already been invoked.
*
* @param mode The new mode that has just been started.
*/
public void onActionModeStarted(ActionMode mode);
/**
* Called when an action mode has been finished. The appropriate mode callback
* method will have already been invoked.
*
* @param mode The mode that was just finished.
*/
public void onActionModeFinished(ActionMode mode);
/**
* Called when Keyboard Shortcuts are requested for the current window.
*
* @param data The data list to populate with shortcuts.
* @param menu The current menu, which may be null.
* @param deviceId The id for the connected device the shortcuts should be provided for.
*/
default public void onProvideKeyboardShortcuts(
List<KeyboardShortcutGroup> data, @Nullable Menu menu, int deviceId) { };
/**
* Called when pointer capture is enabled or disabled for the current window.
*
* @param hasCapture True if the window has pointer capture.
*/
default public void onPointerCaptureChanged(boolean hasCapture) { };
}
/** @hide */
public interface OnWindowDismissedCallback {
/**
* Called when a window is dismissed. This informs the callback that the
* window is gone, and it should finish itself.
* @param finishTask True if the task should also be finished.
* @param suppressWindowTransition True if the resulting exit and enter window transition
* animations should be suppressed.
*/
void onWindowDismissed(boolean finishTask, boolean suppressWindowTransition);
}
/** @hide */
public interface OnWindowSwipeDismissedCallback {
/**
* Called when a window is swipe dismissed. This informs the callback that the
* window is gone, and it should finish itself.
* @param finishTask True if the task should also be finished.
* @param suppressWindowTransition True if the resulting exit and enter window transition
* animations should be suppressed.
*/
void onWindowSwipeDismissed();
}
/** @hide */
public interface WindowControllerCallback {
/**
* Moves the activity between {@link WindowConfiguration#WINDOWING_MODE_FREEFORM} windowing
* mode and {@link WindowConfiguration#WINDOWING_MODE_FULLSCREEN}.
*/
void toggleFreeformWindowingMode();
/**
* Puts the activity in picture-in-picture mode if the activity supports.
* @see android.R.attr#supportsPictureInPicture
*/
void enterPictureInPictureModeIfPossible();
/** Returns whether the window belongs to the task root. */
boolean isTaskRoot();
/**
* Update the status bar color to a forced one.
*/
void updateStatusBarColor(int color);
/**
* Update the navigation bar color to a forced one.
*/
void updateNavigationBarColor(int color);
}
/** @hide */
public interface DecorCallback {
/**
* Called from
* {@link com.android.internal.policy.DecorView#onSystemBarAppearanceChanged(int)}.
*
* @param appearance The newly applied appearance.
*/
void onSystemBarAppearanceChanged(@WindowInsetsController.Appearance int appearance);
/**
* Called from
* {@link com.android.internal.policy.DecorView#updateColorViews(WindowInsets, boolean)}
* when {@link com.android.internal.policy.DecorView#mDrawLegacyNavigationBarBackground} is
* being updated.
*
* @param drawLegacyNavigationBarBackground the new value that is being set to
* {@link com.android.internal.policy.DecorView#mDrawLegacyNavigationBarBackground}.
* @return The value to be set to
* {@link com.android.internal.policy.DecorView#mDrawLegacyNavigationBarBackgroundHandled}
* on behalf of the {@link com.android.internal.policy.DecorView}.
* {@code true} to tell that the Window can render the legacy navigation bar
* background on behalf of the {@link com.android.internal.policy.DecorView}.
* {@code false} to let {@link com.android.internal.policy.DecorView} handle it.
*/
boolean onDrawLegacyNavigationBarBackgroundChanged(
boolean drawLegacyNavigationBarBackground);
}
/**
* Callback for clients that want to be aware of where caption draws content.
*/
public interface OnRestrictedCaptionAreaChangedListener {
/**
* Called when the area where caption draws content changes.
*
* @param rect The area where caption content is positioned, relative to the top view.
*/
void onRestrictedCaptionAreaChanged(Rect rect);
}
/**
* Callback for clients that want frame timing information for each
* frame rendered by the Window.
*/
public interface OnFrameMetricsAvailableListener {
/**
* Called when information is available for the previously rendered frame.
*
* Reports can be dropped if this callback takes too
* long to execute, as the report producer cannot wait for the consumer to
* complete.
*
* It is highly recommended that clients copy the passed in FrameMetrics
* via {@link FrameMetrics#FrameMetrics(FrameMetrics)} within this method and defer
* additional computation or storage to another thread to avoid unnecessarily
* dropping reports.
*
* @param window The {@link Window} on which the frame was displayed.
* @param frameMetrics the available metrics. This object is reused on every call
* and thus <strong>this reference is not valid outside the scope of this method</strong>.
* @param dropCountSinceLastInvocation the number of reports dropped since the last time
* this callback was invoked.
*/
void onFrameMetricsAvailable(Window window, FrameMetrics frameMetrics,
int dropCountSinceLastInvocation);
}
/**
* Listener for applying window insets on the content of a window. Used only by the framework to
* fit content according to legacy SystemUI flags.
*
* @hide
*/
public interface OnContentApplyWindowInsetsListener {
/**
* Called when the window needs to apply insets on the container of its content view which
* are set by calling {@link #setContentView}. The method should determine what insets to
* apply on the container of the root level content view and what should be dispatched to
* the content view's
* {@link View#setOnApplyWindowInsetsListener(OnApplyWindowInsetsListener)} through the view
* hierarchy.
*
* @param view The view for which to apply insets. Must not be directly modified.
* @param insets The root level insets that are about to be dispatched
* @return A pair, with the first element containing the insets to apply as margin to the
* root-level content views, and the second element determining what should be
* dispatched to the content view.
*/
@NonNull
Pair<Insets, WindowInsets> onContentApplyWindowInsets(@NonNull View view,
@NonNull WindowInsets insets);
}
public Window(@UiContext Context context) {
mContext = context;
mFeatures = mLocalFeatures = getDefaultFeatures(context);
}
/**
* Return the Context this window policy is running in, for retrieving
* resources and other information.
*
* @return Context The Context that was supplied to the constructor.
*/
@UiContext
public final Context getContext() {
return mContext;
}
/**
* Return the {@link android.R.styleable#Window} attributes from this
* window's theme.
*/
public final TypedArray getWindowStyle() {
synchronized (this) {
if (mWindowStyle == null) {
mWindowStyle = mContext.obtainStyledAttributes(
com.android.internal.R.styleable.Window);
}
return mWindowStyle;
}
}
/**
* Set the container for this window. If not set, the DecorWindow
* operates as a top-level window; otherwise, it negotiates with the
* container to display itself appropriately.
*
* @param container The desired containing Window.
*/
public void setContainer(Window container) {
mContainer = container;
if (container != null) {
// Embedded screens never have a title.
mFeatures |= 1<<FEATURE_NO_TITLE;
mLocalFeatures |= 1<<FEATURE_NO_TITLE;
container.mHasChildren = true;
}
}
/**
* Return the container for this Window.
*
* @return Window The containing window, or null if this is a
* top-level window.
*/
public final Window getContainer() {
return mContainer;
}
public final boolean hasChildren() {
return mHasChildren;
}
/** @hide */
public final void destroy() {
mDestroyed = true;
}
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public final boolean isDestroyed() {
return mDestroyed;
}
/**
* Set the window manager for use by this Window to, for example,
* display panels. This is <em>not</em> used for displaying the
* Window itself -- that must be done by the client.
*
* @param wm The window manager for adding new windows.
*/
public void setWindowManager(WindowManager wm, IBinder appToken, String appName) {
setWindowManager(wm, appToken, appName, false);
}
/**
* Set the window manager for use by this Window to, for example,
* display panels. This is <em>not</em> used for displaying the
* Window itself -- that must be done by the client.
*
* @param wm The window manager for adding new windows.
*/
public void setWindowManager(WindowManager wm, IBinder appToken, String appName,
boolean hardwareAccelerated) {
mAppToken = appToken;
mAppName = appName;
mHardwareAccelerated = hardwareAccelerated;
if (wm == null) {
wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
}
mWindowManager = ((WindowManagerImpl)wm).createLocalWindowManager(this);
}
void adjustLayoutParamsForSubWindow(WindowManager.LayoutParams wp) {
CharSequence curTitle = wp.getTitle();
if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&
wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
if (wp.token == null) {
View decor = peekDecorView();
if (decor != null) {
wp.token = decor.getWindowToken();
}
}
if (curTitle == null || curTitle.length() == 0) {
final StringBuilder title = new StringBuilder(32);
if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) {
title.append("Media");
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) {
title.append("MediaOvr");
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
title.append("Panel");
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) {
title.append("SubPanel");
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL) {
title.append("AboveSubPanel");
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) {
title.append("AtchDlg");
} else {
title.append(wp.type);
}
if (mAppName != null) {
title.append(":").append(mAppName);
}
wp.setTitle(title);
}
} else if (wp.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW &&
wp.type <= WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
// We don't set the app token to this system window because the life cycles should be
// independent. If an app creates a system window and then the app goes to the stopped
// state, the system window should not be affected (can still show and receive input
// events).
if (curTitle == null || curTitle.length() == 0) {
final StringBuilder title = new StringBuilder(32);
title.append("Sys").append(wp.type);
if (mAppName != null) {
title.append(":").append(mAppName);
}
wp.setTitle(title);
}
} else {
if (wp.token == null) {
wp.token = mContainer == null ? mAppToken : mContainer.mAppToken;
}
if ((curTitle == null || curTitle.length() == 0)
&& mAppName != null) {
wp.setTitle(mAppName);
}
}
if (wp.packageName == null) {
wp.packageName = mContext.getPackageName();
}
if (mHardwareAccelerated ||
(mWindowAttributes.flags & FLAG_HARDWARE_ACCELERATED) != 0) {
wp.flags |= FLAG_HARDWARE_ACCELERATED;
}
}
/**
* Return the window manager allowing this Window to display its own
* windows.
*
* @return WindowManager The ViewManager.
*/
public WindowManager getWindowManager() {
return mWindowManager;
}
/**
* Set the Callback interface for this window, used to intercept key
* events and other dynamic operations in the window.
*
* @param callback The desired Callback interface.
*/
public void setCallback(Callback callback) {
mCallback = callback;
}
/**
* Return the current Callback interface for this window.
*/
public final Callback getCallback() {
return mCallback;
}
/**
* Set an observer to collect frame stats for each frame rendered in this window.
*
* Must be in hardware rendering mode.
*/
public final void addOnFrameMetricsAvailableListener(
@NonNull OnFrameMetricsAvailableListener listener,
Handler handler) {
final View decorView = getDecorView();
if (decorView == null) {
throw new IllegalStateException("can't observe a Window without an attached view");
}
if (listener == null) {
throw new NullPointerException("listener cannot be null");
}
decorView.addFrameMetricsListener(this, listener, handler);
}
/**
* Remove observer and stop listening to frame stats for this window.
*/
public final void removeOnFrameMetricsAvailableListener(OnFrameMetricsAvailableListener listener) {
final View decorView = getDecorView();
if (decorView != null) {
getDecorView().removeFrameMetricsListener(listener);
}
}
/** @hide */
public final void setOnWindowDismissedCallback(OnWindowDismissedCallback dcb) {
mOnWindowDismissedCallback = dcb;
}
/** @hide */
public final void dispatchOnWindowDismissed(
boolean finishTask, boolean suppressWindowTransition) {
if (mOnWindowDismissedCallback != null) {
mOnWindowDismissedCallback.onWindowDismissed(finishTask, suppressWindowTransition);
}
}
/** @hide */
public final void setOnWindowSwipeDismissedCallback(OnWindowSwipeDismissedCallback sdcb) {
mOnWindowSwipeDismissedCallback = sdcb;
}