Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appmenu centering, closes #46 #49

Merged
merged 2 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ public void showAppContextMenu(final String app, View anchor) {
lp.gravity = Gravity.TOP | Gravity.LEFT;
lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;

Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);

lp.x = rect.left;
lp.y = rect.centerY();
int[] location = new int[2];
anchor.getLocationOnScreen(location);
lp.x = location[0];
lp.y = location[1] + Utils.dpToPx(this, anchor.getMeasuredHeight()/2);

view.setOnTouchListener((View p1, MotionEvent p2) -> {
if (p2.getAction() == MotionEvent.ACTION_OUTSIDE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ public void onCreatePreferences(Bundle arg0, String arg1) {

final Preference heightPreference = findPreference("app_menu_height");
final Preference widthPreference = findPreference("app_menu_width");
final Preference centerPreference = findPreference("center_app_menu");
final Preference fullscreenPreference = findPreference("app_menu_fullscreen");
SharedPreferences sp = fullscreenPreference.getSharedPreferences();
heightPreference.setEnabled(!sp.getBoolean(fullscreenPreference.getKey(), false));
widthPreference.setEnabled(!sp.getBoolean(fullscreenPreference.getKey(), false));

centerPreference.setEnabled(!sp.getBoolean(fullscreenPreference.getKey(), false));

fullscreenPreference.setOnPreferenceChangeListener((Preference p0, Object value) -> {
boolean checked = (boolean) value;
heightPreference.setEnabled(!checked);
widthPreference.setEnabled(!checked);
centerPreference.setEnabled(!checked);
return true;
});
}
Expand Down
33 changes: 17 additions & 16 deletions app/src/main/java/cu/axel/smartdock/services/DockService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,8 @@ public void showAppMenu() {

lp.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
lp.gravity = Gravity.BOTTOM | Gravity.LEFT;
int halign = sp.getBoolean("center_app_menu", false) ? Gravity.CENTER_HORIZONTAL : Gravity.LEFT;
lp.gravity = Gravity.BOTTOM | halign;

ImageView avatarIv = appMenu.findViewById(R.id.avatar_iv);
TextView userNameTv = appMenu.findViewById(R.id.user_name_tv);
Expand Down Expand Up @@ -1056,14 +1057,14 @@ public void showAppContextMenu(final String app, View anchor) {
final View view = LayoutInflater.from(context).inflate(R.layout.task_list, null);
WindowManager.LayoutParams lp = Utils.makeWindowParams(-2, -2, context, preferLastDisplay);
ColorUtils.applyMainColor(context, sp, view);
lp.gravity = Gravity.TOP | Gravity.LEFT;
lp.gravity = Gravity.LEFT | Gravity.TOP;
lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;

Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int[] location = new int[2];
anchor.getLocationOnScreen(location);

lp.x = rect.left;
lp.y = rect.centerY();
lp.x = location[0];
lp.y = location[1] + Utils.dpToPx(context, anchor.getMeasuredHeight() / 2);

view.setOnTouchListener((View p1, MotionEvent p2) -> {
if (p2.getAction() == MotionEvent.ACTION_OUTSIDE) {
Expand Down Expand Up @@ -1170,13 +1171,13 @@ private void showTaskContextMenu(final String app, View anchor) {
lp.gravity = Gravity.BOTTOM | Gravity.LEFT;
lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;

lp.y = Utils.dpToPx(context, Integer.parseInt(sp.getString("app_menu_y", "2")))
+ dockLayout.getMeasuredHeight();
lp.y = Utils.dpToPx(context, 2) + dockLayout.getMeasuredHeight();

Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int[] location = new int[2];
anchor.getLocationOnScreen(location);

lp.x = location[0];

lp.x = rect.left;
view.setOnTouchListener((View p1, MotionEvent p2) -> {
if (p2.getAction() == MotionEvent.ACTION_OUTSIDE) {
wm.removeView(view);
Expand Down Expand Up @@ -1233,11 +1234,11 @@ public void showUserContextMenu(View anchor) {
lp.gravity = Gravity.TOP | Gravity.LEFT;
lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;

Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);

lp.x = rect.left;
lp.y = rect.bottom;
int[] location = new int[2];
anchor.getLocationOnScreen(location);
lp.x = location[0];
lp.y = location[1] + Utils.dpToPx(context, anchor.getMeasuredHeight()/2);

view.setOnTouchListener((View p1, MotionEvent p2) -> {
if (p2.getAction() == MotionEvent.ACTION_OUTSIDE) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="app_menu_height_title">App menu height</string>
<string name="app_menu_width_title">App menu width</string>
<string name="num_columns_title">Number of columns</string>
<string name="center_app_menu">Centered app menu</string>
<string name="app_launch">App launch</string>
<string name="launch_mode_dialogTitle">Theme</string>
<string name="launch_mode_title">Default app launch mode</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/preferences_app_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
android:hint="650"
android:defaultValue="650"
android:title="@string/app_menu_width_title"/>
<CheckBoxPreference
android:key="center_app_menu"
android:title="@string/center_app_menu"
android:defaultValue="false" />
<EditTextPreference
android:inputType="number"
android:key="num_columns"
Expand Down