1010import android .graphics .Rect ;
1111import android .graphics .drawable .ColorDrawable ;
1212import 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 ;
1913import android .text .TextUtils ;
2014import android .util .AttributeSet ;
2115import android .view .Gravity ;
2418import android .view .ViewOutlineProvider ;
2519import 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+
2725import 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
3331public 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 ();
0 commit comments