blob: 6296297a81c2ca53741a9b9cabd313d585c354f5 [file] [log] [blame]
Jason Monkf85fc962017-04-19 17:13:41 -04001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui;
16
Jason Monk3b9357f2017-07-14 09:40:54 -040017import android.os.IBinder;
Jason Monkf85fc962017-04-19 17:13:41 -040018import android.os.RemoteException;
19import android.util.Log;
20import android.view.IDockedStackListener;
21import android.view.WindowManagerGlobal;
22
Jason Monk3b9357f2017-07-14 09:40:54 -040023import java.lang.ref.WeakReference;
24import java.util.ArrayList;
Jason Monkf85fc962017-04-19 17:13:41 -040025import java.util.function.Consumer;
26
27/**
28 * Utility wrapper to listen for whether or not a docked stack exists, to be
29 * used for things like the different overview icon in that mode.
30 */
Jason Monk3b9357f2017-07-14 09:40:54 -040031public class DockedStackExistsListener {
Jason Monkf85fc962017-04-19 17:13:41 -040032
33 private static final String TAG = "DockedStackExistsListener";
34
Jason Monk3b9357f2017-07-14 09:40:54 -040035 private static ArrayList<WeakReference<Consumer<Boolean>>> sCallbacks = new ArrayList<>();
Jason Monkf85fc962017-04-19 17:13:41 -040036
Jason Monk3b9357f2017-07-14 09:40:54 -040037 static {
38 try {
39 WindowManagerGlobal.getWindowManagerService().registerDockedStackListener(
40 new IDockedStackListener.Stub() {
41 @Override
42 public void onDividerVisibilityChanged(boolean b) throws RemoteException {
43
44 }
45
46 @Override
47 public void onDockedStackExistsChanged(boolean exists)
48 throws RemoteException {
49 DockedStackExistsListener.onDockedStackExistsChanged(exists);
50 }
51
52 @Override
53 public void onDockedStackMinimizedChanged(boolean b, long l, boolean b1)
54 throws RemoteException {
55
56 }
57
58 @Override
59 public void onAdjustedForImeChanged(boolean b, long l)
60 throws RemoteException {
61
62 }
63
64 @Override
65 public void onDockSideChanged(int i) throws RemoteException {
66
67 }
68 });
69 } catch (RemoteException e) {
70 Log.e(TAG, "Failed registering docked stack exists listener", e);
71 }
Jason Monkf85fc962017-04-19 17:13:41 -040072 }
73
Jason Monkf85fc962017-04-19 17:13:41 -040074
Jason Monk3b9357f2017-07-14 09:40:54 -040075 private static void onDockedStackExistsChanged(boolean exists) {
76 synchronized (sCallbacks) {
77 sCallbacks.removeIf(wf -> wf.get() == null);
78 sCallbacks.forEach(wf -> wf.get().accept(exists));
79 }
Jason Monkf85fc962017-04-19 17:13:41 -040080 }
81
82 public static void register(Consumer<Boolean> callback) {
Jason Monk3b9357f2017-07-14 09:40:54 -040083 synchronized (sCallbacks) {
84 sCallbacks.add(new WeakReference<>(callback));
Jason Monkf85fc962017-04-19 17:13:41 -040085 }
86 }
87}