OSDN Git Service

Continue work on standalone Android 10 Desktop Mode support
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / ui / UIController.java
1 /* Copyright 2019 Braden Farmer
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 package com.farmerbb.taskbar.ui;
17
18 import android.content.Context;
19 import android.content.SharedPreferences;
20
21 import com.farmerbb.taskbar.activity.SecondaryHomeActivity;
22 import com.farmerbb.taskbar.util.LauncherHelper;
23 import com.farmerbb.taskbar.util.U;
24
25 public abstract class UIController {
26     protected Context context;
27
28     public UIController(Context context) {
29         this.context = context;
30     }
31
32     abstract void onCreateHost(UIHost host);
33     abstract void onRecreateHost(UIHost host);
34     abstract void onDestroyHost(UIHost host);
35
36     protected void init(Context context, UIHost host, Runnable runnable) {
37         SharedPreferences pref = U.getSharedPreferences(context);
38         LauncherHelper helper = LauncherHelper.getInstance();
39
40         boolean shouldProceed;
41         if(helper.isOnSecondaryHomeScreen())
42             shouldProceed = host instanceof SecondaryHomeActivity;
43         else
44             shouldProceed = true;
45
46         if(shouldProceed && (pref.getBoolean("taskbar_active", false)
47                 || helper.isOnHomeScreen())) {
48             if(U.canDrawOverlays(context))
49                 runnable.run();
50             else {
51                 pref.edit().putBoolean("taskbar_active", false).apply();
52                 host.terminate();
53             }
54         } else
55             host.terminate();
56     }
57 }