Skip to content

Commit 4d6ecee

Browse files
committed
Lint analyze check.
Code refactoring. Code cleanup. Update readme.
1 parent 001625a commit 4d6ecee

File tree

5 files changed

+94
-134
lines changed

5 files changed

+94
-134
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-NavigationTabBar-blue.svg?style=flat-square)](http://android-arsenal.com/details/1/3382)
22
[![Download](https://api.bintray.com/packages/gigamole/maven/navigationtabbar/images/download.svg) ](https://bintray.com/gigamole/maven/navigationtabbar/_latestVersion)
3+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/06516143fa4448c5a5166ac8873d5527)](https://www.codacy.com/app/gigamole53/NavigationTabBar?utm_source=github.com&utm_medium=referral&utm_content=DevLight-Mobile-Agency/NavigationTabBar&utm_campaign=Badge_Grade)
34

45
NavigationTabBar
56
===================
@@ -296,9 +297,9 @@ Apache 2.0 and MIT. See [LICENSE](https://github.com/DevLight-Mobile-Agency/Navi
296297
Inspiration
297298
======
298299

299-
TapBar interactions| Circle interactions | Title interactions
300-
:-------------------------:|:-------------------------:|:-------------------------:
301-
![](https://s-media-cache-ak0.pinimg.com/originals/39/ee/33/39ee330f3460bd638284f0576bc95b65.gif)|![](https://s-media-cache-ak0.pinimg.com/564x/f4/0d/a9/f40da9e5b73eb5e0e46681eba38f1347.jpg)|![](https://s-media-cache-ak0.pinimg.com/564x/14/eb/dd/14ebddfc0d92f02be3d61ede48a9da6e.jpg)
300+
TapBar interactions| Circle interactions | Title interactions | Player interactions
301+
:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:
302+
![](https://s-media-cache-ak0.pinimg.com/originals/39/ee/33/39ee330f3460bd638284f0576bc95b65.gif)|![](https://s-media-cache-ak0.pinimg.com/564x/f4/0d/a9/f40da9e5b73eb5e0e46681eba38f1347.jpg)|![](https://s-media-cache-ak0.pinimg.com/564x/14/eb/dd/14ebddfc0d92f02be3d61ede48a9da6e.jpg)|![](https://d13yacurqjgara.cloudfront.net/users/25514/screenshots/1367175/attachments/195679/Sleep-Tracker-iPhone-UI-ramotion.png)
302303

303304
Thanks to [Valery Nuzhniy](https://www.pinterest.com/hevbolt/) for NTB badge design.
304305

navigationtabbar/build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ version = "1.2.3"
2323

2424
android {
2525
compileSdkVersion 23
26-
buildToolsVersion "23.0.2"
26+
buildToolsVersion "23.0.3"
2727

2828
defaultConfig {
2929
minSdkVersion 11
@@ -41,6 +41,7 @@ android {
4141

4242
dependencies {
4343
compile fileTree(dir: 'libs', include: ['*.jar'])
44+
//noinspection GradleDependency
4445
compile 'com.android.support:design:23.2.1'
4546
}
4647

@@ -52,24 +53,28 @@ install {
5253
repositories.mavenInstaller {
5354
// This generates POM.xml with proper parameters
5455
pom {
56+
//noinspection GroovyAssignabilityCheck
5557
project {
5658
packaging 'aar'
5759

5860
// Add your description here
61+
//noinspection GroovyAssignabilityCheck
5962
name 'NavigationTabBar'
6063
description = 'Navigation tab bar with colorful interactions.'
6164
url siteUrl
6265

6366
// Set your license
6467
licenses {
6568
license {
69+
//noinspection GroovyAssignabilityCheck
6670
name 'The Apache Software License, Version 2.0'
6771
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
6872
}
6973
}
7074
developers {
7175
developer {
7276
id 'gigamole'
77+
//noinspection GroovyAssignabilityCheck
7378
name 'Basil Miller'
7479
7580
}
@@ -85,17 +90,20 @@ install {
8590
}
8691

8792
task sourcesJar(type: Jar) {
93+
//noinspection GroovyAssignabilityCheck
8894
from android.sourceSets.main.java.srcDirs
8995
classifier = 'sources'
9096
}
9197

9298
task javadoc(type: Javadoc) {
9399
source = android.sourceSets.main.java.srcDirs
100+
//noinspection GroovyAssignabilityCheck
94101
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
95102
}
96103

97104
task javadocJar(type: Jar, dependsOn: javadoc) {
98105
classifier = 'javadoc'
106+
//noinspection GrUnresolvedAccess
99107
from javadoc.destinationDir
100108
}
101109
artifacts {
@@ -119,6 +127,7 @@ bintray {
119127
vcsUrl = gitUrl
120128
licenses = ["Apache-2.0"]
121129
publish = true
130+
//noinspection GroovyAssignabilityCheck
122131
version {
123132
gpg {
124133
sign = true //Determines whether to GPG sign the files. The default is false

navigationtabbar/src/main/java/com/gigamole/navigationtabbar/behavior/NavigationTabBarBehavior.java

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import android.animation.ObjectAnimator;
44
import android.animation.ValueAnimator;
5-
import android.content.Context;
6-
import android.content.res.TypedArray;
75
import android.os.Build;
86
import android.support.design.widget.CoordinatorLayout;
97
import android.support.design.widget.FloatingActionButton;
@@ -12,12 +10,10 @@
1210
import android.support.v4.view.ViewPropertyAnimatorCompat;
1311
import android.support.v4.view.ViewPropertyAnimatorUpdateListener;
1412
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
15-
import android.util.AttributeSet;
1613
import android.view.View;
1714
import android.view.ViewGroup;
1815
import android.view.animation.Interpolator;
1916

20-
import com.gigamole.navigationtabbar.R;
2117
import com.gigamole.navigationtabbar.ntb.NavigationTabBar;
2218

2319
public class NavigationTabBarBehavior extends VerticalScrollingBehavior<NavigationTabBar> {
@@ -27,10 +23,10 @@ public class NavigationTabBarBehavior extends VerticalScrollingBehavior<Navigati
2723

2824
private ViewPropertyAnimatorCompat mTranslationAnimator;
2925
private ObjectAnimator mTranslationObjectAnimator;
30-
private Snackbar.SnackbarLayout mSnackbarLayout;
26+
private Snackbar.SnackbarLayout mSnackBarLayout;
3127
private FloatingActionButton mFloatingActionButton;
3228

33-
private int mSnackbarHeight = -1;
29+
private int mSnackBarHeight = -1;
3430
private float
3531
mTargetOffset = 0,
3632
mFabTargetOffset = 0,
@@ -45,13 +41,6 @@ public NavigationTabBarBehavior(final boolean behaviorTranslationEnabled) {
4541
this.mBehaviorTranslationEnabled = behaviorTranslationEnabled;
4642
}
4743

48-
public NavigationTabBarBehavior(final Context context, final AttributeSet attrs) {
49-
super(context, attrs);
50-
final TypedArray typedArray =
51-
context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
52-
typedArray.recycle();
53-
}
54-
5544
@Override
5645
public boolean onLayoutChild(CoordinatorLayout parent, NavigationTabBar child, int layoutDirection) {
5746
return super.onLayoutChild(parent, child, layoutDirection);
@@ -70,21 +59,23 @@ public void onDependentViewRemoved(CoordinatorLayout parent, NavigationTabBar ch
7059

7160
@Override
7261
public boolean layoutDependsOn(CoordinatorLayout parent, NavigationTabBar child, View dependency) {
73-
updateSnackbar(child, dependency);
62+
updateSnackBar(child, dependency);
7463
updateFloatingActionButton(dependency);
7564
return super.layoutDependsOn(parent, child, dependency);
7665
}
7766

7867
@Override
79-
public void onNestedVerticalOverScroll(CoordinatorLayout coordinatorLayout, NavigationTabBar child, @ScrollDirection int direction, int currentOverScroll, int totalOverScroll) {
68+
public void onNestedVerticalOverScroll() {
69+
// This method is intentionally empty, because of override
8070
}
8171

8272
@Override
83-
public void onDirectionNestedPreScroll(CoordinatorLayout coordinatorLayout, NavigationTabBar child, View target, int dx, int dy, int[] consumed, @ScrollDirection int scrollDirection) {
73+
public void onDirectionNestedPreScroll() {
74+
// This method is intentionally empty, because of override
8475
}
8576

8677
@Override
87-
protected boolean onNestedDirectionFling(CoordinatorLayout coordinatorLayout, NavigationTabBar child, View target, float velocityX, float velocityY, @ScrollDirection int scrollDirection) {
78+
protected boolean onNestedDirectionFling() {
8879
return false;
8980
}
9081

@@ -132,15 +123,15 @@ private void ensureOrCancelAnimator(final NavigationTabBar child, boolean withAn
132123
mTranslationAnimator.setUpdateListener(new ViewPropertyAnimatorUpdateListener() {
133124
@Override
134125
public void onAnimationUpdate(View view) {
135-
// Animate snackbar
136-
if (mSnackbarLayout != null && mSnackbarLayout.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
126+
// Animate snack bar
127+
if (mSnackBarLayout != null && mSnackBarLayout.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
137128
mTargetOffset = child.getBarHeight() - view.getTranslationY();
138129

139130
final ViewGroup.MarginLayoutParams p =
140-
(ViewGroup.MarginLayoutParams) mSnackbarLayout.getLayoutParams();
131+
(ViewGroup.MarginLayoutParams) mSnackBarLayout.getLayoutParams();
141132

142133
p.setMargins(p.leftMargin, p.topMargin, p.rightMargin, (int) mTargetOffset);
143-
mSnackbarLayout.requestLayout();
134+
mSnackBarLayout.requestLayout();
144135
}
145136
// Animate Floating Action Button
146137
if (mFloatingActionButton != null && mFloatingActionButton.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
@@ -183,13 +174,13 @@ private void ensureOrCancelObjectAnimation(final NavigationTabBar child, final i
183174
mTranslationObjectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
184175
@Override
185176
public void onAnimationUpdate(ValueAnimator animation) {
186-
if (mSnackbarLayout != null && mSnackbarLayout.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
177+
if (mSnackBarLayout != null && mSnackBarLayout.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
187178
mTargetOffset = child.getBarHeight() - child.getTranslationY();
188179

189180
final ViewGroup.MarginLayoutParams p =
190-
(ViewGroup.MarginLayoutParams) mSnackbarLayout.getLayoutParams();
181+
(ViewGroup.MarginLayoutParams) mSnackBarLayout.getLayoutParams();
191182
p.setMargins(p.leftMargin, p.topMargin, p.rightMargin, (int) mTargetOffset);
192-
mSnackbarLayout.requestLayout();
183+
mSnackBarLayout.requestLayout();
193184
}
194185
// Animate Floating Action Button
195186
if (mFloatingActionButton != null && mFloatingActionButton.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
@@ -204,6 +195,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
204195
});
205196
}
206197

198+
@SuppressWarnings("unused")
207199
public static NavigationTabBarBehavior from(NavigationTabBar view) {
208200
final ViewGroup.LayoutParams params = view.getLayoutParams();
209201
if (!(params instanceof CoordinatorLayout.LayoutParams))
@@ -232,19 +224,20 @@ public void hideView(NavigationTabBar view, int offset, boolean withAnimation) {
232224
}
233225

234226
// Reset NTB position with animation
227+
@SuppressWarnings("SameParameterValue")
235228
public void resetOffset(NavigationTabBar view, boolean withAnimation) {
236229
if (mHidden) {
237230
mHidden = false;
238231
animateOffset(view, 0, true, withAnimation);
239232
}
240233
}
241234

242-
// Update Snackbar bottom margin
243-
public void updateSnackbar(final NavigationTabBar child, View dependency) {
235+
// Update snack bar bottom margin
236+
private void updateSnackBar(final NavigationTabBar child, View dependency) {
244237
if (dependency != null && dependency instanceof Snackbar.SnackbarLayout) {
245-
mSnackbarLayout = (Snackbar.SnackbarLayout) dependency;
238+
mSnackBarLayout = (Snackbar.SnackbarLayout) dependency;
246239
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
247-
mSnackbarLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
240+
mSnackBarLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
248241
@Override
249242
public void onLayoutChange(View v, int left, int top, int right, int bottom,
250243
int oldLeft, int oldTop, int oldRight, int oldBottom) {
@@ -261,7 +254,7 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom,
261254
});
262255
}
263256

264-
if (mSnackbarHeight == -1) mSnackbarHeight = dependency.getHeight();
257+
if (mSnackBarHeight == -1) mSnackBarHeight = dependency.getHeight();
265258
final int targetMargin = (int) (child.getBarHeight() - child.getTranslationY());
266259

267260
child.bringToFront();
@@ -281,7 +274,7 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom,
281274
}
282275

283276
// Update floating action button bottom margin
284-
public void updateFloatingActionButton(final View dependency) {
277+
private void updateFloatingActionButton(final View dependency) {
285278
if (dependency != null && dependency instanceof FloatingActionButton) {
286279
mFloatingActionButton = (FloatingActionButton) dependency;
287280

navigationtabbar/src/main/java/com/gigamole/navigationtabbar/behavior/VerticalScrollingBehavior.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package com.gigamole.navigationtabbar.behavior;
22

33

4-
import android.content.Context;
4+
import android.annotation.TargetApi;
5+
import android.os.Build;
56
import android.os.Parcelable;
67
import android.support.annotation.IntDef;
78
import android.support.design.widget.CoordinatorLayout;
89
import android.support.v4.view.WindowInsetsCompat;
9-
import android.util.AttributeSet;
1010
import android.view.View;
1111

1212
import java.lang.annotation.Retention;
1313
import java.lang.annotation.RetentionPolicy;
1414

15-
public abstract class VerticalScrollingBehavior<V extends View> extends CoordinatorLayout.Behavior<V> {
15+
@SuppressWarnings({"unused", "EmptyMethod"})
16+
abstract class VerticalScrollingBehavior<V extends View> extends CoordinatorLayout.Behavior<V> {
1617

1718
private int mTotalDyUnconsumed = 0;
1819
private int mTotalDy = 0;
@@ -30,14 +31,10 @@ public abstract class VerticalScrollingBehavior<V extends View> extends Coordina
3031
int SCROLL_NONE = 0;
3132
}
3233

33-
public VerticalScrollingBehavior() {
34+
VerticalScrollingBehavior() {
3435
super();
3536
}
3637

37-
public VerticalScrollingBehavior(final Context context, final AttributeSet attrs) {
38-
super(context, attrs);
39-
}
40-
4138
@ScrollDirection
4239
public int getOverScrollDirection() {
4340
return mOverScrollDirection;
@@ -48,14 +45,15 @@ public int getScrollDirection() {
4845
return mScrollDirection;
4946
}
5047

51-
// Direction of the overscroll: SCROLL_DIRECTION_UP, SCROLL_DIRECTION_DOWN
48+
// Direction of the over scroll: SCROLL_DIRECTION_UP, SCROLL_DIRECTION_DOWN
5249
// Unconsumed value, negative or positive based on the direction
5350
// Cumulative value for current direction
54-
public abstract void onNestedVerticalOverScroll(CoordinatorLayout coordinatorLayout, V child, @ScrollDirection int direction, int currentOverScroll, int totalOverScroll);
51+
protected abstract void onNestedVerticalOverScroll();
5552

56-
// Direction of the overscroll: SCROLL_DIRECTION_UP, SCROLL_DIRECTION_DOWN
57-
public abstract void onDirectionNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dx, int dy, int[] consumed, @ScrollDirection int scrollDirection);
53+
// Direction of the over scroll: SCROLL_DIRECTION_UP, SCROLL_DIRECTION_DOWN
54+
protected abstract void onDirectionNestedPreScroll();
5855

56+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
5957
@Override
6058
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, V child, View directTargetChild, View target, int nestedScrollAxes) {
6159
return (nestedScrollAxes & View.SCROLL_AXIS_VERTICAL) != 0;
@@ -83,7 +81,7 @@ public void onNestedScroll(CoordinatorLayout coordinatorLayout, V child, View ta
8381
}
8482

8583
mTotalDyUnconsumed += dyUnconsumed;
86-
onNestedVerticalOverScroll(coordinatorLayout, child, mOverScrollDirection, dyConsumed, mTotalDyUnconsumed);
84+
onNestedVerticalOverScroll();
8785
}
8886

8987
@Override
@@ -97,17 +95,18 @@ public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View
9795
mScrollDirection = ScrollDirection.SCROLL_DIRECTION_DOWN;
9896
}
9997
mTotalDy += dy;
100-
onDirectionNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, mScrollDirection);
98+
onDirectionNestedPreScroll();
10199
}
102100

103101
@Override
104102
public boolean onNestedFling(CoordinatorLayout coordinatorLayout, V child, View target, float velocityX, float velocityY, boolean consumed) {
105103
super.onNestedFling(coordinatorLayout, child, target, velocityX, velocityY, consumed);
106104
mScrollDirection = velocityY > 0 ? ScrollDirection.SCROLL_DIRECTION_UP : ScrollDirection.SCROLL_DIRECTION_DOWN;
107-
return onNestedDirectionFling(coordinatorLayout, child, target, velocityX, velocityY, mScrollDirection);
105+
return onNestedDirectionFling();
108106
}
109107

110-
protected abstract boolean onNestedDirectionFling(CoordinatorLayout coordinatorLayout, V child, View target, float velocityX, float velocityY, @ScrollDirection int scrollDirection);
108+
@SuppressWarnings("SameReturnValue")
109+
protected abstract boolean onNestedDirectionFling();
111110

112111
@Override
113112
public boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, V child, View target, float velocityX, float velocityY) {

0 commit comments

Comments
 (0)