diff --git a/README.md b/README.md
index e3ab187..70329fe 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,7 @@ Copy(or merge) below files into corresponding file/folder:
+ res/drawable-v14/*
+ res/values/colors.xml
+ res/values/dimens.xml
+ + res/values/attrs.xml
+ res/values/styles.xml (only RadioButton style)
Usage
@@ -52,15 +53,28 @@ Define in xml like this and make sure that the `RadioButton`'s style is: `@style
```
+Attributes
+----------
+
+* ```app:tint_color``` (color)
+* ```app:checked_color``` (color)
+* ```app:pressed_tint_color``` (color)
+* ```app:pressed_stroke_color``` (color)
+* ```app:text_color``` (color)
+* ```app:pressed_text_color``` (color)
+
You also can be change the tint color and title color when button is checked by `setTintColor` method.
+Also you can change the pressed tint color by `setPressedTintColor` method.
Here is sample code:
```java
SegmentedGroup segmented2 = (SegmentedGroup) rootView.findViewById(R.id.segmented2);
segmented2.setTintColor(Color.DKGRAY);
+segmented2.setPressedTintColor(Color.LTGRAY, Color.DKGRAY);
SegmentedGroup segmented3 = (SegmentedGroup) rootView.findViewById(R.id.segmented3);
segmented3.setTintColor(Color.parseColor("#FFD0FF3C"), Color.parseColor("#FF7B07B2"));
+segmented3.setPressedTintColor(Color.parseColor("#DDD0FF3C"), Color.parseColor("#FFD0FF3C"));
SegmentedGroup segmented4 = (SegmentedGroup) rootView.findViewById(R.id.segmented4);
segmented4.setTintColor(getResources().getColor(R.color.radio_button_selected_color));
diff --git a/build.gradle b/build.gradle
index 1879c21..aca5742 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,7 +8,7 @@ buildscript {
}
}
dependencies {
- classpath 'com.android.tools.build:gradle:0.11.+'
+ classpath 'com.android.tools.build:gradle:0.13.2'
}
}
diff --git a/demo/build.gradle b/demo/build.gradle
index 2771750..d9a329d 100644
--- a/demo/build.gradle
+++ b/demo/build.gradle
@@ -3,7 +3,7 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:0.11.+'
+ classpath 'com.android.tools.build:gradle:0.13.2'
}
}
@@ -30,6 +30,7 @@ android {
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
- compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'info.hoang8f:android-segmented:1.0.2'
+ compile fileTree(include: ['*.jar'], dir: 'libs')
+ // compile 'info.hoang8f:android-segmented:1.0.2'
+ compile project(':library')
}
diff --git a/demo/src/main/java/info/hoang8f/mymo/segmented/demo/SampleActivity.java b/demo/src/main/java/info/hoang8f/mymo/segmented/demo/SampleActivity.java
index 0b8ce3f..fb391db 100644
--- a/demo/src/main/java/info/hoang8f/mymo/segmented/demo/SampleActivity.java
+++ b/demo/src/main/java/info/hoang8f/mymo/segmented/demo/SampleActivity.java
@@ -45,19 +45,20 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
SegmentedGroup segmented2 = (SegmentedGroup) rootView.findViewById(R.id.segmented2);
segmented2.setTintColor(Color.DKGRAY);
+ segmented2.setPressedTintColor(Color.LTGRAY, Color.DKGRAY);
SegmentedGroup segmented3 = (SegmentedGroup) rootView.findViewById(R.id.segmented3);
//Tint color, and text color when checked
segmented3.setTintColor(Color.parseColor("#FFD0FF3C"), Color.parseColor("#FF7B07B2"));
-
+ segmented3.setPressedTintColor(Color.parseColor("#DDD0FF3C"), Color.parseColor("#FFD0FF3C"));
SegmentedGroup segmented4 = (SegmentedGroup) rootView.findViewById(R.id.segmented4);
- segmented4.setTintColor(getResources().getColor(R.color.radio_button_selected_color));
+ segmented4.setTintColor(getResources().getColor(R.color.ios_color));
segmented5 = (SegmentedGroup) rootView.findViewById(R.id.segmented5);
Button addBtn = (Button) rootView.findViewById(R.id.add_segmented);
Button removeBtn = (Button) rootView.findViewById(R.id.remove_segmented);
- //Set listencer for button
+ //Set listener for button
addBtn.setOnClickListener(this);
removeBtn.setOnClickListener(this);
@@ -107,10 +108,10 @@ public void onClick(View v) {
switch (v.getId()) {
case R.id.add_segmented:
addButton(segmented5);
- return;
+ break;
case R.id.remove_segmented:
removeButton(segmented5);
- return;
+ break;
}
}
diff --git a/demo/src/main/res/layout/fragment_sample.xml b/demo/src/main/res/layout/fragment_sample.xml
index c49dfa3..0ee95dd 100644
--- a/demo/src/main/res/layout/fragment_sample.xml
+++ b/demo/src/main/res/layout/fragment_sample.xml
@@ -1,188 +1,196 @@
-
+ android:layout_height="match_parent">
-
+ android:orientation="vertical"
+ tools:context="info.hoang8f.android.segmented.SampleActivity$PlaceholderFragment">
-
+ android:background="#ffffff"
+ android:gravity="center"
+ android:minHeight="80dp">
-
+ android:layout_margin="10dp"
+ app:tint_color="@color/ios_color"
+ android:orientation="horizontal">
-
-
+
-
+
+
-
-
-
-
-
-
+ android:background="#ffb1ff69"
+ android:gravity="center"
+ android:minHeight="80dp">
-
-
-
-
-
-
-
-
-
-
-
-
+ android:layout_margin="10dp"
+ android:orientation="horizontal">
-
+
+
+
+
-
+
-
-
-
-
-
+ android:background="#FF7B07B2"
+ android:gravity="center"
+ android:minHeight="80dp">
-
-
-
-
+ android:layout_margin="10dp"
+ android:orientation="horizontal">
-
+
+
+
+
+
+
-
+
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="#ffffff"
+ android:gravity="center"
+ android:minHeight="80dp">
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
+
+
+
+ android:orientation="horizontal">
+
+
+
+
+
-
+
diff --git a/demo/src/main/res/values/colors.xml b/demo/src/main/res/values/colors.xml
index 5b96dbd..8953171 100644
--- a/demo/src/main/res/values/colors.xml
+++ b/demo/src/main/res/values/colors.xml
@@ -1,5 +1,6 @@
- #ff33b5e5
+ #ff0088ff
+
@android:color/transparent
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index affd2cd..36aee06 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Mon Jun 09 14:18:32 JST 2014
+#Wed Nov 26 12:00:34 CET 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
diff --git a/library/src/main/java/info/hoang8f/android/segmented/SegmentedGroup.java b/library/src/main/java/info/hoang8f/android/segmented/SegmentedGroup.java
index 2349f82..bf2b0de 100644
--- a/library/src/main/java/info/hoang8f/android/segmented/SegmentedGroup.java
+++ b/library/src/main/java/info/hoang8f/android/segmented/SegmentedGroup.java
@@ -1,12 +1,15 @@
package info.hoang8f.android.segmented;
+import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
+import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;
+import android.graphics.drawable.TransitionDrawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.TypedValue;
@@ -20,19 +23,43 @@ public class SegmentedGroup extends RadioGroup {
private Resources resources;
private int mTintColor;
private int mCheckedTextColor = Color.WHITE;
+ private int mPressedTintColor;
+ private int mPressedStrokeColor;
public SegmentedGroup(Context context) {
super(context);
- resources = getResources();
- mTintColor = resources.getColor(R.color.radio_button_selected_color);
- oneDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, resources.getDisplayMetrics());
+ init(context, null);
+// resources = getResources();
+// mTintColor = resources.getColor(R.color.radio_button_selected_color);
+// oneDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, resources.getDisplayMetrics());
}
public SegmentedGroup(Context context, AttributeSet attrs) {
super(context, attrs);
+ init(context, attrs);
+// resources = getResources();
+// mTintColor = resources.getColor(R.color.radio_button_selected_color);
+// oneDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, resources.getDisplayMetrics());
+ }
+
+
+ private void init(Context context, AttributeSet attrs) {
resources = getResources();
- mTintColor = resources.getColor(R.color.radio_button_selected_color);
+ mTintColor = resources.getColor(R.color.ios_blue);
+ mCheckedTextColor = Color.WHITE;
+ mPressedTintColor = resources.getColor(R.color.ios_blue_pressed);
+ mPressedStrokeColor = resources.getColor(R.color.ios_blue);
+
+ if (attrs != null) {
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SegmentedGroup);
+ mTintColor = a.getColor(R.styleable.SegmentedGroup_tint_color, resources.getColor(R.color.ios_blue));
+ mCheckedTextColor = a.getColor(R.styleable.SegmentedGroup_checked_color, Color.WHITE);
+ mPressedTintColor = a.getColor(R.styleable.SegmentedGroup_pressed_tint_color, resources.getColor(R.color.ios_blue_pressed));
+ mPressedStrokeColor = a.getColor(R.styleable.SegmentedGroup_pressed_stroke_color, resources.getColor(R.color.ios_blue));
+ }
+
oneDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, resources.getDisplayMetrics());
+
}
@Override
@@ -53,49 +80,71 @@ public void setTintColor(int tintColor, int checkedTextColor) {
updateBackground();
}
+ public void setPressedTintColor(int pressedTintColor) {
+ mPressedTintColor = pressedTintColor;
+ updateBackground();
+ }
+
+ public void setPressedTintColor(int pressedTintColor, int pressedStrokeColor) {
+ mPressedTintColor = pressedTintColor;
+ mPressedStrokeColor = pressedStrokeColor;
+ updateBackground();
+ }
+
public void updateBackground() {
int count = super.getChildCount();
if (count > 1) {
- View child = getChildAt(0);
- LayoutParams initParams = (LayoutParams) child.getLayoutParams();
+ View childFirst = getChildAt(0);
+ LayoutParams initParams = (LayoutParams) childFirst.getLayoutParams();
LayoutParams params = new LayoutParams(initParams.width, initParams.height, initParams.weight);
params.setMargins(0, 0, -oneDP, 0);
- child.setLayoutParams(params);
- updateBackground(getChildAt(0), R.drawable.radio_checked_left, R.drawable.radio_unchecked_left);
+ childFirst.setLayoutParams(params);
+ updateBackground(getChildAt(0), R.drawable.radio_checked_left, R.drawable.radio_unchecked_left,
+ R.drawable.radio_pressed_left);
for (int i = 1; i < count - 1; i++) {
- updateBackground(getChildAt(i), R.drawable.radio_checked_middle, R.drawable.radio_unchecked_middle);
- View child2 = getChildAt(i);
- initParams = (LayoutParams) child2.getLayoutParams();
+ updateBackground(getChildAt(i), R.drawable.radio_checked_middle, R.drawable.radio_unchecked_middle,
+ R.drawable.radio_pressed_middle);
+ View childMiddle = getChildAt(i);
+ initParams = (LayoutParams) childMiddle.getLayoutParams();
params = new LayoutParams(initParams.width, initParams.height, initParams.weight);
params.setMargins(0, 0, -oneDP, 0);
- child2.setLayoutParams(params);
+ childMiddle.setLayoutParams(params);
}
- updateBackground(getChildAt(count - 1), R.drawable.radio_checked_right, R.drawable.radio_unchecked_right);
+ updateBackground(getChildAt(count - 1), R.drawable.radio_checked_right, R.drawable.radio_unchecked_right,
+ R.drawable.radio_pressed_right);
} else if (count == 1) {
- updateBackground(getChildAt(0), R.drawable.radio_checked_default, R.drawable.radio_unchecked_default);
+ updateBackground(getChildAt(0), R.drawable.radio_checked_default, R.drawable.radio_unchecked_default,
+ R.drawable.radio_pressed_default);
}
}
- private void updateBackground(View view, int checked, int unchecked) {
+
+ private void updateBackground(View view, int checked, int unchecked, int pressed) {
//Set text color
ColorStateList colorStateList = new ColorStateList(new int[][]{
- {android.R.attr.state_pressed},
+// {android.R.attr.state_pressed},
{-android.R.attr.state_pressed, -android.R.attr.state_checked},
- {-android.R.attr.state_pressed, android.R.attr.state_checked}},
- new int[]{Color.GRAY, mTintColor, mCheckedTextColor});
+ {android.R.attr.state_pressed, -android.R.attr.state_checked},
+ {-android.R.attr.state_pressed, android.R.attr.state_checked},
+ {android.R.attr.state_pressed, android.R.attr.state_checked}},
+ new int[]{mTintColor, mTintColor, mCheckedTextColor, mCheckedTextColor});
((Button) view).setTextColor(colorStateList);
//Redraw with tint color
Drawable checkedDrawable = resources.getDrawable(checked).mutate();
Drawable uncheckedDrawable = resources.getDrawable(unchecked).mutate();
+ Drawable pressedDrawable = resources.getDrawable(pressed).mutate();
((GradientDrawable) checkedDrawable).setColor(mTintColor);
((GradientDrawable) uncheckedDrawable).setStroke(oneDP, mTintColor);
+ ((GradientDrawable) pressedDrawable).setColor(mPressedTintColor);
+ ((GradientDrawable) pressedDrawable).setStroke(oneDP, mPressedStrokeColor);
//Create drawable
StateListDrawable stateListDrawable = new StateListDrawable();
- stateListDrawable.addState(new int[]{-android.R.attr.state_checked}, uncheckedDrawable);
+// stateListDrawable.addState(new int[]{}, transitionDrawable);
stateListDrawable.addState(new int[]{android.R.attr.state_checked}, checkedDrawable);
-
+ stateListDrawable.addState(new int[]{-android.R.attr.state_pressed, -android.R.attr.state_checked}, uncheckedDrawable);
+ stateListDrawable.addState(new int[]{android.R.attr.state_pressed, -android.R.attr.state_checked}, pressedDrawable);
//Set button background
if (Build.VERSION.SDK_INT >= 16) {
view.setBackground(stateListDrawable);
@@ -103,4 +152,7 @@ private void updateBackground(View view, int checked, int unchecked) {
view.setBackgroundDrawable(stateListDrawable);
}
}
+
+
+
}
diff --git a/library/src/main/res/drawable-v14/radio_checked_left.xml b/library/src/main/res/drawable-v14/radio_checked_left.xml
index c269cc6..d157c5c 100644
--- a/library/src/main/res/drawable-v14/radio_checked_left.xml
+++ b/library/src/main/res/drawable-v14/radio_checked_left.xml
@@ -3,10 +3,12 @@
android:shape="rectangle"
android:padding="10dp">
-
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable-v14/radio_checked_right.xml b/library/src/main/res/drawable-v14/radio_checked_right.xml
index 24ceeca..e7b3eee 100644
--- a/library/src/main/res/drawable-v14/radio_checked_right.xml
+++ b/library/src/main/res/drawable-v14/radio_checked_right.xml
@@ -3,7 +3,7 @@
android:shape="rectangle"
android:padding="10dp">
-
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable-v14/radio_pressed_right.xml b/library/src/main/res/drawable-v14/radio_pressed_right.xml
new file mode 100644
index 0000000..21cdfd4
--- /dev/null
+++ b/library/src/main/res/drawable-v14/radio_pressed_right.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable-v14/radio_unchecked_left.xml b/library/src/main/res/drawable-v14/radio_unchecked_left.xml
index bd6a63a..f187c0b 100644
--- a/library/src/main/res/drawable-v14/radio_unchecked_left.xml
+++ b/library/src/main/res/drawable-v14/radio_unchecked_left.xml
@@ -11,5 +11,5 @@
android:topRightRadius="0.1dp" />
+ android:color="@color/ios_blue" />
\ No newline at end of file
diff --git a/library/src/main/res/drawable-v14/radio_unchecked_right.xml b/library/src/main/res/drawable-v14/radio_unchecked_right.xml
index c29f425..5859d56 100644
--- a/library/src/main/res/drawable-v14/radio_unchecked_right.xml
+++ b/library/src/main/res/drawable-v14/radio_unchecked_right.xml
@@ -11,5 +11,5 @@
android:topRightRadius="@dimen/radio_button_conner_radius" />
+ android:color="@color/ios_blue" />
\ No newline at end of file
diff --git a/library/src/main/res/drawable/button_text_color.xml b/library/src/main/res/drawable/button_text_color.xml
index 4ec1dcc..2f7d07b 100644
--- a/library/src/main/res/drawable/button_text_color.xml
+++ b/library/src/main/res/drawable/button_text_color.xml
@@ -1,7 +1,8 @@
-
-
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/radio_checked_default.xml b/library/src/main/res/drawable/radio_checked_default.xml
index 1f0f8af..6883321 100644
--- a/library/src/main/res/drawable/radio_checked_default.xml
+++ b/library/src/main/res/drawable/radio_checked_default.xml
@@ -3,7 +3,7 @@
android:shape="rectangle"
android:padding="10dp">
-
+
-
+
+
+
-
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/radio_checked_right.xml b/library/src/main/res/drawable/radio_checked_right.xml
index 0c2900f..49c6426 100644
--- a/library/src/main/res/drawable/radio_checked_right.xml
+++ b/library/src/main/res/drawable/radio_checked_right.xml
@@ -3,7 +3,8 @@
android:shape="rectangle"
android:padding="10dp">
-
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/radio_pressed_left.xml b/library/src/main/res/drawable/radio_pressed_left.xml
new file mode 100644
index 0000000..b918efe
--- /dev/null
+++ b/library/src/main/res/drawable/radio_pressed_left.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/radio_pressed_middle.xml b/library/src/main/res/drawable/radio_pressed_middle.xml
new file mode 100644
index 0000000..b1f2286
--- /dev/null
+++ b/library/src/main/res/drawable/radio_pressed_middle.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/radio_pressed_right.xml b/library/src/main/res/drawable/radio_pressed_right.xml
new file mode 100644
index 0000000..0f81ee7
--- /dev/null
+++ b/library/src/main/res/drawable/radio_pressed_right.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/radio_unchecked_default.xml b/library/src/main/res/drawable/radio_unchecked_default.xml
index 261ccc0..6d84088 100644
--- a/library/src/main/res/drawable/radio_unchecked_default.xml
+++ b/library/src/main/res/drawable/radio_unchecked_default.xml
@@ -11,5 +11,7 @@
android:topRightRadius="@dimen/radio_button_conner_radius" />
+ android:color="@color/ios_blue" />
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/radio_unchecked_left.xml b/library/src/main/res/drawable/radio_unchecked_left.xml
index 940c46f..be089e3 100644
--- a/library/src/main/res/drawable/radio_unchecked_left.xml
+++ b/library/src/main/res/drawable/radio_unchecked_left.xml
@@ -11,5 +11,8 @@
android:topRightRadius="0.1dp" />
+ android:color="@color/ios_blue"/>
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/radio_unchecked_middle.xml b/library/src/main/res/drawable/radio_unchecked_middle.xml
index de98a07..fb524c0 100644
--- a/library/src/main/res/drawable/radio_unchecked_middle.xml
+++ b/library/src/main/res/drawable/radio_unchecked_middle.xml
@@ -6,5 +6,5 @@
+ android:color="@color/ios_blue" />
\ No newline at end of file
diff --git a/library/src/main/res/drawable/radio_unchecked_right.xml b/library/src/main/res/drawable/radio_unchecked_right.xml
index 4049a4c..483e1d5 100644
--- a/library/src/main/res/drawable/radio_unchecked_right.xml
+++ b/library/src/main/res/drawable/radio_unchecked_right.xml
@@ -11,5 +11,5 @@
android:topRightRadius="@dimen/radio_button_conner_radius" />
+ android:color="@color/ios_blue" />
\ No newline at end of file
diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml
new file mode 100644
index 0000000..25a4ac7
--- /dev/null
+++ b/library/src/main/res/values/attrs.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/values/colors.xml b/library/src/main/res/values/colors.xml
index 5b96dbd..28ed27d 100644
--- a/library/src/main/res/values/colors.xml
+++ b/library/src/main/res/values/colors.xml
@@ -1,5 +1,8 @@
+ #ff0088ff
+ #DDE9F6
#ff33b5e5
@android:color/transparent
+
\ No newline at end of file