Skip to content

Commit

Permalink
feat: changeable arrow size.
Browse files Browse the repository at this point in the history
  • Loading branch information
VuNgN committed Jan 17, 2025
1 parent 6c1e03a commit 807dd07
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 15 deletions.
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,20 @@ Whether you're building a game of chance, a prize wheel, or a fun decision-makin
In the layout:

```xml
<com.vungn.luckywheel.LuckyWheel
android:id="@+id/lwv"
android:layout_width="400dp"
android:layout_height="400dp"
android:layout_gravity="center"
android:background="@drawable/ig_edge_1"
app:arrow_image="@drawable/ig_arrow_1"
app:shadow_src="@drawable/ig_shadow_1"
app:border_color="#33FFFFFF"
app:border_width="30dp"
app:font_family="@font/roboto_bold"
app:text_padding="10dp" />
<com.vungn.luckywheel.LuckyWheel
android:id="@+id/lwv"
android:layout_width="400dp"
android:layout_height="400dp"
android:layout_gravity="center"
android:background="@drawable/ig_edge_1"
app:arrow_height="50dp"
app:arrow_width="50dp"
app:arrow_image="@drawable/ig_arrow_1"
app:shadow_src="@drawable/ig_shadow_1"
app:border_color="#33FFFFFF"
app:border_width="30dp"
app:font_family="@font/roboto_bold"
app:text_padding="10dp" />
```

In code:
Expand Down Expand Up @@ -168,6 +170,9 @@ lw.rotateWheelTo(randomNum)
| `setWheelPadding()` | `Int` | Set the border width. |
| `setWheelShadow()` | `Int`: resource of image</br> `Bitmap`: bitmap of image | Set the shadow image. |
| `setArrowImage()` | `Int`: resource of image</br> `Bitmap`: bitmap of image</br>`Drawable`: drawable of image | Set the arrow image. |
| `setArrowWidth()` | `Int` | Set the width of the arrow. |
| `setArrowHeight()` | `Int` | Set the height of the arrow. |
| `setArrowSize()` | (`Int`, `Int`): width, height | Set the size of the arrow. |
| `setTextPadding()` | `Int` | Set the padding between text and edge for all slices. |
| `setTextSize()` | `Float` | Set text size for all slices. |
| `setFontFamily()` | `Int`: resource of font | Set the font family for all slices. |
Expand Down Expand Up @@ -208,6 +213,8 @@ val item = WheelItem(
| Border width | `app:border_width` | `setWheelPadding()` | `None` |
| Shadow | `app:shadow_src` | `setWheelShadow()` | `None` |
| Arrow image | `app:arrow_image` | `setArrowImage()` | <img src="https://github.com/user-attachments/assets/dad494a5-25eb-4272-89e1-9582427d688e" alt="" width="40" height="50" /> |
| Arrow width | `app:arrow_width` | `setArrowWidth()` | `50dp` |
| Arrow height | `app:arrow_height` | `setArrowHeight()` | `50dp` |
| Padding between text and edge | `app:text_padding` | `setTextPadding()` | `0` |
| Text size | `app:text_size` | `setTextSize()` | `15sp`|
| Font family | `app:font_family` | `setFontFamily()` | `None` |
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/layout/item_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
android:layout_height="400dp"
android:layout_gravity="center"
android:background="@drawable/ig_edge_1"
LuckyWheel:arrow_height="50dp"
LuckyWheel:arrow_width="50dp"
LuckyWheel:arrow_image="@drawable/ig_arrow_1"
LuckyWheel:shadow_src="@drawable/ig_shadow_1"
LuckyWheel:border_color="#33FFFFFF"
LuckyWheel:border_width="30dp"
LuckyWheel:font_family="@font/roboto_bold"
LuckyWheel:shadow_src="@drawable/ig_shadow_1"
LuckyWheel:text_padding="10dp" />

<LinearLayout
Expand Down
33 changes: 33 additions & 0 deletions luckywheel/src/main/java/com/vungn/luckywheel/LuckyWheel.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public void applyAttribute(AttributeSet attrs) {
int borderWidth = typedArray.getDimensionPixelSize(R.styleable.LuckyWheel_border_width, getDpOf(20));
int shadowSrc = typedArray.getResourceId(R.styleable.LuckyWheel_shadow_src, 0);
int arrowImage = typedArray.getResourceId(R.styleable.LuckyWheel_arrow_image, R.drawable.ig_arrow);
int arrowWidth = typedArray.getDimensionPixelSize(R.styleable.LuckyWheel_arrow_width, getDpOf(50));
int arrowHeight = typedArray.getDimensionPixelSize(R.styleable.LuckyWheel_arrow_height, getDpOf(50));
int imagePadding = typedArray.getDimensionPixelSize(R.styleable.LuckyWheel_image_padding, 0);
int textPadding = typedArray.getDimensionPixelSize(R.styleable.LuckyWheel_text_padding, 0);
int textSize = typedArray.getDimensionPixelSize(R.styleable.LuckyWheel_text_size, getDpOf(15));
Expand All @@ -80,6 +82,8 @@ public void applyAttribute(AttributeSet attrs) {
wheelView.setItemsTextSize(textSize);
wheelView.setItemsFontFamily(ResourcesCompat.getFont(getContext(), fontFamily));
arrow.setImageResource(arrowImage);
arrow.getLayoutParams().width = arrowWidth;
arrow.getLayoutParams().height = arrowHeight;
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -158,6 +162,35 @@ public void setArrowImage(Bitmap arrowImage) {
arrow.setImageBitmap(arrowImage);
}

/**
* Function to set arrow width of wheel
*
* @param width arrow width
*/
public void setArrowWidth(int width) {
arrow.getLayoutParams().width = width;
}

/**
* Function to set arrow height of wheel
*
* @param height arrow height
*/
public void setArrowHeight(int height) {
arrow.getLayoutParams().height = height;
}

/**
* Function to set arrow size of wheel
*
* @param width arrow width
* @param height arrow height
*/
public void setArrowSize(int width, int height) {
arrow.getLayoutParams().width = width;
arrow.getLayoutParams().height = height;
}

/**
* Function to set text padding of wheel items
*
Expand Down
4 changes: 2 additions & 2 deletions luckywheel/src/main/res/layout/lucky_wheel_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<ImageView
android:id="@+id/iv_arrow"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:contentDescription="@string/spin_arrow"
android:src="@drawable/ig_arrow" />
Expand Down
2 changes: 2 additions & 0 deletions luckywheel/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<attr name="border_width" format="dimension" />
<attr name="shadow_src" format="reference" />
<attr name="arrow_image" format="reference" />
<attr name="arrow_height" format="dimension" />
<attr name="arrow_width" format="dimension" />
<attr name="square_layout" format="boolean" />
<attr name="image_padding" format="dimension" />
<attr name="text_padding" format="dimension" />
Expand Down

0 comments on commit 807dd07

Please sign in to comment.