Skip to content

Commit 6820027

Browse files
Merge pull request #14 from amy6/UI
Modify BottomNavigationView behaviour as per material design guidelines
2 parents b7b86a8 + 83c7acd commit 6820027

File tree

11 files changed

+188
-95
lines changed

11 files changed

+188
-95
lines changed
535 Bytes
Binary file not shown.

.idea/codeStyles/Project.xml

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

100755100644
File mode changed.

.idea/misc.xml

100755100644
Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

100755100644
File mode changed.

.idea/runConfigurations.xml

100755100644
File mode changed.

app/build.gradle

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
apply plugin: 'com.android.application'
33

44
android {
5-
compileSdkVersion 26
5+
compileSdkVersion 27
66
defaultConfig {
77
applicationId "com.example.dhananjay.dailygoals"
8-
minSdkVersion 15
9-
targetSdkVersion 26
8+
minSdkVersion 21
9+
targetSdkVersion 27
1010
versionCode 1
1111
versionName "1.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -21,13 +21,13 @@ android {
2121

2222
dependencies {
2323
implementation fileTree(dir: 'libs', include: ['*.jar'])
24-
implementation 'com.android.support:appcompat-v7:26.1.0'
25-
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
24+
implementation 'com.android.support:appcompat-v7:27.1.1'
25+
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
2626
testImplementation 'junit:junit:4.12'
27-
androidTestImplementation 'com.android.support.test:runner:0.5'
28-
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
29-
implementation 'com.android.support:cardview-v7:26.1.0'
30-
implementation 'com.android.support:design:26.1.0'
27+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
28+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
29+
implementation 'com.android.support:cardview-v7:27.1.1'
30+
implementation 'com.android.support:design:27.1.1'
3131
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
32-
implementation 'com.android.support:recyclerview-v7:26.1.0'
32+
implementation 'com.android.support:recyclerview-v7:27.1.1'
3333
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.example.dhananjay.dailygoals;
2+
3+
import android.content.Context;
4+
import android.support.annotation.NonNull;
5+
import android.support.design.widget.BottomNavigationView;
6+
import android.support.design.widget.CoordinatorLayout;
7+
import android.support.v4.view.ViewCompat;
8+
import android.util.AttributeSet;
9+
import android.util.Log;
10+
import android.view.View;
11+
12+
import static java.lang.Math.max;
13+
import static java.lang.Math.min;
14+
15+
16+
public class BottomNavigationBehavior extends CoordinatorLayout.Behavior<BottomNavigationView> {
17+
18+
/**
19+
* Default constructor for instantiating the behavior
20+
*/
21+
public BottomNavigationBehavior() {
22+
super();
23+
}
24+
25+
/**
26+
* Default constructor for inflating behaviors from the layout
27+
*
28+
* @param context
29+
* @param attrs
30+
*/
31+
32+
public BottomNavigationBehavior(Context context, AttributeSet attrs) {
33+
super(context, attrs);
34+
}
35+
36+
37+
/**
38+
* @param coordinatorLayout the CoordinatorLayout with which the behavior is associated
39+
* @param child the child view of the CoordinatorLayout this behavior is associated with
40+
* @param directTargetChild the child view of the CoordinatorLayout that either is or contains the view that is the target of nested
41+
* scrolling operation
42+
* @param target the descendant of the CoordinatorLayout initiating the scroll operation
43+
* @param axes the axis of scrolling - horizontal or vertical
44+
* @param type type of input event that caused the scrolling
45+
* @return true if behavior wishes to accept this nested scroll
46+
*/
47+
@Override
48+
public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull BottomNavigationView child, @NonNull View directTargetChild, @NonNull View target, int axes, int type) {
49+
Log.v("Tag", target.getClass().toString());
50+
return axes == ViewCompat.SCROLL_AXIS_VERTICAL;
51+
}
52+
53+
54+
/**
55+
* @param coordinatorLayout
56+
* @param child
57+
* @param target
58+
* @param dx the horizontal number of pixels that the user attempted to scroll
59+
* @param dy the vertical number of pixels that the user attempted to scroll
60+
* @param consumed an integer array where consumed[0] should be set to dx , consumer[1] should be set
61+
* to dy
62+
* @param type
63+
*/
64+
@Override
65+
public void onNestedPreScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull BottomNavigationView child, @NonNull View target, int dx, int dy, @NonNull int[] consumed, int type) {
66+
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
67+
child.setTranslationY(max(0f, min(((float) child.getHeight()), child.getTranslationY() + dy)));
68+
}
69+
70+
}
Lines changed: 68 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,116 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<ScrollView
2+
<android.support.design.widget.CoordinatorLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:app="http://schemas.android.com/apk/res-auto"
55
xmlns:tools="http://schemas.android.com/tools"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
8-
android:orientation="vertical"
98
android:background="@drawable/dt"
9+
android:orientation="vertical"
1010
android:scaleType="centerCrop"
1111
tools:context="com.example.dhananjay.dailygoals.MainActivity">
1212

13-
<LinearLayout
13+
<android.support.v4.widget.NestedScrollView
1414
android:layout_width="match_parent"
15-
android:layout_height="match_parent"
16-
android:orientation="vertical">
17-
<TextView
18-
android:layout_width="match_parent"
19-
android:layout_height="wrap_content"
20-
android:gravity="center"
21-
android:text="PLAN FOR"
22-
android:textSize="30sp"
23-
android:padding="20dp"
24-
android:textColor="#ffffff"
25-
android:fontFamily="cursive"/>
15+
android:layout_height="match_parent">
2616

27-
28-
<RelativeLayout
17+
<LinearLayout
2918
android:layout_width="match_parent"
30-
android:layout_height="wrap_content"
31-
android:layout_weight="1">
19+
android:layout_height="match_parent"
20+
android:orientation="vertical">
21+
22+
<TextView
23+
android:layout_width="match_parent"
24+
android:layout_height="wrap_content"
25+
android:fontFamily="cursive"
26+
android:gravity="center"
27+
android:padding="20dp"
28+
android:text="PLAN FOR"
29+
android:textColor="#ffffff"
30+
android:textSize="30sp" />
3231

3332
<android.support.v7.widget.RecyclerView
3433
android:id="@+id/recyclerView"
3534
android:layout_width="match_parent"
3635
android:layout_height="match_parent"
3736
android:layout_margin="16dp"
38-
android:elevation="10dp">
37+
android:elevation="10dp"
38+
android:orientation="horizontal">
3939
</android.support.v7.widget.RecyclerView>
40-
</RelativeLayout>
41-
<TextView
42-
android:layout_width="match_parent"
43-
android:layout_height="wrap_content"
44-
android:gravity="center"
45-
android:text="ONGOING..."
46-
android:textSize="30sp"
47-
android:padding="20dp"
48-
android:textColor="#ffffff"
49-
android:fontFamily="cursive"/>
50-
5140

52-
<RelativeLayout
53-
android:layout_width="match_parent"
54-
android:layout_height="wrap_content"
55-
android:layout_weight="1">
41+
<TextView
42+
android:layout_width="match_parent"
43+
android:layout_height="wrap_content"
44+
android:fontFamily="cursive"
45+
android:gravity="center"
46+
android:padding="20dp"
47+
android:text="ONGOING..."
48+
android:textColor="#ffffff"
49+
android:textSize="30sp" />
5650

5751
<android.support.v7.widget.RecyclerView
5852
android:id="@+id/recyclerView1"
5953
android:layout_width="match_parent"
6054
android:layout_height="match_parent"
6155
android:layout_margin="16dp"
62-
android:elevation="10dp">
56+
android:elevation="10dp"
57+
android:orientation="horizontal">
6358
</android.support.v7.widget.RecyclerView>
64-
</RelativeLayout>
65-
<TextView
66-
android:layout_width="match_parent"
67-
android:layout_height="wrap_content"
68-
android:gravity="center"
69-
android:text="COMPLETED/MISSED"
70-
android:textSize="30sp"
71-
android:padding="20dp"
72-
android:textColor="#ffffff"
73-
android:fontFamily="cursive"/>
7459

75-
76-
<RelativeLayout
77-
android:layout_width="match_parent"
78-
android:layout_height="wrap_content"
79-
android:layout_weight="1">
60+
<TextView
61+
android:layout_width="match_parent"
62+
android:layout_height="wrap_content"
63+
android:fontFamily="cursive"
64+
android:gravity="center"
65+
android:padding="20dp"
66+
android:text="COMPLETED/MISSED"
67+
android:textColor="#ffffff"
68+
android:textSize="30sp" />
8069

8170
<android.support.v7.widget.RecyclerView
8271
android:id="@+id/recyclerView2"
8372
android:layout_width="match_parent"
8473
android:layout_height="match_parent"
8574
android:layout_margin="16dp"
86-
android:elevation="10dp">
75+
android:elevation="10dp"
76+
android:orientation="horizontal">
8777
</android.support.v7.widget.RecyclerView>
88-
</RelativeLayout>
89-
<TextView
90-
android:layout_width="match_parent"
91-
android:layout_height="wrap_content"
92-
android:gravity="center"
93-
android:text="ACHIEVEMENTS"
94-
android:textSize="30sp"
95-
android:padding="20dp"
96-
android:textColor="#ffffff"
97-
android:fontFamily="cursive"/>
9878

79+
<TextView
80+
android:layout_width="match_parent"
81+
android:layout_height="wrap_content"
82+
android:fontFamily="cursive"
83+
android:gravity="center"
84+
android:padding="20dp"
85+
android:text="ACHIEVEMENTS"
86+
android:textColor="#ffffff"
87+
android:textSize="30sp" />
9988

100-
<RelativeLayout
101-
android:layout_width="match_parent"
102-
android:layout_height="wrap_content"
103-
android:layout_weight="1">
10489

10590
<android.support.v7.widget.RecyclerView
10691
android:id="@+id/recyclerView3"
10792
android:layout_width="match_parent"
10893
android:layout_height="match_parent"
10994
android:layout_margin="16dp"
110-
android:elevation="10dp">
95+
android:elevation="10dp"
96+
android:orientation="horizontal">
11197
</android.support.v7.widget.RecyclerView>
112-
</RelativeLayout>
11398

114-
<android.support.design.widget.BottomNavigationView
115-
android:layout_width="match_parent"
116-
android:layout_height="60dp"
117-
app:itemIconTint="@android:color/white"
118-
app:itemTextColor="@android:color/white"
119-
app:menu="@menu/navigation"/>
99+
</LinearLayout>
100+
101+
</android.support.v4.widget.NestedScrollView>
102+
103+
<android.support.design.widget.BottomNavigationView
104+
android:id="@+id/bottom_navigation_view"
105+
android:layout_width="match_parent"
106+
android:layout_height="wrap_content"
107+
android:layout_gravity="bottom"
108+
android:background="@android:color/darker_gray"
109+
app:itemIconTint="@android:color/white"
110+
app:itemTextColor="@android:color/white"
111+
app:layout_behavior="com.example.dhananjay.dailygoals.BottomNavigationBehavior"
112+
app:menu="@menu/navigation"/>
113+
120114

121-
</LinearLayout>
122-
</ScrollView>
115+
</android.support.design.widget.CoordinatorLayout>
123116

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.0.1'
10+
classpath 'com.android.tools.build:gradle:3.1.1'
1111

1212

1313
// NOTE: Do not place your application dependencies here; they belong

0 commit comments

Comments
 (0)