1 /* Copyright 2016 Braden Farmer
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com.farmerbb.taskbar.receiver;
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.SharedPreferences;
23 import com.farmerbb.taskbar.activity.DummyActivity;
24 import com.farmerbb.taskbar.service.NotificationService;
25 import com.farmerbb.taskbar.util.U;
27 import static com.farmerbb.taskbar.util.Constants.*;
29 public class StartReceiver extends BroadcastReceiver {
31 public void onReceive(Context context, Intent intent) {
32 SharedPreferences pref = U.getSharedPreferences(context);
34 boolean taskbarNotActive = !U.isServiceRunning(context, NotificationService.class);
35 boolean taskbarActiveButHidden = !taskbarNotActive && pref.getBoolean(PREF_IS_HIDDEN, false);
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);
43 context.startActivity(intent2);
45 } else if(taskbarNotActive || taskbarActiveButHidden) {
48 SharedPreferences.Editor editor = pref.edit();
49 editor.putBoolean(PREF_IS_HIDDEN, false);
51 if(taskbarNotActive) {
52 if(pref.getBoolean(PREF_FIRST_RUN, true)) {
53 editor.putBoolean(PREF_FIRST_RUN, false);
54 editor.putBoolean(PREF_COLLAPSED, true);
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);
61 context.startActivity(intent2);
65 editor.putBoolean(PREF_TASKBAR_ACTIVE, true);
66 editor.putLong(PREF_TIME_OF_SERVICE_START, System.currentTimeMillis());
71 if(taskbarActiveButHidden)
72 context.stopService(new Intent(context, NotificationService.class));
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);
79 context.startActivity(intent2);
82 Intent notificationIntent = new Intent(context, NotificationService.class);
83 notificationIntent.putExtra(EXTRA_START_SERVICES, true);
85 U.startForegroundService(context, notificationIntent);
86 } else if(intent.hasExtra(EXTRA_SECOND_SCREEN))
87 pref.edit().putBoolean(PREF_SKIP_QUIT_RECEIVER, true).apply();