List of usage examples for android.graphics Path Path
public Path()
From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java
public void parseJSON(String jsonFile) { if (jsonFile != null) { // Load all the JSONs with the numbers information try {/*from w w w. ja v a2s . c o m*/ JSONObject obj = new JSONObject(loadJSONFromAsset(jsonFile)); Log.d(TAG, "SHAPE SHADOW JSON FILE " + jsonFile + ": LOADED"); id = obj.getString("id"); JSONArray jsonPathData; JSONArray jsonShadowData; if (!id.equals("5")) { jsonPathData = obj.getJSONArray("path"); jsonShadowData = obj.getJSONArray("shadow"); Log.d(TAG, "JSON PATH DATA LENGTH: " + jsonPathData.length() + ""); Log.d(TAG, "JSON SHADOW DATA LENGTH: " + jsonShadowData.length() + ""); shapePath.reset(); for (int i = 0; i < jsonPathData.length(); i++) { try { JSONObject elem = jsonPathData.getJSONObject(i); String type = elem.getString("type"); JSONArray data = elem.getJSONArray("data"); if (type.equals("move")) { shapePath.moveTo((float) data.getInt(0), (float) data.getInt(1)); } else if (type.equals("line")) { shapePath.lineTo((float) data.getInt(0), (float) data.getInt(1)); } else if (type.equals("bezier")) { shapePath.cubicTo((float) data.getInt(0), (float) data.getInt(1), (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4), (float) data.getInt(5)); } } catch (JSONException e) { Log.d(TAG, "JSON ELEM EXCEPTION" + e.getMessage() + ""); } } shapePath.close(); Random r = new Random(); r.nextGaussian(); JSONArray holesContainer = obj.getJSONArray("holes"); Path holePath = new Path(); for (int i = 0; i < holesContainer.length(); i++) { JSONObject jsonInside = holesContainer.getJSONObject(i); JSONArray hole = jsonInside.getJSONArray("data"); holePath.reset(); for (int j = 0; j < hole.length(); j++) { try { JSONObject elem = hole.getJSONObject(j); String type = elem.getString("type"); JSONArray data = elem.getJSONArray("data"); if (type.equals("move")) { holePath.moveTo((float) data.getInt(0), (float) data.getInt(1)); } else if (type.equals("line")) { holePath.lineTo((float) data.getInt(0), (float) data.getInt(1)); } else if (type.equals("bezier")) { holePath.cubicTo((float) data.getInt(0), (float) data.getInt(1), (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4), (float) data.getInt(5)); } } catch (JSONException e) { Log.d(TAG, "JSON HOLE EXCEPTION" + e.getMessage() + ""); } } holePath.close(); shapePath.op(holePath, Path.Op.DIFFERENCE); } pathTransform.reset(); pathTransform.setScale(scale + 0.04f, scale + 0.04f); shapePath.transform(pathTransform); boundsPath.transform(pathTransform); pathTransform.setTranslate(positionX - 0.3f, positionY - 0.3f); shapePath.transform(pathTransform); boundsPath.transform(pathTransform); int shadowTmpX; int shadowTmpY; shadowPaths.clear(); vertexArray.clear(); for (int i = 0; i < jsonShadowData.length(); i += 2) { shadowTmpX = jsonShadowData.getInt(i); shadowTmpY = jsonShadowData.getInt(i + 1); addVertex(shadowTmpX, shadowTmpY); } } else { jsonPathData = obj.getJSONArray("path"); jsonShadowData = obj.getJSONArray("shadow"); Log.d(TAG, "JSON PATH DATA LENGTH: " + jsonPathData.length() + ""); Log.d(TAG, "JSON SHADOW DATA LENGTH: " + jsonShadowData.length() + ""); shapePath.reset(); for (int i = 0; i < jsonPathData.length(); i++) { JSONArray cords = jsonPathData.getJSONArray(i); Path chunk = new Path(); chunk.reset(); for (int j = 0; j < cords.length(); j++) { try { JSONObject elem = cords.getJSONObject(j); String type = elem.getString("type"); JSONArray data = elem.getJSONArray("data"); if (type.equals("move")) { chunk.moveTo((float) data.getInt(0), (float) data.getInt(1)); } else if (type.equals("line")) { chunk.lineTo((float) data.getInt(0), (float) data.getInt(1)); } else if (type.equals("bezier")) { chunk.cubicTo((float) data.getInt(0), (float) data.getInt(1), (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4), (float) data.getInt(5)); } } catch (JSONException e) { Log.d(TAG, "JSON 5 NUMBER ELEM EXCEPTION" + e.getMessage() + ""); } } chunk.close(); shapePath.op(chunk, Path.Op.UNION); } pathTransform.reset(); pathTransform.setScale(scale, scale); shapePath.transform(pathTransform); boundsPath.transform(pathTransform); pathTransform.setTranslate(positionX, positionY); shapePath.transform(pathTransform); boundsPath.transform(pathTransform); shadowPaths.clear(); vertexArray.clear(); int shadowTmpX; int shadowTmpY; for (int i = 0; i < jsonShadowData.length(); i++) { JSONArray coords = jsonShadowData.getJSONArray(i); for (int j = 0; j < coords.length(); j += 2) { shadowTmpX = coords.getInt(j); shadowTmpY = coords.getInt(j + 1); addVertex((float) shadowTmpX, (float) shadowTmpY); } } } } catch (JSONException e) { Log.d(TAG, "JSON ROOT EXCEPTION" + e.getMessage() + ""); } } }
From source file:com.example.SmartBoard.DrawingView.java
private void setupDrawing() { //get drawing area setup for interaction drawPath = new Path(); drawPathRecv = new Path(); drawPaint = new Paint(); drawPaint.setDither(true);/* w w w .j a va 2s . c o m*/ drawPaint.setPathEffect(new CornerPathEffect(10)); drawPaint.setColor(paintColor); drawPaint.setAntiAlias(true); drawPaint.setStrokeWidth(strokeWidth); drawPaint.setStyle(Paint.Style.STROKE); drawPaint.setStrokeJoin(Paint.Join.ROUND); drawPaint.setStrokeCap(Paint.Cap.ROUND); canvasPaint = new Paint(Paint.DITHER_FLAG); drawPaintSender = new Paint(); drawPaintSender.setDither(true); drawPaintSender.setPathEffect(new CornerPathEffect(10)); drawPaintSender.setColor(paintColor); drawPaintSender.setAntiAlias(true); drawPaintSender.setStrokeWidth(strokeWidth); drawPaintSender.setStyle(Paint.Style.STROKE); drawPaintSender.setStrokeJoin(Paint.Join.ROUND); drawPaintSender.setStrokeCap(Paint.Cap.ROUND); client = MQTTHandler.getInstance().getClientHandle(); }
From source file:com.commit451.inkpageindicator.InkPageIndicator.java
public InkPageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final int density = (int) context.getResources().getDisplayMetrics().density; // Load attributes final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InkPageIndicator, defStyle, 0); dotDiameter = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotDiameter, DEFAULT_DOT_SIZE * density); dotRadius = dotDiameter / 2;/*from ww w.jav a 2 s. c o m*/ halfDotRadius = dotRadius / 2; gap = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotGap, DEFAULT_GAP * density); animDuration = (long) a.getInteger(R.styleable.InkPageIndicator_animationDuration, DEFAULT_ANIM_DURATION); animHalfDuration = animDuration / 2; unselectedColour = a.getColor(R.styleable.InkPageIndicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR); selectedColour = a.getColor(R.styleable.InkPageIndicator_currentPageIndicatorColor, DEFAULT_SELECTED_COLOUR); a.recycle(); unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); unselectedPaint.setColor(unselectedColour); selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); selectedPaint.setColor(selectedColour); interpolator = new FastOutSlowInInterpolator(); // create paths & rect now reuse & rewind later combinedUnselectedPath = new Path(); unselectedDotPath = new Path(); unselectedDotLeftPath = new Path(); unselectedDotRightPath = new Path(); rectF = new RectF(); addOnAttachStateChangeListener(this); }
From source file:io.plaidapp.ui.widget.InkPageIndicator.java
public InkPageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final int density = (int) context.getResources().getDisplayMetrics().density; // Load attributes final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InkPageIndicator, defStyle, 0); dotDiameter = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotDiameter, DEFAULT_DOT_SIZE * density); dotRadius = dotDiameter / 2;/*ww w . j a v a2s. co m*/ halfDotRadius = dotRadius / 2; gap = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotGap, DEFAULT_GAP * density); animDuration = (long) a.getInteger(R.styleable.InkPageIndicator_animationDuration, DEFAULT_ANIM_DURATION); animHalfDuration = animDuration / 2; unselectedColour = a.getColor(R.styleable.InkPageIndicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR); selectedColour = a.getColor(R.styleable.InkPageIndicator_currentPageIndicatorColor, DEFAULT_SELECTED_COLOUR); a.recycle(); unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); unselectedPaint.setColor(unselectedColour); selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); selectedPaint.setColor(selectedColour); interpolator = android.view.animation.AnimationUtils.loadInterpolator(context, android.R.interpolator.fast_out_slow_in); // create paths & rect now reuse & rewind later combinedUnselectedPath = new Path(); unselectedDotPath = new Path(); unselectedDotLeftPath = new Path(); unselectedDotRightPath = new Path(); rectF = new RectF(); addOnAttachStateChangeListener(this); }
From source file:com.ww.administrator.demotest.widget.InkPageIndicator.java
public InkPageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final int density = (int) context.getResources().getDisplayMetrics().density; // Load attributes final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InkPageIndicator, defStyle, 0); dotDiameter = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotDiameter, DEFAULT_DOT_SIZE * density); dotRadius = dotDiameter / 2;//w w w . jav a2 s .c om halfDotRadius = dotRadius / 2; gap = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotGap, DEFAULT_GAP * density); animDuration = (long) a.getInteger(R.styleable.InkPageIndicator_animationDuration, DEFAULT_ANIM_DURATION); animHalfDuration = animDuration / 2; unselectedColour = a.getColor(R.styleable.InkPageIndicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR); selectedColour = a.getColor(R.styleable.InkPageIndicator_currentPageIndicatorColor, DEFAULT_SELECTED_COLOUR); a.recycle(); unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); unselectedPaint.setColor(unselectedColour); selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); selectedPaint.setColor(selectedColour); interpolator = AnimUtil.getFastOutSlowInInterpolator(context); // create paths & rect now reuse & rewind later combinedUnselectedPath = new Path(); unselectedDotPath = new Path(); unselectedDotLeftPath = new Path(); unselectedDotRightPath = new Path(); rectF = new RectF(); addOnAttachStateChangeListener(this); }
From source file:com.amitupadhyay.aboutexample.ui.widget.InkPageIndicator.java
public InkPageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final int density = (int) context.getResources().getDisplayMetrics().density; // Load attributes final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InkPageIndicator, defStyle, 0); dotDiameter = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotDiameter, DEFAULT_DOT_SIZE * density); dotRadius = dotDiameter / 2;//ww w.j a v a2 s . c o m halfDotRadius = dotRadius / 2; gap = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotGap, DEFAULT_GAP * density); animDuration = (long) a.getInteger(R.styleable.InkPageIndicator_animationDuration, DEFAULT_ANIM_DURATION); animHalfDuration = animDuration / 2; unselectedColour = a.getColor(R.styleable.InkPageIndicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR); selectedColour = a.getColor(R.styleable.InkPageIndicator_currentPageIndicatorColor, DEFAULT_SELECTED_COLOUR); a.recycle(); unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); unselectedPaint.setColor(unselectedColour); selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); selectedPaint.setColor(selectedColour); interpolator = AnimUtils.getFastOutSlowInInterpolator(context); // create paths & rect now reuse & rewind later combinedUnselectedPath = new Path(); unselectedDotPath = new Path(); unselectedDotLeftPath = new Path(); unselectedDotRightPath = new Path(); rectF = new RectF(); addOnAttachStateChangeListener(this); }
From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java
private void prepare() { mIconPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mIconPaint.setStyle(Paint.Style.FILL); mIconPaint.setTextAlign(Paint.Align.CENTER); mIconPaint.setUnderlineText(false);//from w ww . ja v a2 s .com mIconPaint.setAntiAlias(true); mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mContourPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mContourPaint.setStyle(Paint.Style.STROKE); mPath = new Path(); mPathBounds = new RectF(); mPaddingBounds = new Rect(); }
From source file:com.amaze.carbonfilemanager.ui.views.Indicator.java
public Indicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final int density = (int) context.getResources().getDisplayMetrics().density; // Load attributes final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Indicator, defStyle, 0); dotDiameter = a.getDimensionPixelSize(R.styleable.Indicator_dotDiameter, DEFAULT_DOT_SIZE * density); dotRadius = dotDiameter / 2;// w w w. j a v a 2 s . co m halfDotRadius = dotRadius / 2; gap = a.getDimensionPixelSize(R.styleable.Indicator_dotGap, DEFAULT_GAP * density); animDuration = (long) a.getInteger(R.styleable.Indicator_animationDuration, DEFAULT_ANIM_DURATION); animHalfDuration = animDuration / 2; selectedColour = a.getColor(R.styleable.Indicator_currentPageIndicatorColor, DEFAULT_SELECTED_COLOUR); // half transparent accent color unselectedColour = Color.argb(80, Color.red(selectedColour), Color.green(selectedColour), Color.blue(selectedColour)); a.recycle(); unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); unselectedPaint.setColor(unselectedColour); selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); selectedPaint.setColor(selectedColour); interpolator = AnimUtils.getFastOutSlowInInterpolator(context); // create paths & rect now reuse & rewind later combinedUnselectedPath = new Path(); unselectedDotPath = new Path(); unselectedDotLeftPath = new Path(); unselectedDotRightPath = new Path(); rectF = new RectF(); addOnAttachStateChangeListener(this); }
From source file:com.github.shareme.gwsinkpageindicator.library.InkPageIndicator.java
public InkPageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final int density = (int) context.getResources().getDisplayMetrics().density; // Load attributes final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InkPageIndicator, defStyle, 0); dotDiameter = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotDiameter, DEFAULT_DOT_SIZE * density); dotRadius = dotDiameter / 2;//from w w w .j ava2 s . com halfDotRadius = dotRadius / 2; gap = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotGap, DEFAULT_GAP * density); animDuration = (long) a.getInteger(R.styleable.InkPageIndicator_animationDuration, DEFAULT_ANIM_DURATION); animHalfDuration = animDuration / 2; unselectedColour = a.getColor(R.styleable.InkPageIndicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR); selectedColour = a.getColor(R.styleable.InkPageIndicator_currentPageIndicatorColor, DEFAULT_SELECTED_COLOUR); a.recycle(); unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); unselectedPaint.setColor(unselectedColour); selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); selectedPaint.setColor(selectedColour); interpolator = new FastOutSlowInInterpolator(); // create paths & rect now reuse & rewind later combinedUnselectedPath = new Path(); unselectedDotPath = new Path(); unselectedDotLeftPath = new Path(); unselectedDotRightPath = new Path(); rectF = new RectF(); addOnAttachStateChangeListener(this); }
From source file:com.frapim.windwatch.Notifier.java
private Path getArrowPath(float degrees) { Path path = new Path(); int leftX = (mBigIconSize / 2) - (mArrowWidth / 2); int leftHeadX = leftX - mArrowWidth; int rightX = (mBigIconSize / 2) + (mArrowWidth / 2); int rightHeadX = rightX + mArrowWidth; path.moveTo(leftX, mArrowHeight); // bottom left path.lineTo(leftX, mArrowHeadHeight); // left, arrow head start path.lineTo(leftHeadX, mArrowHeadHeight); // left, arrow head end path.lineTo(mBigIconSize / 2, 0); // top path.lineTo(rightHeadX, mArrowHeadHeight); // right, arrow head end path.lineTo(rightX, mArrowHeadHeight); // right, arrow head start path.lineTo(rightX, mArrowHeight); // bottom right path.lineTo(leftX, mArrowHeight); // bottom left path.close();/* w ww.j av a 2 s . c om*/ Matrix translateMatrix = new Matrix(); translateMatrix.postTranslate(0, 30); path.transform(translateMatrix); RectF bounds = new RectF(); path.computeBounds(bounds, true); Matrix rotateMatrix = new Matrix(); rotateMatrix.postRotate(degrees, (bounds.right + bounds.left) / 2, (bounds.bottom + bounds.top) / 2); path.transform(rotateMatrix); return path; }