From 5cd705d6d11afb4d630e055e82b3e0895d6255c4 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Sun, 2 Apr 2017 14:10:26 +0200 Subject: [PATCH] Reformat all code in float/, getting rid of tabs --- .../termux/window/TermuxFloatActivity.java | 16 +- .../termux/window/TermuxFloatKeyListener.java | 8 +- .../window/TermuxFloatPermissionActivity.java | 34 +- .../com/termux/window/TermuxFloatPrefs.java | 38 +-- .../com/termux/window/TermuxFloatService.java | 110 +++---- .../com/termux/window/TermuxFloatView.java | 290 +++++++++--------- 6 files changed, 256 insertions(+), 240 deletions(-) diff --git a/float/src/main/java/com/termux/window/TermuxFloatActivity.java b/float/src/main/java/com/termux/window/TermuxFloatActivity.java index 0535e75d..5a73dbd1 100644 --- a/float/src/main/java/com/termux/window/TermuxFloatActivity.java +++ b/float/src/main/java/com/termux/window/TermuxFloatActivity.java @@ -3,14 +3,16 @@ package com.termux.window; import android.app.Activity; import android.content.Intent; -/** Simple activity which immediately launches {@link TermuxFloatService} and exits. */ +/** + * Simple activity which immediately launches {@link TermuxFloatService} and exits. + */ public class TermuxFloatActivity extends Activity { - @Override - protected void onResume() { - super.onResume(); - startService(new Intent(this, TermuxFloatService.class)); - finish(); - } + @Override + protected void onResume() { + super.onResume(); + startService(new Intent(this, TermuxFloatService.class)); + finish(); + } } diff --git a/float/src/main/java/com/termux/window/TermuxFloatKeyListener.java b/float/src/main/java/com/termux/window/TermuxFloatKeyListener.java index 3fed8133..55cb669d 100644 --- a/float/src/main/java/com/termux/window/TermuxFloatKeyListener.java +++ b/float/src/main/java/com/termux/window/TermuxFloatKeyListener.java @@ -15,7 +15,9 @@ import com.termux.view.TerminalKeyListener; public class TermuxFloatKeyListener implements TerminalKeyListener { private final TermuxFloatView view; - /** Keeping track of the special keys acting as Ctrl and Fn for the soft keyboard and other hardware keys. */ + /** + * Keeping track of the special keys acting as Ctrl and Fn for the soft keyboard and other hardware keys. + */ boolean mVirtualControlKeyDown, mVirtualFnKeyDown; public TermuxFloatKeyListener(TermuxFloatView view) { @@ -195,7 +197,9 @@ public class TermuxFloatKeyListener implements TerminalKeyListener { return false; } - /** Handle dedicated volume buttons as virtual keys if applicable. */ + /** + * Handle dedicated volume buttons as virtual keys if applicable. + */ private boolean handleVirtualKeys(int keyCode, KeyEvent event, boolean down) { InputDevice inputDevice = event.getDevice(); if (inputDevice != null && inputDevice.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { diff --git a/float/src/main/java/com/termux/window/TermuxFloatPermissionActivity.java b/float/src/main/java/com/termux/window/TermuxFloatPermissionActivity.java index a43b20ed..af01e054 100644 --- a/float/src/main/java/com/termux/window/TermuxFloatPermissionActivity.java +++ b/float/src/main/java/com/termux/window/TermuxFloatPermissionActivity.java @@ -11,25 +11,25 @@ import android.view.View; @TargetApi(23) public class TermuxFloatPermissionActivity extends Activity { - public static int OVERLAY_PERMISSION_REQ_CODE = 1234; + public static int OVERLAY_PERMISSION_REQ_CODE = 1234; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_permission); - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_permission); + } - public void onOkButton(View view) { - Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); - startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); - } + public void onOkButton(View view) { + Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); + startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); + } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { - startService(new Intent(this, TermuxFloatService.class)); - finish(); - } - } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { + startService(new Intent(this, TermuxFloatService.class)); + finish(); + } + } } diff --git a/float/src/main/java/com/termux/window/TermuxFloatPrefs.java b/float/src/main/java/com/termux/window/TermuxFloatPrefs.java index ef9d7feb..ab5f14a4 100644 --- a/float/src/main/java/com/termux/window/TermuxFloatPrefs.java +++ b/float/src/main/java/com/termux/window/TermuxFloatPrefs.java @@ -7,27 +7,27 @@ import android.view.WindowManager; public class TermuxFloatPrefs { - private static final String PREF_X = "window_x"; - private static final String PREF_Y = "window_y"; - private static final String PREF_WIDTH = "window_width"; - private static final String PREF_HEIGHT = "window_height"; + private static final String PREF_X = "window_x"; + private static final String PREF_Y = "window_y"; + private static final String PREF_WIDTH = "window_width"; + private static final String PREF_HEIGHT = "window_height"; - public static void saveWindowSize(Context context, int width, int height) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.edit().putInt(PREF_WIDTH, width).putInt(PREF_HEIGHT, height).apply(); - } + public static void saveWindowSize(Context context, int width, int height) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + prefs.edit().putInt(PREF_WIDTH, width).putInt(PREF_HEIGHT, height).apply(); + } - public static void saveWindowPosition(Context context, int x, int y) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.edit().putInt(PREF_X, x).putInt(PREF_Y, y).apply(); - } + public static void saveWindowPosition(Context context, int x, int y) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + prefs.edit().putInt(PREF_X, x).putInt(PREF_Y, y).apply(); + } - public static void applySavedGeometry(Context context, WindowManager.LayoutParams layout) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - layout.x = prefs.getInt(PREF_X, 200); - layout.y = prefs.getInt(PREF_Y, 200); - layout.width = prefs.getInt(PREF_WIDTH, 500); - layout.height = prefs.getInt(PREF_HEIGHT, 800); - } + public static void applySavedGeometry(Context context, WindowManager.LayoutParams layout) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + layout.x = prefs.getInt(PREF_X, 200); + layout.y = prefs.getInt(PREF_Y, 200); + layout.width = prefs.getInt(PREF_WIDTH, 500); + layout.height = prefs.getInt(PREF_HEIGHT, 800); + } } diff --git a/float/src/main/java/com/termux/window/TermuxFloatService.java b/float/src/main/java/com/termux/window/TermuxFloatService.java index d5d99d85..efa8c641 100644 --- a/float/src/main/java/com/termux/window/TermuxFloatService.java +++ b/float/src/main/java/com/termux/window/TermuxFloatService.java @@ -29,10 +29,10 @@ import java.io.IOException; public class TermuxFloatService extends Service { - public static final String ACTION_HIDE = "com.termux.float.hide"; - public static final String ACTION_SHOW = "com.termux.float.show"; + public static final String ACTION_HIDE = "com.termux.float.hide"; + public static final String ACTION_SHOW = "com.termux.float.show"; - /** + /** * Note that this is a symlink on the Android M preview. */ @SuppressLint("SdCardPath") @@ -52,7 +52,7 @@ public class TermuxFloatService extends Service { private static final String FONTSIZE_KEY = "fontsize"; private TermuxFloatView mFloatingWindow; private int mFontSize; - private boolean mVisibleWindow = true; + private boolean mVisibleWindow = true; @Override public IBinder onBind(Intent intent) { @@ -71,71 +71,71 @@ public class TermuxFloatService extends Service { mFontSize = DEFAULT_FONTSIZE; } - TermuxFloatView floatingWindow = (TermuxFloatView) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.activity_main, null); - floatingWindow.initializeFloatingWindow(); - floatingWindow.mTerminalView.setTextSize(mFontSize); + TermuxFloatView floatingWindow = (TermuxFloatView) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.activity_main, null); + floatingWindow.initializeFloatingWindow(); + floatingWindow.mTerminalView.setTextSize(mFontSize); TerminalSession session = createTermSession(); - floatingWindow.mTerminalView.attachSession(session); + floatingWindow.mTerminalView.attachSession(session); - try { - floatingWindow.launchFloatingWindow(); - } catch (Exception e) { - // Settings.canDrawOverlays() does not work (always returns false, perhaps due to sharedUserId?). - // So instead we catch the exception and prompt here. - startActivity(new Intent(this, TermuxFloatPermissionActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); - stopSelf(); - return; - } + try { + floatingWindow.launchFloatingWindow(); + } catch (Exception e) { + // Settings.canDrawOverlays() does not work (always returns false, perhaps due to sharedUserId?). + // So instead we catch the exception and prompt here. + startActivity(new Intent(this, TermuxFloatPermissionActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + stopSelf(); + return; + } - mFloatingWindow = floatingWindow; + mFloatingWindow = floatingWindow; - Toast toast = Toast.makeText(this, R.string.initial_instruction_toast, Toast.LENGTH_LONG); - toast.setGravity(Gravity.CENTER, 0, 0); - TextView v = (TextView) toast.getView().findViewById(android.R.id.message); - if (v != null) v.setGravity(Gravity.CENTER); - toast.show(); + Toast toast = Toast.makeText(this, R.string.initial_instruction_toast, Toast.LENGTH_LONG); + toast.setGravity(Gravity.CENTER, 0, 0); + TextView v = (TextView) toast.getView().findViewById(android.R.id.message); + if (v != null) v.setGravity(Gravity.CENTER); + toast.show(); - startForeground(NOTIFICATION_ID, buildNotification()); + startForeground(NOTIFICATION_ID, buildNotification()); } - private Notification buildNotification() { - final Resources res = getResources(); - final String contentTitle = res.getString(R.string.notification_title); - final String contentText = res.getString(mVisibleWindow ? R.string.notification_message_visible : R.string.notification_message_hidden); + private Notification buildNotification() { + final Resources res = getResources(); + final String contentTitle = res.getString(R.string.notification_title); + final String contentText = res.getString(mVisibleWindow ? R.string.notification_message_visible : R.string.notification_message_hidden); - final String intentAction = mVisibleWindow ? ACTION_HIDE : ACTION_SHOW; - Intent actionIntent = new Intent(this, TermuxFloatService.class).setAction(intentAction); + final String intentAction = mVisibleWindow ? ACTION_HIDE : ACTION_SHOW; + Intent actionIntent = new Intent(this, TermuxFloatService.class).setAction(intentAction); - Notification.Builder builder = new Notification.Builder(this).setContentTitle(contentTitle).setContentText(contentText) - .setPriority(Notification.PRIORITY_MIN).setSmallIcon(R.mipmap.ic_service_notification) - .setColor(0xFF000000) - .setContentIntent(PendingIntent.getService(this, 0, actionIntent, 0)) - .setOngoing(true).setShowWhen(false); + Notification.Builder builder = new Notification.Builder(this).setContentTitle(contentTitle).setContentText(contentText) + .setPriority(Notification.PRIORITY_MIN).setSmallIcon(R.mipmap.ic_service_notification) + .setColor(0xFF000000) + .setContentIntent(PendingIntent.getService(this, 0, actionIntent, 0)) + .setOngoing(true).setShowWhen(false); - //final int messageId = mVisibleWindow ? R.string.toggle_hide : R.string.toggle_show; - //builder.addAction(android.R.drawable.ic_menu_preferences, res.getString(messageId), PendingIntent.getService(this, 0, actionIntent, 0)); - return builder.build(); - } + //final int messageId = mVisibleWindow ? R.string.toggle_hide : R.string.toggle_show; + //builder.addAction(android.R.drawable.ic_menu_preferences, res.getString(messageId), PendingIntent.getService(this, 0, actionIntent, 0)); + return builder.build(); + } - @SuppressLint("Wakelock") - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - String action = intent.getAction(); - if (ACTION_HIDE.equals(action)) { - mVisibleWindow = false; - mFloatingWindow.setVisibility(View.GONE); - ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, buildNotification()); - } else if (ACTION_SHOW.equals(action)) { - mFloatingWindow.setVisibility(View.VISIBLE); - mVisibleWindow = true; - ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, buildNotification()); - } - return Service.START_NOT_STICKY; - } + @SuppressLint("Wakelock") + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + String action = intent.getAction(); + if (ACTION_HIDE.equals(action)) { + mVisibleWindow = false; + mFloatingWindow.setVisibility(View.GONE); + ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, buildNotification()); + } else if (ACTION_SHOW.equals(action)) { + mFloatingWindow.setVisibility(View.VISIBLE); + mVisibleWindow = true; + ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, buildNotification()); + } + return Service.START_NOT_STICKY; + } - @Override + @Override public void onDestroy() { super.onDestroy(); if (mFloatingWindow != null) mFloatingWindow.closeFloatingWindow(); diff --git a/float/src/main/java/com/termux/window/TermuxFloatView.java b/float/src/main/java/com/termux/window/TermuxFloatView.java index f57da1fb..64ec6f6a 100644 --- a/float/src/main/java/com/termux/window/TermuxFloatView.java +++ b/float/src/main/java/com/termux/window/TermuxFloatView.java @@ -18,110 +18,114 @@ import com.termux.view.TerminalView; public class TermuxFloatView extends LinearLayout { - public static final float ALPHA_FOCUS = 0.9f; - public static final float ALPHA_NOT_FOCUS = 0.7f; - public static final float ALPHA_MOVING = 0.5f; + public static final float ALPHA_FOCUS = 0.9f; + public static final float ALPHA_NOT_FOCUS = 0.7f; + public static final float ALPHA_MOVING = 0.5f; - private int DISPLAY_WIDTH, DISPLAY_HEIGHT; + private int DISPLAY_WIDTH, DISPLAY_HEIGHT; - final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); - WindowManager mWindowManager; - InputMethodManager imm; + final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); + WindowManager mWindowManager; + InputMethodManager imm; - TerminalView mTerminalView; + TerminalView mTerminalView; - /** The last toast shown, used cancel current toast before showing new in {@link #showToast(String, boolean)}. */ - Toast mLastToast; + /** + * The last toast shown, used cancel current toast before showing new in {@link #showToast(String, boolean)}. + */ + Toast mLastToast; - private boolean withFocus = true; - int initialX; - int initialY; - float initialTouchX; - float initialTouchY; + private boolean withFocus = true; + int initialX; + int initialY; + float initialTouchX; + float initialTouchY; - boolean isInLongPressState; + boolean isInLongPressState; final int[] location = new int[2]; - final ScaleGestureDetector mScaleDetector = new ScaleGestureDetector(getContext(), new OnScaleGestureListener() { - private static final int MIN_SIZE = 50; + final ScaleGestureDetector mScaleDetector = new ScaleGestureDetector(getContext(), new OnScaleGestureListener() { + private static final int MIN_SIZE = 50; - @Override - public boolean onScaleBegin(ScaleGestureDetector detector) { - return true; - } + @Override + public boolean onScaleBegin(ScaleGestureDetector detector) { + return true; + } - @Override - public boolean onScale(ScaleGestureDetector detector) { - int widthChange = (int) (detector.getCurrentSpanX() - detector.getPreviousSpanX()); - int heightChange = (int) (detector.getCurrentSpanY() - detector.getPreviousSpanY()); - layoutParams.width += widthChange; - layoutParams.height += heightChange; - layoutParams.width = Math.max(MIN_SIZE, layoutParams.width); - layoutParams.height = Math.max(MIN_SIZE, layoutParams.height); - mWindowManager.updateViewLayout(TermuxFloatView.this, layoutParams); - TermuxFloatPrefs.saveWindowSize(getContext(), layoutParams.width, layoutParams.height); - return true; - } + @Override + public boolean onScale(ScaleGestureDetector detector) { + int widthChange = (int) (detector.getCurrentSpanX() - detector.getPreviousSpanX()); + int heightChange = (int) (detector.getCurrentSpanY() - detector.getPreviousSpanY()); + layoutParams.width += widthChange; + layoutParams.height += heightChange; + layoutParams.width = Math.max(MIN_SIZE, layoutParams.width); + layoutParams.height = Math.max(MIN_SIZE, layoutParams.height); + mWindowManager.updateViewLayout(TermuxFloatView.this, layoutParams); + TermuxFloatPrefs.saveWindowSize(getContext(), layoutParams.width, layoutParams.height); + return true; + } - @Override - public void onScaleEnd(ScaleGestureDetector detector) { - // Do nothing. - } - }); + @Override + public void onScaleEnd(ScaleGestureDetector detector) { + // Do nothing. + } + }); - public TermuxFloatView(Context context, AttributeSet attrs) { - super(context, attrs); - setAlpha(ALPHA_FOCUS); - } + public TermuxFloatView(Context context, AttributeSet attrs) { + super(context, attrs); + setAlpha(ALPHA_FOCUS); + } - private static int computeLayoutFlags(boolean withFocus) { - if (withFocus) { - return 0; - } else { - return WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; - } - } + private static int computeLayoutFlags(boolean withFocus) { + if (withFocus) { + return 0; + } else { + return WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + } + } - public void initializeFloatingWindow() { - mTerminalView = (TerminalView) findViewById(R.id.terminal_view); - mTerminalView.setOnKeyListener(new TermuxFloatKeyListener(this)); - } + public void initializeFloatingWindow() { + mTerminalView = (TerminalView) findViewById(R.id.terminal_view); + mTerminalView.setOnKeyListener(new TermuxFloatKeyListener(this)); + } - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); - Point displaySize = new Point(); - getDisplay().getSize(displaySize); - DISPLAY_WIDTH = displaySize.x; - DISPLAY_HEIGHT = displaySize.y; + Point displaySize = new Point(); + getDisplay().getSize(displaySize); + DISPLAY_WIDTH = displaySize.x; + DISPLAY_HEIGHT = displaySize.y; - // mTerminalView.checkForFontAndColors(); - } + // mTerminalView.checkForFontAndColors(); + } - @SuppressLint("RtlHardcoded") - public void launchFloatingWindow() { - int widthAndHeight = android.view.ViewGroup.LayoutParams.WRAP_CONTENT; - layoutParams.flags = computeLayoutFlags(true); - layoutParams.width = widthAndHeight; - layoutParams.height = widthAndHeight; - layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE; - layoutParams.format = PixelFormat.RGBA_8888; + @SuppressLint("RtlHardcoded") + public void launchFloatingWindow() { + int widthAndHeight = android.view.ViewGroup.LayoutParams.WRAP_CONTENT; + layoutParams.flags = computeLayoutFlags(true); + layoutParams.width = widthAndHeight; + layoutParams.height = widthAndHeight; + layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE; + layoutParams.format = PixelFormat.RGBA_8888; - layoutParams.gravity = Gravity.TOP | Gravity.LEFT; - TermuxFloatPrefs.applySavedGeometry(getContext(), layoutParams); + layoutParams.gravity = Gravity.TOP | Gravity.LEFT; + TermuxFloatPrefs.applySavedGeometry(getContext(), layoutParams); - mWindowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); - mWindowManager.addView(this, layoutParams); - imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - showTouchKeyboard(); - } + mWindowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); + mWindowManager.addView(this, layoutParams); + imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + showTouchKeyboard(); + } - /** Intercept touch events to obtain and loose focus on touch events. */ - @Override - public boolean onInterceptTouchEvent(MotionEvent event) { - if (isInLongPressState) return true; + /** + * Intercept touch events to obtain and loose focus on touch events. + */ + @Override + public boolean onInterceptTouchEvent(MotionEvent event) { + if (isInLongPressState) return true; getLocationOnScreen(location); int x = layoutParams.x; // location[0]; @@ -141,74 +145,80 @@ public class TermuxFloatView extends LinearLayout { } break; } - return false; - } + return false; + } - void showTouchKeyboard() { - mTerminalView.post(new Runnable() { - @Override - public void run() { - imm.showSoftInput(mTerminalView, InputMethodManager.SHOW_IMPLICIT); - } - }); - } + void showTouchKeyboard() { + mTerminalView.post(new Runnable() { + @Override + public void run() { + imm.showSoftInput(mTerminalView, InputMethodManager.SHOW_IMPLICIT); + } + }); + } - void updateLongPressMode(boolean newValue) { - isInLongPressState = newValue; - setBackgroundResource(newValue ? R.drawable.floating_window_background_resize : R.drawable.floating_window_background); - setAlpha(newValue ? ALPHA_MOVING : (withFocus ? ALPHA_FOCUS : ALPHA_NOT_FOCUS)); - if (newValue) { - Toast toast = Toast.makeText(getContext(), R.string.after_long_press, Toast.LENGTH_SHORT); - toast.setGravity(Gravity.CENTER, 0, 0); - toast.show(); - } - } + void updateLongPressMode(boolean newValue) { + isInLongPressState = newValue; + setBackgroundResource(newValue ? R.drawable.floating_window_background_resize : R.drawable.floating_window_background); + setAlpha(newValue ? ALPHA_MOVING : (withFocus ? ALPHA_FOCUS : ALPHA_NOT_FOCUS)); + if (newValue) { + Toast toast = Toast.makeText(getContext(), R.string.after_long_press, Toast.LENGTH_SHORT); + toast.setGravity(Gravity.CENTER, 0, 0); + toast.show(); + } + } - /** Motion events should only be dispatched here when {@link #onInterceptTouchEvent(MotionEvent)} returns true. */ - @SuppressLint("ClickableViewAccessibility") - @Override - public boolean onTouchEvent(MotionEvent event) { - if (isInLongPressState) { - mScaleDetector.onTouchEvent(event); - if (mScaleDetector.isInProgress()) return true; - switch (event.getAction()) { - case MotionEvent.ACTION_MOVE: - layoutParams.x = Math.min(DISPLAY_WIDTH - layoutParams.width, Math.max(0, initialX + (int) (event.getRawX() - initialTouchX))); - layoutParams.y = Math.min(DISPLAY_HEIGHT - layoutParams.height, Math.max(0, initialY + (int) (event.getRawY() - initialTouchY))); - mWindowManager.updateViewLayout(TermuxFloatView.this, layoutParams); - TermuxFloatPrefs.saveWindowPosition(getContext(), layoutParams.x, layoutParams.y); - break; - case MotionEvent.ACTION_UP: - updateLongPressMode(false); - break; - } - return true; - } - return super.onTouchEvent(event); - } + /** + * Motion events should only be dispatched here when {@link #onInterceptTouchEvent(MotionEvent)} returns true. + */ + @SuppressLint("ClickableViewAccessibility") + @Override + public boolean onTouchEvent(MotionEvent event) { + if (isInLongPressState) { + mScaleDetector.onTouchEvent(event); + if (mScaleDetector.isInProgress()) return true; + switch (event.getAction()) { + case MotionEvent.ACTION_MOVE: + layoutParams.x = Math.min(DISPLAY_WIDTH - layoutParams.width, Math.max(0, initialX + (int) (event.getRawX() - initialTouchX))); + layoutParams.y = Math.min(DISPLAY_HEIGHT - layoutParams.height, Math.max(0, initialY + (int) (event.getRawY() - initialTouchY))); + mWindowManager.updateViewLayout(TermuxFloatView.this, layoutParams); + TermuxFloatPrefs.saveWindowPosition(getContext(), layoutParams.x, layoutParams.y); + break; + case MotionEvent.ACTION_UP: + updateLongPressMode(false); + break; + } + return true; + } + return super.onTouchEvent(event); + } - /** Visually indicate focus and show the soft input as needed. */ - void changeFocus(boolean newFocus) { + /** + * Visually indicate focus and show the soft input as needed. + */ + void changeFocus(boolean newFocus) { if (newFocus == withFocus) { if (newFocus) showTouchKeyboard(); return; } withFocus = newFocus; - layoutParams.flags = computeLayoutFlags(withFocus); - mWindowManager.updateViewLayout(this, layoutParams); - setAlpha(newFocus ? ALPHA_FOCUS : ALPHA_NOT_FOCUS); - } + layoutParams.flags = computeLayoutFlags(withFocus); + mWindowManager.updateViewLayout(this, layoutParams); + setAlpha(newFocus ? ALPHA_FOCUS : ALPHA_NOT_FOCUS); + } - /** Show a toast and dismiss the last one if still visible. */ - void showToast(String text, boolean longDuration) { - if (mLastToast != null) mLastToast.cancel(); - mLastToast = Toast.makeText(getContext(), text, longDuration ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT); - mLastToast.setGravity(Gravity.TOP, 0, 0); - mLastToast.show(); - } + /** + * Show a toast and dismiss the last one if still visible. + */ + void showToast(String text, boolean longDuration) { + if (mLastToast != null) mLastToast.cancel(); + mLastToast = Toast.makeText(getContext(), text, longDuration ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT); + mLastToast.setGravity(Gravity.TOP, 0, 0); + mLastToast.show(); + } - public void closeFloatingWindow() { - mWindowManager.removeView(this); - } + public void closeFloatingWindow() { + mWindowManager.removeView(this); + } }