Skip to content

Bootstrap Well implementation #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ static ColorStateList bootstrapButtonText(Context context, boolean outline, Boot
return new ColorStateList(getStateList(), getColorList(defaultColor, activeColor, disabledColor));
}

static Drawable bootstrapWell(@ColorInt int backgroundColor, int cornerRadius, int strokeWidth, @ColorInt int strokeColor) {
GradientDrawable background = new GradientDrawable();
background.setColor(backgroundColor);
background.setCornerRadius(cornerRadius);
background.setStroke(strokeWidth, strokeColor);
return background;
}

private static StateListDrawable setupStateDrawable(ViewGroupPosition position, int strokeWidth, GradientDrawable defaultGd, GradientDrawable activeGd, GradientDrawable disabledGd) {
StateListDrawable stateListDrawable = new StateListDrawable();
LayerDrawable defaultLayer = new LayerDrawable(new Drawable[]{defaultGd});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.beardedhen.androidbootstrap;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.FrameLayout;

import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapSize;
import com.beardedhen.androidbootstrap.utils.ColorUtils;
import com.beardedhen.androidbootstrap.utils.DimenUtils;

public class BootstrapWell extends FrameLayout {

private float bootstrapSize;

public BootstrapWell(Context context) {
super(context);
initialise(null);
}

public BootstrapWell(Context context, AttributeSet attrs) {
super(context, attrs);
initialise(attrs);
}

public BootstrapWell(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialise(attrs);
}

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

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

bootstrapSize = DefaultBootstrapSize.fromAttributeValue(sizeOrdinal).scaleFactor();
}
finally {
a.recycle();
}
updateBootstrapState();
}

private void updateBootstrapState() {
Drawable bg = BootstrapDrawableFactory.bootstrapWell(ColorUtils.resolveColor(R.color.bootstrap_well_background, getContext()),
(int) (DimenUtils.pixelsFromDpResource(getContext(), R.dimen.bootstrap_well_corner_radius) * bootstrapSize / 2),
(int) DimenUtils.pixelsFromDpResource(getContext(), R.dimen.bootstrap_well_stroke_width),
ColorUtils.resolveColor(R.color.bootstrap_well_border_color, getContext()));

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

int padding = (int) (DimenUtils.pixelsFromDpResource(getContext(), R.dimen.bootstrap_well_default_padding) * bootstrapSize * 2.5);
setPadding(padding, padding, padding, padding);
}
}
4 changes: 4 additions & 0 deletions AndroidBootstrap/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,9 @@
<attr name="bootstrapSize"/>
</declare-styleable>

<declare-styleable name="BootstrapWell">
<attr name="bootstrapSize"/>
</declare-styleable>

</resources>

2 changes: 2 additions & 0 deletions AndroidBootstrap/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
<!-- Misc -->
<color name="bootstrap_edittext_disabled">#ffe0e0e0</color>
<color name="bootstrap_thumbnail_background">#ffffffff</color>
<color name="bootstrap_well_background">#F5F5F5</color>
<color name="bootstrap_well_border_color">#E7E7E7</color>

</resources>
5 changes: 5 additions & 0 deletions AndroidBootstrap/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<dimen name="bthumbnail_rounded_corner">8dp</dimen>
<dimen name="bthumbnail_outer_stroke">2dp</dimen>

<!--Well-->
<dimen name="bootstrap_well_corner_radius">8dp</dimen>
<dimen name="bootstrap_well_stroke_width">1dp</dimen>
<dimen name="bootstrap_well_default_padding">6dp</dimen>

<!-- Headings -->
<dimen name="bootstrap_h1_text_size">31.5sp</dimen>
<dimen name="bootstrap_h1_vert_padding">7.875dp</dimen>
Expand Down
4 changes: 4 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
android:name=".BootstrapEditTextExample"
android:label="BootstrapEditTextExample"
/>
<activity
android:name=".BootstrapWellExample"
android:label="BootstrapEditTextExample"
/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.fractalwrench.androidbootstrap.sample;

import android.app.Activity;
import android.os.Bundle;

public class BootstrapWellExample extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.example_bootstrap_well);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ public class HomeActivity extends AppCompatActivity {
startActivity(new Intent(this, BootstrapThumbnailExample.class));
}

@OnClick(R.id.example_bootstrap_well) void onBootstrapWellExampleClicked() {
startActivity(new Intent(this, BootstrapWellExample.class));
}

}
6 changes: 6 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,11 @@
android:text="BootstrapThumbnail"
/>

<Button
android:id="@+id/example_bootstrap_well"
style="@style/home_button"
android:text="BootstrapWell"
/>

</LinearLayout>
</ScrollView>
49 changes: 49 additions & 0 deletions sample/src/main/res/layout/example_bootstrap_well.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">

<com.beardedhen.androidbootstrap.BootstrapWell
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
app:bootstrapSize="xs">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Look, I'm in a small well!" />
</com.beardedhen.androidbootstrap.BootstrapWell>

<com.beardedhen.androidbootstrap.BootstrapWell
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Look, I'm in a well!" />
</com.beardedhen.androidbootstrap.BootstrapWell>

<com.beardedhen.androidbootstrap.BootstrapWell
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
app:bootstrapSize="xl">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Look, I'm in a large well!" />
</com.beardedhen.androidbootstrap.BootstrapWell>
</LinearLayout>