OSDN Git Service

[WIP] Allow Taskbar to be built as a lib for inclusion into other launchers
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / activity / KeyboardShortcutActivity.java
1 /* Copyright 2016 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.activity;
17
18 import android.annotation.TargetApi;
19 import android.app.Activity;
20 import android.app.SearchManager;
21 import android.content.Intent;
22 import android.content.SharedPreferences;
23 import android.os.Build;
24 import android.os.Bundle;
25 import android.support.v4.content.LocalBroadcastManager;
26
27 import com.farmerbb.taskbar.BuildConfig;
28 import com.farmerbb.taskbar.service.StartMenuService;
29 import com.farmerbb.taskbar.util.FreeformHackHelper;
30 import com.farmerbb.taskbar.util.U;
31
32 import java.util.Set;
33
34 public class KeyboardShortcutActivity extends Activity {
35
36     @TargetApi(Build.VERSION_CODES.N)
37     @Override
38     protected void onCreate(Bundle savedInstanceState) {
39         super.onCreate(savedInstanceState);
40
41         // Perform different actions depending on how this activity was launched
42         switch(getIntent().getAction()) {
43             case Intent.ACTION_MAIN:
44                 Intent selector = getIntent().getSelector();
45                 Set<String> categories = selector != null ? selector.getCategories() : getIntent().getCategories();
46
47                 if(categories.contains(Intent.CATEGORY_APP_MAPS)) {
48                     SharedPreferences pref = U.getSharedPreferences(this);
49                     if(U.hasFreeformSupport(this)
50                             && pref.getBoolean("freeform_hack", false)
51                             && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
52                         U.startFreeformHack(this, true);
53                     }
54
55                     Intent startStopIntent;
56
57                     if(pref.getBoolean("taskbar_active", false))
58                         startStopIntent = new Intent("com.farmerbb.taskbar.QUIT");
59                     else
60                         startStopIntent = new Intent("com.farmerbb.taskbar.START");
61
62                     startStopIntent.setPackage(getPackageName());
63                     sendBroadcast(startStopIntent);
64                 }
65
66                 break;
67             case Intent.ACTION_ASSIST:
68                 if(U.isServiceRunning(this, StartMenuService.class)) {
69                     LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_START_MENU"));
70                 } else {
71                     Intent intent = new Intent("com.google.android.googlequicksearchbox.TEXT_ASSIST");
72                     if(intent.resolveActivity(getPackageManager()) == null)
73                         intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
74
75                     if(intent.resolveActivity(getPackageManager()) != null) {
76                         SharedPreferences pref = U.getSharedPreferences(this);
77                         if(U.hasFreeformSupport(this)
78                                 && pref.getBoolean("freeform_hack", false)
79                                 && isInMultiWindowMode()) {
80                             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
81                             U.startActivityMaximized(getApplicationContext(), intent);
82                         } else {
83                             intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
84                             startActivity(intent);
85                         }
86                     }
87                 }
88                 break;
89         }
90
91         finish();
92     }
93 }