OSDN Git Service

2997bb9d1135a3b6a71311e72c474884e8c7fab7
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / receiver / ToggleFreeformModeReceiver.java
1 /* Copyright 2017 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 import android.support.v4.content.LocalBroadcastManager;
23
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;
28
29 public class ToggleFreeformModeReceiver extends BroadcastReceiver {
30     @Override
31     public void onReceive(Context context, Intent intent) {
32         Intent notificationIntent = new Intent(context, NotificationService.class);
33
34         SharedPreferences pref = U.getSharedPreferences(context);
35         if(pref.getBoolean("freeform_hack", false)) {
36             pref.edit().putBoolean("freeform_hack", false).apply();
37
38             context.stopService(notificationIntent);
39             context.startService(notificationIntent);
40
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();
45
46             context.stopService(notificationIntent);
47
48             Intent intent2 = new Intent(context, DummyActivity.class);
49             intent2.putExtra("start_freeform_hack", true);
50             intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
51
52             context.startActivity(intent2);
53             context.startService(notificationIntent);
54
55             LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX"));
56         } else
57             U.showToastLong(context, R.string.no_freeform_support);
58     }
59 }