Code example for Path

Methods: quadTorewind

0
      onTouchDown( x, y );
    } 
  } 
 
  private void drawQuadTo( float curX, float curY, float controlPointX, float controlPointY ) {
    linePath.quadTo( controlPointX, controlPointY, curX, curY );
    drawPath(); 
    invalidateDrawingRegion( curX, curY );
    lastX = curX;
    lastY = curY;
  } 
 
  private void onTouchUpOrCancel( float x, float y ) {
    drawQuadTo( x, y, x, y );
    sendPolylineRequest(); 
    linePath.rewind();
    recordedCoords.clear();
  } 
 
  private void record( float x, float y ) {
    IWidgetToolkit toolkit = activity.getProcessor().getWidgetToolkit();
    recordedCoords.add( Math.round( toolkit.divideByDensityFactor( x ) ) );
    recordedCoords.add( Math.round( toolkit.divideByDensityFactor( y ) ) );
  } 
 
  private Object[][] createPolyLineParam() {
    IWidgetToolkit toolkit = activity.getProcessor().getWidgetToolkit();
    float lineWidth = toolkit.divideByDensityFactor( getPaint().getStrokeWidth() );
    int color = getStrokeColor();
    Object[][] polylineArray = new Object[][]{
      new Object[]{
        KEY_FOREGROUND, new Object[]{
          Color.red( color ), Color.green( color ), Color.blue( color ), getPaint().getAlpha()
        } 
      }, new Object[]{
        KEY_LINE_WIDTH, new Object[]{
          lineWidth
        } 
      }, new Object[]{
        KEY_POLYLINE, recordedCoords
      }, 
    }; 
    return polylineArray;
  } 
 
  private void sendPolylineRequest() { 
    if( !recordedCoords.isEmpty() && recordedCoordsArePoint() ) {
      convertCoordsToPoint(); 
    } 
    Object[][] polylineArray = createPolyLineParam();
    ProtocolProcessor processor = activity.getProcessor();
    String param = processor.getParser().toJson( polylineArray );
    PostRequest request = new PostRequest();
    request.addParam( getCanvasView().getTag() + IProtocolConstants.DRAWINGS, param );
    processor.processPostRequest( request );
  } 
 
  private void convertCoordsToPoint() { 
    int x = recordedCoords.get( 0 );
    int y = recordedCoords.get( 1 );
    recordedCoords.clear();
    recordedCoords.add( x );
    recordedCoords.add( y );
    recordedCoords.add( x + 1 );
    recordedCoords.add( y );
    recordedCoords.add( x );
    recordedCoords.add( y + 1 );
    recordedCoords.add( x - 1 );
    recordedCoords.add( y );
    recordedCoords.add( x );
    recordedCoords.add( y - 1 );
  } 
 
  private boolean recordedCoordsArePoint() { 
    int x = recordedCoords.get( 0 );
    int y = recordedCoords.get( 1 );
    for( int i = 0; i < recordedCoords.size(); i += 2 ) {
      int curX = recordedCoords.get( i );
      int curY = recordedCoords.get( i + 1 );
      if( x != curX || y != curY ) {
        return false; 
      } 
    } 
    return true; 
  } 
 
  private void drawPath() { 
    Paint paint = getPaint();
    int alpha = paint.getAlpha();
    paint.setStyle( Style.STROKE );
    paint.setColor( getStrokeColor() );
    getCanvas().drawPath( linePath, paint );
    paint.setAlpha( alpha );
  } 
 
  private void initInternal() { 
    if( getCanvas() == null || getPaint() == null ) { 
Experience pair programming with AI  Get Codota for Java