1 /* Copyright 2018 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.accessibilityservice.AccessibilityService;
19 import android.annotation.SuppressLint;
20 import android.app.Activity;
21 import android.content.BroadcastReceiver;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.content.IntentFilter;
25 import android.os.Bundle;
26 import android.os.Handler;
27 import android.support.v4.content.LocalBroadcastManager;
28 import android.widget.FrameLayout;
29 import android.widget.LinearLayout;
31 import com.farmerbb.taskbar.R;
32 import com.farmerbb.taskbar.util.DisplayInfo;
33 import com.farmerbb.taskbar.util.FreeformHackHelper;
34 import com.farmerbb.taskbar.util.U;
36 public class TouchAbsorberActivity extends Activity {
38 private static long lastStartTime = 0;
40 private BroadcastReceiver finishReceiver = new BroadcastReceiver() {
42 public void onReceive(Context context, Intent intent) {
47 @SuppressLint("HardwareIds")
48 @SuppressWarnings("deprecation")
50 protected void onCreate(Bundle savedInstanceState) {
51 super.onCreate(savedInstanceState);
52 setContentView(R.layout.incognito);
54 DisplayInfo display = U.getDisplayInfo(this);
55 LinearLayout layout = U.findViewById(this, R.id.incognitoLayout);
56 layout.setLayoutParams(new FrameLayout.LayoutParams(display.width, display.height));
58 LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
59 lbm.registerReceiver(finishReceiver, new IntentFilter("com.farmerbb.taskbar.FINISH_FREEFORM_ACTIVITY"));
61 FreeformHackHelper.getInstance().setTouchAbsorberActive(true);
62 lbm.sendBroadcast(new Intent("com.farmerbb.taskbar.TOUCH_ABSORBER_STATE_CHANGED"));
64 lastStartTime = System.currentTimeMillis();
68 protected void onStop() {
74 protected void onDestroy() {
75 LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
76 lbm.unregisterReceiver(finishReceiver);
78 FreeformHackHelper.getInstance().setTouchAbsorberActive(false);
79 lbm.sendBroadcast(new Intent("com.farmerbb.taskbar.TOUCH_ABSORBER_STATE_CHANGED"));
85 public void onBackPressed() {
86 if(!U.isAccessibilityServiceEnabled(this) || lastStartTime > System.currentTimeMillis() - 250)
89 super.onBackPressed();
91 new Handler().postDelayed(() -> {
92 U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_BACK);
94 new Handler().postDelayed(() -> U.startTouchAbsorberActivity(this), 100);