use of android.graphics.PointF in project platform_frameworks_base by android.
the class ViewGroup method dispatchDragEvent.
// TODO: Write real docs
@Override
public boolean dispatchDragEvent(DragEvent event) {
boolean retval = false;
final float tx = event.mX;
final float ty = event.mY;
// Dispatch down the view hierarchy
final PointF localPoint = getLocalPoint();
switch(event.mAction) {
case DragEvent.ACTION_DRAG_STARTED:
{
// Clear the state to recalculate which views we drag over.
mCurrentDragChild = null;
// Set up our tracking of drag-started notifications
mCurrentDragStartEvent = DragEvent.obtain(event);
if (mChildrenInterestedInDrag == null) {
mChildrenInterestedInDrag = new HashSet<View>();
} else {
mChildrenInterestedInDrag.clear();
}
// Now dispatch down to our children, caching the responses
final int count = mChildrenCount;
final View[] children = mChildren;
for (int i = 0; i < count; i++) {
final View child = children[i];
child.mPrivateFlags2 &= ~View.DRAG_MASK;
if (child.getVisibility() == VISIBLE) {
if (notifyChildOfDragStart(children[i])) {
retval = true;
}
}
}
// Notify itself of the drag start.
mIsInterestedInDrag = super.dispatchDragEvent(event);
if (mIsInterestedInDrag) {
retval = true;
}
if (!retval) {
// Neither us nor any of our children are interested in this drag, so stop tracking
// the current drag event.
mCurrentDragStartEvent.recycle();
mCurrentDragStartEvent = null;
}
}
break;
case DragEvent.ACTION_DRAG_ENDED:
{
// Release the bookkeeping now that the drag lifecycle has ended
final HashSet<View> childrenInterestedInDrag = mChildrenInterestedInDrag;
if (childrenInterestedInDrag != null) {
for (View child : childrenInterestedInDrag) {
// If a child was interested in the ongoing drag, it's told that it's over
if (child.dispatchDragEvent(event)) {
retval = true;
}
}
childrenInterestedInDrag.clear();
}
if (mCurrentDragStartEvent != null) {
mCurrentDragStartEvent.recycle();
mCurrentDragStartEvent = null;
}
if (mIsInterestedInDrag) {
if (super.dispatchDragEvent(event)) {
retval = true;
}
mIsInterestedInDrag = false;
}
}
break;
case DragEvent.ACTION_DRAG_LOCATION:
case DragEvent.ACTION_DROP:
{
// Find the [possibly new] drag target
View target = findFrontmostDroppableChildAt(event.mX, event.mY, localPoint);
if (target != mCurrentDragChild) {
if (sCascadedDragDrop) {
// For pre-Nougat apps, make sure that the whole hierarchy of views that contain
// the drag location is kept in the state between ENTERED and EXITED events.
// (Starting with N, only the innermost view will be in that state).
final int action = event.mAction;
// Position should not be available for ACTION_DRAG_ENTERED and
// ACTION_DRAG_EXITED.
event.mX = 0;
event.mY = 0;
if (mCurrentDragChild != null) {
event.mAction = DragEvent.ACTION_DRAG_EXITED;
mCurrentDragChild.dispatchDragEnterExitInPreN(event);
}
if (target != null) {
event.mAction = DragEvent.ACTION_DRAG_ENTERED;
target.dispatchDragEnterExitInPreN(event);
}
event.mAction = action;
event.mX = tx;
event.mY = ty;
}
mCurrentDragChild = target;
}
if (target == null && mIsInterestedInDrag) {
target = this;
}
// Dispatch the actual drag notice, localized into the target coordinates.
if (target != null) {
if (target != this) {
event.mX = localPoint.x;
event.mY = localPoint.y;
retval = target.dispatchDragEvent(event);
event.mX = tx;
event.mY = ty;
if (mIsInterestedInDrag) {
final boolean eventWasConsumed;
if (sCascadedDragDrop) {
eventWasConsumed = retval;
} else {
eventWasConsumed = event.mEventHandlerWasCalled;
}
if (!eventWasConsumed) {
retval = super.dispatchDragEvent(event);
}
}
} else {
retval = super.dispatchDragEvent(event);
}
}
}
break;
}
return retval;
}
use of android.graphics.PointF in project platform_frameworks_base by android.
the class ViewGroup method onResolvePointerIcon.
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
final float x = event.getX(pointerIndex);
final float y = event.getY(pointerIndex);
if (isOnScrollbarThumb(x, y) || isDraggingScrollBar()) {
return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_ARROW);
}
// Check what the child under the pointer says about the pointer.
final int childrenCount = mChildrenCount;
if (childrenCount != 0) {
final ArrayList<View> preorderedList = buildOrderedChildList();
final boolean customOrder = preorderedList == null && isChildrenDrawingOrderEnabled();
final View[] children = mChildren;
for (int i = childrenCount - 1; i >= 0; i--) {
final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex);
final PointF point = getLocalPoint();
if (isTransformedTouchPointInView(x, y, child, point)) {
final PointerIcon pointerIcon = dispatchResolvePointerIcon(event, pointerIndex, child);
if (pointerIcon != null) {
if (preorderedList != null)
preorderedList.clear();
return pointerIcon;
}
break;
}
}
if (preorderedList != null)
preorderedList.clear();
}
// implementation.
return super.onResolvePointerIcon(event, pointerIndex);
}
use of android.graphics.PointF in project material by rey5137.
the class TimePicker method onSizeChanged.
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
int left = getPaddingLeft();
int top = getPaddingTop();
int size = Math.min(w - getPaddingLeft() - getPaddingRight(), h - getPaddingTop() - getPaddingBottom());
if (mCenterPoint == null)
mCenterPoint = new PointF();
mOuterRadius = size / 2f;
mCenterPoint.set(left + mOuterRadius, top + mOuterRadius);
mInnerRadius = mOuterRadius - mSelectionRadius - ThemeUtil.dpToPx(getContext(), 4);
calculateTextLocation();
}
use of android.graphics.PointF in project robolectric by robolectric.
the class ShadowMatrixTest method testPostTranslate.
@Test
public void testPostTranslate() {
final Matrix matrix1 = new Matrix();
matrix1.postTranslate(1.0f, 1.0f);
assertPointsEqual(mapPoint(matrix1, 1.0f, 1.0f), new PointF(2.0f, 2.0f));
matrix1.postTranslate(2.0f, 2.0f);
assertPointsEqual(mapPoint(matrix1, 1.0f, 1.0f), new PointF(4.0f, 4.0f));
final Matrix matrix2 = new Matrix();
matrix2.setScale(2.0f, 2.0f);
matrix2.postTranslate(-5.0f, 10.0f);
assertPointsEqual(mapPoint(matrix2, 1.0f, 1.0f), new PointF(-3.0f, 12.0f));
}
use of android.graphics.PointF in project robolectric by robolectric.
the class ShadowMatrixTest method testSetConcat.
@Test
public void testSetConcat() {
final Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(2.0f, 3.0f);
final Matrix translateMatrix = new Matrix();
translateMatrix.postTranslate(5.0f, 7.0f);
final Matrix matrix = new Matrix();
matrix.setConcat(translateMatrix, scaleMatrix);
assertPointsEqual(mapPoint(matrix, 2.0f, 2.0f), new PointF(9.0f, 13.0f));
final Matrix rotateMatrix = new Matrix();
rotateMatrix.postRotate(90.0f);
matrix.setConcat(rotateMatrix, matrix);
assertPointsEqual(mapPoint(matrix, 2.0f, 2.0f), new PointF(-13.0f, 9.0f));
}
Aggregations