use of wei.mark.standout.StandOutWindow.StandOutLayoutParams in project StandOut by pingpongboss.
the class Window method onInterceptTouchEvent.
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
StandOutLayoutParams params = getLayoutParams();
// focus window
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (mContext.getFocusedWindow() != this) {
mContext.focus(id);
}
}
// multitouch
if (event.getPointerCount() >= 2 && Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_PINCH_RESIZE_ENABLE) && (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) {
touchInfo.scale = 1;
touchInfo.dist = -1;
touchInfo.firstWidth = params.width;
touchInfo.firstHeight = params.height;
return true;
}
return false;
}
use of wei.mark.standout.StandOutWindow.StandOutLayoutParams in project StandOut by pingpongboss.
the class Window method getSystemDecorations.
/**
* Returns the system window decorations if the implementation sets
* {@link #FLAG_DECORATION_SYSTEM}.
*
* <p>
* The system window decorations support hiding, closing, moving, and
* resizing.
*
* @return The frame view containing the system window decorations.
*/
private View getSystemDecorations() {
final View decorations = mLayoutInflater.inflate(R.layout.system_window_decorators, null);
// icon
final ImageView icon = (ImageView) decorations.findViewById(R.id.window_icon);
icon.setImageResource(mContext.getAppIcon());
icon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupWindow dropDown = mContext.getDropDown(id);
if (dropDown != null) {
dropDown.showAsDropDown(icon);
}
}
});
// title
TextView title = (TextView) decorations.findViewById(R.id.title);
title.setText(mContext.getTitle(id));
// hide
View hide = decorations.findViewById(R.id.hide);
hide.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mContext.hide(id);
}
});
hide.setVisibility(View.GONE);
// maximize
View maximize = decorations.findViewById(R.id.maximize);
maximize.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
StandOutLayoutParams params = getLayoutParams();
boolean isMaximized = data.getBoolean(WindowDataKeys.IS_MAXIMIZED);
if (isMaximized && params.width == displayWidth && params.height == displayHeight && params.x == 0 && params.y == 0) {
data.putBoolean(WindowDataKeys.IS_MAXIMIZED, false);
int oldWidth = data.getInt(WindowDataKeys.WIDTH_BEFORE_MAXIMIZE, -1);
int oldHeight = data.getInt(WindowDataKeys.HEIGHT_BEFORE_MAXIMIZE, -1);
int oldX = data.getInt(WindowDataKeys.X_BEFORE_MAXIMIZE, -1);
int oldY = data.getInt(WindowDataKeys.Y_BEFORE_MAXIMIZE, -1);
edit().setSize(oldWidth, oldHeight).setPosition(oldX, oldY).commit();
} else {
data.putBoolean(WindowDataKeys.IS_MAXIMIZED, true);
data.putInt(WindowDataKeys.WIDTH_BEFORE_MAXIMIZE, params.width);
data.putInt(WindowDataKeys.HEIGHT_BEFORE_MAXIMIZE, params.height);
data.putInt(WindowDataKeys.X_BEFORE_MAXIMIZE, params.x);
data.putInt(WindowDataKeys.Y_BEFORE_MAXIMIZE, params.y);
edit().setSize(1f, 1f).setPosition(0, 0).commit();
}
}
});
// close
View close = decorations.findViewById(R.id.close);
close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mContext.close(id);
}
});
// move
View titlebar = decorations.findViewById(R.id.titlebar);
titlebar.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// handle dragging to move
boolean consumed = mContext.onTouchHandleMove(id, Window.this, v, event);
return consumed;
}
});
// resize
View corner = decorations.findViewById(R.id.corner);
corner.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// handle dragging to move
boolean consumed = mContext.onTouchHandleResize(id, Window.this, v, event);
return consumed;
}
});
// set window appearance and behavior based on flags
if (Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_HIDE_ENABLE)) {
hide.setVisibility(View.VISIBLE);
}
if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_MAXIMIZE_DISABLE)) {
maximize.setVisibility(View.GONE);
}
if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_CLOSE_DISABLE)) {
close.setVisibility(View.GONE);
}
if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_MOVE_DISABLE)) {
titlebar.setOnTouchListener(null);
}
if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_RESIZE_DISABLE)) {
corner.setVisibility(View.GONE);
}
return decorations;
}
use of wei.mark.standout.StandOutWindow.StandOutLayoutParams in project Roundr by MohammadAdib.
the class Window method onFocus.
/**
* Request or remove the focus from this window.
*
* @param focus
* Whether we want to gain or lose focus.
* @return True if focus changed successfully, false if it failed.
*/
public boolean onFocus(boolean focus) {
if (!Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_FOCUSABLE_DISABLE)) {
if (focus == focused) {
// window already focused/unfocused
return false;
}
focused = focus;
// alert callbacks and cancel if instructed
if (mContext.onFocusChange(id, this, focus)) {
Log.d(TAG, "Window " + id + " focus change " + (focus ? "(true)" : "(false)") + " cancelled by implementation.");
focused = !focus;
return false;
}
if (!Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_FOCUS_INDICATOR_DISABLE)) {
// change visual state
View content = findViewById(R.id.content);
if (focus) {
// gaining focus
content.setBackgroundResource(R.drawable.border_focused);
} else {
// losing focus
if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_SYSTEM)) {
// system decorations
content.setBackgroundResource(R.drawable.border);
} else {
// no decorations
content.setBackgroundResource(0);
}
}
}
// set window manager params
StandOutLayoutParams params = getLayoutParams();
params.setFocusFlag(focus);
mContext.updateViewLayout(id, params);
if (focus) {
mContext.setFocusedWindow(this);
} else {
if (mContext.getFocusedWindow() == this) {
mContext.setFocusedWindow(null);
}
}
return true;
}
return false;
}
use of wei.mark.standout.StandOutWindow.StandOutLayoutParams in project FloatingStickies by MohammadAdib.
the class Window method onInterceptTouchEvent.
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
StandOutLayoutParams params = getLayoutParams();
// focus window
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (mContext.getFocusedWindow() != this) {
mContext.focus(id);
}
}
// multitouch
if (event.getPointerCount() >= 2 && Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_PINCH_RESIZE_ENABLE) && (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) {
touchInfo.scale = 1;
touchInfo.dist = -1;
touchInfo.firstWidth = params.width;
touchInfo.firstHeight = params.height;
return true;
}
return false;
}
use of wei.mark.standout.StandOutWindow.StandOutLayoutParams in project FloatingStickies by MohammadAdib.
the class Window method onFocus.
/**
* Request or remove the focus from this window.
*
* @param focus Whether we want to gain or lose focus.
* @return True if focus changed successfully, false if it failed.
*/
public boolean onFocus(boolean focus) {
if (!Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_FOCUSABLE_DISABLE)) {
if (focus == focused) {
// window already focused/unfocused
return false;
}
focused = focus;
// alert callbacks and cancel if instructed
if (mContext.onFocusChange(id, this, focus)) {
Log.d(TAG, "Window " + id + " focus change " + (focus ? "(true)" : "(false)") + " cancelled by implementation.");
focused = !focus;
return false;
}
if (!Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_FOCUS_INDICATOR_DISABLE)) {
// change visual state
View content = findViewById(R.id.content);
if (focus) {
// gaining focus
// content.setBackgroundResource(R.drawable.border_focused);
} else {
// losing focus
if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_SYSTEM)) {
// system decorations
// content.setBackgroundResource(R.drawable.border);
} else {
// no decorations
content.setBackgroundResource(0);
}
}
}
// set window manager params
StandOutLayoutParams params = getLayoutParams();
params.setFocusFlag(focus);
mContext.updateViewLayout(id, params);
if (focus) {
mContext.setFocusedWindow(this);
} else {
if (mContext.getFocusedWindow() == this) {
mContext.setFocusedWindow(null);
}
}
return true;
}
return false;
}
Aggregations