OSDN Git Service

Extra show_recent_apps_dialog to a constant string
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / receiver / StartReceiver.java
1 /* Copyright 2016 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.receiver;
17
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.SharedPreferences;
22
23 import com.farmerbb.taskbar.activity.DummyActivity;
24 import com.farmerbb.taskbar.service.NotificationService;
25 import com.farmerbb.taskbar.util.U;
26
27 import static com.farmerbb.taskbar.util.Constants.*;
28
29 public class StartReceiver extends BroadcastReceiver {
30     @Override
31     public void onReceive(Context context, Intent intent) {
32         SharedPreferences pref = U.getSharedPreferences(context);
33
34         boolean taskbarNotActive = !U.isServiceRunning(context, NotificationService.class);
35         boolean taskbarActiveButHidden = !taskbarNotActive && pref.getBoolean(PREF_IS_HIDDEN, false);
36
37         if(!U.canDrawOverlays(context)) {
38             U.newHandler().postDelayed(() -> {
39                 Intent intent2 = new Intent(context, DummyActivity.class);
40                 intent2.putExtra(EXTRA_SHOW_PERMISSION_DIALOG, true);
41                 intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
42
43                 context.startActivity(intent2);
44             }, 250);
45         } else if(taskbarNotActive || taskbarActiveButHidden) {
46             U.initPrefs(context);
47
48             SharedPreferences.Editor editor = pref.edit();
49             editor.putBoolean(PREF_IS_HIDDEN, false);
50
51             if(taskbarNotActive) {
52                 if(pref.getBoolean(PREF_FIRST_RUN, true)) {
53                     editor.putBoolean(PREF_FIRST_RUN, false);
54                     editor.putBoolean(PREF_COLLAPSED, true);
55
56                     U.newHandler().postDelayed(() -> {
57                         Intent intent2 = new Intent(context, DummyActivity.class);
58                         intent2.putExtra(EXTRA_SHOW_RECENT_APP_DIALOG, true);
59                         intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
60
61                         context.startActivity(intent2);
62                     }, 250);
63                 }
64
65                 editor.putBoolean(PREF_TASKBAR_ACTIVE, true);
66                 editor.putLong(PREF_TIME_OF_SERVICE_START, System.currentTimeMillis());
67             }
68
69             editor.apply();
70
71             if(taskbarActiveButHidden)
72                 context.stopService(new Intent(context, NotificationService.class));
73
74             if(U.hasFreeformSupport(context) && U.isFreeformModeEnabled(context)) {
75                 Intent intent2 = new Intent(context, DummyActivity.class);
76                 intent2.putExtra(EXTRA_START_FREEFORM_HACK, true);
77                 intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
78
79                 context.startActivity(intent2);
80             }
81
82             Intent notificationIntent = new Intent(context, NotificationService.class);
83             notificationIntent.putExtra(EXTRA_START_SERVICES, true);
84
85             U.startForegroundService(context, notificationIntent);
86         } else if(intent.hasExtra(EXTRA_SECOND_SCREEN))
87             pref.edit().putBoolean(PREF_SKIP_QUIT_RECEIVER, true).apply();
88     }
89 }