Skip to content

Commit

Permalink
#29 #30 bug fixes, #31 improvement and test cases experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashok Varma authored and Ashok Varma committed May 31, 2016
1 parent d3554a2 commit 5a21484
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public void initialise() {
}

if (mBackgroundStyle == BACKGROUND_STYLE_STATIC) {
mBackgroundOverlay.setBackgroundColor(mBackgroundColor);
mBackgroundOverlay.setVisibility(View.GONE);
mContainer.setBackgroundColor(mBackgroundColor);
}

Expand Down Expand Up @@ -419,7 +419,7 @@ public void clearAll() {
mTabContainer.removeAllViews();
mBottomNavigationTabs.clear();
mBottomNavigationItems.clear();
mBackgroundOverlay.setBackgroundColor(Color.TRANSPARENT);
mBackgroundOverlay.setVisibility(View.GONE);
mContainer.setBackgroundColor(Color.TRANSPARENT);
mSelectedPosition = DEFAULT_SELECTED_POSITION;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ private static void setBadgeForTab(BadgeItem badgeItem, BottomNavigationTab bott
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) bottomNavigationTab.badgeView.getLayoutParams();
layoutParams.gravity = badgeItem.getGravity();
bottomNavigationTab.badgeView.setLayoutParams(layoutParams);

if(badgeItem.isHidden()){
// if hide is called before the initialisation of bottom-bar this will handle that
// by hiding it.
badgeItem.hide();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,21 @@ void init() {
iconView = (ImageView) view.findViewById(R.id.fixed_bottom_navigation_icon);
badgeView = (TextView) view.findViewById(R.id.fixed_bottom_navigation_badge);

labelScale = getResources().getDimension(R.dimen.fixed_label_active) / getResources().getDimension(R.dimen.fixed_label_inactive);
labelScale = getResources().getDimension(R.dimen.fixed_label_inactive) / getResources().getDimension(R.dimen.fixed_label_active);

super.init();
}

@Override
public void select(boolean setActiveColor, int animationDuration) {

labelView.animate().scaleX(labelScale).scaleY(labelScale).setDuration(animationDuration).start();
labelView.animate().scaleX(1).scaleY(1).setDuration(animationDuration).start();
// labelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.fixed_label_active));
super.select(setActiveColor, animationDuration);
}

@Override
public void unSelect(boolean setActiveColor, int animationDuration) {
labelView.animate().scaleX(1).scaleY(1).setDuration(animationDuration).start();
labelView.animate().scaleX(labelScale).scaleY(labelScale).setDuration(animationDuration).start();
// labelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.fixed_label_inactive));
super.unSelect(setActiveColor, animationDuration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
android:gravity="center"
android:includeFontPadding="false"
android:lines="1"
android:textSize="@dimen/fixed_label_inactive" />
android:scaleX="@dimen/fixed_label_active_to_inactive_ratio"
android:scaleY="@dimen/fixed_label_active_to_inactive_ratio"
android:textSize="@dimen/fixed_label_active" />

</FrameLayout>
2 changes: 1 addition & 1 deletion bottom-navigation-bar/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<dimen name="fixed_label_active">14sp</dimen>
<dimen name="fixed_label_inactive">12sp</dimen>
<!--<item name="fixed_label_active_to_inactive_ratio" format="float" type="dimen">0.857</item>-->
<item name="fixed_label_active_to_inactive_ratio" format="float" type="dimen">0.857</item>

<dimen name="fixed_icon_grid">24dp</dimen>
<dimen name="fixed_icon_badge_grid_height">36dp
Expand Down
16 changes: 15 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ android {
targetSdkVersion Integer.parseInt(ANDROID_BUILD_TARGET_SDK_VERSION)
versionCode Integer.parseInt(APP_VERSION_CODE)
versionName project.APP_VERSION_NAME

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
Expand All @@ -48,11 +50,23 @@ ext {
}

dependencies {
testCompile 'junit:junit:4.12'
// testCompile 'junit:junit:4.12'
compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
compile "com.android.support:design:${supportLibraryVersion}"
compile project(':bottom-navigation-bar')
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
transitive = true;
}

// Testing-only dependencies

// Android testing support library's runner and rules
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
// Force usage of support annotations in the test app, since it is internally used by the runner module.
// to avoid Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.4.0) and test app (23.1.1) differ.
androidTestCompile "com.android.support:support-annotations:${supportLibraryVersion}"

// Espresso Ui Testing dependencies
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.ashokvarma.sample;

import android.support.test.rule.ActivityTestRule;

import com.ashokvarma.bottomnavigation.sample.HomeActivity;
import com.ashokvarma.bottomnavigation.sample.R;

import org.junit.Rule;
import org.junit.Test;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.isRoot;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

/**
* Class description
*
* @author ashokvarma
* @version 1.0
* @see
* @since 26 May 2016
*/
public class HomeScreenTest {

@Rule
public ActivityTestRule<HomeActivity> mHomeActivityTestRule =
new ActivityTestRule<HomeActivity>(HomeActivity.class);


@Test
public void scrollHome_test() throws Exception {
onView(withId(R.id.nested_scroll_view))
.perform(Utils.swipeUpSlow());

onView(isRoot()).perform(Utils.waitId(R.id.nested_scroll_view, 150 * 1000));

onView(withId(R.id.nested_scroll_view))
.perform(Utils.swipeDownSlow());

onView(withId(R.id.items_3))
.perform(click());

onView(isRoot()).perform(Utils.waitId(R.id.nested_scroll_view, 150 * 1000));

}


}
160 changes: 160 additions & 0 deletions sample/src/androidTest/java/com/ashokvarma/sample/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package com.ashokvarma.sample;

import android.support.test.espresso.PerformException;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.CoordinatesProvider;
import android.support.test.espresso.action.GeneralLocation;
import android.support.test.espresso.action.GeneralSwipeAction;
import android.support.test.espresso.action.Press;
import android.support.test.espresso.action.Swipe;
import android.support.test.espresso.util.HumanReadables;
import android.support.test.espresso.util.TreeIterables;
import android.view.View;

import org.hamcrest.Matcher;

import java.util.concurrent.TimeoutException;

import static android.support.test.espresso.action.ViewActions.actionWithAssertions;
import static android.support.test.espresso.matcher.ViewMatchers.isRoot;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

/**
* Class description
*
* @author ashokvarma
* @version 1.0
* @see
* @since 26 May 2016
*/
public class Utils {
/**
* The distance of a swipe's start position from the view's edge, in terms of the view's length.
* We do not start the swipe exactly on the view's edge, but somewhat more inward, since swiping
* from the exact edge may behave in an unexpected way (e.g. may open a navigation drawer).
*/
private static final float EDGE_FUZZ_FACTOR = 0.083f;


/**
* Perform action of waiting for a specific view id.
*/
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}

@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}

@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);

do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}

uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);

// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}

/**
* Returns an action that performs a swipe right-to-left across the vertical center of the
* view. The swipe doesn't start at the very edge of the view, but is a bit offset.<br>
* <br>
* View constraints:
* <ul>
* <li>must be displayed on screen
* <ul>
*/
public static ViewAction swipeLeftSlow() {
return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
translate(GeneralLocation.CENTER_RIGHT, -EDGE_FUZZ_FACTOR, 0),
GeneralLocation.CENTER_LEFT, Press.FINGER));
}

/**
* Returns an action that performs a swipe left-to-right across the vertical center of the
* view. The swipe doesn't start at the very edge of the view, but is a bit offset.<br>
* <br>
* View constraints:
* <ul>
* <li>must be displayed on screen
* <ul>
*/
public static ViewAction swipeRightSlow() {
return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
translate(GeneralLocation.CENTER_LEFT, EDGE_FUZZ_FACTOR, 0),
GeneralLocation.CENTER_RIGHT, Press.FINGER));
}

/**
* Returns an action that performs a swipe top-to-bottom across the horizontal center of the view.
* The swipe doesn't start at the very edge of the view, but has a bit of offset.<br>
* <br>
* View constraints:
* <ul>
* <li>must be displayed on screen
* <ul>
*/
public static ViewAction swipeDownSlow() {
return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
translate(GeneralLocation.TOP_CENTER, 0, EDGE_FUZZ_FACTOR),
GeneralLocation.BOTTOM_CENTER, Press.FINGER));
}

/**
* Returns an action that performs a swipe bottom-to-top across the horizontal center of the view.
* The swipe doesn't start at the very edge of the view, but has a bit of offset.<br>
* <br>
* View constraints:
* <ul>
* <li>must be displayed on screen
* <ul>
*/
public static ViewAction swipeUpSlow() {
return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
translate(GeneralLocation.BOTTOM_CENTER, 0, -EDGE_FUZZ_FACTOR),
GeneralLocation.TOP_CENTER, Press.FINGER));
}

/**
* Translates the given coordinates by the given distances. The distances are given in term
* of the view's size -- 1.0 means to translate by an amount equivalent to the view's length.
*/
static CoordinatesProvider translate(final CoordinatesProvider coords,
final float dx, final float dy) {
return new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
float xy[] = coords.calculateCoordinates(view);
xy[0] += dx * view.getWidth();
xy[1] += dy * view.getHeight();
return xy;
}
};
}
}
2 changes: 1 addition & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".BottomNavigationActivity">
<activity android:name=".HomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import io.fabric.sdk.android.Fabric;

public class BottomNavigationActivity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener, BottomNavigationBar.OnTabSelectedListener {
public class HomeActivity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener, BottomNavigationBar.OnTabSelectedListener {

BottomNavigationBar bottomNavigationBar;

Expand Down Expand Up @@ -194,9 +194,9 @@ private void refresh() {

if (items3.isChecked()) {
bottomNavigationBar
.addItem(new BottomNavigationItem(R.drawable.ic_location_on_white_24dp, "Location").setActiveColorResource(R.color.orange).setBadgeItem(numberBadgeItem))
.addItem(new BottomNavigationItem(R.drawable.ic_location_on_white_24dp, "Nearby").setActiveColorResource(R.color.orange).setBadgeItem(numberBadgeItem))
.addItem(new BottomNavigationItem(R.drawable.ic_find_replace_white_24dp, "Find").setActiveColorResource(R.color.teal))
.addItem(new BottomNavigationItem(R.drawable.ic_favorite_white_24dp, "Favorites").setActiveColorResource(R.color.blue))
.addItem(new BottomNavigationItem(R.drawable.ic_favorite_white_24dp, "Categories").setActiveColorResource(R.color.blue))
.setFirstSelectedPosition(lastSelectedPosition > 2 ? 2 : lastSelectedPosition)
.initialise();
} else if (items4.isChecked()) {
Expand Down
7 changes: 5 additions & 2 deletions sample/src/main/res/layout/activity_bottom_navigation.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ececec"
tools:context=".BottomNavigationActivity">
tools:context=".HomeActivity">

<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/nested_scroll_child"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Expand Down Expand Up @@ -46,14 +49,14 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="@string/bs_static" />

<CheckBox
android:id="@+id/bg_ripple"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="@string/bs_ripple" />
</LinearLayout>

Expand Down

0 comments on commit 5a21484

Please sign in to comment.