下面列出了android.graphics.Point#set ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressLint("NewApi")
protected int getScreenOrientation() {
// getResources().getConfiguration().orientation returns wrong value in some devices.
// Below is another way to calculate screen orientation.
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
size.set(display.getWidth(), display.getHeight());
} else {
display.getSize(size);
}
int orientation;
if (size.x < size.y) {
orientation = Configuration.ORIENTATION_PORTRAIT;
} else {
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
return orientation;
}
/**
* Scrolls the map to specific location without animation.
*
* @param location
* - instance of {@link android.location.Location} object.
* @throws IllegalStateException
* if map was not calibrated. For more details see
* MapWidget.setShowMyPosition().
*/
public void jumpTo(Location location) {
if (config == null) {
Log.w(TAG, "Jump to skipped. Map is not initialized properly.");
return;
}
if (!config.getGpsConfig().isMapCalibrated()) {
throw new IllegalStateException("Map is not calibrated.");
}
Point point = new Point();
getGpsConfig().getCalibration().translate(location, point);
point.set((int) (point.x * getScale()), (int) (point.y * getScale()));
jumpTo(point);
}
private void drawSelector(Canvas canvas, int posX, int posY) {
if (isSelected) {
paint.setColor(highlightColor);
} else {
paint.setColor(isEnabled() ? arrowColor : disabledColor);
}
Point point1 = selectorPoints[0];
Point point2 = selectorPoints[1];
Point point3 = selectorPoints[2];
point1.set(posX, posY);
point2.set((int) (posX - (arrowSize)), posY);
point3.set((int) (posX - (arrowSize / 2)), (int) (posY + (arrowSize / 2)));
selectorPath.reset();
selectorPath.moveTo(point1.x, point1.y);
selectorPath.lineTo(point2.x, point2.y);
selectorPath.lineTo(point3.x, point3.y);
selectorPath.close();
canvas.drawPath(selectorPath, paint);
}
/**
* Accounting for the settings of {@link Gravity} and {@link Orientation}, find the center point
* around which this layout manager should arrange list items. Place the resulting coordinates
* into {@code out}, to avoid reallocation.
*/
private Point deriveCenter(@Gravity int gravity,
int orientation,
@Dimension int radius,
@Dimension int peekDistance,
Point out) {
final int gravitySign = gravity == Gravity.START ? -1 : 1;
final int distanceMultiplier = gravity == Gravity.START ? 0 : 1;
int x, y;
switch (orientation) {
case Orientation.HORIZONTAL:
y = (distanceMultiplier * getHeight()) + gravitySign * (Math.abs(radius - peekDistance));
x = getWidth() / 2;
break;
case Orientation.VERTICAL:
default:
y = getHeight() / 2;
x = (distanceMultiplier * getWidth()) + gravitySign * (Math.abs(radius - peekDistance));
break;
}
out.set(x, y);
return out;
}
public static Point getScreenSize(Context context){
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point out = new Point();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
display.getSize(out);
}else{
int width = display.getWidth();
int height = display.getHeight();
out.set(width, height);
}
return out;
}
private void autoCenterMap(LatLng latLng) {
//move map camera
Point mMapPoint = mMap.getProjection().toScreenLocation(latLng);
// add y offset to avoid overlay with mDistanceText
mMapPoint.set(mMapPoint.x, mMapPoint.y + MAP_Y_OFFSET);
mMap.moveCamera(CameraUpdateFactory.newLatLng(mMap.getProjection().fromScreenLocation(mMapPoint)));
}
/**
* @return Point View在此window的中心坐标
* */
private Point getViewCenterPoint() {
Point centerPoint = new Point();
int[] location = new int[2];
getLocationInWindow(location);
centerPoint.set(location[0]+getWidth()/2, location[1]+getWidth()/2);
return centerPoint;
}
@SuppressWarnings("deprecation")
private static Point getDefaultDisplaySize(Activity activity, Point size) {
Display d = activity.getWindowManager().getDefaultDisplay();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
d.getSize(size);
} else {
size.set(d.getWidth(), d.getHeight());
}
return size;
}
private void drawRegion(Canvas canvas, float scale) {
canvas.save();
singlePaint.setColor(singleColor);
if (enabledRegionShader) {
singlePaint.setShader(regionShader);
} else {
singlePaint.setShader(null);
}
List<Point> list = new ArrayList<>();
for (int i = 0; i < count; i++) {
int x, y;
x = (int) (centerX + scale * percents[i] * radius * Math.cos(angle * i + Math.PI / 2));
y = (int) (centerY - scale * percents[i] * radius * Math.sin(angle * i + Math.PI / 2));
Point p = new Point();
p.set(x, y);
list.add(p);
}
Path path = new Path();
for (int i = 0; i < list.size(); i++) {
if (i == 0) {
path.moveTo(list.get(i).x, list.get(i).y);
} else {
path.lineTo(list.get(i).x, list.get(i).y);
}
}
path.close();
canvas.drawPath(path, singlePaint);
canvas.restore();
}
@SuppressWarnings("deprecation")
public static void getDisplaySize(Display display, Point outSize) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
outSize.set(display.getWidth(), display.getHeight());
} else {
CompatibilityImpl.getDisplaySize(display, outSize);
}
}
/**
* Reads, one time, values from the camera that are needed by the app.
*/
void initFromCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
screenResolution = new Point();
int width = metrics.widthPixels;
int height = metrics.heightPixels;
// Remove action bar height
TypedValue typedValue = new TypedValue();
DisplayMetrics displayMetrics = this.context.getResources().getDisplayMetrics();
if (this.context.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) {
height -= TypedValue.complexToDimensionPixelSize(typedValue.data, displayMetrics);
} else {
int rotation = context.getApplicationContext().getResources().getConfiguration().orientation;
if (rotation == Configuration.ORIENTATION_PORTRAIT) {
height -= 40 * displayMetrics.density;
} else {
height -= 48 * displayMetrics.density;
}
}
// height -= statusBarHeight();
height -= 50;
screenResolution.set(width, height);
Log.i(TAG, "Screen resolution: " + screenResolution);
cameraResolution = findBestPreviewSizeValue(parameters, screenResolution);
Log.i(TAG, "Camera resolution: " + cameraResolution);
}
private void constrainPoint( Point point ) {
int x = point.x;
int y = point.y;
int mx = Math.max( 0, Math.min( x, getLimitX() ) );
int my = Math.max( 0, Math.min( y, getLimitY() ) );
if ( x != mx || y != my ) {
point.set( mx, my );
}
}
@Override
public void shiftViewCenter(Direction direction, int shiftAmount, Point outCenter) {
int newX = outCenter.x + direction.applyTo(shiftAmount);
outCenter.set(newX, outCenter.y);
}
@OnClick(R.id.playSecondAnim)
protected void playSecondAnim() {
firstAnimContainer.removeAllViews();
secondAnimContainer.removeAllViews();
Point center = new Point(secondAnimContainer.getMeasuredWidth() / 2, secondAnimContainer.getMeasuredHeight() / 2);
int size = getResources().getDimensionPixelSize(R.dimen.circle_size);
float delay = 0;
for (int i = 0; i < 6; i++) {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(size, size);
final ImageView view = new ImageView(this);
view.setLayoutParams(params);
view.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.square));
Point newPos = new Point();
switch (i) {
case 0:
newPos.set(0, 0);
break;
case 1:
newPos.set(0, center.y);
break;
case 2:
newPos.set(0, center.y * 2 - size);
break;
case 3:
newPos.set(center.x * 2 - size, 0);
break;
case 4:
newPos.set(center.x * 2 - size, center.y);
break;
case 5:
newPos.set(center.x * 2 - size, center.y * 2 - size);
break;
}
play(sequence(parallel(fadeOut(), color(-1, Color.BLUE)), moveTo(center.x, center.y),
fadeIn(.5f), parallel(moveTo(newPos.x, newPos.y, 1, Interpolations.ExponentialEaseOut)), run(new Runnable() {
@Override
public void run() {
play(sequence(color(Color.BLUE, Color.GREEN, .1f), forever(sequence(color(Color.GREEN, Color.RED, 1), color(Color.GREEN, Color.RED, 1)))), view);
}
}),
parallel(rotateBy(720, 2, Interpolations.BackEaseOut), sequence(scaleTo(.5f, .5f, 1, Interpolations.BackEaseOut),
scaleTo(1, 1, 1, Interpolations.ElasticEaseOut))), sequence(delay(delay), parallel(fadeOut(.5f, Interpolations.ExponentialEaseOut),
scaleTo(0, 1, .5f, Interpolations.ExponentialEaseOut)))), view);
delay += 1f;
secondAnimContainer.addView(view);
}
}
@Override
public void setCurrentViewCenter(Point recyclerCenter, int scrolled, Point outPoint) {
int newY = recyclerCenter.y - scrolled;
outPoint.set(recyclerCenter.x, newY);
}
@Override
public void shiftViewCenter(Direction direction, int shiftAmount, Point outCenter) {
int newX = outCenter.x + direction.applyTo(shiftAmount);
outCenter.set(newX, outCenter.y);
}
@Override
public void setCurrentViewCenter(Point recyclerCenter, int scrolled, Point outPoint) {
int newY = recyclerCenter.y - scrolled;
outPoint.set(recyclerCenter.x, newY);
}
@Override
public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
Rect rect = mChip.getBounds();
shadowSize.set(rect.width(), rect.height());
shadowTouchPoint.set(rect.centerX(), rect.centerY());
}
@Override
public void onProvideShadowMetrics(Point outShadowSize, Point outShadowTouchPoint) {
super.onProvideShadowMetrics(outShadowSize, outShadowTouchPoint);
outShadowTouchPoint.set(x, y);
}
@Override
public void shiftViewCenter(Direction direction, int shiftAmount, Point outCenter) {
int newY = outCenter.y + direction.applyTo(shiftAmount);
outCenter.set(outCenter.x, newY);
}