Skip to content

Commit bee24bb

Browse files
committed
Change color of disabled state.
1 parent b5a9cc5 commit bee24bb

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
165165
bgColorDisabledCB.setEnabled(isChecked);
166166
txtColorDisabledCB.setEnabled(isChecked);
167167
frameColorDisabledCB.setEnabled(isChecked);
168+
generateCB.setEnabled(isChecked);
168169
}
169170
});
170171
}

library/src/main/java/pl/sigmapoint/customview/CustomButton.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ public class CustomButton extends LinearLayout implements View.OnClickListener {
3333
private final int COLOR_INDEX_PRESSED = 0;
3434
private final int COLOR_INDEX_NORMAL = 1;
3535
private final int COLOR_INDEX_DISABLED = 2;
36-
private final int[][] stateArray = new int[][]{new int[]{android.R.attr.state_pressed}, new int[]{android.R.attr.state_enabled}, new int[]{}}; //array for support states
36+
private final int[][] stateArray = new int[][]{new int[]{android.R.attr.state_pressed}, new int[]{android.R.attr.state_enabled}, new int[]{}}; //array for support states DON'T TOUCH THIS
3737

3838
protected TextView textView; //text container
3939
protected LinearLayout container; //all content container
4040
protected ImageView imageContainer;
4141

4242
private int primaryColor, secondaryColor;
43+
private int primaryColorLight, secondaryColorLight;
4344
private int backgroundColorPressed, backgroundColorDisabled, backgroundColorNormal; // colors for each backgroundColorNormal state
4445
private ColorStateList backgroundColorState; // color state list for backgroundColorNormal
4546
private int textColorPressed, textColorDisabled, textColorNormal; // colors for each text color state
@@ -86,17 +87,8 @@ public CustomButton(Context context, ViewGroup.LayoutParams params, int primaryC
8687

8788
this.drawableNormal = imageNormal;
8889

89-
this.backgroundColorNormal = primaryColor;
90-
this.backgroundColorPressed = secondaryColor;
91-
this.backgroundColorDisabled = secondaryColor;
92-
93-
this.textColorNormal = secondaryColor;
94-
this.textColorDisabled = primaryColor;
95-
this.textColorPressed = primaryColor;
96-
97-
this.frameColorNormal = secondaryColor;
98-
this.frameColorPressed = primaryColor;
99-
this.frameColorDisabled = primaryColor;
90+
updatePrimaryColor(primaryColor);
91+
updateSecondaryColor(secondaryColor);
10092

10193
this.shapeType = 0;
10294
this.shapeRadius = 0;
@@ -127,12 +119,12 @@ public CustomButton(Context context, AttributeSet attrs) {
127119

128120
backgroundColorNormal = attributes.getColor(R.styleable.CustomButton_cb_background, primaryColor);
129121
backgroundColorPressed = attributes.getColor(R.styleable.CustomButton_cb_background_pressed, secondaryColor);
130-
backgroundColorDisabled = attributes.getColor(R.styleable.CustomButton_cb_background_disabled, secondaryColor);
122+
backgroundColorDisabled = attributes.getColor(R.styleable.CustomButton_cb_background_disabled, lighterColor(primaryColor));
131123
backgroundColorState = attributes.getColorStateList(R.styleable.CustomButton_cb_background_state_list);
132124

133125
textColorNormal = attributes.getColor(R.styleable.CustomButton_cb_text_color, secondaryColor);
134126
textColorPressed = attributes.getColor(R.styleable.CustomButton_cb_text_color_pressed, primaryColor);
135-
textColorDisabled = attributes.getColor(R.styleable.CustomButton_cb_text_color_disabled, primaryColor);
127+
textColorDisabled = attributes.getColor(R.styleable.CustomButton_cb_text_color_disabled, lighterColor(secondaryColor));
136128
textColorState = attributes.getColorStateList(R.styleable.CustomButton_android_textColor);
137129
textSize = attributes.getDimension(R.styleable.CustomButton_cb_text_size, 0);
138130
text = attributes.getString(R.styleable.CustomButton_android_text);
@@ -147,7 +139,7 @@ public CustomButton(Context context, AttributeSet attrs) {
147139
shapeTypeAttr = attributes.getInt(R.styleable.CustomButton_cb_shape_type, 0);
148140
frameColorNormal = attributes.getColor(R.styleable.CustomButton_cb_frame_color, secondaryColor);
149141
frameColorPressed = attributes.getColor(R.styleable.CustomButton_cb_frame_color_pressed, primaryColor);
150-
frameColorDisabled = attributes.getColor(R.styleable.CustomButton_cb_frame_color_disabled, primaryColor);
142+
frameColorDisabled = attributes.getColor(R.styleable.CustomButton_cb_frame_color_disabled, lighterColor(secondaryColor));
151143
frameColorState = attributes.getColorStateList(R.styleable.CustomButton_cb_frame_state_list);
152144
frameSize = attributes.getDimension(R.styleable.CustomButton_cb_frame_size, 0);
153145

@@ -402,26 +394,36 @@ private void updateText() {
402394
private void updatePrimaryColor(int color) {
403395

404396
this.primaryColor = color;
397+
this.primaryColorLight = lighterColor(color);
405398

406399
this.backgroundColorNormal = color;
407-
408-
this.textColorDisabled = color;
409400
this.textColorPressed = color;
410-
411401
this.frameColorPressed = color;
412-
this.frameColorDisabled = color;
402+
this.textColorDisabled = primaryColorLight;
403+
this.frameColorDisabled = primaryColorLight;
413404
}
414405

415406
private void updateSecondaryColor(int color) {
416407

417408
this.secondaryColor = color;
409+
this.secondaryColorLight = lighterColor(color);
418410

419411
this.backgroundColorPressed = color;
420-
this.backgroundColorDisabled = color;
421-
422412
this.textColorNormal = color;
423-
424413
this.frameColorNormal = color;
414+
this.backgroundColorDisabled = secondaryColorLight;
415+
}
416+
417+
private int lighterColor(int color) {
418+
419+
int redPC = Color.red(color);
420+
int greenPC = Color.green(color);
421+
int blueRC = Color.blue(color);
422+
float hsv[] = new float[3];
423+
424+
Color.RGBToHSV(redPC, greenPC, blueRC, hsv);
425+
hsv[1] = (hsv[1] - 0.3f) < 0 ? 0.1f : hsv[1] - 0.3f;
426+
return Color.HSVToColor(hsv);
425427
}
426428

427429

0 commit comments

Comments
 (0)