Skip to content

Commit

Permalink
Bug fix/shadow not respecting flag (#749)
Browse files Browse the repository at this point in the history
* Data binding fixes clean (#712)

* Fix Bottom Bar issues with Android Data Binding

* keep .idea

* travis changes

* Fix for shadow (#716)

* - Removing the view for API 21
- Adding a negative margin for API 20 or less so that the content is overlapped with the shadow
- Fix the annotation for the MiscUtils

* - Removing the view for API 21
- Adding a negative margin for API 20 or less so that the content is overlapped with the shadow
- Fix the annotation for the MiscUtils

* - Removing the view for API 21
- Adding a negative margin for API 20 or less so that the content is overlapped with the shadow
- Fix the annotation for the MiscUtils

* SelectableItemBackground Ripple! (#713)

* Add selectableItemBackground programmatically which shows user touch response with either ripple or slight change of colour if below lollipop.

* Remove style in tablet mode which makes ripple go out of bounds. Without it ripple is contained within its view.

* Remove unnecessary local reference.

* Added getTypedValue and getDrawableRes methods in MiscUtils and changed to selectableItemBackgroundBorderless.

* Change color to resId.

* Fix for wrong size in tabs

- Setting the modified LayoutParams so that the views are changed (#719)

* Tabs without titles (#717)

* Update CHANGELOG.md

* Update README.md

* Update README.md

* Basic support for tabs that have no title, only icons.

* Reverted debug code.

* Made sure that icon-only tabs throw an exception if they don't have icons.

* There's no need to set visibility to the title, as it's already visible.

* Added a sample for the icons only mode.

* Made the titleless mode combined with shifting mode work.

* Removed the eight dp padding from XML layout, since that offsets titleless tab icons from the center & isn't needed anyway since it's set dynamically.

* Added some zoom to active tab icons that are both shifting and titleless.

* Cleared up the select & unselect methods.

* Modified the color changing tabs sample height, so it looks less crammed and more like the design specs.

* Show & Hide methods when on shy mode. (#722)

* Added methods for showing / hiding the BottomBar when on shy mode.

* Better naming.

* Refactored the hide / show methods to a separate ShySettings class, since they were only related for a shy BottomBar.

* Made getting shy settings not throw an exception when the bottombar isn't shy, but have a log warning instead.

* Made it possible to have individual titleless tabs. (#726)

* Feature/optional long press toasts (#714)

* Update CHANGELOG.md

* Update README.md

* Update README.md

* Made it possible to control whether or not the Toasts are shown when long pressing tabs.

* Updated changelog.

* - Fix for shadow not respecting flag
   - API 21+ was not using the flag at all
   - API 20- where not removing the margin when no shadow was displayed
   - API 20- set the default visibility of the shadow to GONE
  • Loading branch information
yombunker authored and roughike committed Apr 12, 2017
1 parent 9bfea75 commit 0c64559
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 33 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ Thanks for @yombunker, @MarcRubio and @tushar-acharya for their contributions!
* Overriding tab selections is now supported, by using [TabSelectionInterceptor](https://github.com/roughike/BottomBar/blob/master/bottom-bar/src/main/java/com/roughike/bottombar/TabSelectionInterceptor.java)
* Internal code quality improvements and small changes

### 2.2.0

* Ability to change icons when the tabs are selected, using drawable selectors
* Overriding tab selections is now supported, by using [TabSelectionInterceptor](https://github.com/roughike/BottomBar/blob/master/bottom-bar/src/main/java/com/roughike/bottombar/TabSelectionInterceptor.java)
* Internal code quality improvements and small changes

### 2.1.2

* Merged [#703](https://github.com/roughike/BottomBar/pull/703) that allows controlling badge visibility for tabs that are active.
Expand Down
69 changes: 40 additions & 29 deletions bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class BottomBar extends LinearLayout implements View.OnClickListener, Vie
private Typeface titleTypeFace;
private boolean showShadow;
private float shadowElevation;
private View shadowView;

private View backgroundOverlay;
private ViewGroup outerContainer;
Expand Down Expand Up @@ -153,7 +154,8 @@ protected void onAttachedToWindow() {
super.onAttachedToWindow();

// This is so that in Pre-Lollipop devices there is a shadow BUT without pushing the content
if (showShadow) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && showShadow && shadowView != null) {
shadowView.setVisibility(VISIBLE);
ViewGroup.LayoutParams params = getLayoutParams();
if (params instanceof MarginLayoutParams) {
MarginLayoutParams layoutParams = (MarginLayoutParams) params;
Expand All @@ -170,12 +172,14 @@ protected void onAttachedToWindow() {

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

private void populateAttributes(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
Expand All @@ -184,7 +188,8 @@ private void populateAttributes(Context context, AttributeSet attrs, int defStyl
tenDp = MiscUtils.dpToPixel(getContext(), 10);
maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168);

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

try {
tabXmlResource = ta.getResourceId(R.styleable.BottomBar_bb_tabXmlResource, 0);
Expand Down Expand Up @@ -230,7 +235,9 @@ boolean isShyHeightAlreadyCalculated() {
return shyHeightAlreadyCalculated;
}

private boolean isIconsOnlyMode() { return !isTabletMode && hasBehavior(BEHAVIOR_ICONS_ONLY); }
private boolean isIconsOnlyMode() {
return !isTabletMode && hasBehavior(BEHAVIOR_ICONS_ONLY);
}

private boolean hasBehavior(int behavior) {
return (behaviors | behavior) == behaviors;
Expand Down Expand Up @@ -260,6 +267,7 @@ private void initializeViews() {
backgroundOverlay = rootView.findViewById(R.id.bb_bottom_bar_background_overlay);
outerContainer = (ViewGroup) rootView.findViewById(R.id.bb_bottom_bar_outer_container);
tabContainer = (ViewGroup) rootView.findViewById(R.id.bb_bottom_bar_item_container);
shadowView = findViewById(R.id.bb_bottom_bar_shadow);
}

private void determineInitialBackgroundColor() {
Expand Down Expand Up @@ -386,7 +394,8 @@ private void resizeTabsToCorrectSizes(BottomBarTab[] tabsToAdd) {

inActiveShiftingItemWidth = (int) (proposedItemWidth * 0.9);
activeShiftingItemWidth = (int) (proposedItemWidth + (proposedItemWidth * ((tabsToAdd.length - 1) * 0.1)));
int height = Math.round(getContext().getResources().getDimension(R.dimen.bb_height));
int height = Math.round(getContext().getResources()
.getDimension(R.dimen.bb_height));

for (BottomBarTab tabView : tabsToAdd) {
ViewGroup.LayoutParams params = tabView.getLayoutParams();
Expand Down Expand Up @@ -925,7 +934,8 @@ private boolean handleLongClick(BottomBarTab longClickedTab) {
&& longPressHintsEnabled;

if (shouldShowHint) {
Toast.makeText(getContext(), longClickedTab.getTitle(), Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), longClickedTab.getTitle(), Toast.LENGTH_SHORT)
.show();
}

return true;
Expand Down Expand Up @@ -1044,23 +1054,24 @@ private void onEnd() {
private void backgroundCrossfadeAnimation(final int newColor) {
ViewCompat.setAlpha(backgroundOverlay, 0);
ViewCompat.animate(backgroundOverlay)
.alpha(1)
.setListener(new ViewPropertyAnimatorListenerAdapter() {
@Override
public void onAnimationEnd(View view) {
onEnd();
}

@Override
public void onAnimationCancel(View view) {
onEnd();
}

private void onEnd() {
outerContainer.setBackgroundColor(newColor);
backgroundOverlay.setVisibility(View.INVISIBLE);
ViewCompat.setAlpha(backgroundOverlay, 1);
}
}).start();
.alpha(1)
.setListener(new ViewPropertyAnimatorListenerAdapter() {
@Override
public void onAnimationEnd(View view) {
onEnd();
}

@Override
public void onAnimationCancel(View view) {
onEnd();
}

private void onEnd() {
outerContainer.setBackgroundColor(newColor);
backgroundOverlay.setVisibility(View.INVISIBLE);
ViewCompat.setAlpha(backgroundOverlay, 1);
}
})
.start();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
android:id="@+id/bb_bottom_bar_shadow"
android:layout_width="match_parent"
android:layout_height="@dimen/bb_fake_shadow_height"
android:background="@drawable/bb_bottom_bar_top_shadow" />
android:background="@drawable/bb_bottom_bar_top_shadow"
android:visibility="gone"/>

<FrameLayout
android:id="@+id/bb_bottom_bar_outer_container"
Expand All @@ -16,14 +17,14 @@
android:id="@+id/bb_bottom_bar_background_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
android:visibility="invisible"/>

<LinearLayout
android:id="@+id/bb_bottom_bar_item_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal" />
android:orientation="horizontal"/>

</FrameLayout>

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.4.0'
Expand Down

0 comments on commit 0c64559

Please sign in to comment.