blob: a54c21c5f30e5babb8a388368cae18d49f1075ca [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;
Sunny Goyal64a75aa2017-07-03 13:50:52 -070022import android.content.Intent;
Sunny Goyal27835952017-01-13 12:15:53 -080023import android.view.View.AccessibilityDelegate;
24
Sunny Goyala535ae42017-02-27 10:07:13 -080025import com.android.launcher3.logging.UserEventDispatcher;
Sunny Goyal8392c822017-06-20 10:03:56 -070026import com.android.launcher3.util.SystemUiController;
Sunny Goyala535ae42017-02-27 10:07:13 -080027
Sunny Goyal27835952017-01-13 12:15:53 -080028public abstract class BaseActivity extends Activity {
29
30 protected DeviceProfile mDeviceProfile;
Sunny Goyala535ae42017-02-27 10:07:13 -080031 protected UserEventDispatcher mUserEventDispatcher;
Sunny Goyal8392c822017-06-20 10:03:56 -070032 protected SystemUiController mSystemUiController;
Sunny Goyal27835952017-01-13 12:15:53 -080033
Sunny Goyalcc96aa12018-01-11 09:56:07 -080034 private boolean mStarted;
35
Sunny Goyal27835952017-01-13 12:15:53 -080036 public DeviceProfile getDeviceProfile() {
37 return mDeviceProfile;
38 }
39
40 public AccessibilityDelegate getAccessibilityDelegate() {
41 return null;
42 }
43
Sunny Goyala535ae42017-02-27 10:07:13 -080044 public final UserEventDispatcher getUserEventDispatcher() {
45 if (mUserEventDispatcher == null) {
Jon Mirandafe964322017-03-22 10:25:17 -070046 mUserEventDispatcher = UserEventDispatcher.newInstance(this,
Hyunyoung Songd5a9b572017-05-16 11:04:26 -070047 mDeviceProfile.isLandscape, isInMultiWindowModeCompat());
Sunny Goyala535ae42017-02-27 10:07:13 -080048 }
49 return mUserEventDispatcher;
50 }
51
Jon Mirandafe964322017-03-22 10:25:17 -070052 public boolean isInMultiWindowModeCompat() {
53 return Utilities.ATLEAST_NOUGAT && isInMultiWindowMode();
54 }
55
Sunny Goyal27835952017-01-13 12:15:53 -080056 public static BaseActivity fromContext(Context context) {
57 if (context instanceof BaseActivity) {
58 return (BaseActivity) context;
59 }
60 return ((BaseActivity) ((ContextWrapper) context).getBaseContext());
61 }
Sunny Goyal8392c822017-06-20 10:03:56 -070062
63 public SystemUiController getSystemUiController() {
64 if (mSystemUiController == null) {
65 mSystemUiController = new SystemUiController(getWindow());
66 }
67 return mSystemUiController;
68 }
Sunny Goyal64a75aa2017-07-03 13:50:52 -070069
70 @Override
71 public void onActivityResult(int requestCode, int resultCode, Intent data) {
72 super.onActivityResult(requestCode, resultCode, data);
73 }
Sunny Goyalcc96aa12018-01-11 09:56:07 -080074
75 @Override
76 protected void onStart() {
77 mStarted = true;
78 super.onStart();
79 }
80
81 @Override
82 protected void onStop() {
83 mStarted = false;
84 super.onStop();
85 }
86
87 public boolean isStarted() {
88 return mStarted;
89 }
Sunny Goyal27835952017-01-13 12:15:53 -080090}