Skip to content

Commit 216f1f0

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents c985435 + cd95bd9 commit 216f1f0

20 files changed

Lines changed: 969 additions & 17 deletions

AndroidBootstrap/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ android {
1515

1616
dependencies {
1717
compile 'com.android.support:support-annotations:23.1.1'
18+
compile 'com.android.support:support-v4:23.1.1'
1819
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class BootstrapButton extends AwesomeTextView implements BootstrapSizeVie
4343

4444
private boolean roundedCorners;
4545
private boolean showOutline;
46+
private boolean mustBeSelected;
4647

4748
private float baselineFontSize;
4849
private float baselineVertPadding;
@@ -72,6 +73,7 @@ private void initialise(AttributeSet attrs) {
7273
try {
7374
this.roundedCorners = a.getBoolean(R.styleable.BootstrapButton_roundedCorners, false);
7475
this.showOutline = a.getBoolean(R.styleable.BootstrapButton_showOutline, false);
76+
this.mustBeSelected = a.getBoolean(R.styleable.BootstrapButton_checked, false);
7577

7678
int sizeOrdinal = a.getInt(R.styleable.BootstrapButton_bootstrapSize, -1);
7779
int modeOrdinal = a.getInt(R.styleable.BootstrapButtonGroup_buttonMode, -1);
@@ -239,6 +241,14 @@ void updateFromParent(BootstrapBrand bootstrapBrand,
239241
* Getters/Setters
240242
*/
241243

244+
public boolean isMustBeSelected() {
245+
return mustBeSelected;
246+
}
247+
248+
public void setChecked(boolean checked) {
249+
this.mustBeSelected = checked;
250+
}
251+
242252
@Override public boolean isShowOutline() {
243253
return showOutline;
244254
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.res.TypedArray;
55
import android.os.Bundle;
66
import android.os.Parcelable;
7+
import android.support.annotation.IdRes;
78
import android.support.annotation.NonNull;
89
import android.util.AttributeSet;
910
import android.view.View;
@@ -52,6 +53,8 @@ public class BootstrapButtonGroup extends LinearLayout implements BootstrapSizeV
5253
private boolean rounded;
5354
private boolean outline;
5455

56+
private int checkedButtonId = 0;
57+
5558
public BootstrapButtonGroup(Context context) {
5659
super(context);
5760
initialise(null);
@@ -78,6 +81,7 @@ private void initialise(AttributeSet attrs) {
7881
int brandOrdinal = a.getInt(R.styleable.BootstrapButtonGroup_bootstrapBrand, -1);
7982
int sizeOrdinal = a.getInt(R.styleable.BootstrapButtonGroup_bootstrapSize, -1);
8083

84+
this.checkedButtonId = a.getResourceId(R.styleable.BootstrapButtonGroup_checkedButton, 0);
8185
this.buttonMode = ButtonMode.fromAttributeValue(typeOrdinal);
8286
this.bootstrapBrand = DefaultBootstrapBrand.fromAttributeValue(brandOrdinal);
8387
this.bootstrapSize = DefaultBootstrapSize.fromAttributeValue(sizeOrdinal).scaleFactor();
@@ -164,6 +168,15 @@ else if (i == size - 1) { // last view
164168
}
165169
button.setViewGroupPosition(position, i);
166170
button.updateFromParent(bootstrapBrand, bootstrapSize, buttonMode, outline, rounded);
171+
if (buttonMode == ButtonMode.RADIO && button.isMustBeSelected()) {
172+
button.setSelected(true);
173+
onRadioToggle(i);
174+
checkedButtonId = 0; //BootstrapButton "checked" attribute is preferable
175+
}
176+
else if (buttonMode == ButtonMode.RADIO && button.getId() == checkedButtonId) {
177+
button.setSelected(true);
178+
onRadioToggle(i);
179+
}
167180
}
168181
}
169182

@@ -198,6 +211,10 @@ void onRadioToggle(int index) {
198211
* Getters / Setters
199212
*/
200213

214+
public void check(@IdRes int id) {
215+
this.checkedButtonId = id;
216+
}
217+
201218
@Override public float getBootstrapSize() {
202219
return bootstrapSize;
203220
}

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import android.content.Context;
44
import android.content.res.ColorStateList;
5+
import android.graphics.Bitmap;
6+
import android.graphics.Canvas;
57
import android.graphics.Color;
8+
import android.graphics.Paint;
9+
import android.graphics.Path;
10+
import android.graphics.drawable.BitmapDrawable;
611
import android.graphics.drawable.Drawable;
712
import android.graphics.drawable.GradientDrawable;
813
import android.graphics.drawable.LayerDrawable;
@@ -13,6 +18,7 @@
1318
import com.beardedhen.androidbootstrap.api.attributes.BootstrapBrand;
1419
import com.beardedhen.androidbootstrap.api.attributes.ViewGroupPosition;
1520
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand;
21+
import com.beardedhen.androidbootstrap.api.defaults.ExpandDirection;
1622
import com.beardedhen.androidbootstrap.utils.ColorUtils;
1723
import com.beardedhen.androidbootstrap.utils.DimenUtils;
1824

@@ -196,6 +202,14 @@ static ColorStateList bootstrapButtonText(Context context, boolean outline, Boot
196202
return new ColorStateList(getStateList(), getColorList(defaultColor, activeColor, disabledColor));
197203
}
198204

205+
static Drawable bootstrapWell(@ColorInt int backgroundColor, int cornerRadius, int strokeWidth, @ColorInt int strokeColor) {
206+
GradientDrawable background = new GradientDrawable();
207+
background.setColor(backgroundColor);
208+
background.setCornerRadius(cornerRadius);
209+
background.setStroke(strokeWidth, strokeColor);
210+
return background;
211+
}
212+
199213
private static StateListDrawable setupStateDrawable(ViewGroupPosition position, int strokeWidth, GradientDrawable defaultGd, GradientDrawable activeGd, GradientDrawable disabledGd) {
200214
StateListDrawable stateListDrawable = new StateListDrawable();
201215
LayerDrawable defaultLayer = new LayerDrawable(new Drawable[]{defaultGd});
@@ -306,6 +320,74 @@ private static int[] getColorList(int defaultColor, int activeColor, int disable
306320
}
307321
}
308322

323+
static StateListDrawable bootstrapDropDownArrow(Context context, int width, int height, ExpandDirection expandDirection, boolean outline, BootstrapBrand brand) {
324+
StateListDrawable stateListDrawable = new StateListDrawable();
325+
326+
int defaultColor = outline ? brand.defaultFill(context) : brand.defaultTextColor(context);
327+
int activeColor = outline ? ColorUtils.resolveColor(android.R.color.white, context) : brand.activeTextColor(context);
328+
int disabledColor = outline ? brand.disabledFill(context) : brand.disabledTextColor(context);
329+
330+
if (Build.VERSION.SDK_INT >= 14) {
331+
stateListDrawable.addState(new int[]{android.R.attr.state_hovered}, createArrowIcon(context, width, height, activeColor, expandDirection));
332+
}
333+
334+
stateListDrawable.addState(new int[]{android.R.attr.state_activated}, createArrowIcon(context, width, height, activeColor, expandDirection));
335+
stateListDrawable.addState(new int[]{android.R.attr.state_focused}, createArrowIcon(context, width, height, activeColor, expandDirection));
336+
stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, createArrowIcon(context, width, height, activeColor, expandDirection));
337+
stateListDrawable.addState(new int[]{android.R.attr.state_selected}, createArrowIcon(context, width, height, activeColor, expandDirection));
338+
stateListDrawable.addState(new int[]{-android.R.attr.state_enabled}, createArrowIcon(context, width, height, disabledColor, expandDirection));
339+
stateListDrawable.addState(new int[]{}, createArrowIcon(context, width, height, defaultColor, expandDirection));
340+
return stateListDrawable;
341+
}
342+
343+
/**
344+
* Creates arrow icon that depends on ExpandDirection
345+
*
346+
* @param context context
347+
* @param width width of icon in pixels
348+
* @param height height of icon in pixels
349+
* @param color arrow color
350+
* @param expandDirection arrow direction
351+
* @return icon drawable
352+
*/
353+
private static Drawable createArrowIcon(Context context, int width, int height, int color, ExpandDirection expandDirection) {
354+
Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
355+
Canvas canvas = new Canvas(canvasBitmap);
356+
Paint paint = new Paint();
357+
paint.setStyle(Paint.Style.FILL_AND_STROKE);
358+
paint.setStrokeWidth(1);
359+
paint.setColor(color);
360+
paint.setAntiAlias(true);
361+
Path path = new Path();
362+
path.setFillType(Path.FillType.EVEN_ODD);
363+
switch (expandDirection) {
364+
case UP:
365+
path.moveTo(0, (height / 3) * 2);
366+
path.lineTo(width, (height / 3) * 2);
367+
path.lineTo(width / 2, height / 3);
368+
path.lineTo(0, (height / 3) * 2);
369+
break;
370+
case DOWN:
371+
path.moveTo(0, height / 3);
372+
path.lineTo(width, height / 3);
373+
path.lineTo(width / 2, (height / 3) * 2);
374+
path.lineTo(0, height / 3);
375+
break;
376+
}
377+
path.close();
378+
canvas.drawPath(path, paint);
379+
return new BitmapDrawable(context.getResources(), canvasBitmap);
380+
}
381+
382+
static ColorStateList bootstrapDropDownViewText(Context context) {
383+
384+
int defaultColor = context.getResources().getColor(R.color.bootstrap_gray_dark);
385+
int activeColor = context.getResources().getColor(android.R.color.black);
386+
int disabledColor = context.getResources().getColor(R.color.bootstrap_gray_light);
387+
388+
return new ColorStateList(getStateList(), getColorList(defaultColor, activeColor, disabledColor));
389+
}
390+
309391
private static void setInsetOnLayers(LayerDrawable[] ary, int l, int t, int r, int b) {
310392
for (LayerDrawable ld : ary) {
311393
ld.setLayerInset(0, l, t, r, b);

0 commit comments

Comments
 (0)