blob: 4a0f52d8159d09f5fea9441f99650b8ea585f0fe [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) {
Jon Mirandafe964322017-03-22 10:25:17 -070051 mUserEventDispatcher = UserEventDispatcher.newInstance(this,
Hyunyoung Songd5a9b572017-05-16 11:04:26 -070052 mDeviceProfile.isLandscape, isInMultiWindowModeCompat());
Sunny Goyala535ae42017-02-27 10:07:13 -080053 }
54 return mUserEventDispatcher;
55 }
56
Jon Mirandafe964322017-03-22 10:25:17 -070057 public boolean isInMultiWindowModeCompat() {
58 return Utilities.ATLEAST_NOUGAT && isInMultiWindowMode();
59 }
60
Sunny Goyal27835952017-01-13 12:15:53 -080061 public static BaseActivity fromContext(Context context) {
62 if (context instanceof BaseActivity) {
63 return (BaseActivity) context;
64 }
65 return ((BaseActivity) ((ContextWrapper) context).getBaseContext());
66 }
Sunny Goyal8392c822017-06-20 10:03:56 -070067
68 public SystemUiController getSystemUiController() {
69 if (mSystemUiController == null) {
70 mSystemUiController = new SystemUiController(getWindow());
71 }
72 return mSystemUiController;
73 }
Sunny Goyal64a75aa2017-07-03 13:50:52 -070074
75 @Override
76 public void onActivityResult(int requestCode, int resultCode, Intent data) {
77 super.onActivityResult(requestCode, resultCode, data);
78 }
Sunny Goyalcc96aa12018-01-11 09:56:07 -080079
80 @Override
81 protected void onStart() {
82 mStarted = true;
83 super.onStart();
84 }
85
86 @Override
87 protected void onStop() {
88 mStarted = false;
89 super.onStop();
90 }
91
92 public boolean isStarted() {
93 return mStarted;
94 }
Sunny Goyalfde55052018-02-01 14:46:13 -080095
96 public void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
97 mDPChangeListeners.add(listener);
98 }
99
100 protected void dispatchDeviceProfileChanged() {
101 int count = mDPChangeListeners.size();
102 for (int i = 0; i < count; i++) {
103 mDPChangeListeners.get(i).onDeviceProfileChanged(mDeviceProfile);
104 }
105 }
Sunny Goyal27835952017-01-13 12:15:53 -0800106}