From 546c488d520382315014b15e61414b6f6659f3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=9B=AA=E5=90=9B?= Date: Mon, 26 Oct 2015 15:25:22 +0800 Subject: [PATCH 1/5] change: add border color. --- demo/src/main/res/layout/fragment_sample.xml | 8 ++-- library/build.gradle | 8 ++-- .../android/segmented/SegmentedGroup.java | 45 ++++++++----------- library/src/main/res/values/attrs.xml | 3 +- 4 files changed, 26 insertions(+), 38 deletions(-) diff --git a/demo/src/main/res/layout/fragment_sample.xml b/demo/src/main/res/layout/fragment_sample.xml index ea5a81c..0368468 100644 --- a/demo/src/main/res/layout/fragment_sample.xml +++ b/demo/src/main/res/layout/fragment_sample.xml @@ -25,8 +25,7 @@ android:orientation="horizontal" segmentedgroup:sc_border_width="1dp" segmentedgroup:sc_corner_radius="10dp" - segmentedgroup:sc_tint_color="#FFEB3B" - segmentedgroup:sc_checked_text_color="#7C4DFF"> + segmentedgroup:sc_tint_color="#FFEB3B"> + segmentedgroup:sc_tint_color="@android:color/white" > @@ -213,4 +211,4 @@ - \ No newline at end of file + diff --git a/library/build.gradle b/library/build.gradle index fc605ec..c7eb24b 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'android-library' android { - compileSdkVersion 21 - buildToolsVersion "22.0.1" + compileSdkVersion 23 + buildToolsVersion "23.0.1" defaultConfig { minSdkVersion 8 - targetSdkVersion 21 + targetSdkVersion 23 versionCode 1 versionName "1.0" } @@ -23,4 +23,4 @@ dependencies { } // Used to push in maven -apply from: '../maven_push.gradle' +//apply from: '../maven_push.gradle' 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 cfdcb39..3b85020 100644 --- a/library/src/main/java/info/hoang8f/android/segmented/SegmentedGroup.java +++ b/library/src/main/java/info/hoang8f/android/segmented/SegmentedGroup.java @@ -4,15 +4,15 @@ 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.os.Build; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.util.AttributeSet; import android.util.TypedValue; import android.view.View; -import android.widget.Button; import android.widget.LinearLayout; import android.widget.RadioGroup; @@ -21,7 +21,7 @@ public class SegmentedGroup extends RadioGroup { private int mMarginDp; private Resources resources; private int mTintColor; - private int mCheckedTextColor = Color.WHITE; + private ColorStateList mBorderColor; private LayoutSelector mLayoutSelector; private Float mCornerRadius; @@ -46,18 +46,13 @@ private void initAttrs(AttributeSet attrs) { R.styleable.SegmentedGroup_sc_border_width, getResources().getDimension(R.dimen.radio_button_stroke_border)); - mCornerRadius = typedArray.getDimension( - R.styleable.SegmentedGroup_sc_corner_radius, - getResources().getDimension(R.dimen.radio_button_conner_radius)); + mCornerRadius = typedArray.getDimension(R.styleable.SegmentedGroup_sc_corner_radius, + getResources().getDimension(R.dimen.radio_button_conner_radius)); - mTintColor = typedArray.getColor( - R.styleable.SegmentedGroup_sc_tint_color, - getResources().getColor(R.color.radio_button_selected_color)); - - mCheckedTextColor = typedArray.getColor( - R.styleable.SegmentedGroup_sc_checked_text_color, - getResources().getColor(android.R.color.white)); + mTintColor = typedArray.getColor(R.styleable.SegmentedGroup_sc_tint_color, + getResources().getColor(R.color.radio_button_selected_color)); + mBorderColor = typedArray.getColorStateList(R.styleable.SegmentedGroup_sc_border_color); } finally { typedArray.recycle(); } @@ -85,9 +80,8 @@ public void setTintColor(int tintColor) { updateBackground(); } - public void setTintColor(int tintColor, int checkedTextColor) { - mTintColor = tintColor; - mCheckedTextColor = checkedTextColor; + public void setBorderColor(ColorStateList color) { + mBorderColor = color; updateBackground(); } @@ -115,20 +109,17 @@ public void updateBackground() { private void updateBackground(View view) { int checked = mLayoutSelector.getSelected(); int unchecked = mLayoutSelector.getUnselected(); - //Set text color - ColorStateList colorStateList = new ColorStateList(new int[][]{ - {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}); - ((Button) view).setTextColor(colorStateList); - //Redraw with tint color Drawable checkedDrawable = resources.getDrawable(checked).mutate(); Drawable uncheckedDrawable = resources.getDrawable(unchecked).mutate(); ((GradientDrawable) checkedDrawable).setColor(mTintColor); - ((GradientDrawable) checkedDrawable).setStroke(mMarginDp, mTintColor); - ((GradientDrawable) uncheckedDrawable).setStroke(mMarginDp, mTintColor); + if (null != mBorderColor && VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { + ((GradientDrawable) uncheckedDrawable).setStroke(mMarginDp, mBorderColor); + ((GradientDrawable) checkedDrawable).setStroke(mMarginDp, mBorderColor); + } else { + ((GradientDrawable) checkedDrawable).setStroke(mMarginDp, mTintColor); + ((GradientDrawable) uncheckedDrawable).setStroke(mMarginDp, mTintColor); + } //Set proper radius ((GradientDrawable) checkedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view)); ((GradientDrawable) uncheckedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view)); @@ -231,4 +222,4 @@ public float[] getChildRadii(View view) { return radii; } } -} \ No newline at end of file +} diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 315db4d..ea1ed15 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -3,8 +3,7 @@ + - - From 28bfb1695e7bf12fd01ce90023c53e3adcbdf12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=9B=AA=E5=90=9B?= Date: Mon, 26 Oct 2015 15:49:12 +0800 Subject: [PATCH 2/5] change: make unvisibale work. --- .../android/segmented/SegmentedGroup.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) 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 3b85020..1de354d 100644 --- a/library/src/main/java/info/hoang8f/android/segmented/SegmentedGroup.java +++ b/library/src/main/java/info/hoang8f/android/segmented/SegmentedGroup.java @@ -85,14 +85,38 @@ public void setBorderColor(ColorStateList color) { updateBackground(); } + private int getLastVisibleIndex() { + for (int i = getChildCount() - 1; i >= 0; i--) { + if (getChildAt(i).getVisibility() == VISIBLE) { + return i; + } + } + return 0; + } + + private int getFirstVisibleIndex() { + int count = getChildCount(); + for (int i = 0; i < count; i++) { + if (getChildAt(i).getVisibility() == VISIBLE) { + return i; + } + } + return count - 1; + } + public void updateBackground() { int count = super.getChildCount(); + int lastVisible = getLastVisibleIndex(); + for (int i = 0; i < count; i++) { View child = getChildAt(i); - updateBackground(child); + if (child.getVisibility() == VISIBLE) { + updateBackground(child); + } // If this is the last view, don't set LayoutParams - if (i == count - 1) break; + if (i == lastVisible) + break; LayoutParams initParams = (LayoutParams) child.getLayoutParams(); LayoutParams params = new LayoutParams(initParams.width, initParams.height, initParams.weight); @@ -195,9 +219,9 @@ private void setChildRadii(int newChildren, int newChild) { // if there is only one child provide the default radio button if (children == 1) { radii = rDefault; - } else if (child == 0) { //left or top + } else if (child == getFirstVisibleIndex()) { //left or top radii = (getOrientation() == LinearLayout.HORIZONTAL) ? rLeft : rTop; - } else if (child == children - 1) { //right or bottom + } else if (child == getLastVisibleIndex()) { //right or bottom radii = (getOrientation() == LinearLayout.HORIZONTAL) ? rRight : rBot; } else { //middle radii = rMiddle; From 2bb19a05564954b84a98b5b619c8cbb010673208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=9B=AA=E5=90=9B?= Date: Mon, 26 Oct 2015 16:00:23 +0800 Subject: [PATCH 3/5] change: Removing redundant LayoutParam creation. --- .../java/info/hoang8f/android/segmented/SegmentedGroup.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 1de354d..f2e821d 100644 --- a/library/src/main/java/info/hoang8f/android/segmented/SegmentedGroup.java +++ b/library/src/main/java/info/hoang8f/android/segmented/SegmentedGroup.java @@ -118,8 +118,7 @@ public void updateBackground() { if (i == lastVisible) break; - LayoutParams initParams = (LayoutParams) child.getLayoutParams(); - LayoutParams params = new LayoutParams(initParams.width, initParams.height, initParams.weight); + LayoutParams params = (LayoutParams) child.getLayoutParams(); // Check orientation for proper margins if (getOrientation() == LinearLayout.HORIZONTAL) { params.setMargins(0, 0, -mMarginDp, 0); @@ -127,6 +126,7 @@ public void updateBackground() { params.setMargins(0, 0, 0, -mMarginDp); } child.setLayoutParams(params); + child.requestLayout(); } } From 3e38fe921ec4fac8a983a2eea1f174c27e46452b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=9B=AA=E5=90=9B?= Date: Fri, 4 Dec 2015 18:03:54 +0800 Subject: [PATCH 4/5] =?UTF-8?q?change:=20=E6=9B=B4=E6=96=B0Gradle.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++-- demo/build.gradle | 10 +++++----- library/build.gradle | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 40c5c5e..9c34adb 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:1.0.1' + classpath 'com.android.tools.build:gradle:1.3.0' } } @@ -29,4 +29,4 @@ allprojects { } } -apply plugin: 'android-reporting' \ No newline at end of file +apply plugin: 'android-reporting' diff --git a/demo/build.gradle b/demo/build.gradle index a6c8220..05699ff 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -3,18 +3,18 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:1.0.1' + classpath 'com.android.tools.build:gradle:1.3.0' } } apply plugin: 'com.android.application' android { - compileSdkVersion 21 - buildToolsVersion '22.0.1' + compileSdkVersion 23 + buildToolsVersion '23.0.2' defaultConfig { minSdkVersion 8 - targetSdkVersion 21 + targetSdkVersion 23 versionCode 1 versionName '1.0' } @@ -29,7 +29,7 @@ android { } dependencies { - compile 'com.android.support:appcompat-v7:22.0.0' + compile 'com.android.support:appcompat-v7:23.1.1' compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':library') // compile 'info.hoang8f:android-segmented:1.0.6' diff --git a/library/build.gradle b/library/build.gradle index c7eb24b..d27fc98 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,8 +1,8 @@ -apply plugin: 'android-library' +apply plugin: 'com.android.library' android { compileSdkVersion 23 - buildToolsVersion "23.0.1" + buildToolsVersion "23.0.2" defaultConfig { minSdkVersion 8 From 212b29660dd3ce40452912f0b0f819e408949e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=9B=AA=E5=90=9B?= Date: Thu, 18 Feb 2016 10:27:30 +0800 Subject: [PATCH 5/5] =?UTF-8?q?change:=20=E5=B0=86=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E6=8F=90=E5=8F=96=E5=88=B0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 +++-- demo/build.gradle | 14 ++++++++------ gradle.properties.sample | 30 ++++++++++++++++++++++++++++++ library/build.gradle | 8 ++++---- 4 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 gradle.properties.sample diff --git a/build.gradle b/build.gradle index 9c34adb..b0f1be8 100644 --- a/build.gradle +++ b/build.gradle @@ -2,13 +2,14 @@ buildscript { repositories { + mavenLocal() mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots" } } dependencies { - classpath 'com.android.tools.build:gradle:1.3.0' + classpath project.ANDROID_GRADLE_TOOLS_VERSION } } @@ -21,8 +22,8 @@ allprojects { group = GROUP repositories { - mavenCentral() mavenLocal() + mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots" } diff --git a/demo/build.gradle b/demo/build.gradle index 05699ff..4fed5f7 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -3,21 +3,23 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:1.3.0' + classpath project.ANDROID_GRADLE_TOOLS_VERSION } } apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion '23.0.2' + compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION) + buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION + defaultConfig { - minSdkVersion 8 - targetSdkVersion 23 + minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION) + targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION) versionCode 1 - versionName '1.0' + versionName "1.0" } + buildTypes { release { minifyEnabled false diff --git a/gradle.properties.sample b/gradle.properties.sample new file mode 100644 index 0000000..7bc6511 --- /dev/null +++ b/gradle.properties.sample @@ -0,0 +1,30 @@ +## Project-wide Gradle settings. +# +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +#Wed Feb 17 08:14:49 CST 2016 + +# 代理配置 +systemProp.http.proxyHost=127.0.0.1 +systemProp.http.proxyPort=1080 + +# Gradle 插件版本 +ANDROID_GRADLE_TOOLS_VERSION=com.android.tools.build:gradle:2.0.0-beta4 +# 编译SDK版本 +ANDROID_BUILD_SDK_VERSION=23 +# 编译目标SDK版本 +ANDROID_BUILD_TARGET_SDK_VERSION=23 +# 最小支持SDK版本 +ANDROID_BUILD_MIN_SDK_VERSION=10 +# Android编译工具版本 +ANDROID_BUILD_TOOLS_VERSION=23.0.2 diff --git a/library/build.gradle b/library/build.gradle index d27fc98..1937e08 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 23 - buildToolsVersion "23.0.2" + compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION) + buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION defaultConfig { - minSdkVersion 8 - targetSdkVersion 23 + minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION) + targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION) versionCode 1 versionName "1.0" }