blob: 2b59ede47652c970d6f98de071a92150b1445f85 [file] [log] [blame]
Sunny Goyal27835952017-01-13 12:15:53 -08001/*
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
17package com.android.launcher3;
18
19import android.app.Activity;
20import android.content.Context;
21import android.content.ContextWrapper;
22import android.view.View.AccessibilityDelegate;
23
Sunny Goyala535ae42017-02-27 10:07:13 -080024import com.android.launcher3.logging.UserEventDispatcher;
Sunny Goyal8392c822017-06-20 10:03:56 -070025import com.android.launcher3.util.SystemUiController;
Sunny Goyala535ae42017-02-27 10:07:13 -080026
Sunny Goyal27835952017-01-13 12:15:53 -080027public abstract class BaseActivity extends Activity {
28
29 protected DeviceProfile mDeviceProfile;
Sunny Goyala535ae42017-02-27 10:07:13 -080030 protected UserEventDispatcher mUserEventDispatcher;
Sunny Goyal8392c822017-06-20 10:03:56 -070031 protected SystemUiController mSystemUiController;
Sunny Goyal27835952017-01-13 12:15:53 -080032
33 public DeviceProfile getDeviceProfile() {
34 return mDeviceProfile;
35 }
36
37 public AccessibilityDelegate getAccessibilityDelegate() {
38 return null;
39 }
40
Sunny Goyala535ae42017-02-27 10:07:13 -080041 public final UserEventDispatcher getUserEventDispatcher() {
42 if (mUserEventDispatcher == null) {
Jon Mirandafe964322017-03-22 10:25:17 -070043 mUserEventDispatcher = UserEventDispatcher.newInstance(this,
Hyunyoung Songd5a9b572017-05-16 11:04:26 -070044 mDeviceProfile.isLandscape, isInMultiWindowModeCompat());
Sunny Goyala535ae42017-02-27 10:07:13 -080045 }
46 return mUserEventDispatcher;
47 }
48
Jon Mirandafe964322017-03-22 10:25:17 -070049 public boolean isInMultiWindowModeCompat() {
50 return Utilities.ATLEAST_NOUGAT && isInMultiWindowMode();
51 }
52
Sunny Goyal27835952017-01-13 12:15:53 -080053 public static BaseActivity fromContext(Context context) {
54 if (context instanceof BaseActivity) {
55 return (BaseActivity) context;
56 }
57 return ((BaseActivity) ((ContextWrapper) context).getBaseContext());
58 }
Sunny Goyal8392c822017-06-20 10:03:56 -070059
60 public SystemUiController getSystemUiController() {
61 if (mSystemUiController == null) {
62 mSystemUiController = new SystemUiController(getWindow());
63 }
64 return mSystemUiController;
65 }
Sunny Goyal27835952017-01-13 12:15:53 -080066}