1 /* Copyright 2017 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 android.support.v4.content.LocalBroadcastManager;
24 import com.farmerbb.taskbar.R;
25 import com.farmerbb.taskbar.activity.DummyActivity;
26 import com.farmerbb.taskbar.service.NotificationService;
27 import com.farmerbb.taskbar.util.U;
29 public class ToggleFreeformModeReceiver extends BroadcastReceiver {
31 public void onReceive(Context context, Intent intent) {
32 Intent notificationIntent = new Intent(context, NotificationService.class);
34 SharedPreferences pref = U.getSharedPreferences(context);
35 if(pref.getBoolean("freeform_hack", false)) {
36 pref.edit().putBoolean("freeform_hack", false).apply();
38 context.stopService(notificationIntent);
39 context.startService(notificationIntent);
41 LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.FINISH_FREEFORM_ACTIVITY"));
42 LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX"));
43 } else if(U.hasFreeformSupport(context)) {
44 pref.edit().putBoolean("freeform_hack", true).apply();
46 context.stopService(notificationIntent);
48 Intent intent2 = new Intent(context, DummyActivity.class);
49 intent2.putExtra("start_freeform_hack", true);
50 intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
52 context.startActivity(intent2);
53 context.startService(notificationIntent);
55 LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX"));
57 U.showToastLong(context, R.string.no_freeform_support);