Skip to content

Commit b70655f

Browse files
committed
Use minSdkVersion to 19
1 parent 60ffd2c commit b70655f

File tree

10 files changed

+162
-30
lines changed

10 files changed

+162
-30
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![License Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=true)](http://www.apache.org/licenses/LICENSE-2.0)
2-
![minSdkVersion 21](https://img.shields.io/badge/minSdkVersion-21-red.svg?style=true)
3-
![compileSdkVersion 27](https://img.shields.io/badge/compileSdkVersion-27-yellow.svg?style=true)
2+
![minSdkVersion 19](https://img.shields.io/badge/minSdkVersion-19-red.svg?style=true)
3+
![compileSdkVersion 29](https://img.shields.io/badge/compileSdkVersion-29-yellow.svg?style=true)
44
[![maven-central](https://img.shields.io/maven-central/v/com.github.andremion/floatingnavigationview.svg)](https://search.maven.org/#artifactdetails%7Ccom.github.andremion%7Cfloatingnavigationview%7C1.1.1%7Caar)
55

66
[![Android Arsenal Floating-Navigation-View](https://img.shields.io/badge/Android%20Arsenal-Floating--Navigation--View-green.svg?style=true)](https://android-arsenal.com/details/1/4134)
@@ -41,12 +41,16 @@ or in your `pom.xml` if you are using Maven
4141

4242
```xml
4343
<?xml version="1.0" encoding="utf-8"?>
44-
<android.support.design.widget.CoordinatorLayout
44+
<androidx.coordinatorlayout.widget.CoordinatorLayout
4545
xmlns:android="http://schemas.android.com/apk/res/android"
4646
xmlns:app="http://schemas.android.com/apk/res-auto"
4747
android:layout_width="match_parent"
48-
android:layout_height="match_parent"
49-
android:fitsSystemWindows="true">
48+
android:layout_height="match_parent">
49+
50+
<com.google.android.material.appbar.AppBarLayout
51+
android:layout_width="match_parent"
52+
android:layout_height="wrap_content"
53+
android:fitsSystemWindows="true">
5054

5155
...
5256

@@ -61,7 +65,7 @@ or in your `pom.xml` if you are using Maven
6165
app:headerLayout="@layout/navigation_view_header"
6266
app:menu="@menu/menu_navigation_view" />
6367

64-
</android.support.design.widget.CoordinatorLayout>
68+
</androidx.coordinatorlayout.widget.CoordinatorLayout>
6569
```
6670

6771
###Custom attributes
@@ -100,7 +104,7 @@ VectAlign is a developer's tool which aligns two VectorDrawable "pathData" strin
100104

101105
## License
102106

103-
Copyright 2016 André Mion
107+
Copyright 2019 André Mion
104108

105109
Licensed under the Apache License, Version 2.0 (the "License");
106110
you may not use this file except in compliance with the License.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ allprojects {
1515
}
1616
ext {
1717
compileSdkVersion = 29
18-
minSdkVersion = 21
18+
minSdkVersion = 19
1919
targetSdkVersion = 29
2020
materialDesignVersion = '1.0.0'
2121
junitVersion = '4.12'

library/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ android {
99
targetSdkVersion project.ext.targetSdkVersion
1010
versionCode = VERSION_CODE
1111
versionName = VERSION_NAME
12+
vectorDrawables.useSupportLibrary = true
1213
}
1314
buildTypes {
1415
release {
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2019. André Mion
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.andremion.floatingnavigationview;
18+
19+
import android.annotation.SuppressLint;
20+
import android.content.Context;
21+
import android.graphics.Canvas;
22+
import android.graphics.drawable.Drawable;
23+
import android.util.AttributeSet;
24+
25+
import com.google.android.material.circularreveal.CircularRevealHelper;
26+
import com.google.android.material.circularreveal.CircularRevealWidget;
27+
import com.google.android.material.navigation.NavigationView;
28+
29+
import androidx.annotation.NonNull;
30+
import androidx.annotation.Nullable;
31+
32+
@SuppressWarnings("JavaDoc")
33+
class CircularRevealNavigationView extends NavigationView implements CircularRevealWidget {
34+
35+
private final CircularRevealHelper helper;
36+
37+
public CircularRevealNavigationView(Context context) {
38+
this(context, null);
39+
}
40+
41+
public CircularRevealNavigationView(Context context, AttributeSet attrs) {
42+
this(context, attrs, 0);
43+
}
44+
45+
public CircularRevealNavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
46+
super(context, attrs, defStyleAttr);
47+
helper = new CircularRevealHelper(this);
48+
}
49+
50+
@Override public void buildCircularRevealCache() {
51+
helper.buildCircularRevealCache();
52+
}
53+
54+
@Override public void destroyCircularRevealCache() {
55+
helper.destroyCircularRevealCache();
56+
}
57+
58+
@Nullable @Override public RevealInfo getRevealInfo() {
59+
return helper.getRevealInfo();
60+
}
61+
62+
@Override public void setRevealInfo(@Nullable RevealInfo revealInfo) {
63+
helper.setRevealInfo(revealInfo);
64+
}
65+
66+
@Override public int getCircularRevealScrimColor() {
67+
return helper.getCircularRevealScrimColor();
68+
}
69+
70+
@Override public void setCircularRevealScrimColor(int color) {
71+
helper.setCircularRevealScrimColor(color);
72+
}
73+
74+
@Nullable @Override public Drawable getCircularRevealOverlayDrawable() {
75+
return helper.getCircularRevealOverlayDrawable();
76+
}
77+
78+
@Override public void setCircularRevealOverlayDrawable(@Nullable Drawable drawable) {
79+
helper.setCircularRevealOverlayDrawable(drawable);
80+
}
81+
82+
@SuppressLint("MissingSuperCall") @Override public void draw(@NonNull Canvas canvas) {
83+
helper.draw(canvas);
84+
}
85+
86+
@SuppressLint("RestrictedApi") @Override public void actualDraw(Canvas canvas) {
87+
super.draw(canvas);
88+
}
89+
90+
@Override public boolean actualIsOpaque() {
91+
return isOpaque();
92+
}
93+
}

library/src/main/java/com/andremion/floatingnavigationview/FloatingNavigationView.java

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import android.content.res.TypedArray;
2626
import android.graphics.PixelFormat;
2727
import android.graphics.Rect;
28-
import android.graphics.drawable.AnimatedVectorDrawable;
28+
import android.graphics.drawable.ColorDrawable;
29+
import android.graphics.drawable.Drawable;
2930
import android.os.Parcel;
3031
import android.os.Parcelable;
3132
import android.util.AttributeSet;
@@ -35,34 +36,37 @@
3536
import android.view.Menu;
3637
import android.view.MotionEvent;
3738
import android.view.View;
38-
import android.view.ViewAnimationUtils;
3939
import android.view.ViewTreeObserver;
4040
import android.view.WindowManager;
4141
import android.widget.FrameLayout;
4242
import android.widget.ImageView;
4343

44+
import com.google.android.material.circularreveal.CircularRevealCompat;
4445
import com.google.android.material.floatingactionbutton.FloatingActionButton;
4546
import com.google.android.material.internal.NavigationMenuView;
4647
import com.google.android.material.navigation.NavigationView;
4748

49+
import androidx.annotation.ColorInt;
4850
import androidx.annotation.IdRes;
4951
import androidx.annotation.LayoutRes;
5052
import androidx.annotation.MenuRes;
5153
import androidx.annotation.NonNull;
5254
import androidx.annotation.Nullable;
55+
import androidx.appcompat.app.AppCompatDelegate;
5356
import androidx.coordinatorlayout.widget.CoordinatorLayout;
54-
import androidx.core.content.ContextCompat;
5557
import androidx.core.os.ParcelableCompat;
5658
import androidx.core.os.ParcelableCompatCreatorCallbacks;
5759
import androidx.core.view.MotionEventCompat;
60+
import androidx.core.view.ViewCompat;
5861
import androidx.customview.view.AbsSavedState;
62+
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat;
5963

6064
@SuppressWarnings({"FieldCanBeLocal", "InflateParams", "RtlHardcoded", "unused", "WeakerAccess"})
6165
public class FloatingNavigationView extends FloatingActionButton {
6266

6367
private final WindowManager mWindowManager;
6468

65-
private final NavigationView mNavigationView;
69+
private final CircularRevealNavigationView mNavigationView;
6670
private final NavigationMenuView mNavigationMenuView;
6771
private final ImageView mFabView;
6872

@@ -104,12 +108,13 @@ public FloatingNavigationView(Context context, AttributeSet attrs) {
104108

105109
public FloatingNavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
106110
super(context, attrs, defStyleAttr);
111+
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
107112
setImageResource(R.drawable.ic_menu_vector);
108113

109114
mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
110115

111-
mNavigationView = (NavigationView) LayoutInflater.from(context).inflate(R.layout.navigation_view, null);
112-
mNavigationView.setBackgroundTintList(getBackgroundTintList());
116+
mNavigationView = (CircularRevealNavigationView) LayoutInflater.from(context).inflate(R.layout.navigation_view, null);
117+
mNavigationView.setBackground(new ColorDrawable(getBackgroundColor()));
113118
mNavigationView.setOnTouchListener(mNavigationTouchListener);
114119
mNavigationMenuView = (NavigationMenuView) mNavigationView.findViewById(R.id.design_navigation_view);
115120

@@ -130,10 +135,22 @@ public FloatingNavigationView(Context context, AttributeSet attrs, int defStyleA
130135
a.recycle();
131136
}
132137

138+
private @ColorInt int getBackgroundColor() {
139+
ColorStateList colorStateList = getBackgroundTintList();
140+
if (colorStateList != null) {
141+
return colorStateList.getDefaultColor();
142+
}
143+
Drawable background = getBackground();
144+
if (background instanceof ColorDrawable) {
145+
return ((ColorDrawable) background).getColor();
146+
}
147+
return getSolidColor();
148+
}
149+
133150
@Override
134151
public void setBackgroundTintList(@Nullable ColorStateList tint) {
135152
super.setBackgroundTintList(tint);
136-
mNavigationView.setBackgroundTintList(tint);
153+
ViewCompat.setBackgroundTintList(mNavigationView, tint);
137154
}
138155

139156
@NonNull
@@ -201,7 +218,7 @@ private void attachNavigationView() {
201218
// We need to convert script specific gravity to absolute horizontal value
202219
// If horizontal direction is LTR, then START will set LEFT and END will set RIGHT.
203220
// If horizontal direction is RTL, then START will set RIGHT and END will set LEFT.
204-
gravity = Gravity.getAbsoluteGravity(gravity, getLayoutDirection());
221+
gravity = Gravity.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
205222

206223
mWindowManager.addView(mNavigationView, createLayoutParams(gravity));
207224
}
@@ -215,7 +232,7 @@ private void detachNavigationView() {
215232
private void startOpenAnimations() {
216233

217234
// Icon
218-
AnimatedVectorDrawable menuIcon = (AnimatedVectorDrawable) ContextCompat.getDrawable(getContext(),
235+
AnimatedVectorDrawableCompat menuIcon = AnimatedVectorDrawableCompat.create(getContext(),
219236
R.drawable.ic_menu_animated);
220237
mFabView.setImageDrawable(menuIcon);
221238
menuIcon.start();
@@ -225,9 +242,9 @@ private void startOpenAnimations() {
225242
int centerY = mFabRect.centerY();
226243
float startRadius = getMinRadius();
227244
float endRadius = getMaxRadius();
228-
Animator reveal = ViewAnimationUtils
229-
.createCircularReveal(mNavigationView,
230-
centerX, centerY, startRadius, endRadius);
245+
Animator reveal = CircularRevealCompat.createCircularReveal(
246+
mNavigationView, centerX, centerY, startRadius, endRadius
247+
);
231248

232249
// Fade in
233250
mNavigationMenuView.setAlpha(0);
@@ -242,7 +259,7 @@ private void startOpenAnimations() {
242259
private void startCloseAnimations() {
243260

244261
// Icon
245-
AnimatedVectorDrawable closeIcon = (AnimatedVectorDrawable) ContextCompat.getDrawable(getContext(),
262+
AnimatedVectorDrawableCompat closeIcon = AnimatedVectorDrawableCompat.create(getContext(),
246263
R.drawable.ic_close_animated);
247264
mFabView.setImageDrawable(closeIcon);
248265
closeIcon.start();
@@ -252,9 +269,9 @@ private void startCloseAnimations() {
252269
int centerY = mFabRect.centerY();
253270
float startRadius = getMaxRadius();
254271
float endRadius = getMinRadius();
255-
Animator reveal = ViewAnimationUtils
256-
.createCircularReveal(mNavigationView,
257-
centerX, centerY, startRadius, endRadius);
272+
Animator reveal = CircularRevealCompat.createCircularReveal(
273+
mNavigationView, centerX, centerY, startRadius, endRadius
274+
);
258275
reveal.addListener(new AnimatorListenerAdapter() {
259276
@Override
260277
public void onAnimationEnd(Animator animation) {
@@ -278,7 +295,7 @@ private void updateFabBounds() {
278295
layoutParams.width = getWidth();
279296
layoutParams.height = getHeight();
280297
layoutParams.topMargin = mFabRect.top;
281-
if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
298+
if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL) {
282299
layoutParams.rightMargin = mNavigationView.getWidth() - mFabRect.right;
283300
} else {
284301
layoutParams.leftMargin = mFabRect.left;

library/src/main/res/layout/navigation_view.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
16-
<com.google.android.material.navigation.NavigationView
16+
<com.andremion.floatingnavigationview.CircularRevealNavigationView
1717
xmlns:android="http://schemas.android.com/apk/res/android"
1818
xmlns:tools="http://schemas.android.com/tools"
1919
android:id="@+id/navigation_view"
2020
android:layout_width="wrap_content"
2121
android:layout_height="match_parent"
22-
android:fitsSystemWindows="true"
2322
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
2423

2524
<ImageView
@@ -30,4 +29,4 @@
3029
android:scaleType="center"
3130
tools:src="@drawable/ic_menu_vector" />
3231

33-
</com.google.android.material.navigation.NavigationView>
32+
</com.andremion.floatingnavigationview.CircularRevealNavigationView>

sample/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
android:label="@string/app_name"
99
android:supportsRtl="true"
1010
android:theme="@style/AppTheme">
11-
<activity android:name=".MainActivity">
11+
<activity
12+
android:name=".MainActivity"
13+
android:theme="@style/AppTheme.TranslucentStatus">
1214
<intent-filter>
1315
<action android:name="android.intent.action.MAIN" />
1416

sample/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:fitsSystemWindows="true"
87
tools:context=".MainActivity">
98

109
<com.google.android.material.appbar.AppBarLayout
1110
android:layout_width="match_parent"
1211
android:layout_height="wrap_content"
12+
android:fitsSystemWindows="true"
1313
android:theme="@style/AppTheme.AppBarOverlay">
1414

1515
<androidx.appcompat.widget.Toolbar
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<style name="AppTheme.TranslucentStatus" parent="AppTheme">
5+
<item name="android:windowTranslucentStatus">true</item>
6+
</style>
7+
8+
</resources>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<style name="AppTheme.TranslucentStatus" parent="AppTheme">
5+
<item name="android:windowTranslucentStatus">false</item>
6+
</style>
7+
8+
</resources>

0 commit comments

Comments
 (0)