DO NOT MERGE Rename PointerIcon and Pointer Capture APIs

This is a response to API council feedback.

Bug: 26830970
Change-Id: I19d3919dc201fdf2b949074f02490669b4a5d775
This commit is contained in:
Michael Wright
2016-05-13 17:43:04 +01:00
parent 3a1d9d5f06
commit 71620c8898
8 changed files with 122 additions and 121 deletions

View File

@@ -115,7 +115,7 @@ class TouchSurfaceView extends GLSurfaceView {
if (hasPointerCapture()) {
releasePointerCapture();
} else {
setPointerCapture();
requestPointerCapture();
}
}
break;

View File

@@ -45,7 +45,7 @@ public class LivePointerIconButton extends Button {
}
@Override
public PointerIcon getPointerIcon(MotionEvent event, float x, float y) {
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
int cursorSize = getHeight();
Bitmap bitmap = Bitmap.createBitmap(cursorSize, cursorSize, Bitmap.Config.ARGB_8888);
@@ -65,8 +65,8 @@ public class LivePointerIconButton extends Button {
// Compute relative offset of the mouse pointer from the view center.
// It should be between -0.5 and 0.5.
final float relativeX = (x / getWidth()) - 0.5f;
final float relativeY = (y / getHeight()) - 0.5f;
final float relativeX = (event.getX(pointerIndex) / getWidth()) - 0.5f;
final float relativeY = (event.getY(pointerIndex) / getHeight()) - 0.5f;
// Draw a smaller circle inside the large circle, offset towards the center of the view.
final int innerCenterX = (int) (cursorSize * (1 - relativeX) / 2);
@@ -80,6 +80,6 @@ public class LivePointerIconButton extends Button {
final int hotSpotX = bitmap.getWidth() / 2;
final int hotSpotY = bitmap.getHeight() / 2;
return PointerIcon.createCustomIcon(bitmap, hotSpotX, hotSpotY);
return PointerIcon.create(bitmap, hotSpotX, hotSpotY);
}
}

View File

@@ -29,6 +29,6 @@ public class PointerShapes extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pointer_shapes);
setContentView(R.layout.pointer_types);
}
}

View File

@@ -44,9 +44,9 @@ public class ResourcePointerIconButton extends Button {
}
@Override
public PointerIcon getPointerIcon(MotionEvent event, float x, float y) {
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
if (mCustomIcon == null) {
mCustomIcon = PointerIcon.loadCustomIcon(getResources(), R.drawable.custom_pointer_icon);
mCustomIcon = PointerIcon.load(getResources(), R.drawable.custom_pointer_icon);
}
return mCustomIcon;
}

View File

@@ -46,14 +46,13 @@ public class StaticPointerIconButton extends Button {
}
@Override
public PointerIcon getPointerIcon(MotionEvent event, float x, float y) {
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
if (mCustomIcon == null) {
Drawable d = getContext().getDrawable(R.drawable.smile);
final BitmapDrawable bitmapDrawable = (BitmapDrawable) d;
final int hotSpotX = d.getIntrinsicWidth() / 2;
final int hotSpotY = d.getIntrinsicHeight() / 2;
mCustomIcon = PointerIcon.createCustomIcon(
bitmapDrawable.getBitmap(), hotSpotX, hotSpotY);
mCustomIcon = PointerIcon.create(bitmapDrawable.getBitmap(), hotSpotX, hotSpotY);
}
return mCustomIcon;
}

View File

@@ -42,28 +42,30 @@ public class SystemPointerIconButton extends Button {
}
@Override
public PointerIcon getPointerIcon(MotionEvent event, float x, float y) {
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
final int minX = getWidth() / 4;
final int maxX = getWidth() - minX;
final int minY = getHeight() / 4;
final int maxY = getHeight() - minY;
int style;
final float x = event.getX(pointerIndex);
final float y = event.getY(pointerIndex);
int type;
if ((x < minX && y < minY) || (x > maxX && y > maxY)) {
// Top/left or bottom/right corner.
style = PointerIcon.STYLE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW;
type = PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW;
} else if ((x < minX && y > maxY) || (x > maxX && y < minY)) {
// Top/rightor bottom/left corner.
style = PointerIcon.STYLE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW;
type = PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW;
} else if (x < minX || x > maxX) {
// Left or right edge.
style = PointerIcon.STYLE_HORIZONTAL_DOUBLE_ARROW;
type = PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW;
} else if (y < minY || y > maxY) {
// Top or bottom edge edge.
style = PointerIcon.STYLE_VERTICAL_DOUBLE_ARROW;
type = PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW;
} else {
// Everything else (the middle).
style = PointerIcon.STYLE_ALL_SCROLL;
type = PointerIcon.TYPE_ALL_SCROLL;
}
return PointerIcon.getSystemIcon(getContext(), style);
return PointerIcon.getSystemIcon(getContext(), type);
}
}