Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.launcher3; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.content.Context; |
| 21 | import android.content.ContextWrapper; |
| 22 | import android.view.View.AccessibilityDelegate; |
| 23 | |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 24 | import com.android.launcher3.logging.UserEventDispatcher; |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 25 | import com.android.launcher3.util.SystemUiController; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 26 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 27 | public abstract class BaseActivity extends Activity { |
| 28 | |
| 29 | protected DeviceProfile mDeviceProfile; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 30 | protected UserEventDispatcher mUserEventDispatcher; |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 31 | protected SystemUiController mSystemUiController; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 32 | |
| 33 | public DeviceProfile getDeviceProfile() { |
| 34 | return mDeviceProfile; |
| 35 | } |
| 36 | |
| 37 | public AccessibilityDelegate getAccessibilityDelegate() { |
| 38 | return null; |
| 39 | } |
| 40 | |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 41 | public final UserEventDispatcher getUserEventDispatcher() { |
| 42 | if (mUserEventDispatcher == null) { |
Jon Miranda | fe96432 | 2017-03-22 10:25:17 -0700 | [diff] [blame] | 43 | mUserEventDispatcher = UserEventDispatcher.newInstance(this, |
Hyunyoung Song | d5a9b57 | 2017-05-16 11:04:26 -0700 | [diff] [blame] | 44 | mDeviceProfile.isLandscape, isInMultiWindowModeCompat()); |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 45 | } |
| 46 | return mUserEventDispatcher; |
| 47 | } |
| 48 | |
Jon Miranda | fe96432 | 2017-03-22 10:25:17 -0700 | [diff] [blame] | 49 | public boolean isInMultiWindowModeCompat() { |
| 50 | return Utilities.ATLEAST_NOUGAT && isInMultiWindowMode(); |
| 51 | } |
| 52 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 53 | public static BaseActivity fromContext(Context context) { |
| 54 | if (context instanceof BaseActivity) { |
| 55 | return (BaseActivity) context; |
| 56 | } |
| 57 | return ((BaseActivity) ((ContextWrapper) context).getBaseContext()); |
| 58 | } |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 59 | |
| 60 | public SystemUiController getSystemUiController() { |
| 61 | if (mSystemUiController == null) { |
| 62 | mSystemUiController = new SystemUiController(getWindow()); |
| 63 | } |
| 64 | return mSystemUiController; |
| 65 | } |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 66 | } |