Skip to content

Commit ebd42d2

Browse files
Merge pull request #143 from redwerk/bootstrap_well
Bootstrap Well implementation
2 parents bea2195 + c169228 commit ebd42d2

File tree

10 files changed

+158
-0
lines changed

10 files changed

+158
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ static ColorStateList bootstrapButtonText(Context context, boolean outline, Boot
196196
return new ColorStateList(getStateList(), getColorList(defaultColor, activeColor, disabledColor));
197197
}
198198

199+
static Drawable bootstrapWell(@ColorInt int backgroundColor, int cornerRadius, int strokeWidth, @ColorInt int strokeColor) {
200+
GradientDrawable background = new GradientDrawable();
201+
background.setColor(backgroundColor);
202+
background.setCornerRadius(cornerRadius);
203+
background.setStroke(strokeWidth, strokeColor);
204+
return background;
205+
}
206+
199207
private static StateListDrawable setupStateDrawable(ViewGroupPosition position, int strokeWidth, GradientDrawable defaultGd, GradientDrawable activeGd, GradientDrawable disabledGd) {
200208
StateListDrawable stateListDrawable = new StateListDrawable();
201209
LayerDrawable defaultLayer = new LayerDrawable(new Drawable[]{defaultGd});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.beardedhen.androidbootstrap;
2+
3+
import android.content.Context;
4+
import android.content.res.TypedArray;
5+
import android.graphics.drawable.Drawable;
6+
import android.os.Build;
7+
import android.util.AttributeSet;
8+
import android.widget.FrameLayout;
9+
10+
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapSize;
11+
import com.beardedhen.androidbootstrap.utils.ColorUtils;
12+
import com.beardedhen.androidbootstrap.utils.DimenUtils;
13+
14+
public class BootstrapWell extends FrameLayout {
15+
16+
private float bootstrapSize;
17+
18+
public BootstrapWell(Context context) {
19+
super(context);
20+
initialise(null);
21+
}
22+
23+
public BootstrapWell(Context context, AttributeSet attrs) {
24+
super(context, attrs);
25+
initialise(attrs);
26+
}
27+
28+
public BootstrapWell(Context context, AttributeSet attrs, int defStyleAttr) {
29+
super(context, attrs, defStyleAttr);
30+
initialise(attrs);
31+
}
32+
33+
private void initialise(AttributeSet attrs) {
34+
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BootstrapButton);
35+
36+
try {
37+
int sizeOrdinal = a.getInt(R.styleable.BootstrapButton_bootstrapSize, -1);
38+
39+
bootstrapSize = DefaultBootstrapSize.fromAttributeValue(sizeOrdinal).scaleFactor();
40+
}
41+
finally {
42+
a.recycle();
43+
}
44+
updateBootstrapState();
45+
}
46+
47+
private void updateBootstrapState() {
48+
Drawable bg = BootstrapDrawableFactory.bootstrapWell(ColorUtils.resolveColor(R.color.bootstrap_well_background, getContext()),
49+
(int) (DimenUtils.pixelsFromDpResource(getContext(), R.dimen.bootstrap_well_corner_radius) * bootstrapSize / 2),
50+
(int) DimenUtils.pixelsFromDpResource(getContext(), R.dimen.bootstrap_well_stroke_width),
51+
ColorUtils.resolveColor(R.color.bootstrap_well_border_color, getContext()));
52+
53+
if (Build.VERSION.SDK_INT >= 16) {
54+
setBackground(bg);
55+
}
56+
else {
57+
setBackgroundDrawable(bg);
58+
}
59+
60+
int padding = (int) (DimenUtils.pixelsFromDpResource(getContext(), R.dimen.bootstrap_well_default_padding) * bootstrapSize * 2.5);
61+
setPadding(padding, padding, padding, padding);
62+
}
63+
}

AndroidBootstrap/src/main/res/values/attrs.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,9 @@
103103
<attr name="bootstrapSize"/>
104104
</declare-styleable>
105105

106+
<declare-styleable name="BootstrapWell">
107+
<attr name="bootstrapSize"/>
108+
</declare-styleable>
109+
106110
</resources>
107111

AndroidBootstrap/src/main/res/values/colors.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@
2727
<!-- Misc -->
2828
<color name="bootstrap_edittext_disabled">#ffe0e0e0</color>
2929
<color name="bootstrap_thumbnail_background">#ffffffff</color>
30+
<color name="bootstrap_well_background">#F5F5F5</color>
31+
<color name="bootstrap_well_border_color">#E7E7E7</color>
3032

3133
</resources>

AndroidBootstrap/src/main/res/values/dimens.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<dimen name="bthumbnail_rounded_corner">8dp</dimen>
2020
<dimen name="bthumbnail_outer_stroke">2dp</dimen>
2121

22+
<!--Well-->
23+
<dimen name="bootstrap_well_corner_radius">8dp</dimen>
24+
<dimen name="bootstrap_well_stroke_width">1dp</dimen>
25+
<dimen name="bootstrap_well_default_padding">6dp</dimen>
26+
2227
<!-- Headings -->
2328
<dimen name="bootstrap_h1_text_size">31.5sp</dimen>
2429
<dimen name="bootstrap_h1_vert_padding">7.875dp</dimen>

sample/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
android:name=".BootstrapEditTextExample"
5353
android:label="BootstrapEditTextExample"
5454
/>
55+
<activity
56+
android:name=".BootstrapWellExample"
57+
android:label="BootstrapEditTextExample"
58+
/>
5559
</application>
5660

5761
</manifest>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.fractalwrench.androidbootstrap.sample;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
6+
public class BootstrapWellExample extends Activity {
7+
8+
@Override
9+
protected void onCreate(Bundle savedInstanceState) {
10+
super.onCreate(savedInstanceState);
11+
setContentView(R.layout.example_bootstrap_well);
12+
}
13+
}

sample/src/main/java/com/fractalwrench/androidbootstrap/sample/HomeActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@ public class HomeActivity extends AppCompatActivity {
4747
startActivity(new Intent(this, BootstrapThumbnailExample.class));
4848
}
4949

50+
@OnClick(R.id.example_bootstrap_well) void onBootstrapWellExampleClicked() {
51+
startActivity(new Intent(this, BootstrapWellExample.class));
52+
}
53+
5054
}

sample/src/main/res/layout/activity_main.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,11 @@
6161
android:text="BootstrapThumbnail"
6262
/>
6363

64+
<Button
65+
android:id="@+id/example_bootstrap_well"
66+
style="@style/home_button"
67+
android:text="BootstrapWell"
68+
/>
69+
6470
</LinearLayout>
6571
</ScrollView>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:background="@android:color/white"
7+
android:orientation="vertical">
8+
9+
<com.beardedhen.androidbootstrap.BootstrapWell
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:layout_gravity="center"
13+
android:layout_margin="8dp"
14+
app:bootstrapSize="xs">
15+
16+
<TextView
17+
android:layout_width="wrap_content"
18+
android:layout_height="wrap_content"
19+
android:gravity="right"
20+
android:text="Look, I'm in a small well!" />
21+
</com.beardedhen.androidbootstrap.BootstrapWell>
22+
23+
<com.beardedhen.androidbootstrap.BootstrapWell
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:layout_gravity="center"
27+
android:layout_margin="8dp">
28+
29+
<TextView
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:gravity="right"
33+
android:text="Look, I'm in a well!" />
34+
</com.beardedhen.androidbootstrap.BootstrapWell>
35+
36+
<com.beardedhen.androidbootstrap.BootstrapWell
37+
android:layout_width="match_parent"
38+
android:layout_height="wrap_content"
39+
android:layout_gravity="center"
40+
android:layout_margin="8dp"
41+
app:bootstrapSize="xl">
42+
43+
<TextView
44+
android:layout_width="wrap_content"
45+
android:layout_height="wrap_content"
46+
android:gravity="right"
47+
android:text="Look, I'm in a large well!" />
48+
</com.beardedhen.androidbootstrap.BootstrapWell>
49+
</LinearLayout>

0 commit comments

Comments
 (0)