blob: 12db3b69db6e445e83ffceec03d5ffd5c582d983 [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 Goyalfde55052018-02-01 14:46:13 -080025import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
Sunny Goyala535ae42017-02-27 10:07:13 -080026import com.android.launcher3.logging.UserEventDispatcher;
Sunny Goyal8392c822017-06-20 10:03:56 -070027import com.android.launcher3.util.SystemUiController;
Sunny Goyala535ae42017-02-27 10:07:13 -080028
Sunny Goyalfde55052018-02-01 14:46:13 -080029import java.util.ArrayList;
30
Sunny Goyal27835952017-01-13 12:15:53 -080031public abstract class BaseActivity extends Activity {
32
Sunny Goyalfde55052018-02-01 14:46:13 -080033 private final ArrayList<OnDeviceProfileChangeListener> mDPChangeListeners = new ArrayList<>();
34
Sunny Goyal27835952017-01-13 12:15:53 -080035 protected DeviceProfile mDeviceProfile;
Sunny Goyala535ae42017-02-27 10:07:13 -080036 protected UserEventDispatcher mUserEventDispatcher;
Sunny Goyal8392c822017-06-20 10:03:56 -070037 protected SystemUiController mSystemUiController;
Sunny Goyal27835952017-01-13 12:15:53 -080038
Sunny Goyalcc96aa12018-01-11 09:56:07 -080039 private boolean mStarted;
40
Sunny Goyal27835952017-01-13 12:15:53 -080041 public DeviceProfile getDeviceProfile() {
42 return mDeviceProfile;
43 }
44
45 public AccessibilityDelegate getAccessibilityDelegate() {
46 return null;
47 }
48
Sunny Goyala535ae42017-02-27 10:07:13 -080049 public final UserEventDispatcher getUserEventDispatcher() {
50 if (mUserEventDispatcher == null) {
Sunny Goyald70e75a2018-02-22 10:07:32 -080051 mUserEventDispatcher = UserEventDispatcher.newInstance(this, mDeviceProfile);
Sunny Goyala535ae42017-02-27 10:07:13 -080052 }
53 return mUserEventDispatcher;
54 }
55
Jon Mirandafe964322017-03-22 10:25:17 -070056 public boolean isInMultiWindowModeCompat() {
57 return Utilities.ATLEAST_NOUGAT && isInMultiWindowMode();
58 }
59
Sunny Goyal27835952017-01-13 12:15:53 -080060 public static BaseActivity fromContext(Context context) {
61 if (context instanceof BaseActivity) {
62 return (BaseActivity) context;
63 }
64 return ((BaseActivity) ((ContextWrapper) context).getBaseContext());
65 }
Sunny Goyal8392c822017-06-20 10:03:56 -070066
67 public SystemUiController getSystemUiController() {
68 if (mSystemUiController == null) {
69 mSystemUiController = new SystemUiController(getWindow());
70 }
71 return mSystemUiController;
72 }
Sunny Goyal64a75aa2017-07-03 13:50:52 -070073
74 @Override
75 public void onActivityResult(int requestCode, int resultCode, Intent data) {
76 super.onActivityResult(requestCode, resultCode, data);
77 }
Sunny Goyalcc96aa12018-01-11 09:56:07 -080078
79 @Override
80 protected void onStart() {
81 mStarted = true;
82 super.onStart();
83 }
84
85 @Override
86 protected void onStop() {
87 mStarted = false;
88 super.onStop();
89 }
90
91 public boolean isStarted() {
92 return mStarted;
93 }
Sunny Goyalfde55052018-02-01 14:46:13 -080094
95 public void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
96 mDPChangeListeners.add(listener);
97 }
98
99 protected void dispatchDeviceProfileChanged() {
100 int count = mDPChangeListeners.size();
101 for (int i = 0; i < count; i++) {
102 mDPChangeListeners.get(i).onDeviceProfileChanged(mDeviceProfile);
103 }
104 }
Sunny Goyal27835952017-01-13 12:15:53 -0800105}