Java Code Examples for android.graphics.Point#set()

The following examples show how to use android.graphics.Point#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CordovaActivity.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: TurnLayoutManager.java    From turn-layout-manager with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: MaterialSpinner.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 4
Source File: MapWidget.java    From mappwidget with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: PopupCircleView.java    From PopupCircleMenu with MIT License 5 votes vote down vote up
/**
 * @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;
}
 
Example 6
Source File: Util.java    From VideoFaceDetection with MIT License 5 votes vote down vote up
@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;
}
 
Example 7
Source File: XRadarView.java    From XRadarView with MIT License 5 votes vote down vote up
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();
}
 
Example 8
Source File: CompatibilityUtils.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example 9
Source File: RunActivity.java    From SEAL-Demo with MIT License 5 votes vote down vote up
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)));
}
 
Example 10
Source File: CameraConfigurationManager.java    From reacteu-app with MIT License 5 votes vote down vote up
/**
   * 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);
  }
 
Example 11
Source File: ZoomPanLayout.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
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 );
	}
}
 
Example 12
Source File: ScreenUtils.java    From Luban-Circle-Demo with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 13
Source File: MainActivity.java    From AndroidAnimationsActions with MIT License 4 votes vote down vote up
@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);
    }
}
 
Example 14
Source File: VerticalHelper.java    From OmegaRecyclerView with MIT License 4 votes vote down vote up
@Override
public void setCurrentViewCenter(Point recyclerCenter, int scrolled, Point outPoint) {
    int newY = recyclerCenter.y - scrolled;
    outPoint.set(recyclerCenter.x, newY);
}
 
Example 15
Source File: DSVOrientation.java    From XPlayer2 with Apache License 2.0 4 votes vote down vote up
@Override
public void shiftViewCenter(Direction direction, int shiftAmount, Point outCenter) {
    int newX = outCenter.x + direction.applyTo(shiftAmount);
    outCenter.set(newX, outCenter.y);
}
 
Example 16
Source File: DSVOrientation.java    From XPlayer2 with Apache License 2.0 4 votes vote down vote up
@Override
public void setCurrentViewCenter(Point recyclerCenter, int scrolled, Point outPoint) {
    int newY = recyclerCenter.y - scrolled;
    outPoint.set(recyclerCenter.x, newY);
}
 
Example 17
Source File: RecipientEditTextView.java    From talk-android with MIT License 4 votes vote down vote up
@Override
public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
    Rect rect = mChip.getBounds();
    shadowSize.set(rect.width(), rect.height());
    shadowTouchPoint.set(rect.centerX(), rect.centerY());
}
 
Example 18
Source File: MeasurementPreferences.java    From openScale with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onProvideShadowMetrics(Point outShadowSize, Point outShadowTouchPoint) {
    super.onProvideShadowMetrics(outShadowSize, outShadowTouchPoint);
    outShadowTouchPoint.set(x, y);
}
 
Example 19
Source File: HorizontalHelper.java    From OmegaRecyclerView with MIT License 4 votes vote down vote up
@Override
public void shiftViewCenter(Direction direction, int shiftAmount, Point outCenter) {
    int newX = outCenter.x + direction.applyTo(shiftAmount);
    outCenter.set(newX, outCenter.y);
}
 
Example 20
Source File: VerticalHelper.java    From OmegaRecyclerView with MIT License 4 votes vote down vote up
@Override
public void shiftViewCenter(Direction direction, int shiftAmount, Point outCenter) {
    int newY = outCenter.y + direction.applyTo(shiftAmount);
    outCenter.set(outCenter.x, newY);
}