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

Commit

Permalink
fixed calling deselect() method, changed library package name
Browse files Browse the repository at this point in the history
  • Loading branch information
ceryle committed May 2, 2017
1 parent 744933d commit 0329724
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 121 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ and:

```gradle
dependencies {
compile 'com.github.ceryle:RadioRealButton:v2.0.5'
compile 'com.github.ceryle:RadioRealButton:v2.0.6'
}
```

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

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

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

<co.ceryle.radiorealbutton.library.RadioRealButton
<co.ceryle.radiorealbutton.RadioRealButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:rrb_drawable="@mipmap/ic_launcher"
Expand All @@ -170,7 +170,7 @@ how I have used ImageView in RadioRealButton is no different than regular drawab
app:rrb_rippleColor="@color/black"
app:rrb_text="Button 2"
app:rrb_textColor="@color/black"/>
</co.ceryle.radiorealbutton.library.RadioRealButtonGroup>
</co.ceryle.radiorealbutton.RadioRealButtonGroup>
```

##### Listener Example
Expand Down
1 change: 0 additions & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ group = 'com.github.ceryle'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
enforceUniquePackageName = false

defaultConfig {
minSdkVersion 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package co.ceryle.radiorealbutton.library;
package co.ceryle.radiorealbutton;

import android.graphics.drawable.Drawable;
import android.os.Build;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.ceryle.radiorealbutton.library;
package co.ceryle.radiorealbutton;

import android.content.Context;
import android.os.Build;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package co.ceryle.radiorealbutton.library;
package co.ceryle.radiorealbutton;

import android.content.Context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package co.ceryle.radiorealbutton.library;
package co.ceryle.radiorealbutton;

import android.annotation.TargetApi;
import android.content.Context;
Expand All @@ -22,17 +22,15 @@
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import co.ceryle.radiorealbutton.R;

public class RadioRealButton extends LinearLayout {
public RadioRealButton(Context context) {
Expand Down Expand Up @@ -69,22 +67,22 @@ private void init(AttributeSet attrs) {
setPaddingAttrs();
}

private ImageView imageView;
private TextView textView;
private AppCompatImageView imageView;
private AppCompatTextView textView;

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

imageView = new ImageView(getContext());
imageView = new AppCompatImageView(getContext());
imageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) {{
gravity = Gravity.CENTER;
}});
setDrawableAttrs();
addView(imageView);

textView = new TextView(getContext());
textView = new AppCompatTextView(getContext());
textView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) {{
gravity = Gravity.CENTER;
}});
Expand Down Expand Up @@ -210,7 +208,7 @@ private void setDrawableGravity() {
return;

if (drawableGravity == DrawableGravity.LEFT || drawableGravity == DrawableGravity.TOP) {
if (getChildAt(0) instanceof TextView) {
if (getChildAt(0) instanceof AppCompatTextView) {
removeViewAt(0);
addView(textView, 1);

Expand All @@ -221,7 +219,7 @@ private void setDrawableGravity() {
}
}
} else {
if (getChildAt(0) instanceof ImageView) {
if (getChildAt(0) instanceof AppCompatImageView) {
removeViewAt(0);
addView(imageView, 1);

Expand Down Expand Up @@ -359,7 +357,7 @@ public boolean isHorizontal() {
/**
* TEXT VIEW
*/
public TextView getTextView() {
public AppCompatTextView getTextView() {
return textView;
}

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

if (hasOtherView) {
int g = drawableGravity.getIntValue();
if (view instanceof ImageView) {
if (view instanceof AppCompatImageView) {
g = g > 1 ? g - 2 : g + 2;
}
paddings[g] = drawablePadding / 2;
Expand Down Expand Up @@ -516,7 +514,7 @@ public boolean hasPaddingBottom() {
/**
* DRAWABLE
*/
public ImageView getImageView() {
public AppCompatImageView getImageView() {
return imageView;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package co.ceryle.radiorealbutton.library;
package co.ceryle.radiorealbutton;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
Expand Down Expand Up @@ -46,8 +46,6 @@
import java.util.ArrayList;
import java.util.List;

import co.ceryle.radiorealbutton.R;

public class RadioRealButtonGroup extends RoundedCornerLayout {

public RadioRealButtonGroup(Context context) {
Expand Down Expand Up @@ -486,8 +484,10 @@ private void makeSelection(int position, boolean isToggledByTouch, boolean hasAn
if (null != buttonOut)
buttonOut.setChecked(false);
} else {
if (lastPosition == position && buttonIn.isChecked())
if (lastPosition == position && buttonIn.isChecked()){
buttonIn.setChecked(false);
position = -1;
}
else
buttonIn.setChecked(true);
}
Expand Down Expand Up @@ -592,7 +592,7 @@ private void animateSelectorSliding(int toPosition, String property, boolean has
initialPosition = 0;

View view = v_selectors.get(initialPosition);
view.setTranslationX(-buttons.get(initialPosition).getWidth());
view.setTranslationX(-buttons.get(initialPosition).getMeasuredWidth());
view.setVisibility(VISIBLE);
}

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

float position = toPosition - initialPosition;

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

public void deselect() {
if(!buttons.get(lastPosition).isChecked())
if (lastPosition == -1 || !buttons.get(lastPosition).isChecked())
return;

if (animationType == ANIM_TRANSLATE_X) {
deselect(lastPosition, true);
} else {
if (lastPosition != -1) {
setPosition(lastPosition);
}
setPosition(lastPosition);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package co.ceryle.radiorealbutton.library;
package co.ceryle.radiorealbutton;

import android.annotation.TargetApi;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package co.ceryle.radiorealbutton.library;
package co.ceryle.radiorealbutton;

import android.graphics.drawable.GradientDrawable;
import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* I extended this by adding border.
*/
package co.ceryle.radiorealbutton.library;
package co.ceryle.radiorealbutton;

import android.annotation.TargetApi;
import android.content.Context;
Expand Down
3 changes: 1 addition & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
enforceUniquePackageName = false

defaultConfig {
applicationId "co.ceryle.radiorealbutton"
applicationId "co.ceryle.radiorealbutton.sample"
minSdkVersion 11
targetSdkVersion 25
versionCode 1
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="co.ceryle.radiorealbutton"
<manifest package="co.ceryle.radiorealbutton.sample"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package co.ceryle.radiorealbutton;
package co.ceryle.radiorealbutton.sample;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import co.ceryle.radiorealbutton.library.RadioRealButton;
import co.ceryle.radiorealbutton.library.RadioRealButtonGroup;
import co.ceryle.radiorealbutton.RadioRealButton;
import co.ceryle.radiorealbutton.RadioRealButtonGroup;

public class MainActivity extends AppCompatActivity {

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

group1.setOnClickedButtonListener(new RadioRealButtonGroup.OnClickedButtonListener() {
group1.setOnPositionChangedListener(new RadioRealButtonGroup.OnPositionChangedListener() {
@Override
public void onClickedButton(RadioRealButton button, int position) {
public void onPositionChanged(RadioRealButton button, int position) {
updateText(position);
}
});
Expand All @@ -61,16 +61,14 @@ public void onClick(View v) {
int position = group1.getPosition();
position = ++position % group1.getNumberOfButtons();
group1.setPosition(position);

updateText(position);
}
});

RadioRealButtonGroup group2 = (RadioRealButtonGroup) findViewById(R.id.radioRealButtonGroup_2);
group2.setOnPositionChangedListener(new RadioRealButtonGroup.OnPositionChangedListener() {
@Override
public void onPositionChanged(RadioRealButton button, int position) {
Toast.makeText(MainActivity.this, "Id: " + position, Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "Position: " + position, Toast.LENGTH_SHORT).show();
}
});
}
Expand Down
Loading

0 comments on commit 0329724

Please sign in to comment.