Skip to content

Commit

Permalink
Merge pull request #149 from fractalwrench/master
Browse files Browse the repository at this point in the history
Update docs
  • Loading branch information
jamie-beardedhen committed Feb 26, 2016
2 parents cd95bd9 + 0fbbf41 commit 7d3fc6d
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 39 deletions.
6 changes: 3 additions & 3 deletions AndroidBootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply from: 'push.gradle'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 11
Expand All @@ -14,6 +14,6 @@ android {
}

dependencies {
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:support-annotations:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
import java.io.Serializable;
import java.util.regex.Pattern;

/**
* BootstrapButtons are buttons which provide contextual menus, styled with BootstrapBrand colors,
* roundable corners, and an 'outlineable' mode.
*/
public class BootstrapDropDown extends AwesomeTextView implements View.OnClickListener, RoundableView, OutlineableView, PopupWindow.OnDismissListener {

private static final String TAG = "com.beardedhen.androidbootstrap.BootstrapDropDown";
Expand Down Expand Up @@ -99,7 +103,8 @@ private void initialise(AttributeSet attrs) {
dropdownData = getContext().getResources().getStringArray(dataOrdinal);
bootstrapSize = DefaultBootstrapSize.fromAttributeValue(sizeOrdinal).scaleFactor();
itemHeight = a.getDimensionPixelSize(R.styleable.BootstrapDropDown_itemHeight, (int) DimenUtils.pixelsFromDpResource(getContext(), R.dimen.bootstrap_dropdown_default_item_height));
} finally {
}
finally {
a.recycle();
}

Expand Down Expand Up @@ -134,8 +139,9 @@ private void createDropDown() {

if (longestStringWidth < getMeasuredWidth()) {
dropdownWindow.setWidth(DimenUtils.dpToPixels(getMeasuredWidth()));
} else {
dropdownWindow.setWidth((int)longestStringWidth + DimenUtils.dpToPixels(8));
}
else {
dropdownWindow.setWidth((int) longestStringWidth + DimenUtils.dpToPixels(8));
}
}

Expand Down Expand Up @@ -163,8 +169,9 @@ private ScrollView createDropDownView() {
@Override
public void onClick(View v) {
dropdownWindow.dismiss();
if (onDropDownItemClickListener != null)
if (onDropDownItemClickListener != null) {
onDropDownItemClickListener.onItemClick(dropdownView, v, v.getId());
}
}
});

Expand All @@ -173,15 +180,18 @@ public void onClick(View v) {
childView.setTextSize((baselineDropDownViewFontSize - 2F) * bootstrapSize);
childView.setClickable(false);
childView.setTextColor(getResources().getColor(R.color.bootstrap_gray_light));
} else if (Pattern.matches(SEARCH_REGEX_SEPARATOR, text)) {
}
else if (Pattern.matches(SEARCH_REGEX_SEPARATOR, text)) {
childView = new DividerView(getContext());
childView.setClickable(false);
childView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 3));
} else if (Pattern.matches(SEARCH_REGEX_DISABLED, text)) {
}
else if (Pattern.matches(SEARCH_REGEX_DISABLED, text)) {
childView.setEnabled(false);
childView.setId(clickableChildCounter++);
childView.setText(text.replaceFirst(REPLACE_REGEX_DISABLED, ""));
} else {
}
else {
childView.setText(text);
childView.setId(clickableChildCounter++);
}
Expand Down Expand Up @@ -217,7 +227,7 @@ private void updateDropDownState() {

setCompoundDrawablesWithIntrinsicBounds(null, null,
BootstrapDrawableFactory.bootstrapDropDownArrow(getContext(),
DimenUtils.dpToPixels(8 *bootstrapSize),
DimenUtils.dpToPixels(8 * bootstrapSize),
DimenUtils.dpToPixels(12 * bootstrapSize),
expandDirection,
showOutline,
Expand All @@ -240,7 +250,8 @@ private void updateDropDownState() {

if (Build.VERSION.SDK_INT >= 16) {
setBackground(bg);
} else {
}
else {
setBackgroundDrawable(bg);
}

Expand Down Expand Up @@ -290,6 +301,11 @@ private void cleanData() {
dropdownData = cleanArray;
}

/**
* Sets a listener which will be called when an item is clicked in the dropdown.
*
* @param onDropDownItemClickListener the listener
*/
public void setOnDropDownItemClickListener(OnDropDownItemClickListener onDropDownItemClickListener) {
this.onDropDownItemClickListener = onDropDownItemClickListener;
}
Expand All @@ -302,10 +318,20 @@ public void setOnDropDownItemClickListener(OnDropDownItemClickListener onDropDow
return roundedCorners;
}

/**
* Gets the direction in which the dropdown expands.
*
* @return the direction
*/
public ExpandDirection getExpandDirection() {
return expandDirection;
}

/**
* Retrieves the data used to populate the dropdown.
*
* @return a string array of values
*/
public String[] getDropdownData() {
return dropdownData;
}
Expand All @@ -320,11 +346,21 @@ public String[] getDropdownData() {
updateDropDownState();
}

/**
* Sets the direction in which the dropdown should expand.
*
* @param expandDirection the direction
*/
public void setExpandDirection(ExpandDirection expandDirection) {
this.expandDirection = expandDirection;
updateDropDownState();
}

/**
* Sets the String values which should be used to populate the menu displayed in the dropdown.
*
* @param dropdownData an array of string values.
*/
public void setDropdownData(String[] dropdownData) {
this.dropdownData = dropdownData;
createDropDown();
Expand All @@ -337,17 +373,20 @@ public void setDropdownData(String[] dropdownData) {
}

@Override public void onClick(View v) {
if (clickListener != null) clickListener.onClick(v);
if (clickListener != null) {
clickListener.onClick(v);
}
//using 8dip on axisX offset to make dropdown view visually be at start of dropdown itself
//using 4dip on axisY offset to make space between dropdown view and dropdown itself
//all offsets are necessary because of the dialog_holo_light_frame to display correctly on screen(shadow was made by inset)
int gravity;
int axisXOffset;
if (dropDownViewWidth + getX() > screenWidth) {
gravity = Gravity.TOP|Gravity.RIGHT;
gravity = Gravity.TOP | Gravity.RIGHT;
axisXOffset = DimenUtils.dpToPixels(8);
} else {
gravity = Gravity.TOP|Gravity.LEFT;
}
else {
gravity = Gravity.TOP | Gravity.LEFT;
axisXOffset = -DimenUtils.dpToPixels(8);
}
int axisYOffset = DimenUtils.dpToPixels(4);
Expand Down Expand Up @@ -401,22 +440,33 @@ public void setDropdownData(String[] dropdownData) {
this.clickListener = clickListener;
}

/**
* A listener which provides methods relating to {@link BootstrapDropDown}
*/
public interface OnDropDownItemClickListener {

/**
* Called when an item is clicked in a {@link BootstrapDropDown}
*
* @param parent the parent viewgroup
* @param v the view
* @param id the id
*/
void onItemClick(ViewGroup parent, View v, int id);
}

private class DividerView extends TextView {
private static class DividerView extends TextView {

private Paint mPaint;
private final Paint paint;

public DividerView(Context context) {
super(context);
mPaint = new Paint();
mPaint.setColor(getResources().getColor(R.color.bootstrap_dropdown_divider));
paint = new Paint();
paint.setColor(getResources().getColor(R.color.bootstrap_dropdown_divider));
}

@Override protected void onDraw(Canvas canvas) {
canvas.drawLine(0, 1, canvas.getWidth(), 1, mPaint);
canvas.drawLine(0, 1, canvas.getWidth(), 1, paint);
super.onDraw(canvas);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import com.beardedhen.androidbootstrap.utils.ColorUtils;
import com.beardedhen.androidbootstrap.utils.DimenUtils;

/**
* BootstrapWells are used as a container layout for other views, typically text.
*/
public class BootstrapWell extends FrameLayout {

private float bootstrapSize;
Expand All @@ -35,7 +38,6 @@ private void initialise(AttributeSet attrs) {

try {
int sizeOrdinal = a.getInt(R.styleable.BootstrapButton_bootstrapSize, -1);

bootstrapSize = DefaultBootstrapSize.fromAttributeValue(sizeOrdinal).scaleFactor();
}
finally {
Expand Down
10 changes: 0 additions & 10 deletions AndroidBootstrap/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,5 @@
<attr name="bootstrapSize"/>
</declare-styleable>

<declare-styleable name="BootstrapDropDown">
<attr name="bootstrapExpandDirection"/>
<attr name="dropdownResource"/>
<attr name="showOutline"/>
<attr name="roundedCorners"/>
<attr name="bootstrapBrand"/>
<attr name="bootstrapSize"/>
<attr name="itemHeight"/>
</declare-styleable>

</resources>

4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=2.0.1
VERSION_CODE=201
VERSION_NAME=2.1.0
VERSION_CODE=210
GROUP=com.beardedhen

POM_DESCRIPTION=Bootstrap style widgets for Android, with Glyph Icons
Expand Down
10 changes: 5 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.fractalwrench.androidbootstrap.sample"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
versionCode 210
versionName "2.1.0"
}
lintOptions {
disable 'InvalidPackage'
Expand All @@ -29,6 +29,6 @@ dependencies {
compile project (':AndroidBootstrap') // replace with Maven dependency in your app

compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:support-annotations:23.2.0'
}

0 comments on commit 7d3fc6d

Please sign in to comment.