use of org.adw.launcher2.quickactionbar.QuickAction in project ADWLauncher2 by boombuler.
the class DragController method onTouchEvent.
/**
* Call this from a drag source view.
*/
public boolean onTouchEvent(MotionEvent ev) {
View scrollView = mScrollView;
if (!mDragging) {
return false;
}
final int action = ev.getAction();
final int screenX = clamp((int) ev.getRawX(), 0, mDisplayMetrics.widthPixels);
final int screenY = clamp((int) ev.getRawY(), 0, mDisplayMetrics.heightPixels);
switch(action) {
case MotionEvent.ACTION_DOWN:
// Remember where the motion event started
mMotionDownX = screenX;
mMotionDownY = screenY;
if ((screenX < mScrollZone) || (screenX > scrollView.getWidth() - mScrollZone)) {
mScrollState = SCROLL_WAITING_IN_ZONE;
mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY);
} else {
mScrollState = SCROLL_OUTSIDE_ZONE;
}
break;
case MotionEvent.ACTION_MOVE:
// Update the drag view. Don't use the clamped pos here so the dragging looks
// like it goes off screen a little, intead of bumping up against the edge.
mDragView.move((int) ev.getRawX(), (int) ev.getRawY());
// Drop on someone?
final int[] coordinates = mCoordinatesTemp;
DropTarget dropTarget = findDropTarget(screenX, screenY, coordinates);
if (dropTarget != null) {
if (mLastDropTarget == dropTarget) {
dropTarget.onDragOver(mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
} else {
if (mLastDropTarget != null) {
mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
}
dropTarget.onDragEnter(mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
}
} else {
if (mLastDropTarget != null) {
mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
}
}
mLastDropTarget = dropTarget;
if (mTagPopup != null) {
final float movX = Math.abs(screenX - mMotionDownX);
final float movY = Math.abs(screenY - mMotionDownY);
if (movX > QA_HIDE_OFFSET || movY > QA_HIDE_OFFSET) {
final QuickAction qa = (QuickAction) mTagPopup;
qa.dismiss();
mTagPopup = null;
}
}
// Scroll, maybe, but not if we're in the delete region.
boolean inDeleteRegion = false;
if (mDeleteRegion != null) {
inDeleteRegion = mDeleteRegion.contains(screenX, screenY);
}
// + " mScrollZone=" + mScrollZone);
if (!inDeleteRegion && screenX < mScrollZone) {
if (mScrollState == SCROLL_OUTSIDE_ZONE) {
mScrollState = SCROLL_WAITING_IN_ZONE;
mScrollRunnable.setDirection(SCROLL_LEFT);
mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY);
}
} else if (!inDeleteRegion && screenX > scrollView.getWidth() - mScrollZone) {
if (mScrollState == SCROLL_OUTSIDE_ZONE) {
mScrollState = SCROLL_WAITING_IN_ZONE;
mScrollRunnable.setDirection(SCROLL_RIGHT);
mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY);
}
} else {
if (mScrollState == SCROLL_WAITING_IN_ZONE) {
mScrollState = SCROLL_OUTSIDE_ZONE;
mScrollRunnable.setDirection(SCROLL_RIGHT);
mHandler.removeCallbacks(mScrollRunnable);
}
}
break;
case MotionEvent.ACTION_UP:
mHandler.removeCallbacks(mScrollRunnable);
if (mDragging) {
drop(screenX, screenY);
}
endDrag();
break;
case MotionEvent.ACTION_CANCEL:
cancelDrag();
}
return true;
}
use of org.adw.launcher2.quickactionbar.QuickAction in project ADWLauncher2 by boombuler.
the class Launcher method showActions.
public void showActions(ItemInfo info, View view, PopupWindow.OnDismissListener onDismissListener) {
if (info == null || view == null)
return;
List<EditAction> actions = info.getAvailableActions(view, this);
if (actions.size() <= 0)
return;
final View finalview = view;
final ItemInfo finalInfo = info;
int[] xy = new int[2];
//fills the array with the computed coordinates
view.getLocationInWindow(xy);
new Rect(xy[0], xy[1], xy[0] + view.getWidth(), xy[1] + view.getHeight());
//a new QuickActionWindow object
final QuickAction qa = new QuickAction(view);
view.setTag(org.adw.launcher2.R.id.TAG_PREVIEW, qa);
if (onDismissListener != null) {
qa.setOnDismissListener(onDismissListener);
}
//when the item is clicked on
for (EditAction action : actions) {
final EditAction finalaction = action;
Drawable icon;
CharSequence title;
if (action.getIconResourceId() == 0) {
icon = action.getIconDrawable();
} else {
icon = getResources().getDrawable(action.getIconResourceId());
}
if (action.getTitleResourceId() == 0) {
title = action.getTitleString();
} else {
title = getResources().getString(action.getTitleResourceId());
}
ActionItem ai = new ActionItem(icon);
if (title != null)
ai.setTitle(title.toString());
ai.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
qa.dismiss();
finalInfo.executeAction(finalaction, finalview, Launcher.this);
}
});
qa.addActionItem(ai);
}
//shows the quick action window on the screen
qa.show();
}
Aggregations