Skip to content

Commit

Permalink
Merge pull request #168 from tom-beardedhen/master
Browse files Browse the repository at this point in the history
Fixed bugs and implemented Material icons, progress bar group
  • Loading branch information
jamie-beardedhen authored Jul 2, 2016
2 parents 14abd26 + 430e6b7 commit 221ba81
Show file tree
Hide file tree
Showing 33 changed files with 4,892 additions and 189 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.beardedhen.androidbootstrap.api.view.BootstrapTextView;
import com.beardedhen.androidbootstrap.font.FontAwesome;
import com.beardedhen.androidbootstrap.font.IconSet;
import com.beardedhen.androidbootstrap.font.MaterialIcons;
import com.beardedhen.androidbootstrap.font.Typicon;

import java.io.Serializable;
Expand Down Expand Up @@ -81,6 +82,9 @@ private void initialise(AttributeSet attrs) {
int typeOrdinal = a.getInt(R.styleable.AwesomeTextView_bootstrapBrand, -1);
int faIconOrdinal = a.getInt(R.styleable.AwesomeTextView_fontAwesomeIcon, -1);
int typiconOrdinal = a.getInt(R.styleable.AwesomeTextView_typicon, -1);
int materialIconOrdinal = a.getInt(R.styleable.AwesomeTextView_materialIcon, -1);

boolean clickable = a.getBoolean(R.styleable.AwesomeTextView_android_clickable, true);

this.bootstrapBrand = DefaultBootstrapBrand.fromAttributeValue(typeOrdinal);
boolean editMode = isInEditMode();
Expand All @@ -99,12 +103,20 @@ private void initialise(AttributeSet attrs) {
setIcon(fontAwesome.iconCodeForAttrIndex(faIconOrdinal), fontAwesome);
}
}
if (materialIconOrdinal != -1) {
final IconSet materialIcons = TypefaceProvider.retrieveRegisteredIconSet(MaterialIcons.FONT_PATH, editMode);

if (!editMode) {
setIcon(materialIcons.iconCodeForAttrIndex(materialIconOrdinal), materialIcons);
}
}
markdownText = a.getString(R.styleable.AwesomeTextView_bootstrapText);

setClickable(clickable); // allows view to reach android:state_pressed
}
finally {
a.recycle();
}
setClickable(true); // allows view to reach android:state_pressed
setGravity(Gravity.CENTER);

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

/**
* Sets the text to display a MaterialIcon, replacing whatever text is already present.
* Used to set the text to display a MaterialIcon Icon.
*
* @param iconCode the fontawesome icon code e.g. "md_share"
*/
public void setMaterialIcon(@FontAwesome.Icon CharSequence iconCode) {
setBootstrapText(new BootstrapText.Builder(getContext(), isInEditMode()).addMaterialIcon(iconCode).build());
}

/**
* Sets the text to display a FontIcon, replacing whatever text is already present.
* Used to set the text to display a Typicon.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.beardedhen.androidbootstrap;

import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
Expand All @@ -9,6 +10,7 @@
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewParent;

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


/**
* instances of this can be used with .setOnCheckedChangedLisener to notify you when the state of a radio, togle or checkbox button has changed.
*/
public interface OnCheckedChangedListener{
/**
* This method will get called when the state of a radio button, checkbox or toggle button changes.
* @param bootstrapButton the view thats state is changing
* @param isChecked weather the button is checked or not.
*/
public void OnCheckedChanged(BootstrapButton bootstrapButton, boolean isChecked);
}

private static final String TAG = "com.beardedhen.androidbootstrap.BootstrapButton";
private static final String KEY_MODE = "com.beardedhen.androidbootstrap.BootstrapButton.MODE";
private static final String KEY_INDEX = "com.beardedhen.androidbootstrap.BootstrapButton.KEY_INDEX";
Expand All @@ -57,6 +72,8 @@ public class BootstrapButton extends AwesomeTextView implements BootstrapSizeVie
private BootstrapBadge bootstrapBadge;
private String badgeText;

private OnCheckedChangedListener onCheckedChangedListener;

public BootstrapButton(Context context) {
super(context);
initialise(null);
Expand All @@ -83,7 +100,7 @@ private void initialise(AttributeSet attrs) {
this.badgeText = a.getString(R.styleable.BootstrapButton_badgeText);

int sizeOrdinal = a.getInt(R.styleable.BootstrapButton_bootstrapSize, -1);
int modeOrdinal = a.getInt(R.styleable.BootstrapButtonGroup_buttonMode, -1);
int modeOrdinal = a.getInt(R.styleable.BootstrapButton_buttonMode, -1);

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

@Override public boolean onTouchEvent(@NonNull MotionEvent event) {

switch (buttonMode) {
case REGULAR:
return super.onTouchEvent(event);
Expand All @@ -195,6 +211,14 @@ private void initialise(AttributeSet attrs) {
}
}

@Override
public void setSelected(boolean selected) {
super.setSelected(selected);
if (onCheckedChangedListener != null) {
onCheckedChangedListener.OnCheckedChanged(this, selected);
}
}

private boolean handleRadioEvent(@NonNull MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (isSelected()) {
Expand Down Expand Up @@ -344,4 +368,23 @@ public void setBadgeText(@Nullable String badgeText) {
this.bootstrapSize = bootstrapSize;
updateBootstrapState();
}

/**
* NOTE this method only works if the buttons mode is not set to regular.
* for non Toggle, checkbox and radio see {@link BootstrapButton#setOnClickListener}
* @param listener OnCheckedChangedListener that will be fired when the schecked state ofa button is changed.
*/
public void setOnCheckedChangedListener(OnCheckedChangedListener listener){
onCheckedChangedListener = listener;
}

/**
* NOTE this method only works if the buttons mode is set to regular.
* for Toggle, checkbox and radio see {@link BootstrapButton#setOnCheckedChangedListener}
* @param l OnClickListener that will be fired on click.
*/
@Override
public void setOnClickListener(OnClickListener l) {
super.setOnClickListener(l);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

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

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

private void initialise(AttributeSet attrs) {
protected void initialise(AttributeSet attrs) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BootstrapButtonGroup);

try {
Expand All @@ -89,7 +88,7 @@ private void initialise(AttributeSet attrs) {
finally {
a.recycle();
}
updateBootstrapPositions();
updateBootstrapGroup();
}

@Override public Parcelable onSaveInstanceState() {
Expand Down Expand Up @@ -125,10 +124,20 @@ private void initialise(AttributeSet attrs) {
state = bundle.getParcelable(TAG);
}
super.onRestoreInstanceState(state);
updateBootstrapPositions();
updateBootstrapGroup();
}

private void updateBootstrapPositions() {
@Override
protected void onBootstrapViewAdded() {
updateBootstrapGroup();
}

@Override
protected void onBootstrapViewRemoved() {
updateBootstrapGroup();
}

protected void updateBootstrapGroup() {
int childCount = getChildCount();
int orientation = getOrientation();

Expand Down Expand Up @@ -284,100 +293,4 @@ public void setButtonMode(@NonNull ButtonMode buttonMode) {
return rounded;
}

/*
* Overrides
*/


@Override public void setOrientation(int orientation) {
super.setOrientation(orientation);
updateBootstrapPositions();
}

@Override public void addView(@NonNull View child) {
super.addView(child);
updateBootstrapPositions();
}

@Override public void addView(@NonNull View child, int index) {
super.addView(child, index);
updateBootstrapPositions();
}

@Override public void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) {
super.addView(child, index, params);
updateBootstrapPositions();
}

@Override public void addView(@NonNull View child, ViewGroup.LayoutParams params) {
super.addView(child, params);
updateBootstrapPositions();
}

@Override public void addView(@NonNull View child, int width, int height) {
super.addView(child, width, height);
updateBootstrapPositions();
}

@Override
protected boolean addViewInLayout(
@NonNull View child, int index, ViewGroup.LayoutParams params) {
boolean b = super.addViewInLayout(child, index, params);
updateBootstrapPositions();
return b;
}

@Override
protected boolean addViewInLayout(@NonNull
View child, int index, ViewGroup.LayoutParams params, boolean preventRequestLayout) {
boolean b = super.addViewInLayout(child, index, params, preventRequestLayout);
updateBootstrapPositions();
return b;
}

@Override public void removeView(@NonNull View view) {
super.removeView(view);
updateBootstrapPositions();
}

@Override protected void removeDetachedView(@NonNull View child, boolean animate) {
super.removeDetachedView(child, animate);
updateBootstrapPositions();
}

@Override public void removeAllViews() {
super.removeAllViews();
updateBootstrapPositions();
}

@Override public void removeAllViewsInLayout() {
super.removeAllViewsInLayout();
updateBootstrapPositions();
}

@Override public void removeViewAt(int index) {
super.removeViewAt(index);
updateBootstrapPositions();
}

@Override public void removeViewInLayout(@NonNull View view) {
super.removeViewInLayout(view);
updateBootstrapPositions();
}

@Override public void removeViews(int start, int count) {
super.removeViews(start, count);
updateBootstrapPositions();
}

@Override public void removeViewsInLayout(int start, int count) {
super.removeViewsInLayout(start, count);
updateBootstrapPositions();
}

@Override protected void onFinishInflate() {
super.onFinishInflate();
updateBootstrapPositions();
}

}
Loading

0 comments on commit 221ba81

Please sign in to comment.