Skip to content

Commit ee7d6f1

Browse files
committed
Add more javadocs
1 parent 0be1ca7 commit ee7d6f1

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-13
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ android {
66

77
defaultConfig {
88
applicationId "com.savvyapps.togglebuttonlayout.sample"
9-
minSdkVersion 15
9+
minSdkVersion 16
1010
targetSdkVersion rootProject.ext.targetSdkVersion
1111
versionCode 1
1212
versionName "1.0"

app/src/main/java/com/savvyapps/togglebuttonlayout/sample/ToggleButtonLayoutActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public void onClick(View v) {
3636
}
3737
});
3838

39-
toggleButtonLayout.setOnToggleSelectedListener(new ToggleButtonLayout.OnToggleSelectedListener() {
39+
toggleButtonLayout.setOnToggleSelectedListener(new ToggleButtonLayout.OnToggledListener() {
4040
@Override
41-
public void onToggleSelected(Toggle toggle, boolean selected) {
41+
public void onToggled(Toggle toggle, boolean selected) {
4242
Snackbar.make(root, "Toggle " + toggle.getId() + " selected state " + selected, Snackbar.LENGTH_LONG)
4343
.show();
4444
}

togglebuttonlayout/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ android {
55
buildToolsVersion rootProject.ext.buildToolsVersion
66

77
defaultConfig {
8-
minSdkVersion 15
8+
minSdkVersion 16
99
targetSdkVersion rootProject.ext.targetSdkVersion
1010
versionCode 1
1111
versionName "1.0"

togglebuttonlayout/src/main/java/com/savvyapps/togglebuttonlayout/Toggle.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.savvyapps.togglebuttonlayout;
22

33
import android.graphics.drawable.Drawable;
4-
import android.support.annotation.NonNull;
4+
import android.support.annotation.Nullable;
55

66
/**
77
* An item within a {@link ToggleButtonLayout}
@@ -13,7 +13,7 @@ public class Toggle {
1313
private CharSequence title;
1414
protected boolean selected;
1515

16-
public Toggle(int id, @NonNull Drawable icon, @NonNull CharSequence title) {
16+
public Toggle(int id, @Nullable Drawable icon, @Nullable CharSequence title) {
1717
if (id == 0) {
1818
throw new IllegalArgumentException("Toggle must have a non-zero id");
1919
}
@@ -22,10 +22,18 @@ public Toggle(int id, @NonNull Drawable icon, @NonNull CharSequence title) {
2222
this.title = title;
2323
}
2424

25+
/**
26+
* The ID provided within the Toggle
27+
* @return id
28+
*/
2529
public int getId() {
2630
return id;
2731
}
2832

33+
/**
34+
* The icon drawable inflated by the menu resource or passed during creation
35+
* @return the icon
36+
*/
2937
public Drawable getIcon() {
3038
return icon;
3139
}
@@ -34,6 +42,10 @@ public CharSequence getTitle() {
3442
return title;
3543
}
3644

45+
/**
46+
* The selection state of the toggle
47+
* @return true if toggle is selected, false otherwise
48+
*/
3749
public boolean isSelected() {
3850
return selected;
3951
}

togglebuttonlayout/src/main/java/com/savvyapps/togglebuttonlayout/ToggleButtonLayout.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ public class ToggleButtonLayout extends CardView {
3838

3939
@Retention(SOURCE)
4040
@IntDef({MODE_WRAP, MODE_EVEN})
41-
public @interface Mode {
41+
@interface Mode {
4242
}
4343

44+
/**
45+
* Toggles will wrap content. Default
46+
*/
4447
public static final int MODE_WRAP = 0;
48+
49+
/**
50+
* Toggles will be evenly distributed within view
51+
*/
4552
public static final int MODE_EVEN = 1;
4653

4754
private LinearLayout linearLayout;
@@ -59,7 +66,7 @@ public class ToggleButtonLayout extends CardView {
5966
@Mode
6067
private int mode;
6168
//callbacks
62-
private OnToggleSelectedListener listener;
69+
private OnToggledListener listener;
6370

6471
private OnClickListener onClickListener = new OnClickListener() {
6572
@Override
@@ -73,7 +80,7 @@ public void onClick(View v) {
7380
} else {
7481
setToggled(toggle.getId(), !toggle.selected);
7582
if (listener != null) {
76-
listener.onToggleSelected(toggle, toggle.selected);
83+
listener.onToggled(toggle, toggle.selected);
7784
}
7885
}
7986
}
@@ -148,7 +155,7 @@ public void inflateMenu(@MenuRes int menuId) {
148155
*
149156
* @param toggle the toggle to add
150157
*/
151-
public void addToggle(Toggle toggle) {
158+
public void addToggle(@NonNull Toggle toggle) {
152159
toggles.add(toggle);
153160
ToggleView toggleView = new ToggleView(getContext(), toggle, layoutRes);
154161
toggleView.setOnClickListener(onClickListener);
@@ -171,7 +178,7 @@ public void addToggle(Toggle toggle) {
171178
*
172179
* @param listener listener
173180
*/
174-
public void setOnToggleSelectedListener(OnToggleSelectedListener listener) {
181+
public void setOnToggleSelectedListener(OnToggledListener listener) {
175182
this.listener = listener;
176183
}
177184

@@ -204,6 +211,11 @@ public void reset() {
204211
}
205212
}
206213

214+
/**
215+
* Manually set the toggled state of the specified toggle. This will not notify any {@link OnToggledListener}
216+
* @param toggleId the id of the toggle
217+
* @param toggled true if should be toggled on, false otherwise
218+
*/
207219
public void setToggled(int toggleId, boolean toggled) {
208220
for (Toggle toggle : toggles) {
209221
if (toggle.getId() == toggleId) {
@@ -223,6 +235,10 @@ public void setToggled(int toggleId, boolean toggled) {
223235
}
224236
}
225237

238+
/**
239+
* Get a list of selected toggles
240+
* @return the selected toggles
241+
*/
226242
@NonNull
227243
public List<Toggle> getSelectedToggles() {
228244
List<Toggle> selectedToggles = new ArrayList<>();
@@ -247,6 +263,7 @@ private void toggleState(Toggle toggle) {
247263
/**
248264
* Default view for Toggle
249265
*/
266+
@SuppressLint("ViewConstructor")
250267
static class ToggleView extends FrameLayout {
251268

252269
Toggle toggle;
@@ -279,7 +296,16 @@ public ToggleView(Context context, Toggle toggle, @Nullable @LayoutRes Integer l
279296
}
280297
}
281298

282-
public interface OnToggleSelectedListener {
283-
void onToggleSelected(Toggle toggle, boolean selected);
299+
/**
300+
* Listener for when a toggle is toggled
301+
*/
302+
public interface OnToggledListener {
303+
304+
/**
305+
* The toggle has been toggled
306+
* @param toggle the toggle
307+
* @param selected true if selected, false if unselected
308+
*/
309+
void onToggled(Toggle toggle, boolean selected);
284310
}
285311
}

0 commit comments

Comments
 (0)