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;
22 import com.farmerbb.taskbar.service.DashboardService;
23 import com.farmerbb.taskbar.service.NotificationService;
24 import com.farmerbb.taskbar.service.StartMenuService;
25 import com.farmerbb.taskbar.service.TaskbarService;
26 import com.farmerbb.taskbar.util.IconCache;
27 import com.farmerbb.taskbar.helper.LauncherHelper;
28 import com.farmerbb.taskbar.util.U;
30 import static com.farmerbb.taskbar.util.Constants.*;
32 public class QuitReceiver extends BroadcastReceiver {
34 public void onReceive(Context context, Intent intent) {
35 if (intent == null || !ACTION_QUIT.equals(intent.getAction())) {
38 SharedPreferences pref = U.getSharedPreferences(context);
39 if(!pref.getBoolean(PREF_SKIP_QUIT_RECEIVER, false)) {
40 Intent taskbarIntent = new Intent(context, TaskbarService.class);
41 Intent startMenuIntent = new Intent(context, StartMenuService.class);
42 Intent dashboardIntent = new Intent(context, DashboardService.class);
43 Intent notificationIntent = new Intent(context, NotificationService.class);
45 pref.edit().putBoolean(PREF_TASKBAR_ACTIVE, false).apply();
47 if(!LauncherHelper.getInstance().isOnHomeScreen(context)) {
48 context.stopService(taskbarIntent);
49 context.stopService(startMenuIntent);
50 context.stopService(dashboardIntent);
52 U.clearCaches(context);
53 U.sendBroadcast(context, ACTION_START_MENU_DISAPPEARING);
56 context.stopService(notificationIntent);
58 pref.edit().remove(PREF_SKIP_QUIT_RECEIVER).apply();