• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.recents;
18 
19 import android.graphics.Rect;
20 import android.os.Handler;
21 import android.os.Message;
22 import android.os.RemoteException;
23 
24 import com.android.internal.os.SomeArgs;
25 
26 /**
27  * A proxy class which directs all methods from {@link IRecentsNonSystemUserCallbacks} to
28  * {@link RecentsImpl} and makes sure they are called from the main thread.
29  */
30 public class RecentsImplProxy extends IRecentsNonSystemUserCallbacks.Stub {
31 
32     private static final int MSG_PRELOAD_RECENTS = 1;
33     private static final int MSG_CANCEL_PRELOADING_RECENTS = 2;
34     private static final int MSG_SHOW_RECENTS = 3;
35     private static final int MSG_HIDE_RECENTS = 4;
36     private static final int MSG_TOGGLE_RECENTS = 5;
37     private static final int MSG_ON_CONFIGURATION_CHANGED = 6;
38     private static final int MSG_DOCK_TOP_TASK = 7;
39     private static final int MSG_ON_DRAGGING_IN_RECENTS = 8;
40     private static final int MSG_ON_DRAGGING_IN_RECENTS_ENDED = 9;
41     private static final int MSG_SHOW_USER_TOAST = 10;
42 
43     private RecentsImpl mImpl;
44 
RecentsImplProxy(RecentsImpl recentsImpl)45     public RecentsImplProxy(RecentsImpl recentsImpl) {
46         mImpl = recentsImpl;
47     }
48 
49     @Override
preloadRecents()50     public void preloadRecents() throws RemoteException {
51         mHandler.sendEmptyMessage(MSG_PRELOAD_RECENTS);
52     }
53 
54     @Override
cancelPreloadingRecents()55     public void cancelPreloadingRecents() throws RemoteException {
56         mHandler.sendEmptyMessage(MSG_CANCEL_PRELOADING_RECENTS);
57     }
58 
59     @Override
showRecents(boolean triggeredFromAltTab, boolean draggingInRecents, boolean animate, int growTarget)60     public void showRecents(boolean triggeredFromAltTab, boolean draggingInRecents, boolean animate,
61             int growTarget) throws RemoteException {
62         SomeArgs args = SomeArgs.obtain();
63         args.argi1 = triggeredFromAltTab ? 1 : 0;
64         args.argi2 = draggingInRecents ? 1 : 0;
65         args.argi3 = animate ? 1 : 0;
66         args.argi4 = growTarget;
67         mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_RECENTS, args));
68     }
69 
70     @Override
hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey)71     public void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey)
72             throws RemoteException {
73         mHandler.sendMessage(mHandler.obtainMessage(MSG_HIDE_RECENTS, triggeredFromAltTab ? 1 :0,
74                 triggeredFromHomeKey ? 1 : 0));
75     }
76 
77     @Override
toggleRecents(int growTarget)78     public void toggleRecents(int growTarget) throws RemoteException {
79         SomeArgs args = SomeArgs.obtain();
80         args.argi1 = growTarget;
81         mHandler.sendMessage(mHandler.obtainMessage(MSG_TOGGLE_RECENTS, args));
82     }
83 
84     @Override
onConfigurationChanged()85     public void onConfigurationChanged() throws RemoteException {
86         mHandler.sendEmptyMessage(MSG_ON_CONFIGURATION_CHANGED);
87     }
88 
89     @Override
splitPrimaryTask(int topTaskId, int dragMode, int stackCreateMode, Rect initialBounds)90     public void splitPrimaryTask(int topTaskId, int dragMode, int stackCreateMode,
91             Rect initialBounds) throws RemoteException {
92         SomeArgs args = SomeArgs.obtain();
93         args.argi1 = topTaskId;
94         args.argi2 = dragMode;
95         args.argi3 = stackCreateMode;
96         args.arg1 = initialBounds;
97         mHandler.sendMessage(mHandler.obtainMessage(MSG_DOCK_TOP_TASK, args));
98     }
99 
100     @Override
onDraggingInRecents(float distanceFromTop)101     public void onDraggingInRecents(float distanceFromTop) throws RemoteException {
102         mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_DRAGGING_IN_RECENTS, distanceFromTop));
103     }
104 
105     @Override
onDraggingInRecentsEnded(float velocity)106     public void onDraggingInRecentsEnded(float velocity) throws RemoteException {
107         mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_DRAGGING_IN_RECENTS_ENDED, velocity));
108     }
109 
110     @Override
showCurrentUserToast(int msgResId, int msgLength)111     public void showCurrentUserToast(int msgResId, int msgLength) {
112         mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_USER_TOAST, msgResId, msgLength));
113     }
114 
115     private final Handler mHandler = new Handler() {
116 
117         @Override
118         public void handleMessage(Message msg) {
119             SomeArgs args;
120             switch (msg.what) {
121                 case MSG_PRELOAD_RECENTS:
122                     mImpl.preloadRecents();
123                     break;
124                 case MSG_CANCEL_PRELOADING_RECENTS:
125                     mImpl.cancelPreloadingRecents();
126                     break;
127                 case MSG_SHOW_RECENTS:
128                     args = (SomeArgs) msg.obj;
129                     mImpl.showRecents(args.argi1 != 0, args.argi2 != 0, args.argi3 != 0,
130                             args.argi4);
131                     break;
132                 case MSG_HIDE_RECENTS:
133                     mImpl.hideRecents(msg.arg1 != 0, msg.arg2 != 0);
134                     break;
135                 case MSG_TOGGLE_RECENTS:
136                     args = (SomeArgs) msg.obj;
137                     mImpl.toggleRecents(args.argi1);
138                     break;
139                 case MSG_ON_CONFIGURATION_CHANGED:
140                     mImpl.onConfigurationChanged();
141                     break;
142                 case MSG_DOCK_TOP_TASK:
143                     args = (SomeArgs) msg.obj;
144                     mImpl.splitPrimaryTask(args.argi1, args.argi2, args.argi3 = 0,
145                             (Rect) args.arg1);
146                     break;
147                 case MSG_ON_DRAGGING_IN_RECENTS:
148                     mImpl.onDraggingInRecents((Float) msg.obj);
149                     break;
150                 case MSG_ON_DRAGGING_IN_RECENTS_ENDED:
151                     mImpl.onDraggingInRecentsEnded((Float) msg.obj);
152                     break;
153                 case MSG_SHOW_USER_TOAST:
154                     mImpl.onShowCurrentUserToast(msg.arg1, msg.arg2);
155                     break;
156                 default:
157                     super.handleMessage(msg);
158             }
159             super.handleMessage(msg);
160         }
161     };
162 }
163