<commit_before>package softpro.naseemali;

/**
 * Created by Naseem on 18-10-2017.
 */


import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.design.internal.NavigationMenuView;
import android.support.design.internal.ScrimInsetsFrameLayout;
import android.support.design.widget.NavigationView;
import android.util.AttributeSet;
import android.view.View;

import java.lang.reflect.Field;

/**
 * Created by rom4ek on 10.01.2017.
 */

public class ShapedNavigationView extends NavigationView {

    private ShapedViewSettings settings;
    private int height = 0;
    private int width = 0;

    public ShapedNavigationView(Context context) {
        super(context);
        init(context, null);
    }

    public ShapedNavigationView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public void init(Context context, AttributeSet attrs) {
        settings = new ShapedViewSettings(context, attrs);

        /**
         * If hardware acceleration is on (default from API 14), clipPath worked correctly
         * from API 18.
         *
         * So we will disable hardware Acceleration if API < 18
         *
         * https://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
         * Section #Unsupported Drawing Operations
         */
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
            setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
        setBackgroundColor(Color.TRANSPARENT);
        setInsetsColor(Color.TRANSPARENT);
    }

    private void setInsetsColor(int color) {
        try {
            Field insetForegroundField = ScrimInsetsFrameLayout.class.getDeclaredField("mInsetForeground");
            insetForegroundField.setAccessible(true);
            ColorDrawable colorDrawable = new ColorDrawable(color);
            insetForegroundField.set(this, colorDrawable);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        final int count = getChildCount();
        for (int i = 0; i < count; i++) {
            final View v = getChildAt(i);

            if (v instanceof NavigationMenuView) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    v.setBackground(settings.getBackgroundDrawable());
                } else {
                    v.setBackgroundDrawable(settings.getBackgroundDrawable());
                }
            }
        }
    }


    @Override
    protected void measureChild(View child, int parentWidthMeasureSpec, int parentHeightMeasureSpec) {
        if (child instanceof NavigationMenuView) {
            child.measure(View.MeasureSpec.makeMeasureSpec(getMeasuredWidth(),
                    View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(
                    getMeasuredHeight(), View.MeasureSpec.EXACTLY));
        } else {
            super.measureChild(child, parentWidthMeasureSpec, parentHeightMeasureSpec);
        }
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        canvas.save();
        canvas.clipPath(createClipPath(settings.getShapeType()));
        super.dispatchDraw(canvas);
        canvas.restore();
    }

    @SuppressLint("RtlHardcoded")
    private Path createClipPath(int type) {
        Path path=new Path();
        width=getMeasuredWidth();
        height=getMeasuredHeight();
        boolean rtl=getResources().getBoolean(R.bool.is_right_to_left);
        if(rtl==false) {
            switch (type) {
                case ShapedViewSettings.ARC_CONVEX:<commit_msg>some changes<commit_after>package softpro.naseemali;

/**
 * Created by Naseem on 18-10-2017.
 */


import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.design.internal.NavigationMenuView;
import android.support.design.internal.ScrimInsetsFrameLayout;
import android.support.design.widget.NavigationView;
import android.util.AttributeSet;
import android.view.View;

import java.lang.reflect.Field;

/**
 * Created by rom4ek on 10.01.2017.
 */

public class ShapedNavigationView extends NavigationView {

    private ShapedViewSettings settings;
    private int height = 0;
    private int width = 0;

    public ShapedNavigationView(Context context) {
        super(context);
        init(context, null);
    }

    public ShapedNavigationView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public void init(Context context, AttributeSet attrs) {
        settings = new ShapedViewSettings(context, attrs);

        /**
         * If hardware acceleration is on (default from API 14), clipPath worked correctly
         * from API 18.
         *
         * So we will disable hardware Acceleration if API < 18
         *
         * https://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
         * Section #Unsupported Drawing Operations
         */
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
            setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
        setBackgroundColor(Color.TRANSPARENT);
        setInsetsColor(Color.TRANSPARENT);
    }

    private void setInsetsColor(int color) {
        try {
            Field insetForegroundField = ScrimInsetsFrameLayout.class.getDeclaredField("mInsetForeground");
            insetForegroundField.setAccessible(true);
            ColorDrawable colorDrawable = new ColorDrawable(color);
            insetForegroundField.set(this, colorDrawable);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        final int count = getChildCount();
        for (int i = 0; i < count; i++) {
            final View v = getChildAt(i);

            if (v instanceof NavigationMenuView) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    v.setBackground(settings.getBackgroundDrawable());
                } else {
                    v.setBackgroundDrawable(settings.getBackgroundDrawable());
                }
            }
        }
    }


    @Override
    protected void measureChild(View child, int parentWidthMeasureSpec, int parentHeightMeasureSpec) {
        if (child instanceof NavigationMenuView) {
            child.measure(View.MeasureSpec.makeMeasureSpec(getMeasuredWidth(),
                    View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(
                    getMeasuredHeight(), View.MeasureSpec.EXACTLY));
        } else {
            super.measureChild(child, parentWidthMeasureSpec, parentHeightMeasureSpec);
        }
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        canvas.save();
        canvas.clipPath(createClipPath(settings.getShapeType()));
        super.dispatchDraw(canvas);
        canvas.restore();
    }

    @SuppressLint("RtlHardcoded")
    private Path createClipPath(int type) {
        Path path=new Path();
        width=getMeasuredWidth();
        height=getMeasuredHeight();
        boolean rtl=getResources().getBoolean(R.bool.is_right_to_left);
        if(rtl) {
            switch (type) {
                case ShapedViewSettings.ARC_CONVEX:
{'fraction_non_alphanumeric': 0.09297725024727992, 'fraction_numerical': 0.0066765578635014835, 'mean_word_length': 2.627354260089686, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3405945', 'n_tokens_mistral': 2250, 'n_tokens_neox': 2157, 'n_words': 458}