Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added attribute for text color change #99

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}

Expand All @@ -21,10 +26,17 @@ allprojects {
group = GROUP

repositories {
google()
jcenter()

mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

Expand Down
1 change: 1 addition & 0 deletions demo/src/main/res/layout/fragment_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal"
segmentedgroup:sc_text_color="@color/radio_button_text_color"
segmentedgroup:sc_border_width="1dp"
segmentedgroup:sc_corner_radius="5dp"
segmentedgroup:sc_tint_color="#009688">
Expand Down
1 change: 0 additions & 1 deletion demo/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="radio_button_selected_color">#ff33b5e5</color>
<color name="radio_button_unselected_color">@android:color/transparent</color>
</resources>
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
5 changes: 3 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:23.2.0'
}

apply plugin: 'com.github.dcendents.android-maven'
// Used to push in maven
apply from: '../maven_push.gradle'
//apply from: '../maven_push.gradle'
group='com.github.MuhammadTouseeq'
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class SegmentedGroup extends RadioGroup {
private int mMarginDp;
private Resources resources;
private int mTintColor;
private int mTextColor;
private int mUnCheckedTintColor;
private int mCheckedTextColor = Color.WHITE;
private LayoutSelector mLayoutSelector;
Expand All @@ -39,6 +40,7 @@ public SegmentedGroup(Context context) {
super(context);
resources = getResources();
mTintColor = resources.getColor(R.color.radio_button_selected_color);
mTextColor = resources.getColor(R.color.radio_button_text_color);
mUnCheckedTintColor = resources.getColor(R.color.radio_button_unselected_color);
mMarginDp = (int) getResources().getDimension(R.dimen.radio_button_stroke_border);
mCornerRadius = getResources().getDimension(R.dimen.radio_button_conner_radius);
Expand All @@ -49,6 +51,8 @@ public SegmentedGroup(Context context, AttributeSet attrs) {
super(context, attrs);
resources = getResources();
mTintColor = resources.getColor(R.color.radio_button_selected_color);
mTextColor = resources.getColor(R.color.radio_button_text_color);

mUnCheckedTintColor = resources.getColor(R.color.radio_button_unselected_color);
mMarginDp = (int) getResources().getDimension(R.dimen.radio_button_stroke_border);
mCornerRadius = getResources().getDimension(R.dimen.radio_button_conner_radius);
Expand All @@ -75,7 +79,9 @@ private void initAttrs(AttributeSet attrs) {
mTintColor = typedArray.getColor(
R.styleable.SegmentedGroup_sc_tint_color,
getResources().getColor(R.color.radio_button_selected_color));

mTextColor = typedArray.getColor(
R.styleable.SegmentedGroup_sc_text_color,
getResources().getColor(R.color.radio_button_text_color));
mCheckedTextColor = typedArray.getColor(
R.styleable.SegmentedGroup_sc_checked_text_color,
getResources().getColor(android.R.color.white));
Expand Down Expand Up @@ -140,7 +146,7 @@ private void updateBackground(View view) {
ColorStateList colorStateList = new ColorStateList(new int[][]{
{-android.R.attr.state_checked},
{android.R.attr.state_checked}},
new int[]{mTintColor, mCheckedTextColor});
new int[]{mTextColor, mCheckedTextColor});
((Button) view).setTextColor(colorStateList);

//Redraw with tint color
Expand All @@ -158,7 +164,7 @@ private void updateBackground(View view) {
maskDrawable.setStroke(mMarginDp, mTintColor);
maskDrawable.setColor(mUnCheckedTintColor);
maskDrawable.setCornerRadii(mLayoutSelector.getChildRadii(view));
int maskColor = Color.argb(50, Color.red(mTintColor), Color.green(mTintColor), Color.blue(mTintColor));
int maskColor = Color.argb(50, Color.red(mTintColor), Color.green(mTintColor), Color.blue(mTintColor));
maskDrawable.setColor(maskColor);
LayerDrawable pressedDrawable = new LayerDrawable(new Drawable[] {uncheckedDrawable, maskDrawable});

Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<attr name="sc_corner_radius" format="dimension" />
<attr name="sc_border_width" format="dimension" />
<attr name="sc_tint_color" format="color" />
<attr name="sc_text_color" format="color" />
<attr name="sc_checked_text_color" format="color" />
<attr name="sc_unchecked_tint_color" format="color"/>
</declare-styleable>
Expand Down
4 changes: 3 additions & 1 deletion library/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="radio_button_selected_color">#ff33b5e5</color>
<color name="radio_button_unselected_color">#e0e0e0</color>
<color name="radio_button_unselected_color">#ffffff</color>
<color name="radio_button_text_color">#000000</color>

</resources>