Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame^] | 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 | |
| 42 | private RecentsImpl mImpl; |
| 43 | |
| 44 | public RecentsImplProxy(RecentsImpl recentsImpl) { |
| 45 | mImpl = recentsImpl; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public void preloadRecents() throws RemoteException { |
| 50 | mHandler.sendEmptyMessage(MSG_PRELOAD_RECENTS); |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public void cancelPreloadingRecents() throws RemoteException { |
| 55 | mHandler.sendEmptyMessage(MSG_CANCEL_PRELOADING_RECENTS); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void showRecents(boolean triggeredFromAltTab, boolean draggingInRecents, boolean animate, |
| 60 | boolean reloadTasks) throws RemoteException { |
| 61 | SomeArgs args = SomeArgs.obtain(); |
| 62 | args.argi1 = triggeredFromAltTab ? 1 : 0; |
| 63 | args.argi2 = draggingInRecents ? 1 : 0; |
| 64 | args.argi3 = animate ? 1 : 0; |
| 65 | args.argi4 = reloadTasks ? 1 : 0; |
| 66 | mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_RECENTS, args)); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) |
| 71 | throws RemoteException { |
| 72 | mHandler.sendMessage(mHandler.obtainMessage(MSG_HIDE_RECENTS, triggeredFromAltTab ? 1 :0, |
| 73 | triggeredFromHomeKey ? 1 : 0)); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void toggleRecents() throws RemoteException { |
| 78 | mHandler.sendEmptyMessage(MSG_TOGGLE_RECENTS); |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public void onConfigurationChanged() throws RemoteException { |
| 83 | mHandler.sendEmptyMessage(MSG_ON_CONFIGURATION_CHANGED); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void dockTopTask(int topTaskId, int dragMode, int stackCreateMode, |
| 88 | Rect initialBounds) throws RemoteException { |
| 89 | SomeArgs args = SomeArgs.obtain(); |
| 90 | args.argi1 = topTaskId; |
| 91 | args.argi2 = dragMode; |
| 92 | args.argi3 = stackCreateMode; |
| 93 | args.arg1 = initialBounds; |
| 94 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DOCK_TOP_TASK, args)); |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public void onDraggingInRecents(float distanceFromTop) throws RemoteException { |
| 99 | mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_DRAGGING_IN_RECENTS, distanceFromTop)); |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public void onDraggingInRecentsEnded(float velocity) throws RemoteException { |
| 104 | mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_DRAGGING_IN_RECENTS_ENDED, velocity)); |
| 105 | } |
| 106 | |
| 107 | private final Handler mHandler = new Handler() { |
| 108 | |
| 109 | @Override |
| 110 | public void handleMessage(Message msg) { |
| 111 | switch (msg.what) { |
| 112 | case MSG_PRELOAD_RECENTS: |
| 113 | mImpl.preloadRecents(); |
| 114 | break; |
| 115 | case MSG_CANCEL_PRELOADING_RECENTS: |
| 116 | mImpl.cancelPreloadingRecents(); |
| 117 | break; |
| 118 | case MSG_SHOW_RECENTS: |
| 119 | SomeArgs args = (SomeArgs) msg.obj; |
| 120 | mImpl.showRecents(args.argi1 != 0, args.argi2 != 0, args.argi3 != 0, |
| 121 | args.argi4 != 0); |
| 122 | break; |
| 123 | case MSG_HIDE_RECENTS: |
| 124 | mImpl.hideRecents(msg.arg1 != 0, msg.arg2 != 0); |
| 125 | break; |
| 126 | case MSG_TOGGLE_RECENTS: |
| 127 | mImpl.toggleRecents(); |
| 128 | break; |
| 129 | case MSG_ON_CONFIGURATION_CHANGED: |
| 130 | mImpl.onConfigurationChanged(); |
| 131 | break; |
| 132 | case MSG_DOCK_TOP_TASK: |
| 133 | args = (SomeArgs) msg.obj; |
| 134 | mImpl.dockTopTask(args.argi1, args.argi2, args.argi3 = 0, |
| 135 | (Rect) args.arg1); |
| 136 | break; |
| 137 | case MSG_ON_DRAGGING_IN_RECENTS: |
| 138 | mImpl.onDraggingInRecents((Float) msg.obj); |
| 139 | break; |
| 140 | case MSG_ON_DRAGGING_IN_RECENTS_ENDED: |
| 141 | mImpl.onDraggingInRecentsEnded((Float) msg.obj); |
| 142 | break; |
| 143 | default: |
| 144 | super.handleMessage(msg); |
| 145 | } |
| 146 | super.handleMessage(msg); |
| 147 | } |
| 148 | }; |
| 149 | } |