1 /* Copyright 2016 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.activity;
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;
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;
34 public class KeyboardShortcutActivity extends Activity {
36 @TargetApi(Build.VERSION_CODES.N)
38 protected void onCreate(Bundle savedInstanceState) {
39 super.onCreate(savedInstanceState);
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();
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);
55 Intent startStopIntent;
57 if(pref.getBoolean("taskbar_active", false))
58 startStopIntent = new Intent("com.farmerbb.taskbar.QUIT");
60 startStopIntent = new Intent("com.farmerbb.taskbar.START");
62 startStopIntent.setPackage(getPackageName());
63 sendBroadcast(startStopIntent);
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"));
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);
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);
83 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
84 startActivity(intent);