Skip to content

Commit

Permalink
- Removing the view for API 21
Browse files Browse the repository at this point in the history
- Adding a negative margin for API 20 or less so that the content is overlapped with the shadow
- Fix the annotation for the MiscUtils
  • Loading branch information
yombunker committed Mar 27, 2017
1 parent 7b8f597 commit cc0f5d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
26 changes: 18 additions & 8 deletions bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class BottomBar extends LinearLayout implements View.OnClickListener, Vie
private int titleTextAppearance;
private Typeface titleTypeFace;
private boolean showShadow;
private float shadowElevation;

private View backgroundOverlay;
private ViewGroup outerContainer;
Expand Down Expand Up @@ -118,16 +119,16 @@ public BottomBar(Context context, AttributeSet attrs) {
}

private void init(Context context, AttributeSet attrs) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
init21(context);
}

batchPropertyApplier = new BatchTabPropertyApplier(this);

populateAttributes(context, attrs);
initializeViews();
determineInitialBackgroundColor();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
init21(context);
}

if (tabXmlResource != 0) {
setItems(tabXmlResource);
}
Expand All @@ -137,19 +138,29 @@ private void init(Context context, AttributeSet attrs) {
protected void onAttachedToWindow() {
super.onAttachedToWindow();

// This is so that in Pre-Lollipop devices there is a shadow BUT without pushing the content
if (showShadow) {
ViewGroup.LayoutParams params = getLayoutParams();
if (params instanceof MarginLayoutParams) {
MarginLayoutParams layoutParams = (MarginLayoutParams) params;
layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin - MiscUtils.dpToPixel(getContext(), 4), layoutParams.rightMargin, layoutParams.bottomMargin);
final int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bb_fake_shadow_height);

layoutParams.setMargins(layoutParams.leftMargin,
layoutParams.topMargin - shadowHeight,
layoutParams.rightMargin,
layoutParams.bottomMargin);
setLayoutParams(params);
}
}
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private void init21(Context context) {
setElevation(MiscUtils.dpToPixel(context, 8));
shadowElevation = getElevation();
shadowElevation = shadowElevation > 0
? shadowElevation
: getResources().getDimensionPixelSize(R.dimen.bb_default_elevation);
setElevation(MiscUtils.dpToPixel(context, shadowElevation));
setOutlineProvider(ViewOutlineProvider.BOUNDS);
}

Expand All @@ -159,8 +170,7 @@ private void populateAttributes(Context context, AttributeSet attrs) {
tenDp = MiscUtils.dpToPixel(getContext(), 10);
maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168);

TypedArray ta = context.getTheme().obtainStyledAttributes(
attrs, R.styleable.BottomBar, 0, 0);
TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BottomBar, 0, 0);

try {
tabXmlResource = ta.getResourceId(R.styleable.BottomBar_bb_tabXmlResource, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<View
android:id="@+id/bb_bottom_bar_shadow"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_height="@dimen/bb_fake_shadow_height"
android:background="@drawable/bb_bottom_bar_top_shadow" />

<FrameLayout
Expand Down
2 changes: 2 additions & 0 deletions bottom-bar/src/main/res/values/dimensions.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="bb_height">56dp</dimen>
<dimen name="bb_default_elevation">8dp</dimen>
<dimen name="bb_fake_shadow_height">4dp</dimen>
</resources>

0 comments on commit cc0f5d1

Please sign in to comment.