Skip to content

Commit

Permalink
Attributes Prefix
Browse files Browse the repository at this point in the history
- Renamed all attributes to include civ_ prefix. This avoids the error described in issue #21 . Now I understand the importance of prefixing attribute names.
  • Loading branch information
Pkmmte Xeleon committed Jan 16, 2015
1 parent bf87d0a commit a74bac7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 40 deletions.
8 changes: 4 additions & 4 deletions circularimageview-sample/src/main/res/layout/footer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
android:layout_height="72dp"
android:layout_margin="16dp"
android:src="@drawable/grumpy_cat"
app:border="true"
app:border_color="@android:color/white"
app:border_width="2dp"
app:shadow="true" />
app:civ_border="true"
app:civ_border_color="@android:color/white"
app:civ_border_width="2dp"
app:civ_shadow="true" />
</LinearLayout>

</LinearLayout>
16 changes: 8 additions & 8 deletions circularimageview-sample/src/main/res/layout/header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
android:layout_margin="8dp"
android:clickable="true"
android:src="@drawable/doge"
app:border="true"
app:border_color="#FFFFFFFF"
app:border_width="4dp"
app:selector="true"
app:selector_color="#4403a9f4"
app:selector_stroke_color="#aa5677fc"
app:selector_stroke_width="4dp"
app:shadow="true" />
app:civ_border="true"
app:civ_border_color="#FFFFFFFF"
app:civ_border_width="4dp"
app:civ_selector="true"
app:civ_selector_color="#4403a9f4"
app:civ_selector_stroke_color="#aa5677fc"
app:civ_selector_stroke_width="4dp"
app:civ_shadow="true" />

<TextView
android:id="@+id/txtClick"
Expand Down
8 changes: 4 additions & 4 deletions circularimageview-sample/src/main/res/layout/row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:clickable="true"
app:selector="true"
app:selector_color="#44FFBB33"
app:selector_stroke_color="#88FF8800"
app:selector_stroke_width="2dp" />
app:civ_selector="true"
app:civ_selector_color="#44FFBB33"
app:civ_selector_stroke_color="#88FF8800"
app:civ_selector_stroke_width="2dp" />

<TextView
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,26 @@ private void init(Context context, AttributeSet attrs, int defStyle) {
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.CircularImageView, defStyle, 0);

// Check if border and/or border is enabled
hasBorder = attributes.getBoolean(R.styleable.CircularImageView_border, false);
hasSelector = attributes.getBoolean(R.styleable.CircularImageView_selector, false);
hasBorder = attributes.getBoolean(R.styleable.CircularImageView_civ_border, false);
hasSelector = attributes.getBoolean(R.styleable.CircularImageView_civ_selector, false);

// Set border properties if enabled
if(hasBorder) {
int defaultBorderSize = (int) (2 * context.getResources().getDisplayMetrics().density + 0.5f);
setBorderWidth(attributes.getDimensionPixelOffset(R.styleable.CircularImageView_border_width, defaultBorderSize));
setBorderColor(attributes.getColor(R.styleable.CircularImageView_border_color, Color.WHITE));
setBorderWidth(attributes.getDimensionPixelOffset(R.styleable.CircularImageView_civ_border_width, defaultBorderSize));
setBorderColor(attributes.getColor(R.styleable.CircularImageView_civ_border_color, Color.WHITE));
}

// Set selector properties if enabled
if(hasSelector) {
int defaultSelectorSize = (int) (2 * context.getResources().getDisplayMetrics().density + 0.5f);
setSelectorColor(attributes.getColor(R.styleable.CircularImageView_selector_color, Color.TRANSPARENT));
setSelectorStrokeWidth(attributes.getDimensionPixelOffset(R.styleable.CircularImageView_selector_stroke_width, defaultSelectorSize));
setSelectorStrokeColor(attributes.getColor(R.styleable.CircularImageView_selector_stroke_color, Color.BLUE));
setSelectorColor(attributes.getColor(R.styleable.CircularImageView_civ_selector_color, Color.TRANSPARENT));
setSelectorStrokeWidth(attributes.getDimensionPixelOffset(R.styleable.CircularImageView_civ_selector_stroke_width, defaultSelectorSize));
setSelectorStrokeColor(attributes.getColor(R.styleable.CircularImageView_civ_selector_stroke_color, Color.BLUE));
}

// Add shadow if enabled
if(attributes.getBoolean(R.styleable.CircularImageView_shadow, false))
if(attributes.getBoolean(R.styleable.CircularImageView_civ_shadow, false))
setShadow(true);

// We no longer need our attributes TypedArray, give it back to cache
Expand Down Expand Up @@ -415,16 +415,15 @@ public void setIconModeEnabled(boolean e) {}
public void updateBitmapShader() {
if (image == null)
return;
long time = System.currentTimeMillis();
shader = new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

Matrix matrix = new Matrix();
float scale = (float) canvasSize / (float) image.getWidth();
Log.d(TAG, "Scale: " + scale);
matrix.setScale(scale, scale);
shader.setLocalMatrix(matrix);
shader = new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

Log.w(TAG, "updateBitmapShader took " + (System.currentTimeMillis() - time) + "ms");
if(canvasSize != image.getWidth() || canvasSize != image.getHeight()) {
Matrix matrix = new Matrix();
float scale = (float) canvasSize / (float) image.getWidth();
matrix.setScale(scale, scale);
shader.setLocalMatrix(matrix);
}
}

/**
Expand Down
16 changes: 8 additions & 8 deletions circularimageview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
<declare-styleable name="CircularImageView">

<!-- Specifies whether or not to draw a circular border around the image. -->
<attr name="border" format="boolean"></attr>
<attr name="civ_border" format="boolean"/>
<!-- Specifies the color of the border draw around the image. (if enabled) -->
<attr name="border_color" format="color"></attr>
<attr name="civ_border_color" format="color"/>
<!-- Makes the border this pixels wide. (if enabled) -->
<attr name="border_width" format="dimension"></attr>
<attr name="civ_border_width" format="dimension"/>
<!-- Specifies whether or not to draw a selector on this view upon touch events. -->
<attr name="selector" format="boolean"></attr>
<attr name="civ_selector" format="boolean"/>
<!-- Specifies the color of the selector draw on top of the image upon touch events. (if enabled) -->
<attr name="selector_color" format="color"></attr>
<attr name="civ_selector_color" format="color"/>
<!-- Specifies the color of the selector stroke drawn around the image upon touch events. Be sure to provide some opacity. (if enabled) -->
<attr name="selector_stroke_color" format="color"></attr>
<attr name="civ_selector_stroke_color" format="color"/>
<!-- Makes the selector stroke drawn around the image upon touch events this pixels wide. (if enabled) -->
<attr name="selector_stroke_width" format="dimension"></attr>
<attr name="civ_selector_stroke_width" format="dimension"/>
<!-- Specifies whether or not to draw a shadow around your circular image. -->
<attr name="shadow" format="boolean"></attr>
<attr name="civ_shadow" format="boolean"/>
</declare-styleable>

<declare-styleable name="CircularImageViewStyle">
Expand Down

0 comments on commit a74bac7

Please sign in to comment.