Skip to content
This repository was archived by the owner on Jun 28, 2020. It is now read-only.

Commit ff1215f

Browse files
committed
Convert to AndroidX, Gradle 6.5, AGP 4.0
1 parent 86e38c8 commit ff1215f

8 files changed

Lines changed: 63 additions & 87 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,5 @@ android {
1313
}
1414

1515
dependencies {
16-
compile fileTree(include: ['*.jar'], dir: 'libs')
17-
compile "com.android.support:appcompat-v7:$supportVersion"
18-
compile "com.android.support:design:$supportVersion"
19-
compile project(':arcnavigationview')
16+
implementation project(':arcnavigationview')
2017
}

app/src/main/java/com/rom4ek/sample/arcnavigationview/MainActivity.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package com.rom4ek.sample.arcnavigationview;
22

33
import android.os.Bundle;
4-
import android.support.annotation.NonNull;
5-
import android.support.annotation.Nullable;
6-
import android.support.design.widget.FloatingActionButton;
7-
import android.support.design.widget.NavigationView;
8-
import android.support.design.widget.Snackbar;
9-
import android.support.v4.view.GravityCompat;
10-
import android.support.v4.widget.DrawerLayout;
11-
import android.support.v7.app.ActionBarDrawerToggle;
12-
import android.support.v7.app.AppCompatActivity;
13-
import android.support.v7.widget.Toolbar;
144
import android.view.Menu;
155
import android.view.MenuItem;
166
import android.view.View;
177

188
import com.arcnavigationview.R;
9+
import com.google.android.material.floatingactionbutton.FloatingActionButton;
10+
import com.google.android.material.navigation.NavigationView;
11+
import com.google.android.material.snackbar.Snackbar;
12+
13+
import androidx.annotation.NonNull;
14+
import androidx.annotation.Nullable;
15+
import androidx.appcompat.app.ActionBarDrawerToggle;
16+
import androidx.appcompat.app.AppCompatActivity;
17+
import androidx.appcompat.widget.Toolbar;
18+
import androidx.core.view.GravityCompat;
19+
import androidx.drawerlayout.widget.DrawerLayout;
1920

2021
public class MainActivity extends AppCompatActivity
2122
implements NavigationView.OnNavigationItemSelectedListener {
@@ -25,10 +26,10 @@ public class MainActivity extends AppCompatActivity
2526
protected void onCreate(@Nullable Bundle savedInstanceState) {
2627
super.onCreate(savedInstanceState);
2728
setContentView(R.layout.activity_main);
28-
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
29+
Toolbar toolbar = findViewById(R.id.toolbar);
2930
setSupportActionBar(toolbar);
3031

31-
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
32+
FloatingActionButton fab = findViewById(R.id.fab);
3233
fab.setOnClickListener(new View.OnClickListener() {
3334
@Override
3435
public void onClick(View view) {
@@ -37,20 +38,20 @@ public void onClick(View view) {
3738
}
3839
});
3940

40-
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
41+
drawer = findViewById(R.id.drawer_layout);
4142
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
4243
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
4344
toggle.syncState();
4445

45-
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
46-
NavigationView navigationViewRight = (NavigationView) findViewById(R.id.nav_view_right);
46+
NavigationView navigationView = findViewById(R.id.nav_view);
47+
NavigationView navigationViewRight = findViewById(R.id.nav_view_right);
4748
navigationViewRight.setNavigationItemSelectedListener(this);
4849
navigationView.setNavigationItemSelectedListener(this);
4950
}
5051

5152
@Override
5253
public void onBackPressed() {
53-
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
54+
DrawerLayout drawer = findViewById(R.id.drawer_layout);
5455
if (drawer.isDrawerOpen(GravityCompat.START)) {
5556
drawer.closeDrawer(GravityCompat.START);
5657
} else if (drawer.isDrawerOpen(GravityCompat.END)) {
@@ -107,7 +108,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
107108

108109
}
109110

110-
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
111+
DrawerLayout drawer = findViewById(R.id.drawer_layout);
111112
drawer.closeDrawer(GravityCompat.START);
112113
return true;
113114
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.v4.widget.DrawerLayout
2+
<androidx.core.widget.DrawerLayout
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"
@@ -41,4 +41,4 @@
4141
app:headerLayout="@layout/nav_header_main"
4242
app:menu="@menu/activity_main_drawer"/>
4343

44-
</android.support.v4.widget.DrawerLayout>
44+
</androidx.core.widget.DrawerLayout>

arcnavigationview/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ android {
2020
}
2121

2222
dependencies {
23-
compile fileTree(dir: 'libs', include: ['*.jar'])
24-
compile "com.android.support:appcompat-v7:$supportVersion"
25-
compile "com.android.support:design:$supportVersion"
23+
api "com.google.android.material:material:1.1.0"
2624
}
2725

2826

arcnavigationview/src/main/java/com/rom4ek/arcnavigationview/ArcNavigationView.java

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
import android.graphics.Rect;
1111
import android.graphics.drawable.ColorDrawable;
1212
import android.os.Build;
13-
import android.support.annotation.RequiresApi;
14-
import android.support.design.internal.NavigationMenuView;
15-
import android.support.design.internal.ScrimInsetsFrameLayout;
16-
import android.support.design.widget.NavigationView;
17-
import android.support.v4.view.ViewCompat;
18-
import android.support.v4.widget.DrawerLayout;
1913
import android.text.TextUtils;
2014
import android.util.AttributeSet;
2115
import android.view.Gravity;
@@ -24,11 +18,15 @@
2418
import android.view.ViewOutlineProvider;
2519
import android.widget.TextView;
2620

21+
import com.google.android.material.internal.NavigationMenuView;
22+
import com.google.android.material.internal.ScrimInsetsFrameLayout;
23+
import com.google.android.material.navigation.NavigationView;
24+
2725
import java.lang.reflect.Field;
2826

29-
/**
30-
* Created by rom4ek on 10.01.2017.
31-
*/
27+
import androidx.annotation.RequiresApi;
28+
import androidx.core.view.ViewCompat;
29+
import androidx.drawerlayout.widget.DrawerLayout;
3230

3331
public class ArcNavigationView extends NavigationView {
3432

@@ -53,32 +51,19 @@ public void init(Context context, AttributeSet attrs) {
5351
settings = new ArcViewSettings(context, attrs);
5452
settings.setElevation(ViewCompat.getElevation(this));
5553

56-
/**
57-
* If hardware acceleration is on (default from API 14), clipPath worked correctly
58-
* from API 18.
59-
*
60-
* So we will disable hardware Acceleration if API < 18
61-
*
62-
* https://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
63-
* Section #Unsupported Drawing Operations
64-
*/
65-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
66-
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
67-
}
6854
setBackgroundColor(Color.TRANSPARENT);
6955
setInsetsColor(Color.TRANSPARENT);
7056
THRESHOLD = Math.round(ArcViewSettings.dpToPx(getContext(), 15)); //some threshold for child views while remeasuring them
7157
}
7258

59+
@SuppressWarnings("SameParameterValue")
7360
private void setInsetsColor(int color) {
7461
try {
75-
Field insetForegroundField = ScrimInsetsFrameLayout.class.getDeclaredField("mInsetForeground");
62+
Field insetForegroundField = ScrimInsetsFrameLayout.class.getDeclaredField("insetForeground");
7663
insetForegroundField.setAccessible(true);
7764
ColorDrawable colorDrawable = new ColorDrawable(color);
7865
insetForegroundField.set(this, colorDrawable);
79-
} catch (NoSuchFieldException e) {
80-
e.printStackTrace();
81-
} catch (IllegalAccessException e) {
66+
} catch (NoSuchFieldException | IllegalAccessException e) {
8267
e.printStackTrace();
8368
}
8469
}
@@ -93,51 +78,51 @@ private Path createClipPath() {
9378
if (settings.isCropInside()) {
9479
if (layoutParams.gravity == Gravity.START || layoutParams.gravity == Gravity.LEFT) {
9580
arcPath.moveTo(width, 0);
96-
arcPath.quadTo(width - arcWidth, height / 2,
81+
arcPath.quadTo(width - arcWidth, height / 2.0f,
9782
width, height);
9883
arcPath.close();
9984

10085
path.moveTo(0, 0);
10186
path.lineTo(width, 0);
102-
path.quadTo(width - arcWidth, height / 2,
87+
path.quadTo(width - arcWidth, height / 2.0f,
10388
width, height);
10489
path.lineTo(0, height);
10590
path.close();
10691
} else if (layoutParams.gravity == Gravity.END || layoutParams.gravity == Gravity.RIGHT) {
10792
arcPath.moveTo(0, 0);
108-
arcPath.quadTo(arcWidth, height / 2,
93+
arcPath.quadTo(arcWidth, height / 2.0f,
10994
0, height);
11095
arcPath.close();
11196

11297
path.moveTo(width, 0);
11398
path.lineTo(0, 0);
114-
path.quadTo(arcWidth, height / 2,
99+
path.quadTo(arcWidth, height / 2.0f,
115100
0, height);
116101
path.lineTo(width, height);
117102
path.close();
118103
}
119104
} else {
120105
if (layoutParams.gravity == Gravity.START || layoutParams.gravity == Gravity.LEFT) {
121106
arcPath.moveTo(width - arcWidth / 2, 0);
122-
arcPath.quadTo(width + arcWidth / 2, height / 2,
107+
arcPath.quadTo(width + arcWidth / 2, height / 2.0f,
123108
width - arcWidth / 2, height);
124109
arcPath.close();
125110

126111
path.moveTo(0, 0);
127112
path.lineTo(width - arcWidth / 2, 0);
128-
path.quadTo(width + arcWidth / 2, height / 2,
113+
path.quadTo(width + arcWidth / 2, height / 2.0f,
129114
width - arcWidth / 2, height);
130115
path.lineTo(0, height);
131116
path.close();
132117
} else if (layoutParams.gravity == Gravity.END || layoutParams.gravity == Gravity.RIGHT) {
133118
arcPath.moveTo(arcWidth / 2, 0);
134-
arcPath.quadTo(-arcWidth / 2, height / 2,
119+
arcPath.quadTo(-arcWidth / 2, height / 2.0f,
135120
arcWidth / 2, height);
136121
arcPath.close();
137122

138123
path.moveTo(width, 0);
139124
path.lineTo(arcWidth / 2, 0);
140-
path.quadTo(-arcWidth / 2, height / 2,
125+
path.quadTo(-arcWidth / 2, height / 2.0f,
141126
arcWidth / 2, height);
142127
path.lineTo(width, height);
143128
path.close();
@@ -174,34 +159,26 @@ private void calculateLayoutAndChildren() {
174159
width = getMeasuredWidth();
175160
if (width > 0 && height > 0) {
176161
clipPath = createClipPath();
177-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
178-
ViewCompat.setElevation(this, settings.getElevation());
179-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
180-
setOutlineProvider(new ViewOutlineProvider() {
181-
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
182-
@Override
183-
public void getOutline(View view, Outline outline) {
184-
if (clipPath.isConvex()) {
185-
outline.setConvexPath(clipPath);
186-
}
162+
ViewCompat.setElevation(this, settings.getElevation());
163+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
164+
setOutlineProvider(new ViewOutlineProvider() {
165+
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
166+
@Override
167+
public void getOutline(View view, Outline outline) {
168+
if (clipPath.isConvex()) {
169+
outline.setConvexPath(clipPath);
187170
}
188-
});
189-
}
171+
}
172+
});
190173
}
191174

192175
final int count = getChildCount();
193176
for (int i = 0; i < count; i++) {
194177
final View v = getChildAt(i);
195178

196179
if (v instanceof NavigationMenuView) {
197-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
198-
v.setBackground(settings.getBackgroundDrawable());
199-
} else {
200-
v.setBackgroundDrawable(settings.getBackgroundDrawable());
201-
}
202-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
203-
ViewCompat.setElevation(v, settings.getElevation());
204-
}
180+
v.setBackground(settings.getBackgroundDrawable());
181+
ViewCompat.setElevation(v, settings.getElevation());
205182
//TODO: adjusting child views to new width in their rightmost/leftmost points related to path
206183
// adjustChildViews((ViewGroup) v);
207184
}
@@ -221,7 +198,7 @@ private void adjustChildViews(ViewGroup container) {
221198
if (child instanceof ViewGroup) {
222199
adjustChildViews((ViewGroup) child);
223200
} else {
224-
float pathCenterPointForItem[] = {0f, 0f};
201+
float[] pathCenterPointForItem = {0f, 0f};
225202
Rect location = locateView(child);
226203
int halfHeight = location.height() / 2;
227204

@@ -269,7 +246,7 @@ private Rect locateView(View view) {
269246
protected void dispatchDraw(Canvas canvas) {
270247
canvas.save();
271248

272-
canvas.clipPath(clipPath);;
249+
canvas.clipPath(clipPath);
273250
super.dispatchDraw(canvas);
274251

275252
canvas.restore();

build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
buildscript {
44
repositories {
55
jcenter()
6+
google()
67
}
78
dependencies {
8-
classpath ('com.android.tools.build:gradle:2.3.0')
9+
classpath ('com.android.tools.build:gradle:4.0.0')
910
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
1011
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
1112
// NOTE: Do not place your application dependencies here; they belong
@@ -16,13 +17,13 @@ buildscript {
1617
allprojects {
1718
repositories {
1819
jcenter()
20+
google()
1921
}
2022
}
2123

2224
ext {
23-
sdk = 25
24-
buildTools = "25.0.2"
25-
minSdk = 14
25+
sdk = 29
26+
buildTools = "29.0.3"
27+
minSdk = 19
2628
libraryVersion = "1.0.3"
27-
supportVersion = "25.3.0"
2829
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
# Specifies the JVM arguments used for the daemon process.
1111
# The setting is particularly useful for tweaking memory settings.
12+
android.useAndroidX=true
1213
org.gradle.jvmargs=-Xmx1536m
14+
#android.useAndroidX=true
1315

1416
# When configured, Gradle will run in incubating parallel mode.
1517
# This option should only be used with decoupled projects. More details, visit

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

0 commit comments

Comments
 (0)