Skip to content

Commit

Permalink
Add checkedButton attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3z committed Aug 17, 2018
1 parent 78de6ca commit b9b192a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ org.gradle.jvmargs=-Xmx1536m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

PUBLISH_VERSION=1.0.0
PUBLISH_VERSION=1.1.7
USER_ORG=nex3z
GROUP_ID=com.nex3z
ARTIFACT_ID=toggle-button-group
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ public MultiSelectToggleGroup(Context context, AttributeSet attrs) {
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if (mInitialCheckedId != View.NO_ID) {
setCheckedStateForView(mInitialCheckedId, true);
int initialCheckedId = mInitialCheckedId != View.NO_ID ?
mInitialCheckedId : mSilentInitialCheckedId;
if (initialCheckedId != View.NO_ID) {
setCheckedStateForView(initialCheckedId, true);
}
}

@Override
protected <T extends View & Checkable> void onChildCheckedChange(T child, boolean isChecked) {
checkSelectCount();
notifyCheckedStateChange(child.getId(), isChecked);

if (mSilentInitialCheckedId == child.getId()) {
mSilentInitialCheckedId = View.NO_ID;
} else {
notifyCheckedStateChange(child.getId(), isChecked);
}
}

public void check(int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public SingleSelectToggleGroup(Context context, AttributeSet attrs) {
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if (mInitialCheckedId != View.NO_ID) {
setCheckedStateForView(mInitialCheckedId, true);
setCheckedId(mInitialCheckedId);
int initialCheckedId = mInitialCheckedId != View.NO_ID ?
mInitialCheckedId : mSilentInitialCheckedId;
if (initialCheckedId != View.NO_ID) {
setCheckedStateForView(initialCheckedId, true);
setCheckedId(initialCheckedId, false);
}
}

Expand Down Expand Up @@ -58,7 +60,12 @@ protected <T extends View & Checkable> void onChildCheckedChange(T child, boolea
setCheckedStateForView(mCheckedId, false);
}
int id = child.getId();
setCheckedId(id);
if (mSilentInitialCheckedId == id) {
mSilentInitialCheckedId = View.NO_ID;
setCheckedId(id, false);
} else {
setCheckedId(id);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public abstract class ToggleButtonGroup extends FlowLayout {
private static final String LOG_TAG = ToggleButtonGroup.class.getSimpleName();

protected int mInitialCheckedId = View.NO_ID;
protected int mSilentInitialCheckedId = View.NO_ID;
private OnCheckedChangeListener mCheckedStateTracker;
private CompoundButton.OnCheckedChangeListener mCompoundButtonStateTracker;
private PassThroughHierarchyChangeListener mPassThroughListener;
Expand All @@ -35,6 +36,8 @@ public ToggleButtonGroup(Context context, AttributeSet attrs) {
try {
mInitialCheckedId = a.getResourceId(R.styleable.ToggleButtonGroup_tbgCheckedButton,
View.NO_ID);
mSilentInitialCheckedId = a.getResourceId(
R.styleable.ToggleButtonGroup_android_checkedButton, View.NO_ID);
} finally {
a.recycle();
}
Expand Down
1 change: 1 addition & 0 deletions togglebuttongroup/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</declare-styleable>

<declare-styleable name="ToggleButtonGroup">
<attr name="android:checkedButton"/>
<attr name="tbgCheckedButton" format="reference"/>
</declare-styleable>

Expand Down

0 comments on commit b9b192a

Please sign in to comment.