Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ public class TiC
public static final String PROPERTY_CROP_RECT = "cropRect";
public static final String PROPERTY_CURRENT_PAGE = "currentPage";
public static final String PROPERTY_CURVE = "curve";
public static final String PROPERTY_DASHED = "dashed";
public static final String PROPERTY_DATA = "data";
public static final String PROPERTY_DATE = "date";
public static final String PROPERTY_DATE_PICKER_STYLE = "datePickerStyle";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
TiC.PROPERTY_BORDER_COLOR,
TiC.PROPERTY_BORDER_RADIUS,
TiC.PROPERTY_BORDER_WIDTH,
TiC.PROPERTY_DASHED,
// layout / dimension (size/width/height have custom accessors)
TiC.PROPERTY_LEFT,
TiC.PROPERTY_TOP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.util.TiConvert;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Path;
Expand All @@ -38,6 +40,7 @@ public class TiBorderWrapperView extends FrameLayout
private int backgroundColor = Color.TRANSPARENT;
private final float[] radius = { 0, 0, 0, 0, 0, 0, 0, 0 };
private float borderWidth = 0;
private float[] dashed = null;
private int alpha = -1;
private Paint paint;
private Rect bounds;
Expand Down Expand Up @@ -74,13 +77,15 @@ public void reset()
}
}

@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas)
{
getDrawingRect(bounds);

int maxPadding = (int) Math.min(bounds.right / 2, bounds.bottom / 2);
int padding = (int) Math.min(borderWidth, maxPadding);
float halfPadding = padding * 0.5f;
RectF innerRect =
new RectF(bounds.left + padding, bounds.top + padding, bounds.right - padding, bounds.bottom - padding);
RectF outerRect = new RectF(bounds);
Expand Down Expand Up @@ -114,7 +119,18 @@ protected void onDraw(Canvas canvas)
}
} else {
outerPath.addRect(outerRect, Direction.CW);
outerPath.addRect(innerRect, Direction.CCW);
innerRect = new RectF(bounds.left + halfPadding, bounds.top + halfPadding,
bounds.right - halfPadding, bounds.bottom - halfPadding);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(borderWidth);

if (dashed != null) {
try {
paint.setPathEffect(new DashPathEffect(dashed, 0f));
} catch (Exception ex) {
Log.e(TAG, "dashed needs to have at least two values");
}
}
canvas.drawPath(outerPath, paint);
canvas.clipRect(innerRect);
}
Expand Down Expand Up @@ -149,6 +165,10 @@ public void setBgColor(int color)
{
this.backgroundColor = color;
}
public void setDashed(float[] value)
{
this.dashed = value;
}

public boolean hasRadius()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,18 @@ private void initializeBorder(KrollDict d, Integer bgColor)
borderView.setRadius(d.get(TiC.PROPERTY_BORDER_RADIUS));
}

if (d.containsKeyAndNotNull(TiC.PROPERTY_DASHED)) {
try {
Object[] inArray = (Object[]) d.get(TiC.PROPERTY_DASHED);
float[] outArray = new float[inArray.length];
for (int i = 0; i < inArray.length; i++) {
outArray[i] = ((Number) inArray[i]).intValue();
}
borderView.setDashed(outArray);
} catch (Exception ex) {
Log.e(TAG, "dashed needs to be an array of float values with 2 or more values");
}
}
if (bgColor != null) {
borderView.setBgColor(bgColor);
borderView.setColor(bgColor);
Expand Down
Loading