🔧 - Add long press gesture detection for empty areas in the home screen.
This commit is contained in:
7 files changed
+210
-70
No files matched your search
@@ -8,10 +8,11 @@
|
||||
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" />
|
||||
|
||||
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
|
||||
|
||||
<!-- Permissions for app detection -->
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"
|
||||
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
|
||||
<application
|
||||
|
||||
@@ -50,6 +50,7 @@ import android.text.TextWatcher;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.ArrayMap;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -94,6 +95,7 @@ import io.github.sankalp.lunox.utils.CrashUtils;
|
||||
import io.github.sankalp.lunox.utils.DbUtils;
|
||||
import io.github.sankalp.lunox.utils.DeviceAdminManager;
|
||||
import io.github.sankalp.lunox.utils.Gestures;
|
||||
import io.github.sankalp.lunox.utils.NotificationPanelManager;
|
||||
import io.github.sankalp.lunox.utils.ShortcutUtils;
|
||||
import io.github.sankalp.lunox.utils.Utils;
|
||||
import io.github.sankalp.lunox.views.textview.AppTextView;
|
||||
@@ -164,6 +166,9 @@ public class LauncherActivity extends Activity implements View.OnClickListener,
|
||||
private Gestures detector;
|
||||
private ShortcutUtils shortcutUtils;
|
||||
|
||||
// For handling long press on empty areas
|
||||
private GestureDetector longPressDetector;
|
||||
|
||||
private static final TextWatcher mTextWatcher= new TextWatcher() {
|
||||
|
||||
@Override
|
||||
@@ -207,9 +212,37 @@ public class LauncherActivity extends Activity implements View.OnClickListener,
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
//pass touch event to detector
|
||||
detector.onTouchEvent(ev);
|
||||
longPressDetector.onTouchEvent(ev);
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to find the view at the given coordinates
|
||||
*/
|
||||
private View findViewAt(float x, float y) {
|
||||
// Convert coordinates to the home layout's coordinate system
|
||||
int[] location = new int[2];
|
||||
mHomeLayout.getLocationOnScreen(location);
|
||||
|
||||
// Check if the touch is within the home layout bounds
|
||||
if (x >= location[0] && x <= location[0] + mHomeLayout.getWidth() &&
|
||||
y >= location[1] && y <= location[1] + mHomeLayout.getHeight()) {
|
||||
|
||||
// Check each child view in the home layout
|
||||
for (int i = 0; i < mHomeLayout.getChildCount(); i++) {
|
||||
View child = mHomeLayout.getChildAt(i);
|
||||
child.getLocationOnScreen(location);
|
||||
|
||||
if (x >= location[0] && x <= location[0] + child.getWidth() &&
|
||||
y >= location[1] && y <= location[1] + child.getHeight()) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null; // No specific view found, it's empty space
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -252,6 +285,20 @@ public class LauncherActivity extends Activity implements View.OnClickListener,
|
||||
|
||||
detector = new Gestures(this, this);
|
||||
|
||||
// Initialize long press detector for empty areas
|
||||
longPressDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
|
||||
@Override
|
||||
public void onLongPress(MotionEvent e) {
|
||||
// Check if the touch is on an empty area (not on an app)
|
||||
View touchedView = findViewAt(e.getX(), e.getY());
|
||||
if (!(touchedView instanceof AppTextView)) {
|
||||
// Show launcher settings on long press in free space
|
||||
dialogs = new GlobalSettingsDialog(LauncherActivity.this, LauncherActivity.this);
|
||||
dialogs.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// initGestures();
|
||||
|
||||
// Check permissions before loading apps
|
||||
@@ -599,7 +646,7 @@ public class LauncherActivity extends Activity implements View.OnClickListener,
|
||||
// show app setting
|
||||
showPopup((String) view.getTag(), (AppTextView) view);
|
||||
} else if (view instanceof FlowLayout) {
|
||||
// show launcher setting
|
||||
// show launcher setting for FlowLayout (this handles long press on FlowLayout itself)
|
||||
dialogs = new GlobalSettingsDialog(this, this);
|
||||
dialogs.show();
|
||||
}
|
||||
@@ -607,9 +654,9 @@ public class LauncherActivity extends Activity implements View.OnClickListener,
|
||||
}
|
||||
|
||||
private void showPopup(String activityName, AppTextView view) {
|
||||
// show app settings popup instead of popup menu
|
||||
// show app settings dialog instead of popup menu
|
||||
AppSettingsPopup popup = new AppSettingsPopup(this, activityName, view, this);
|
||||
popup.showAsDropDown(view);
|
||||
popup.show();
|
||||
}
|
||||
|
||||
//reset the app color to default color;
|
||||
@@ -1152,17 +1199,15 @@ public class LauncherActivity extends Activity implements View.OnClickListener,
|
||||
@Override
|
||||
public void onSwipe(Gestures.Direction direction) {
|
||||
if (direction == Gestures.Direction.SWIPE_UP) {
|
||||
// Open search bar on swipe up (down to up gesture)
|
||||
searching = true;
|
||||
mSearchBox.setText("");
|
||||
mSearchBox.setVisibility(View.VISIBLE);
|
||||
mSearchBox.requestFocus();
|
||||
imm.showSoftInput(mSearchBox, InputMethodManager.SHOW_IMPLICIT);
|
||||
} else if (direction == Gestures.Direction.SWIPE_DOWN) {
|
||||
if (searching) {
|
||||
mSearchBox.setVisibility(View.GONE);
|
||||
imm.hideSoftInputFromWindow(mSearchBox.getWindowToken(), 0);
|
||||
onResume();
|
||||
}
|
||||
// Open notification panel on swipe down (up to down gesture)
|
||||
NotificationPanelManager.expandNotificationPanel(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1172,12 +1217,7 @@ public class LauncherActivity extends Activity implements View.OnClickListener,
|
||||
DeviceAdminManager.lockDevice(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress() {
|
||||
// Show launcher settings on long press in free space
|
||||
dialogs = new GlobalSettingsDialog(this, this);
|
||||
dialogs.show();
|
||||
}
|
||||
|
||||
|
||||
static class SearchTask extends AsyncTask<CharSequence, Void, ArrayList<Apps>> {
|
||||
@Override
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
|
||||
package io.github.sankalp.lunox.dialogs;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.PopupWindow;
|
||||
import android.view.Window;
|
||||
import android.widget.TextView;
|
||||
|
||||
import io.github.sankalp.lunox.LauncherActivity;
|
||||
@@ -32,9 +32,9 @@ import io.github.sankalp.lunox.utils.DbUtils;
|
||||
import io.github.sankalp.lunox.views.textview.AppTextView;
|
||||
|
||||
/**
|
||||
* App settings popup that shows options for individual apps
|
||||
* App settings dialog that shows options for individual apps
|
||||
*/
|
||||
public class AppSettingsPopup extends PopupWindow implements View.OnClickListener {
|
||||
public class AppSettingsPopup extends Dialog implements View.OnClickListener {
|
||||
|
||||
private final LauncherActivity launcherActivity;
|
||||
private final Context context;
|
||||
@@ -51,46 +51,43 @@ public class AppSettingsPopup extends PopupWindow implements View.OnClickListene
|
||||
this.activityName = activityName;
|
||||
this.appTextView = appTextView;
|
||||
this.launcherActivity = launcherActivity;
|
||||
|
||||
initPopup();
|
||||
}
|
||||
|
||||
private void initPopup() {
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View contentView = inflater.inflate(R.layout.dialog_app_settings, null);
|
||||
setContentView(contentView);
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// no old title: Last Launcher use Activity class not AppCompatActivity so it show very old title
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.dialog_app_settings);
|
||||
|
||||
// Set popup properties
|
||||
setWidth(android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
setHeight(android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
setFocusable(true);
|
||||
setOutsideTouchable(true);
|
||||
|
||||
// Set background to match the dialog style with border
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
setBackgroundDrawable(context.getResources().getDrawable(R.drawable.popup_background, null));
|
||||
} else {
|
||||
setBackgroundDrawable(context.getResources().getDrawable(R.drawable.popup_background));
|
||||
// Set the dialog background to match popup style with border
|
||||
Window window = getWindow();
|
||||
if (window != null) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
window.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.popup_background, null));
|
||||
} else {
|
||||
window.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.popup_background));
|
||||
}
|
||||
}
|
||||
|
||||
// Set up click listeners
|
||||
contentView.findViewById(R.id.app_settings_color).setOnClickListener(this);
|
||||
contentView.findViewById(R.id.app_settings_rename).setOnClickListener(this);
|
||||
findViewById(R.id.app_settings_color).setOnClickListener(this);
|
||||
findViewById(R.id.app_settings_rename).setOnClickListener(this);
|
||||
|
||||
freezeSize = contentView.findViewById(R.id.app_settings_freeze_size);
|
||||
freezeSize = findViewById(R.id.app_settings_freeze_size);
|
||||
freezeSize.setOnClickListener(this);
|
||||
|
||||
contentView.findViewById(R.id.app_settings_app_info).setOnClickListener(this);
|
||||
contentView.findViewById(R.id.app_settings_reset_color).setOnClickListener(this);
|
||||
findViewById(R.id.app_settings_app_info).setOnClickListener(this);
|
||||
findViewById(R.id.app_settings_reset_color).setOnClickListener(this);
|
||||
|
||||
hideApp = contentView.findViewById(R.id.app_settings_hide);
|
||||
hideApp = findViewById(R.id.app_settings_hide);
|
||||
hideApp.setOnClickListener(this);
|
||||
|
||||
resetToDefault = contentView.findViewById(R.id.app_settings_reset_to_default);
|
||||
resetToDefault = findViewById(R.id.app_settings_reset_to_default);
|
||||
resetToDefault.setOnClickListener(this);
|
||||
resetToDefault.setTextColor(Color.parseColor("#E53935"));
|
||||
|
||||
uninstallApp = contentView.findViewById(R.id.app_settings_uninstall);
|
||||
uninstallApp = findViewById(R.id.app_settings_uninstall);
|
||||
uninstallApp.setOnClickListener(this);
|
||||
uninstallApp.setTextColor(Color.parseColor("#E53935"));
|
||||
|
||||
@@ -105,48 +102,44 @@ public class AppSettingsPopup extends PopupWindow implements View.OnClickListene
|
||||
if (appTextView.isShortcut()) {
|
||||
uninstallApp.setText(R.string.remove);
|
||||
hideApp.setVisibility(View.GONE);
|
||||
contentView.findViewById(R.id.app_settings_rename).setVisibility(View.GONE);
|
||||
contentView.findViewById(R.id.app_settings_app_info).setVisibility(View.GONE);
|
||||
findViewById(R.id.app_settings_rename).setVisibility(View.GONE);
|
||||
findViewById(R.id.app_settings_app_info).setVisibility(View.GONE);
|
||||
} else {
|
||||
hideApp.setTextColor(Color.parseColor("#E53935"));
|
||||
}
|
||||
}
|
||||
|
||||
public void showAsDropDown(View anchor) {
|
||||
showAsDropDown(anchor, 0, 0, Gravity.START);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
if (id == R.id.app_settings_color) {
|
||||
launcherActivity.changeColorSize(activityName, appTextView);
|
||||
dismiss();
|
||||
cancel();
|
||||
} else if (id == R.id.app_settings_rename) {
|
||||
launcherActivity.renameApp(activityName, appTextView.getText().toString());
|
||||
dismiss();
|
||||
cancel();
|
||||
} else if (id == R.id.app_settings_freeze_size) {
|
||||
launcherActivity.freezeAppSize(activityName);
|
||||
dismiss();
|
||||
cancel();
|
||||
} else if (id == R.id.app_settings_app_info) {
|
||||
launcherActivity.showAppInfo(activityName);
|
||||
dismiss();
|
||||
cancel();
|
||||
} else if (id == R.id.app_settings_reset_color) {
|
||||
launcherActivity.resetAppColor(activityName);
|
||||
dismiss();
|
||||
cancel();
|
||||
} else if (id == R.id.app_settings_hide) {
|
||||
launcherActivity.hideApp(activityName);
|
||||
dismiss();
|
||||
cancel();
|
||||
} else if (id == R.id.app_settings_reset_to_default) {
|
||||
launcherActivity.resetApp(activityName);
|
||||
dismiss();
|
||||
cancel();
|
||||
} else if (id == R.id.app_settings_uninstall) {
|
||||
if (appTextView.isShortcut()) {
|
||||
launcherActivity.removeShortcut(appTextView);
|
||||
} else {
|
||||
launcherActivity.uninstallApp(activityName);
|
||||
}
|
||||
dismiss();
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,11 +79,6 @@ public class Gestures extends GestureDetector.SimpleOnGestureListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent e) {
|
||||
this.listener.onLongPress();
|
||||
}
|
||||
|
||||
|
||||
public enum Direction {
|
||||
SWIPE_UP, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT
|
||||
@@ -93,8 +88,6 @@ public class Gestures extends GestureDetector.SimpleOnGestureListener {
|
||||
void onSwipe(Direction direction);
|
||||
|
||||
void onDoubleTap();
|
||||
|
||||
void onLongPress();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Last Launcher
|
||||
* Copyright (C) 2019,2020 Shubham Tyagi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.github.sankalp.lunox.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Utility class to manage notification panel expansion
|
||||
*/
|
||||
public class NotificationPanelManager {
|
||||
|
||||
private static final String TAG = "NotificationPanelManager";
|
||||
|
||||
/**
|
||||
* Attempts to expand the notification panel using reflection
|
||||
* @param context The application context
|
||||
* @return true if successful, false otherwise
|
||||
*/
|
||||
public static boolean expandNotificationPanel(Context context) {
|
||||
try {
|
||||
// Get the StatusBarManager service
|
||||
Object statusBarService = context.getSystemService("statusbar");
|
||||
|
||||
if (statusBarService == null) {
|
||||
Log.w(TAG, "StatusBar service not available");
|
||||
return false;
|
||||
}
|
||||
|
||||
Class<?> statusBarManager = Class.forName("android.app.StatusBarManager");
|
||||
Method expandMethod;
|
||||
|
||||
// Different method names for different Android versions
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
// Android 4.2+ uses expandNotificationsPanel
|
||||
expandMethod = statusBarManager.getMethod("expandNotificationsPanel");
|
||||
} else {
|
||||
// Older versions use expand
|
||||
expandMethod = statusBarManager.getMethod("expand");
|
||||
}
|
||||
|
||||
expandMethod.setAccessible(true);
|
||||
expandMethod.invoke(statusBarService);
|
||||
|
||||
Log.d(TAG, "Notification panel expanded successfully");
|
||||
return true;
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to expand notification panel: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to collapse the notification panel using reflection
|
||||
* @param context The application context
|
||||
* @return true if successful, false otherwise
|
||||
*/
|
||||
public static boolean collapseNotificationPanel(Context context) {
|
||||
try {
|
||||
// Get the StatusBarManager service
|
||||
Object statusBarService = context.getSystemService("statusbar");
|
||||
|
||||
if (statusBarService == null) {
|
||||
Log.w(TAG, "StatusBar service not available");
|
||||
return false;
|
||||
}
|
||||
|
||||
Class<?> statusBarManager = Class.forName("android.app.StatusBarManager");
|
||||
Method collapseMethod;
|
||||
|
||||
// Different method names for different Android versions
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
// Android 4.2+ uses collapsePanels
|
||||
collapseMethod = statusBarManager.getMethod("collapsePanels");
|
||||
} else {
|
||||
// Older versions use collapse
|
||||
collapseMethod = statusBarManager.getMethod("collapse");
|
||||
}
|
||||
|
||||
collapseMethod.setAccessible(true);
|
||||
collapseMethod.invoke(statusBarService);
|
||||
|
||||
Log.d(TAG, "Notification panel collapsed successfully");
|
||||
return true;
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to collapse notification panel: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<!-- Border/stroke around the popup -->
|
||||
<stroke
|
||||
android:width="2dp"
|
||||
android:width="1dp"
|
||||
android:color="#DEDEDE" />
|
||||
|
||||
<!-- Rounded corners for better appearance -->
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp">
|
||||
android:background="@android:color/black"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<TextView
|
||||
|
||||
Reference in new issue
Block a user