Skip to content

Commit 221ba81

Browse files
Merge pull request #168 from tom-beardedhen/master
Fixed bugs and implemented Material icons, progress bar group
2 parents 14abd26 + 430e6b7 commit 221ba81

33 files changed

+4892
-189
lines changed
Binary file not shown.

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/AwesomeTextView.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.beardedhen.androidbootstrap.api.view.BootstrapTextView;
2121
import com.beardedhen.androidbootstrap.font.FontAwesome;
2222
import com.beardedhen.androidbootstrap.font.IconSet;
23+
import com.beardedhen.androidbootstrap.font.MaterialIcons;
2324
import com.beardedhen.androidbootstrap.font.Typicon;
2425

2526
import java.io.Serializable;
@@ -81,6 +82,9 @@ private void initialise(AttributeSet attrs) {
8182
int typeOrdinal = a.getInt(R.styleable.AwesomeTextView_bootstrapBrand, -1);
8283
int faIconOrdinal = a.getInt(R.styleable.AwesomeTextView_fontAwesomeIcon, -1);
8384
int typiconOrdinal = a.getInt(R.styleable.AwesomeTextView_typicon, -1);
85+
int materialIconOrdinal = a.getInt(R.styleable.AwesomeTextView_materialIcon, -1);
86+
87+
boolean clickable = a.getBoolean(R.styleable.AwesomeTextView_android_clickable, true);
8488

8589
this.bootstrapBrand = DefaultBootstrapBrand.fromAttributeValue(typeOrdinal);
8690
boolean editMode = isInEditMode();
@@ -99,12 +103,20 @@ private void initialise(AttributeSet attrs) {
99103
setIcon(fontAwesome.iconCodeForAttrIndex(faIconOrdinal), fontAwesome);
100104
}
101105
}
106+
if (materialIconOrdinal != -1) {
107+
final IconSet materialIcons = TypefaceProvider.retrieveRegisteredIconSet(MaterialIcons.FONT_PATH, editMode);
108+
109+
if (!editMode) {
110+
setIcon(materialIcons.iconCodeForAttrIndex(materialIconOrdinal), materialIcons);
111+
}
112+
}
102113
markdownText = a.getString(R.styleable.AwesomeTextView_bootstrapText);
114+
115+
setClickable(clickable); // allows view to reach android:state_pressed
103116
}
104117
finally {
105118
a.recycle();
106119
}
107-
setClickable(true); // allows view to reach android:state_pressed
108120
setGravity(Gravity.CENTER);
109121

110122
if (markdownText != null) {
@@ -209,6 +221,16 @@ public void setFontAwesomeIcon(@FontAwesome.Icon CharSequence iconCode) {
209221
setBootstrapText(new BootstrapText.Builder(getContext(), isInEditMode()).addFontAwesomeIcon(iconCode).build());
210222
}
211223

224+
/**
225+
* Sets the text to display a MaterialIcon, replacing whatever text is already present.
226+
* Used to set the text to display a MaterialIcon Icon.
227+
*
228+
* @param iconCode the fontawesome icon code e.g. "md_share"
229+
*/
230+
public void setMaterialIcon(@FontAwesome.Icon CharSequence iconCode) {
231+
setBootstrapText(new BootstrapText.Builder(getContext(), isInEditMode()).addMaterialIcon(iconCode).build());
232+
}
233+
212234
/**
213235
* Sets the text to display a FontIcon, replacing whatever text is already present.
214236
* Used to set the text to display a Typicon.

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapButton.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.beardedhen.androidbootstrap;
22

33
import android.content.Context;
4+
import android.content.DialogInterface;
45
import android.content.res.TypedArray;
56
import android.graphics.drawable.Drawable;
67
import android.os.Bundle;
@@ -9,6 +10,7 @@
910
import android.support.annotation.Nullable;
1011
import android.util.AttributeSet;
1112
import android.view.MotionEvent;
13+
import android.view.View;
1214
import android.view.ViewParent;
1315

1416
import com.beardedhen.androidbootstrap.api.attributes.BootstrapBrand;
@@ -35,6 +37,19 @@ public class BootstrapButton extends AwesomeTextView implements BootstrapSizeVie
3537
OutlineableView, RoundableView, ButtonModeView, BadgeContainerView,
3638
BootstrapBadgeView {
3739

40+
41+
/**
42+
* instances of this can be used with .setOnCheckedChangedLisener to notify you when the state of a radio, togle or checkbox button has changed.
43+
*/
44+
public interface OnCheckedChangedListener{
45+
/**
46+
* This method will get called when the state of a radio button, checkbox or toggle button changes.
47+
* @param bootstrapButton the view thats state is changing
48+
* @param isChecked weather the button is checked or not.
49+
*/
50+
public void OnCheckedChanged(BootstrapButton bootstrapButton, boolean isChecked);
51+
}
52+
3853
private static final String TAG = "com.beardedhen.androidbootstrap.BootstrapButton";
3954
private static final String KEY_MODE = "com.beardedhen.androidbootstrap.BootstrapButton.MODE";
4055
private static final String KEY_INDEX = "com.beardedhen.androidbootstrap.BootstrapButton.KEY_INDEX";
@@ -57,6 +72,8 @@ public class BootstrapButton extends AwesomeTextView implements BootstrapSizeVie
5772
private BootstrapBadge bootstrapBadge;
5873
private String badgeText;
5974

75+
private OnCheckedChangedListener onCheckedChangedListener;
76+
6077
public BootstrapButton(Context context) {
6178
super(context);
6279
initialise(null);
@@ -83,7 +100,7 @@ private void initialise(AttributeSet attrs) {
83100
this.badgeText = a.getString(R.styleable.BootstrapButton_badgeText);
84101

85102
int sizeOrdinal = a.getInt(R.styleable.BootstrapButton_bootstrapSize, -1);
86-
int modeOrdinal = a.getInt(R.styleable.BootstrapButtonGroup_buttonMode, -1);
103+
int modeOrdinal = a.getInt(R.styleable.BootstrapButton_buttonMode, -1);
87104

88105
bootstrapSize = DefaultBootstrapSize.fromAttributeValue(sizeOrdinal).scaleFactor();
89106
buttonMode = ButtonMode.fromAttributeValue(modeOrdinal);
@@ -180,7 +197,6 @@ private void initialise(AttributeSet attrs) {
180197
}
181198

182199
@Override public boolean onTouchEvent(@NonNull MotionEvent event) {
183-
184200
switch (buttonMode) {
185201
case REGULAR:
186202
return super.onTouchEvent(event);
@@ -195,6 +211,14 @@ private void initialise(AttributeSet attrs) {
195211
}
196212
}
197213

214+
@Override
215+
public void setSelected(boolean selected) {
216+
super.setSelected(selected);
217+
if (onCheckedChangedListener != null) {
218+
onCheckedChangedListener.OnCheckedChanged(this, selected);
219+
}
220+
}
221+
198222
private boolean handleRadioEvent(@NonNull MotionEvent event) {
199223
if (event.getAction() == MotionEvent.ACTION_DOWN) {
200224
if (isSelected()) {
@@ -344,4 +368,23 @@ public void setBadgeText(@Nullable String badgeText) {
344368
this.bootstrapSize = bootstrapSize;
345369
updateBootstrapState();
346370
}
371+
372+
/**
373+
* NOTE this method only works if the buttons mode is not set to regular.
374+
* for non Toggle, checkbox and radio see {@link BootstrapButton#setOnClickListener}
375+
* @param listener OnCheckedChangedListener that will be fired when the schecked state ofa button is changed.
376+
*/
377+
public void setOnCheckedChangedListener(OnCheckedChangedListener listener){
378+
onCheckedChangedListener = listener;
379+
}
380+
381+
/**
382+
* NOTE this method only works if the buttons mode is set to regular.
383+
* for Toggle, checkbox and radio see {@link BootstrapButton#setOnCheckedChangedListener}
384+
* @param l OnClickListener that will be fired on click.
385+
*/
386+
@Override
387+
public void setOnClickListener(OnClickListener l) {
388+
super.setOnClickListener(l);
389+
}
347390
}

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapButtonGroup.java

Lines changed: 16 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import android.support.annotation.NonNull;
99
import android.util.AttributeSet;
1010
import android.view.View;
11-
import android.view.ViewGroup;
12-
import android.widget.LinearLayout;
1311

1412
import com.beardedhen.androidbootstrap.api.attributes.BootstrapBrand;
1513
import com.beardedhen.androidbootstrap.api.attributes.ViewGroupPosition;
@@ -39,8 +37,9 @@
3937
* to set the properties of all children with one method call to this view. Options include
4038
* BootstrapBrand colors, roundable corners, 'outlineable' mode and different selection modes
4139
* e.g. Checkbox/Radio group.
40+
* If button mode is set to radio only one button is a button group may be selected at a time.
4241
*/
43-
public class BootstrapButtonGroup extends LinearLayout implements BootstrapSizeView,
42+
public class BootstrapButtonGroup extends BootstrapGroup implements BootstrapSizeView,
4443
OutlineableView, RoundableView, BootstrapBrandView, ButtonModeView {
4544

4645
private static final String TAG = "com.beardedhen.androidbootstrap.BootstrapButtonGroup";
@@ -70,7 +69,7 @@ public BootstrapButtonGroup(Context context, AttributeSet attrs, int defStyleAtt
7069
initialise(attrs);
7170
}
7271

73-
private void initialise(AttributeSet attrs) {
72+
protected void initialise(AttributeSet attrs) {
7473
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BootstrapButtonGroup);
7574

7675
try {
@@ -89,7 +88,7 @@ private void initialise(AttributeSet attrs) {
8988
finally {
9089
a.recycle();
9190
}
92-
updateBootstrapPositions();
91+
updateBootstrapGroup();
9392
}
9493

9594
@Override public Parcelable onSaveInstanceState() {
@@ -125,10 +124,20 @@ private void initialise(AttributeSet attrs) {
125124
state = bundle.getParcelable(TAG);
126125
}
127126
super.onRestoreInstanceState(state);
128-
updateBootstrapPositions();
127+
updateBootstrapGroup();
129128
}
130129

131-
private void updateBootstrapPositions() {
130+
@Override
131+
protected void onBootstrapViewAdded() {
132+
updateBootstrapGroup();
133+
}
134+
135+
@Override
136+
protected void onBootstrapViewRemoved() {
137+
updateBootstrapGroup();
138+
}
139+
140+
protected void updateBootstrapGroup() {
132141
int childCount = getChildCount();
133142
int orientation = getOrientation();
134143

@@ -284,100 +293,4 @@ public void setButtonMode(@NonNull ButtonMode buttonMode) {
284293
return rounded;
285294
}
286295

287-
/*
288-
* Overrides
289-
*/
290-
291-
292-
@Override public void setOrientation(int orientation) {
293-
super.setOrientation(orientation);
294-
updateBootstrapPositions();
295-
}
296-
297-
@Override public void addView(@NonNull View child) {
298-
super.addView(child);
299-
updateBootstrapPositions();
300-
}
301-
302-
@Override public void addView(@NonNull View child, int index) {
303-
super.addView(child, index);
304-
updateBootstrapPositions();
305-
}
306-
307-
@Override public void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) {
308-
super.addView(child, index, params);
309-
updateBootstrapPositions();
310-
}
311-
312-
@Override public void addView(@NonNull View child, ViewGroup.LayoutParams params) {
313-
super.addView(child, params);
314-
updateBootstrapPositions();
315-
}
316-
317-
@Override public void addView(@NonNull View child, int width, int height) {
318-
super.addView(child, width, height);
319-
updateBootstrapPositions();
320-
}
321-
322-
@Override
323-
protected boolean addViewInLayout(
324-
@NonNull View child, int index, ViewGroup.LayoutParams params) {
325-
boolean b = super.addViewInLayout(child, index, params);
326-
updateBootstrapPositions();
327-
return b;
328-
}
329-
330-
@Override
331-
protected boolean addViewInLayout(@NonNull
332-
View child, int index, ViewGroup.LayoutParams params, boolean preventRequestLayout) {
333-
boolean b = super.addViewInLayout(child, index, params, preventRequestLayout);
334-
updateBootstrapPositions();
335-
return b;
336-
}
337-
338-
@Override public void removeView(@NonNull View view) {
339-
super.removeView(view);
340-
updateBootstrapPositions();
341-
}
342-
343-
@Override protected void removeDetachedView(@NonNull View child, boolean animate) {
344-
super.removeDetachedView(child, animate);
345-
updateBootstrapPositions();
346-
}
347-
348-
@Override public void removeAllViews() {
349-
super.removeAllViews();
350-
updateBootstrapPositions();
351-
}
352-
353-
@Override public void removeAllViewsInLayout() {
354-
super.removeAllViewsInLayout();
355-
updateBootstrapPositions();
356-
}
357-
358-
@Override public void removeViewAt(int index) {
359-
super.removeViewAt(index);
360-
updateBootstrapPositions();
361-
}
362-
363-
@Override public void removeViewInLayout(@NonNull View view) {
364-
super.removeViewInLayout(view);
365-
updateBootstrapPositions();
366-
}
367-
368-
@Override public void removeViews(int start, int count) {
369-
super.removeViews(start, count);
370-
updateBootstrapPositions();
371-
}
372-
373-
@Override public void removeViewsInLayout(int start, int count) {
374-
super.removeViewsInLayout(start, count);
375-
updateBootstrapPositions();
376-
}
377-
378-
@Override protected void onFinishInflate() {
379-
super.onFinishInflate();
380-
updateBootstrapPositions();
381-
}
382-
383296
}

0 commit comments

Comments
 (0)