Skip to content
This repository was archived by the owner on Mar 27, 2022. It is now read-only.

Commit 0329724

Browse files
committed
fixed calling deselect() method, changed library package name
1 parent 744933d commit 0329724

File tree

14 files changed

+112
-121
lines changed

14 files changed

+112
-121
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ and:
3636

3737
```gradle
3838
dependencies {
39-
compile 'com.github.ceryle:RadioRealButton:v2.0.5'
39+
compile 'com.github.ceryle:RadioRealButton:v2.0.6'
4040
}
4141
```
4242

@@ -135,7 +135,7 @@ how I have used ImageView in RadioRealButton is no different than regular drawab
135135
##### In Xml Layout
136136

137137
```xml
138-
<co.ceryle.radiorealbutton.library.RadioRealButtonGroup
138+
<co.ceryle.radiorealbutton.RadioRealButtonGroup
139139
android:layout_width="match_parent"
140140
android:layout_height="wrap_content"
141141
app:rrbg_animateDrawables_enter="overshoot"
@@ -146,7 +146,7 @@ how I have used ImageView in RadioRealButton is no different than regular drawab
146146
app:rrbg_selectorColor="@color/red_700"
147147
app:rrbg_selectorSize="6dp">
148148

149-
<co.ceryle.radiorealbutton.library.RadioRealButton
149+
<co.ceryle.radiorealbutton.RadioRealButton
150150
android:layout_width="wrap_content"
151151
android:layout_height="wrap_content"
152152
app:rrb_drawable="@mipmap/ic_launcher"
@@ -158,7 +158,7 @@ how I have used ImageView in RadioRealButton is no different than regular drawab
158158
app:rrb_text="Button 1"
159159
app:rrb_textColor="@color/black"/>
160160

161-
<co.ceryle.radiorealbutton.library.RadioRealButton
161+
<co.ceryle.radiorealbutton.RadioRealButton
162162
android:layout_width="wrap_content"
163163
android:layout_height="wrap_content"
164164
app:rrb_drawable="@mipmap/ic_launcher"
@@ -170,7 +170,7 @@ how I have used ImageView in RadioRealButton is no different than regular drawab
170170
app:rrb_rippleColor="@color/black"
171171
app:rrb_text="Button 2"
172172
app:rrb_textColor="@color/black"/>
173-
</co.ceryle.radiorealbutton.library.RadioRealButtonGroup>
173+
</co.ceryle.radiorealbutton.RadioRealButtonGroup>
174174
```
175175

176176
##### Listener Example

library/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ group = 'com.github.ceryle'
66
android {
77
compileSdkVersion 25
88
buildToolsVersion "25.0.2"
9-
enforceUniquePackageName = false
109

1110
defaultConfig {
1211
minSdkVersion 11

library/src/main/java/co/ceryle/radiorealbutton/library/BackgroundHelper.java renamed to library/src/main/java/co/ceryle/radiorealbutton/BackgroundHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package co.ceryle.radiorealbutton.library;
16+
package co.ceryle.radiorealbutton;
1717

1818
import android.graphics.drawable.Drawable;
1919
import android.os.Build;

library/src/main/java/co/ceryle/radiorealbutton/library/BackgroundView.java renamed to library/src/main/java/co/ceryle/radiorealbutton/BackgroundView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package co.ceryle.radiorealbutton.library;
1+
package co.ceryle.radiorealbutton;
22

33
import android.content.Context;
44
import android.os.Build;

library/src/main/java/co/ceryle/radiorealbutton/library/ConversionHelper.java renamed to library/src/main/java/co/ceryle/radiorealbutton/ConversionHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package co.ceryle.radiorealbutton.library;
16+
package co.ceryle.radiorealbutton;
1717

1818
import android.content.Context;
1919

library/src/main/java/co/ceryle/radiorealbutton/library/RadioRealButton.java renamed to library/src/main/java/co/ceryle/radiorealbutton/RadioRealButton.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package co.ceryle.radiorealbutton.library;
16+
package co.ceryle.radiorealbutton;
1717

1818
import android.annotation.TargetApi;
1919
import android.content.Context;
@@ -22,17 +22,15 @@
2222
import android.graphics.Typeface;
2323
import android.graphics.drawable.Drawable;
2424
import android.os.Build;
25+
import android.support.v7.widget.AppCompatImageView;
26+
import android.support.v7.widget.AppCompatTextView;
2527
import android.util.AttributeSet;
2628
import android.util.TypedValue;
2729
import android.view.Gravity;
2830
import android.view.View;
2931
import android.view.ViewGroup;
3032
import android.view.animation.Interpolator;
31-
import android.widget.ImageView;
3233
import android.widget.LinearLayout;
33-
import android.widget.TextView;
34-
35-
import co.ceryle.radiorealbutton.R;
3634

3735
public class RadioRealButton extends LinearLayout {
3836
public RadioRealButton(Context context) {
@@ -69,22 +67,22 @@ private void init(AttributeSet attrs) {
6967
setPaddingAttrs();
7068
}
7169

72-
private ImageView imageView;
73-
private TextView textView;
70+
private AppCompatImageView imageView;
71+
private AppCompatTextView textView;
7472

7573
private void initViews() {
7674
setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
7775
setOrientation(HORIZONTAL);
7876
setGravity(Gravity.CENTER);
7977

80-
imageView = new ImageView(getContext());
78+
imageView = new AppCompatImageView(getContext());
8179
imageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) {{
8280
gravity = Gravity.CENTER;
8381
}});
8482
setDrawableAttrs();
8583
addView(imageView);
8684

87-
textView = new TextView(getContext());
85+
textView = new AppCompatTextView(getContext());
8886
textView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) {{
8987
gravity = Gravity.CENTER;
9088
}});
@@ -210,7 +208,7 @@ private void setDrawableGravity() {
210208
return;
211209

212210
if (drawableGravity == DrawableGravity.LEFT || drawableGravity == DrawableGravity.TOP) {
213-
if (getChildAt(0) instanceof TextView) {
211+
if (getChildAt(0) instanceof AppCompatTextView) {
214212
removeViewAt(0);
215213
addView(textView, 1);
216214

@@ -221,7 +219,7 @@ private void setDrawableGravity() {
221219
}
222220
}
223221
} else {
224-
if (getChildAt(0) instanceof ImageView) {
222+
if (getChildAt(0) instanceof AppCompatImageView) {
225223
removeViewAt(0);
226224
addView(imageView, 1);
227225

@@ -359,7 +357,7 @@ public boolean isHorizontal() {
359357
/**
360358
* TEXT VIEW
361359
*/
362-
public TextView getTextView() {
360+
public AppCompatTextView getTextView() {
363361
return textView;
364362
}
365363

@@ -467,7 +465,7 @@ private void updatePadding(View view, boolean hasOtherView) {
467465

468466
if (hasOtherView) {
469467
int g = drawableGravity.getIntValue();
470-
if (view instanceof ImageView) {
468+
if (view instanceof AppCompatImageView) {
471469
g = g > 1 ? g - 2 : g + 2;
472470
}
473471
paddings[g] = drawablePadding / 2;
@@ -516,7 +514,7 @@ public boolean hasPaddingBottom() {
516514
/**
517515
* DRAWABLE
518516
*/
519-
public ImageView getImageView() {
517+
public AppCompatImageView getImageView() {
520518
return imageView;
521519
}
522520

library/src/main/java/co/ceryle/radiorealbutton/library/RadioRealButtonGroup.java renamed to library/src/main/java/co/ceryle/radiorealbutton/RadioRealButtonGroup.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package co.ceryle.radiorealbutton.library;
16+
package co.ceryle.radiorealbutton;
1717

1818
import android.animation.AnimatorSet;
1919
import android.animation.ObjectAnimator;
@@ -46,8 +46,6 @@
4646
import java.util.ArrayList;
4747
import java.util.List;
4848

49-
import co.ceryle.radiorealbutton.R;
50-
5149
public class RadioRealButtonGroup extends RoundedCornerLayout {
5250

5351
public RadioRealButtonGroup(Context context) {
@@ -486,8 +484,10 @@ private void makeSelection(int position, boolean isToggledByTouch, boolean hasAn
486484
if (null != buttonOut)
487485
buttonOut.setChecked(false);
488486
} else {
489-
if (lastPosition == position && buttonIn.isChecked())
487+
if (lastPosition == position && buttonIn.isChecked()){
490488
buttonIn.setChecked(false);
489+
position = -1;
490+
}
491491
else
492492
buttonIn.setChecked(true);
493493
}
@@ -592,7 +592,7 @@ private void animateSelectorSliding(int toPosition, String property, boolean has
592592
initialPosition = 0;
593593

594594
View view = v_selectors.get(initialPosition);
595-
view.setTranslationX(-buttons.get(initialPosition).getWidth());
595+
view.setTranslationX(-buttons.get(initialPosition).getMeasuredWidth());
596596
view.setVisibility(VISIBLE);
597597
}
598598

@@ -602,21 +602,19 @@ private void animateSelectorSliding(int toPosition, String property, boolean has
602602

603603
float position = toPosition - initialPosition;
604604

605-
float value = buttons.get(initialPosition).getWidth() * position + dividerSize * position;
605+
float value = buttons.get(initialPosition).getMeasuredWidth() * position + dividerSize * position;
606606
ObjectAnimator animator = createAnimator(v_selectors.get(initialPosition), property, value, false, hasAnimation);
607607
animator.start();
608608
}
609609

610610
public void deselect() {
611-
if(!buttons.get(lastPosition).isChecked())
611+
if (lastPosition == -1 || !buttons.get(lastPosition).isChecked())
612612
return;
613613

614614
if (animationType == ANIM_TRANSLATE_X) {
615615
deselect(lastPosition, true);
616616
} else {
617-
if (lastPosition != -1) {
618-
setPosition(lastPosition);
619-
}
617+
setPosition(lastPosition);
620618
}
621619
}
622620

library/src/main/java/co/ceryle/radiorealbutton/library/RippleHelper.java renamed to library/src/main/java/co/ceryle/radiorealbutton/RippleHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package co.ceryle.radiorealbutton.library;
16+
package co.ceryle.radiorealbutton;
1717

1818
import android.annotation.TargetApi;
1919
import android.content.Context;

library/src/main/java/co/ceryle/radiorealbutton/library/RoundHelper.java renamed to library/src/main/java/co/ceryle/radiorealbutton/RoundHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package co.ceryle.radiorealbutton.library;
16+
package co.ceryle.radiorealbutton;
1717

1818
import android.graphics.drawable.GradientDrawable;
1919
import android.view.View;

library/src/main/java/co/ceryle/radiorealbutton/library/RoundedCornerLayout.java renamed to library/src/main/java/co/ceryle/radiorealbutton/RoundedCornerLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* I extended this by adding border.
1111
*/
12-
package co.ceryle.radiorealbutton.library;
12+
package co.ceryle.radiorealbutton;
1313

1414
import android.annotation.TargetApi;
1515
import android.content.Context;

sample/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ apply plugin: 'com.android.application'
33
android {
44
compileSdkVersion 25
55
buildToolsVersion "25.0.2"
6-
enforceUniquePackageName = false
76

87
defaultConfig {
9-
applicationId "co.ceryle.radiorealbutton"
8+
applicationId "co.ceryle.radiorealbutton.sample"
109
minSdkVersion 11
1110
targetSdkVersion 25
1211
versionCode 1

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest package="co.ceryle.radiorealbutton"
2+
<manifest package="co.ceryle.radiorealbutton.sample"
33
xmlns:android="http://schemas.android.com/apk/res/android">
44

55
<application

sample/src/main/java/co/ceryle/radiorealbutton/MainActivity.java renamed to sample/src/main/java/co/ceryle/radiorealbutton/sample/MainActivity.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package co.ceryle.radiorealbutton;
16+
package co.ceryle.radiorealbutton.sample;
1717

1818
import android.support.v7.app.AppCompatActivity;
1919
import android.os.Bundle;
2020
import android.view.View;
2121
import android.widget.Button;
2222
import android.widget.Toast;
2323

24-
import co.ceryle.radiorealbutton.library.RadioRealButton;
25-
import co.ceryle.radiorealbutton.library.RadioRealButtonGroup;
24+
import co.ceryle.radiorealbutton.RadioRealButton;
25+
import co.ceryle.radiorealbutton.RadioRealButtonGroup;
2626

2727
public class MainActivity extends AppCompatActivity {
2828

@@ -40,9 +40,9 @@ protected void onCreate(Bundle savedInstanceState) {
4040
button.setTransformationMethod(null);
4141
updateText(group1.getPosition());
4242

43-
group1.setOnClickedButtonListener(new RadioRealButtonGroup.OnClickedButtonListener() {
43+
group1.setOnPositionChangedListener(new RadioRealButtonGroup.OnPositionChangedListener() {
4444
@Override
45-
public void onClickedButton(RadioRealButton button, int position) {
45+
public void onPositionChanged(RadioRealButton button, int position) {
4646
updateText(position);
4747
}
4848
});
@@ -61,16 +61,14 @@ public void onClick(View v) {
6161
int position = group1.getPosition();
6262
position = ++position % group1.getNumberOfButtons();
6363
group1.setPosition(position);
64-
65-
updateText(position);
6664
}
6765
});
6866

6967
RadioRealButtonGroup group2 = (RadioRealButtonGroup) findViewById(R.id.radioRealButtonGroup_2);
7068
group2.setOnPositionChangedListener(new RadioRealButtonGroup.OnPositionChangedListener() {
7169
@Override
7270
public void onPositionChanged(RadioRealButton button, int position) {
73-
Toast.makeText(MainActivity.this, "Id: " + position, Toast.LENGTH_SHORT).show();
71+
Toast.makeText(MainActivity.this, "Position: " + position, Toast.LENGTH_SHORT).show();
7472
}
7573
});
7674
}

0 commit comments

Comments
 (0)