OSDN Git Service

Extract TOGGLE_START_MENU string to TaskbarIntent.ACTION_TOGGLE_START_MENU
[android-x86/packages-apps-Taskbar.git] / app / src / playstore / java / com / farmerbb / taskbar / receiver / TaskerActionReceiver.java
1 /* Copyright 2018 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.os.Bundle;
22 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
23
24 import com.farmerbb.taskbar.content.TaskbarIntent;
25 import com.farmerbb.taskbar.util.BundleScrubber;
26 import com.farmerbb.taskbar.util.PluginBundleManager;
27 import com.farmerbb.taskbar.util.U;
28
29 public final class TaskerActionReceiver extends BroadcastReceiver {
30     @Override
31     public void onReceive(Context context, Intent intent) {
32         if(U.isExternalAccessDisabled(context)) return;
33
34         BundleScrubber.scrub(intent);
35
36         final Bundle bundle = intent.getBundleExtra(com.twofortyfouram.locale.api.Intent.EXTRA_BUNDLE);
37         BundleScrubber.scrub(bundle);
38
39         if(bundle.containsKey(PluginBundleManager.BUNDLE_EXTRA_STRING_MESSAGE)
40                 && PluginBundleManager.isBundleValid(bundle)) {
41             String action = bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_MESSAGE);
42             Intent actionIntent = generateIntent(action);
43
44             if(actionIntent != null) switch(action) {
45                 case "tasker_on":
46                 case "tasker_off":
47                     actionIntent.setPackage(context.getPackageName());
48                     context.sendBroadcast(actionIntent);
49                     break;
50                 default:
51                     LocalBroadcastManager.getInstance(context).sendBroadcast(actionIntent);
52                     break;
53             }
54         }
55     }
56     
57     private Intent generateIntent(String action) {
58         if(action != null) switch(action) {
59             case "tasker_on":
60                 return new Intent("com.farmerbb.taskbar.START");
61             case "tasker_off":
62                 return new Intent("com.farmerbb.taskbar.QUIT");
63             case "show_taskbar":
64                 return new Intent("com.farmerbb.taskbar.SHOW_TASKBAR");
65             case "hide_taskbar":
66                 return new Intent(TaskbarIntent.ACTION_HIDE_TASKBAR);
67             case "toggle_start_menu":
68                 return new Intent(TaskbarIntent.ACTION_TOGGLE_START_MENU);
69             case "toggle_dashboard":
70                 return new Intent("com.farmerbb.taskbar.TOGGLE_DASHBOARD");
71         }
72
73         return null;
74     }
75 }