Skip to content

Commit 650279d

Browse files
committed
Merge branch 'feature/color_siplification' into develop
2 parents 27abf87 + 78d604d commit 650279d

File tree

6 files changed

+337
-78
lines changed

6 files changed

+337
-78
lines changed

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@ Then select library folder from project. And start use. </p>
77
<p> >=API 8 </p>
88

99
<h2> Reference </h2>
10+
<p> Default image position is left and centered text in button. When image is bigger than half of width, weight automatically is setting to 1. <br>
11+
Only when image is in horizontal position text can be center. </p>
1012
<h3> XML tag's </h3>
1113

1214
This is the base tag of CustomButton:<br>
1315
```xml
14-
<pl.sigmapoint.customview.CustomButton<br>
16+
<pl.sigmapoint.customview.CustomButton
1517
android:id="@+id/sigmapoint_button"
1618
android:layout_width="match_parent"
1719
android:layout_height="match_parent"
1820
android:text="text"/>
1921
```
20-
<p> You can specify the following things:<br>
21-
cb_background - background color of normal button {format - color} - recommended <br>
22+
<p> You can specify the following things:
23+
cb_primary_color - \/
24+
cb_secondary_color - you can specify only two colors for all button. But it will be override by background, text, frame color. {format - color} <br>
25+
cb_background - background color of normal button {format - color} <br>
2226
cb_background_pressed - background color of pressed button {format - color} <br>
2327
cb_background_disabled - background color of disabled button {format - color} <br>
2428
cb_background_state_list - {format - ColorStateList} <br>
@@ -33,6 +37,7 @@ cb_text_padding_top - {format - dimension} <br>
3337
cb_text_padding_right - {format - dimension} <br>
3438
cb_text_padding_bottom - {format - dimension} <br>
3539
cb_text_weight - {format - integer} <br>
40+
cb_text_center or android:textAlignment - only works when image weight doesn't specify. Center text in button. {format - boolean or only "center" value} <br>
3641
<br>
3742
cb_shape_radius - corner radius {format - dimension}<br>
3843
cb_shape_type - shape type, you can choose: rect or oval <br>
@@ -49,6 +54,10 @@ cb_image - image source {format - drawable or color} <br>
4954
cb_image_normal - normal state image source (if you choose cb_image, it will be override) {format - drawable or color} <br>
5055
cb_image_disabled - disabled state image source (if you choose cb_image, it will be override) {format - drawable or color} <br>
5156
cb_image_pressed - pressed state image source (if you choose cb_image, it will be override) {format - drawable or color} <br>
57+
cb_image_color_normal - only for image {format - color} <br>
58+
cb_image_color_pressed - only for image {format - color} <br>
59+
cb_image_color_disable - only for image {format - color} <br>
60+
cb_image_color_list - only for image {format - colorStateList} <br>
5261
cb_image_padding - {format - dimension} <br>
5362
cb_image_padding_left - {format - dimension} <br>
5463
cb_image_padding_top - {format - dimension} <br>
@@ -58,7 +67,10 @@ cb_image_scale_type - {center, center_inside, center_crop, fit_center, fit_start
5867
cb_image_weight - {format - integer} </p>
5968
<h3> Java Code </h3>
6069
```java
61-
CustomButton(Context context, LayoutParams layoutParams, int backgroundColor, int textColor, Drawable icon)
70+
CustomButton(Context context, LayoutParams layoutParams, int primaryColor, int secondaryColor, Drawable icon)
71+
setPrimaryColor(int color)
72+
setSecondaryColor(int color)
73+
setMainColors(int primaryColor, int secondaryColor)
6274
setShapeBackground(int shapeType, int shapeRadius)
6375
setBackgroundColorStateList(ColorStateList colorStateList)
6476
setBackgroundColor(int color)
@@ -74,6 +86,7 @@ setFrameColorDisabled(int color)
7486
setFrameSize(float frameSize)
7587
removeFrame()
7688
setText(String text)
89+
setTextCenter(boolean center)
7790
setTextColor(int color)
7891
setTextColorNormal(int color)
7992
setTextColorPressed(int color)
@@ -84,6 +97,10 @@ setTextPadding(int[] padding) - int[4]{CustomButton.LEFT, CustomButton.TOP, Cust
8497
setTextParams(int weight, int[] padding)
8598
setImage(int position, Drawable drawableNormal, Drawable drawablePressed, Drawable drawableDisabled, ImageView.ScaleType scaleType, int weight, int[] padding)
8699
setImage(int position, Drawable drawable, ImageView.ScaleType scaleType, int weight, int[] padding)
100+
setImageColors(int nomal, int pressed, int disabled)
101+
setImageNormalColor(int color)
102+
setImagePressedColor(int color)
103+
setImageDisableColor(int color)
87104
setElevationEnabled(boolean enabled)
88105
and evry XML tag have getter
89106
```

app/src/main/java/pl/sigmapoint/StartFragment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ private void init() {
9292
enableTB = (ToggleButton) view.findViewById(R.id.enable);
9393

9494
enableTB.setChecked(true);
95+
generateCB.setImageColors(Color.CYAN, Color.GREEN, Color.MAGENTA);
9596

9697
array = new String[4];
9798
array[CustomButton.LEFT] = "Left";
9899
array[CustomButton.TOP] = "Top";
99100
array[CustomButton.RIGHT] = "Right";
100101
array[CustomButton.BOTTOM] = "Bottom";
101102

102-
ArrayAdapter<String> adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item, array);
103+
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, array);
103104
iconPositionS.setAdapter(adapter);
104105

105106
colorPickerDialog = new AmbilWarnaDialog(getActivity(), Color.WHITE, new AmbilWarnaDialog.OnAmbilWarnaListener() {
@@ -165,6 +166,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
165166
bgColorDisabledCB.setEnabled(isChecked);
166167
txtColorDisabledCB.setEnabled(isChecked);
167168
frameColorDisabledCB.setEnabled(isChecked);
169+
generateCB.setEnabled(isChecked);
168170
}
169171
});
170172
}
@@ -241,7 +243,7 @@ private void generate() {
241243
break;
242244
}
243245
}
244-
generatedCB.setImage(position, getResources().getDrawable(R.drawable.ic_owl), ImageView.ScaleType.FIT_CENTER, 1, null);
246+
generatedCB.setImage(position, getResources().getDrawable(R.drawable.ic_owl), ImageView.ScaleType.FIT_CENTER, 0, null);
245247
}
246248
generatedCB.setElevationEnabled(elevationTB.isChecked());
247249
if (getActivity() instanceof MainActivity) {

app/src/main/res/drawable/owl.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="oval">
4+
5+
<solid android:color="@color/red_dark" />
6+
7+
</shape>

app/src/main/res/layout/fragment_start.xml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,12 @@
312312
android:layout_weight="1"
313313
android:padding="2dp"
314314
android:text="@string/generate"
315-
app:cb_background="@color/blue_normal"
316-
app:cb_background_disabled="@color/blue_light"
317-
app:cb_background_pressed="@color/blue_dark"
318-
app:cb_elevation_enabled="true"
319-
app:cb_frame_color="@color/red_normal"
320-
app:cb_frame_color_disabled="@color/red_light"
321-
app:cb_frame_color_pressed="@color/red_dark"
322315
app:cb_frame_size="5dp"
323-
app:cb_shape_radius="5dp"
324-
app:cb_shape_type="rect"
325-
app:cb_text_color="@color/pink_normal"
326-
app:cb_text_color_disabled="@color/pink_light"
327-
app:cb_text_color_pressed="@color/pink_dark"
328-
app:cb_text_padding="5dp"
329-
app:cb_text_size="30dp" />
316+
app:cb_image="@drawable/ic_owl"
317+
app:cb_image_padding="6dp"
318+
app:cb_image_position="left"
319+
app:cb_primary_color="@color/blue_normal"
320+
app:cb_secondary_color="@color/red_normal"
321+
app:cb_shape_radius="5dp" />
330322

331323
</LinearLayout>

0 commit comments

Comments
 (0)