OSDN Git Service

Abstract logic for setting components enabled / disabled
[android-x86/packages-apps-Taskbar.git] / app / src / playstore / java / com / farmerbb / taskbar / receiver / EnableHomeReceiver.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 com.farmerbb.taskbar.activity.HomeActivity;
23 import com.farmerbb.taskbar.content.TaskbarIntent;
24 import com.farmerbb.taskbar.util.U;
25
26 public class EnableHomeReceiver extends BroadcastReceiver {
27     @Override
28     public void onReceive(Context context, Intent intent) {
29         SharedPreferences pref = U.getSharedPreferences(context);
30         if(intent.hasExtra("secondscreen") && pref.getBoolean("launcher", false))
31             pref.edit().putBoolean("skip_disable_home_receiver", true).apply();
32         else if(U.canDrawOverlays(context)) {
33             SharedPreferences.Editor editor = pref.edit();
34             editor.putBoolean("launcher", true);
35             editor.apply();
36
37             U.setComponentEnabled(context, HomeActivity.class, true);
38             U.sendBroadcast(context, TaskbarIntent.ACTION_LAUNCHER_PREF_CHANGED);
39         }
40     }
41 }