1cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi/* 2cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * Copyright (C) 2016 The Android Open Source Project 3cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * 4cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * Licensed under the Apache License, Version 2.0 (the "License"); 5cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * you may not use this file except in compliance with the License. 6cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * You may obtain a copy of the License at 7cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * 8cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * http://www.apache.org/licenses/LICENSE-2.0 9cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * 10cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * Unless required by applicable law or agreed to in writing, software 11cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * distributed under the License is distributed on an "AS IS" BASIS, 12cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * See the License for the specific language governing permissions and 14cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * limitations under the License 15cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi */ 16cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 17cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggipackage com.android.systemui.recents; 18cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 19cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggiimport android.graphics.Rect; 20cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggiimport android.os.Handler; 21cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggiimport android.os.Message; 22cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggiimport android.os.RemoteException; 23cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 24cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggiimport com.android.internal.os.SomeArgs; 25cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 26cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi/** 27cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * A proxy class which directs all methods from {@link IRecentsNonSystemUserCallbacks} to 28cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi * {@link RecentsImpl} and makes sure they are called from the main thread. 29cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi */ 30cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggipublic class RecentsImplProxy extends IRecentsNonSystemUserCallbacks.Stub { 31cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 32cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi private static final int MSG_PRELOAD_RECENTS = 1; 33cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi private static final int MSG_CANCEL_PRELOADING_RECENTS = 2; 34cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi private static final int MSG_SHOW_RECENTS = 3; 35cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi private static final int MSG_HIDE_RECENTS = 4; 36cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi private static final int MSG_TOGGLE_RECENTS = 5; 37cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi private static final int MSG_ON_CONFIGURATION_CHANGED = 6; 38cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi private static final int MSG_DOCK_TOP_TASK = 7; 39cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi private static final int MSG_ON_DRAGGING_IN_RECENTS = 8; 40cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi private static final int MSG_ON_DRAGGING_IN_RECENTS_ENDED = 9; 41cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 42cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi private RecentsImpl mImpl; 43cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 44cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi public RecentsImplProxy(RecentsImpl recentsImpl) { 45cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mImpl = recentsImpl; 46cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 47cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 48cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi @Override 49cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi public void preloadRecents() throws RemoteException { 50cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mHandler.sendEmptyMessage(MSG_PRELOAD_RECENTS); 51cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 52cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 53cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi @Override 54cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi public void cancelPreloadingRecents() throws RemoteException { 55cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mHandler.sendEmptyMessage(MSG_CANCEL_PRELOADING_RECENTS); 56cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 57cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 58cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi @Override 59cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi public void showRecents(boolean triggeredFromAltTab, boolean draggingInRecents, boolean animate, 60db21bbd2caf05322864f09ec45a0c572cf071123Jorim Jaggi boolean reloadTasks, boolean fromHome, int growTarget) 61db21bbd2caf05322864f09ec45a0c572cf071123Jorim Jaggi throws RemoteException { 62cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi SomeArgs args = SomeArgs.obtain(); 63cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi args.argi1 = triggeredFromAltTab ? 1 : 0; 64cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi args.argi2 = draggingInRecents ? 1 : 0; 65cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi args.argi3 = animate ? 1 : 0; 66cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi args.argi4 = reloadTasks ? 1 : 0; 67681fc7b2670542aae0f3b9ef8f6c7a88db984ea9Jorim Jaggi args.argi5 = fromHome ? 1 : 0; 68db21bbd2caf05322864f09ec45a0c572cf071123Jorim Jaggi args.argi6 = growTarget; 69cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_RECENTS, args)); 70cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 71cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 72cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi @Override 73cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi public void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) 74cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi throws RemoteException { 75cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mHandler.sendMessage(mHandler.obtainMessage(MSG_HIDE_RECENTS, triggeredFromAltTab ? 1 :0, 76cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi triggeredFromHomeKey ? 1 : 0)); 77cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 78cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 79cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi @Override 80db21bbd2caf05322864f09ec45a0c572cf071123Jorim Jaggi public void toggleRecents(int growTarget) throws RemoteException { 81ae165154a2a80ef160927d81a0b898660153f25eWinson SomeArgs args = SomeArgs.obtain(); 82ae165154a2a80ef160927d81a0b898660153f25eWinson args.argi1 = growTarget; 83ae165154a2a80ef160927d81a0b898660153f25eWinson mHandler.sendMessage(mHandler.obtainMessage(MSG_TOGGLE_RECENTS, args)); 84cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 85cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 86cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi @Override 87cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi public void onConfigurationChanged() throws RemoteException { 88cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mHandler.sendEmptyMessage(MSG_ON_CONFIGURATION_CHANGED); 89cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 90cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 91cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi @Override 92cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi public void dockTopTask(int topTaskId, int dragMode, int stackCreateMode, 93cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi Rect initialBounds) throws RemoteException { 94cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi SomeArgs args = SomeArgs.obtain(); 95cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi args.argi1 = topTaskId; 96cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi args.argi2 = dragMode; 97cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi args.argi3 = stackCreateMode; 98cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi args.arg1 = initialBounds; 99cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mHandler.sendMessage(mHandler.obtainMessage(MSG_DOCK_TOP_TASK, args)); 100cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 101cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 102cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi @Override 103cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi public void onDraggingInRecents(float distanceFromTop) throws RemoteException { 104cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_DRAGGING_IN_RECENTS, distanceFromTop)); 105cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 106cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 107cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi @Override 108cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi public void onDraggingInRecentsEnded(float velocity) throws RemoteException { 109cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_DRAGGING_IN_RECENTS_ENDED, velocity)); 110cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 111cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 112cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi private final Handler mHandler = new Handler() { 113cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi 114cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi @Override 115cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi public void handleMessage(Message msg) { 116ae165154a2a80ef160927d81a0b898660153f25eWinson SomeArgs args; 117cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi switch (msg.what) { 118cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi case MSG_PRELOAD_RECENTS: 119cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mImpl.preloadRecents(); 120cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi break; 121cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi case MSG_CANCEL_PRELOADING_RECENTS: 122cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mImpl.cancelPreloadingRecents(); 123cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi break; 124cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi case MSG_SHOW_RECENTS: 125ae165154a2a80ef160927d81a0b898660153f25eWinson args = (SomeArgs) msg.obj; 126cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mImpl.showRecents(args.argi1 != 0, args.argi2 != 0, args.argi3 != 0, 127db21bbd2caf05322864f09ec45a0c572cf071123Jorim Jaggi args.argi4 != 0, args.argi5 != 0, args.argi6); 128cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi break; 129cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi case MSG_HIDE_RECENTS: 130cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mImpl.hideRecents(msg.arg1 != 0, msg.arg2 != 0); 131cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi break; 132cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi case MSG_TOGGLE_RECENTS: 133ae165154a2a80ef160927d81a0b898660153f25eWinson args = (SomeArgs) msg.obj; 134ae165154a2a80ef160927d81a0b898660153f25eWinson mImpl.toggleRecents(args.argi1); 135cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi break; 136cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi case MSG_ON_CONFIGURATION_CHANGED: 137cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mImpl.onConfigurationChanged(); 138cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi break; 139cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi case MSG_DOCK_TOP_TASK: 140cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi args = (SomeArgs) msg.obj; 141cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mImpl.dockTopTask(args.argi1, args.argi2, args.argi3 = 0, 142cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi (Rect) args.arg1); 143cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi break; 144cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi case MSG_ON_DRAGGING_IN_RECENTS: 145cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mImpl.onDraggingInRecents((Float) msg.obj); 146cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi break; 147cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi case MSG_ON_DRAGGING_IN_RECENTS_ENDED: 148cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi mImpl.onDraggingInRecentsEnded((Float) msg.obj); 149cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi break; 150cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi default: 151cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi super.handleMessage(msg); 152cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 153cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi super.handleMessage(msg); 154cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi } 155cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi }; 156cdb06caebb5f6f554b2ed8c76963970d8cc0ab54Jorim Jaggi} 157