Reformat all code in float/, getting rid of tabs

This commit is contained in:
Fredrik Fornwall
2017-04-02 14:10:26 +02:00
parent af8b269b51
commit 5cd705d6d1
6 changed files with 256 additions and 240 deletions

View File

@@ -3,14 +3,16 @@ package com.termux.window;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; 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 { public class TermuxFloatActivity extends Activity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
startService(new Intent(this, TermuxFloatService.class)); startService(new Intent(this, TermuxFloatService.class));
finish(); finish();
} }
} }

View File

@@ -15,7 +15,9 @@ import com.termux.view.TerminalKeyListener;
public class TermuxFloatKeyListener implements TerminalKeyListener { public class TermuxFloatKeyListener implements TerminalKeyListener {
private final TermuxFloatView view; 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; boolean mVirtualControlKeyDown, mVirtualFnKeyDown;
public TermuxFloatKeyListener(TermuxFloatView view) { public TermuxFloatKeyListener(TermuxFloatView view) {
@@ -195,7 +197,9 @@ public class TermuxFloatKeyListener implements TerminalKeyListener {
return false; 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) { private boolean handleVirtualKeys(int keyCode, KeyEvent event, boolean down) {
InputDevice inputDevice = event.getDevice(); InputDevice inputDevice = event.getDevice();
if (inputDevice != null && inputDevice.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { if (inputDevice != null && inputDevice.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {

View File

@@ -11,25 +11,25 @@ import android.view.View;
@TargetApi(23) @TargetApi(23)
public class TermuxFloatPermissionActivity extends Activity { public class TermuxFloatPermissionActivity extends Activity {
public static int OVERLAY_PERMISSION_REQ_CODE = 1234; public static int OVERLAY_PERMISSION_REQ_CODE = 1234;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_permission); setContentView(R.layout.activity_permission);
} }
public void onOkButton(View view) { public void onOkButton(View view) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
} }
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
startService(new Intent(this, TermuxFloatService.class)); startService(new Intent(this, TermuxFloatService.class));
finish(); finish();
} }
} }
} }

View File

@@ -7,27 +7,27 @@ import android.view.WindowManager;
public class TermuxFloatPrefs { public class TermuxFloatPrefs {
private static final String PREF_X = "window_x"; private static final String PREF_X = "window_x";
private static final String PREF_Y = "window_y"; private static final String PREF_Y = "window_y";
private static final String PREF_WIDTH = "window_width"; private static final String PREF_WIDTH = "window_width";
private static final String PREF_HEIGHT = "window_height"; private static final String PREF_HEIGHT = "window_height";
public static void saveWindowSize(Context context, int width, int height) { public static void saveWindowSize(Context context, int width, int height) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putInt(PREF_WIDTH, width).putInt(PREF_HEIGHT, height).apply(); prefs.edit().putInt(PREF_WIDTH, width).putInt(PREF_HEIGHT, height).apply();
} }
public static void saveWindowPosition(Context context, int x, int y) { public static void saveWindowPosition(Context context, int x, int y) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putInt(PREF_X, x).putInt(PREF_Y, y).apply(); prefs.edit().putInt(PREF_X, x).putInt(PREF_Y, y).apply();
} }
public static void applySavedGeometry(Context context, WindowManager.LayoutParams layout) { public static void applySavedGeometry(Context context, WindowManager.LayoutParams layout) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
layout.x = prefs.getInt(PREF_X, 200); layout.x = prefs.getInt(PREF_X, 200);
layout.y = prefs.getInt(PREF_Y, 200); layout.y = prefs.getInt(PREF_Y, 200);
layout.width = prefs.getInt(PREF_WIDTH, 500); layout.width = prefs.getInt(PREF_WIDTH, 500);
layout.height = prefs.getInt(PREF_HEIGHT, 800); layout.height = prefs.getInt(PREF_HEIGHT, 800);
} }
} }

View File

@@ -29,10 +29,10 @@ import java.io.IOException;
public class TermuxFloatService extends Service { public class TermuxFloatService extends Service {
public static final String ACTION_HIDE = "com.termux.float.hide"; 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_SHOW = "com.termux.float.show";
/** /**
* Note that this is a symlink on the Android M preview. * Note that this is a symlink on the Android M preview.
*/ */
@SuppressLint("SdCardPath") @SuppressLint("SdCardPath")
@@ -52,7 +52,7 @@ public class TermuxFloatService extends Service {
private static final String FONTSIZE_KEY = "fontsize"; private static final String FONTSIZE_KEY = "fontsize";
private TermuxFloatView mFloatingWindow; private TermuxFloatView mFloatingWindow;
private int mFontSize; private int mFontSize;
private boolean mVisibleWindow = true; private boolean mVisibleWindow = true;
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
@@ -71,71 +71,71 @@ public class TermuxFloatService extends Service {
mFontSize = DEFAULT_FONTSIZE; mFontSize = DEFAULT_FONTSIZE;
} }
TermuxFloatView floatingWindow = (TermuxFloatView) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.activity_main, null); TermuxFloatView floatingWindow = (TermuxFloatView) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.activity_main, null);
floatingWindow.initializeFloatingWindow(); floatingWindow.initializeFloatingWindow();
floatingWindow.mTerminalView.setTextSize(mFontSize); floatingWindow.mTerminalView.setTextSize(mFontSize);
TerminalSession session = createTermSession(); TerminalSession session = createTermSession();
floatingWindow.mTerminalView.attachSession(session); floatingWindow.mTerminalView.attachSession(session);
try { try {
floatingWindow.launchFloatingWindow(); floatingWindow.launchFloatingWindow();
} catch (Exception e) { } catch (Exception e) {
// Settings.canDrawOverlays() does not work (always returns false, perhaps due to sharedUserId?). // Settings.canDrawOverlays() does not work (always returns false, perhaps due to sharedUserId?).
// So instead we catch the exception and prompt here. // So instead we catch the exception and prompt here.
startActivity(new Intent(this, TermuxFloatPermissionActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); startActivity(new Intent(this, TermuxFloatPermissionActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
stopSelf(); stopSelf();
return; return;
} }
mFloatingWindow = floatingWindow; mFloatingWindow = floatingWindow;
Toast toast = Toast.makeText(this, R.string.initial_instruction_toast, Toast.LENGTH_LONG); Toast toast = Toast.makeText(this, R.string.initial_instruction_toast, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0); toast.setGravity(Gravity.CENTER, 0, 0);
TextView v = (TextView) toast.getView().findViewById(android.R.id.message); TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
if (v != null) v.setGravity(Gravity.CENTER); if (v != null) v.setGravity(Gravity.CENTER);
toast.show(); toast.show();
startForeground(NOTIFICATION_ID, buildNotification()); startForeground(NOTIFICATION_ID, buildNotification());
} }
private Notification buildNotification() { private Notification buildNotification() {
final Resources res = getResources(); final Resources res = getResources();
final String contentTitle = res.getString(R.string.notification_title); 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 contentText = res.getString(mVisibleWindow ? R.string.notification_message_visible : R.string.notification_message_hidden);
final String intentAction = mVisibleWindow ? ACTION_HIDE : ACTION_SHOW; final String intentAction = mVisibleWindow ? ACTION_HIDE : ACTION_SHOW;
Intent actionIntent = new Intent(this, TermuxFloatService.class).setAction(intentAction); Intent actionIntent = new Intent(this, TermuxFloatService.class).setAction(intentAction);
Notification.Builder builder = new Notification.Builder(this).setContentTitle(contentTitle).setContentText(contentText) Notification.Builder builder = new Notification.Builder(this).setContentTitle(contentTitle).setContentText(contentText)
.setPriority(Notification.PRIORITY_MIN).setSmallIcon(R.mipmap.ic_service_notification) .setPriority(Notification.PRIORITY_MIN).setSmallIcon(R.mipmap.ic_service_notification)
.setColor(0xFF000000) .setColor(0xFF000000)
.setContentIntent(PendingIntent.getService(this, 0, actionIntent, 0)) .setContentIntent(PendingIntent.getService(this, 0, actionIntent, 0))
.setOngoing(true).setShowWhen(false); .setOngoing(true).setShowWhen(false);
//final int messageId = mVisibleWindow ? R.string.toggle_hide : R.string.toggle_show; //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)); //builder.addAction(android.R.drawable.ic_menu_preferences, res.getString(messageId), PendingIntent.getService(this, 0, actionIntent, 0));
return builder.build(); return builder.build();
} }
@SuppressLint("Wakelock") @SuppressLint("Wakelock")
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
String action = intent.getAction(); String action = intent.getAction();
if (ACTION_HIDE.equals(action)) { if (ACTION_HIDE.equals(action)) {
mVisibleWindow = false; mVisibleWindow = false;
mFloatingWindow.setVisibility(View.GONE); mFloatingWindow.setVisibility(View.GONE);
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, buildNotification()); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, buildNotification());
} else if (ACTION_SHOW.equals(action)) { } else if (ACTION_SHOW.equals(action)) {
mFloatingWindow.setVisibility(View.VISIBLE); mFloatingWindow.setVisibility(View.VISIBLE);
mVisibleWindow = true; mVisibleWindow = true;
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, buildNotification()); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, buildNotification());
} }
return Service.START_NOT_STICKY; return Service.START_NOT_STICKY;
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (mFloatingWindow != null) mFloatingWindow.closeFloatingWindow(); if (mFloatingWindow != null) mFloatingWindow.closeFloatingWindow();

View File

@@ -18,110 +18,114 @@ import com.termux.view.TerminalView;
public class TermuxFloatView extends LinearLayout { public class TermuxFloatView extends LinearLayout {
public static final float ALPHA_FOCUS = 0.9f; public static final float ALPHA_FOCUS = 0.9f;
public static final float ALPHA_NOT_FOCUS = 0.7f; public static final float ALPHA_NOT_FOCUS = 0.7f;
public static final float ALPHA_MOVING = 0.5f; 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(); final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
WindowManager mWindowManager; WindowManager mWindowManager;
InputMethodManager imm; 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; private boolean withFocus = true;
int initialX; int initialX;
int initialY; int initialY;
float initialTouchX; float initialTouchX;
float initialTouchY; float initialTouchY;
boolean isInLongPressState; boolean isInLongPressState;
final int[] location = new int[2]; final int[] location = new int[2];
final ScaleGestureDetector mScaleDetector = new ScaleGestureDetector(getContext(), new OnScaleGestureListener() { final ScaleGestureDetector mScaleDetector = new ScaleGestureDetector(getContext(), new OnScaleGestureListener() {
private static final int MIN_SIZE = 50; private static final int MIN_SIZE = 50;
@Override @Override
public boolean onScaleBegin(ScaleGestureDetector detector) { public boolean onScaleBegin(ScaleGestureDetector detector) {
return true; return true;
} }
@Override @Override
public boolean onScale(ScaleGestureDetector detector) { public boolean onScale(ScaleGestureDetector detector) {
int widthChange = (int) (detector.getCurrentSpanX() - detector.getPreviousSpanX()); int widthChange = (int) (detector.getCurrentSpanX() - detector.getPreviousSpanX());
int heightChange = (int) (detector.getCurrentSpanY() - detector.getPreviousSpanY()); int heightChange = (int) (detector.getCurrentSpanY() - detector.getPreviousSpanY());
layoutParams.width += widthChange; layoutParams.width += widthChange;
layoutParams.height += heightChange; layoutParams.height += heightChange;
layoutParams.width = Math.max(MIN_SIZE, layoutParams.width); layoutParams.width = Math.max(MIN_SIZE, layoutParams.width);
layoutParams.height = Math.max(MIN_SIZE, layoutParams.height); layoutParams.height = Math.max(MIN_SIZE, layoutParams.height);
mWindowManager.updateViewLayout(TermuxFloatView.this, layoutParams); mWindowManager.updateViewLayout(TermuxFloatView.this, layoutParams);
TermuxFloatPrefs.saveWindowSize(getContext(), layoutParams.width, layoutParams.height); TermuxFloatPrefs.saveWindowSize(getContext(), layoutParams.width, layoutParams.height);
return true; return true;
} }
@Override @Override
public void onScaleEnd(ScaleGestureDetector detector) { public void onScaleEnd(ScaleGestureDetector detector) {
// Do nothing. // Do nothing.
} }
}); });
public TermuxFloatView(Context context, AttributeSet attrs) { public TermuxFloatView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
setAlpha(ALPHA_FOCUS); setAlpha(ALPHA_FOCUS);
} }
private static int computeLayoutFlags(boolean withFocus) { private static int computeLayoutFlags(boolean withFocus) {
if (withFocus) { if (withFocus) {
return 0; return 0;
} else { } else {
return WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; return WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
} }
} }
public void initializeFloatingWindow() { public void initializeFloatingWindow() {
mTerminalView = (TerminalView) findViewById(R.id.terminal_view); mTerminalView = (TerminalView) findViewById(R.id.terminal_view);
mTerminalView.setOnKeyListener(new TermuxFloatKeyListener(this)); mTerminalView.setOnKeyListener(new TermuxFloatKeyListener(this));
} }
@Override @Override
protected void onAttachedToWindow() { protected void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
Point displaySize = new Point(); Point displaySize = new Point();
getDisplay().getSize(displaySize); getDisplay().getSize(displaySize);
DISPLAY_WIDTH = displaySize.x; DISPLAY_WIDTH = displaySize.x;
DISPLAY_HEIGHT = displaySize.y; DISPLAY_HEIGHT = displaySize.y;
// mTerminalView.checkForFontAndColors(); // mTerminalView.checkForFontAndColors();
} }
@SuppressLint("RtlHardcoded") @SuppressLint("RtlHardcoded")
public void launchFloatingWindow() { public void launchFloatingWindow() {
int widthAndHeight = android.view.ViewGroup.LayoutParams.WRAP_CONTENT; int widthAndHeight = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
layoutParams.flags = computeLayoutFlags(true); layoutParams.flags = computeLayoutFlags(true);
layoutParams.width = widthAndHeight; layoutParams.width = widthAndHeight;
layoutParams.height = widthAndHeight; layoutParams.height = widthAndHeight;
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE; layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
layoutParams.format = PixelFormat.RGBA_8888; layoutParams.format = PixelFormat.RGBA_8888;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
TermuxFloatPrefs.applySavedGeometry(getContext(), layoutParams); TermuxFloatPrefs.applySavedGeometry(getContext(), layoutParams);
mWindowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); mWindowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
mWindowManager.addView(this, layoutParams); mWindowManager.addView(this, layoutParams);
imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
showTouchKeyboard(); showTouchKeyboard();
} }
/** Intercept touch events to obtain and loose focus on touch events. */ /**
@Override * Intercept touch events to obtain and loose focus on touch events.
public boolean onInterceptTouchEvent(MotionEvent event) { */
if (isInLongPressState) return true; @Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (isInLongPressState) return true;
getLocationOnScreen(location); getLocationOnScreen(location);
int x = layoutParams.x; // location[0]; int x = layoutParams.x; // location[0];
@@ -141,74 +145,80 @@ public class TermuxFloatView extends LinearLayout {
} }
break; break;
} }
return false; return false;
} }
void showTouchKeyboard() { void showTouchKeyboard() {
mTerminalView.post(new Runnable() { mTerminalView.post(new Runnable() {
@Override @Override
public void run() { public void run() {
imm.showSoftInput(mTerminalView, InputMethodManager.SHOW_IMPLICIT); imm.showSoftInput(mTerminalView, InputMethodManager.SHOW_IMPLICIT);
} }
}); });
} }
void updateLongPressMode(boolean newValue) { void updateLongPressMode(boolean newValue) {
isInLongPressState = newValue; isInLongPressState = newValue;
setBackgroundResource(newValue ? R.drawable.floating_window_background_resize : R.drawable.floating_window_background); setBackgroundResource(newValue ? R.drawable.floating_window_background_resize : R.drawable.floating_window_background);
setAlpha(newValue ? ALPHA_MOVING : (withFocus ? ALPHA_FOCUS : ALPHA_NOT_FOCUS)); setAlpha(newValue ? ALPHA_MOVING : (withFocus ? ALPHA_FOCUS : ALPHA_NOT_FOCUS));
if (newValue) { if (newValue) {
Toast toast = Toast.makeText(getContext(), R.string.after_long_press, Toast.LENGTH_SHORT); Toast toast = Toast.makeText(getContext(), R.string.after_long_press, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0); toast.setGravity(Gravity.CENTER, 0, 0);
toast.show(); toast.show();
} }
} }
/** Motion events should only be dispatched here when {@link #onInterceptTouchEvent(MotionEvent)} returns true. */ /**
@SuppressLint("ClickableViewAccessibility") * Motion events should only be dispatched here when {@link #onInterceptTouchEvent(MotionEvent)} returns true.
@Override */
public boolean onTouchEvent(MotionEvent event) { @SuppressLint("ClickableViewAccessibility")
if (isInLongPressState) { @Override
mScaleDetector.onTouchEvent(event); public boolean onTouchEvent(MotionEvent event) {
if (mScaleDetector.isInProgress()) return true; if (isInLongPressState) {
switch (event.getAction()) { mScaleDetector.onTouchEvent(event);
case MotionEvent.ACTION_MOVE: if (mScaleDetector.isInProgress()) return true;
layoutParams.x = Math.min(DISPLAY_WIDTH - layoutParams.width, Math.max(0, initialX + (int) (event.getRawX() - initialTouchX))); switch (event.getAction()) {
layoutParams.y = Math.min(DISPLAY_HEIGHT - layoutParams.height, Math.max(0, initialY + (int) (event.getRawY() - initialTouchY))); case MotionEvent.ACTION_MOVE:
mWindowManager.updateViewLayout(TermuxFloatView.this, layoutParams); layoutParams.x = Math.min(DISPLAY_WIDTH - layoutParams.width, Math.max(0, initialX + (int) (event.getRawX() - initialTouchX)));
TermuxFloatPrefs.saveWindowPosition(getContext(), layoutParams.x, layoutParams.y); layoutParams.y = Math.min(DISPLAY_HEIGHT - layoutParams.height, Math.max(0, initialY + (int) (event.getRawY() - initialTouchY)));
break; mWindowManager.updateViewLayout(TermuxFloatView.this, layoutParams);
case MotionEvent.ACTION_UP: TermuxFloatPrefs.saveWindowPosition(getContext(), layoutParams.x, layoutParams.y);
updateLongPressMode(false); break;
break; case MotionEvent.ACTION_UP:
} updateLongPressMode(false);
return true; break;
} }
return super.onTouchEvent(event); 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 == withFocus) {
if (newFocus) showTouchKeyboard(); if (newFocus) showTouchKeyboard();
return; return;
} }
withFocus = newFocus; withFocus = newFocus;
layoutParams.flags = computeLayoutFlags(withFocus); layoutParams.flags = computeLayoutFlags(withFocus);
mWindowManager.updateViewLayout(this, layoutParams); mWindowManager.updateViewLayout(this, layoutParams);
setAlpha(newFocus ? ALPHA_FOCUS : ALPHA_NOT_FOCUS); setAlpha(newFocus ? ALPHA_FOCUS : ALPHA_NOT_FOCUS);
} }
/** Show a toast and dismiss the last one if still visible. */ /**
void showToast(String text, boolean longDuration) { * Show a toast and dismiss the last one if still visible.
if (mLastToast != null) mLastToast.cancel(); */
mLastToast = Toast.makeText(getContext(), text, longDuration ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT); void showToast(String text, boolean longDuration) {
mLastToast.setGravity(Gravity.TOP, 0, 0); if (mLastToast != null) mLastToast.cancel();
mLastToast.show(); mLastToast = Toast.makeText(getContext(), text, longDuration ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
} mLastToast.setGravity(Gravity.TOP, 0, 0);
mLastToast.show();
}
public void closeFloatingWindow() { public void closeFloatingWindow() {
mWindowManager.removeView(this); mWindowManager.removeView(this);
} }
} }