// Path: AndroidClient/app/src/main/java/com/hufeiya/SignIn/helper/ApiLevelHelper.java
// public class ApiLevelHelper {
// 
//     private ApiLevelHelper() {
//         //no instance
//     }
// 
//     /**
//      * Checks if the current api level is at least the provided value.
//      *
//      * @param apiLevel One of the values within {@link Build.VERSION_CODES}.
//      * @return <code>true</code> if the calling version is at least <code>apiLevel</code>.
//      * Else <code>false</code> is returned.
//      */
//     public static boolean isAtLeast(int apiLevel) {
//         return Build.VERSION.SDK_INT >= apiLevel;
//     }
// 
//     /**
//      * Checks if the current api level is at lower than the provided value.
//      *
//      * @param apiLevel One of the values within {@link Build.VERSION_CODES}.
//      * @return <code>true</code> if the calling version is lower than <code>apiLevel</code>.
//      * Else <code>false</code> is returned.
//      */
//     public static boolean isLowerThan(int apiLevel) {
//         return Build.VERSION.SDK_INT < apiLevel;
//     }
// }
// 
// Path: AndroidClient/app/src/main/java/com/hufeiya/SignIn/widget/outlineprovider/RoundOutlineProvider.java
// @TargetApi(Build.VERSION_CODES.LOLLIPOP)
// public class RoundOutlineProvider extends ViewOutlineProvider {
// 
//     private final int mSize;
// 
//     public RoundOutlineProvider(int size) {
//         if (0 > size) {
//             throw new IllegalArgumentException("size needs to be > 0. Actually was " + size);
//         }
//         mSize = size;
//     }
// 
//     @Override
//     public final void getOutline(View view, Outline outline) {
//         outline.setOval(0, 0, mSize, mSize);
//     }
// 
// }


import android.widget.ImageView;
import com.hufeiya.SignIn.R;
import com.hufeiya.SignIn.helper.ApiLevelHelper;
import com.hufeiya.SignIn.widget.outlineprovider.RoundOutlineProvider;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.util.AttributeSet;
import android.widget.Checkable;

    private void setAvatarPreLollipop(@DrawableRes int resId) {
        Drawable drawable = ResourcesCompat.getDrawable(getResources(), resId,
                getContext().getTheme());
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        @SuppressWarnings("ConstantConditions")
        RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(getResources(),
                bitmapDrawable.getBitmap());
        roundedDrawable.setCircular(true);
        setImageDrawable(roundedDrawable);
    }

    @Override
    protected void onDraw(@NonNull Canvas canvas) {
        super.onDraw(canvas);
        if (mChecked) {
            Drawable border = ContextCompat.getDrawable(getContext(), R.drawable.selector_avatar);
            border.setBounds(0, 0, getWidth(), getHeight());
            border.draw(canvas);
        }
    }

    @Override
    @SuppressLint("NewApi")
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        if (ApiLevelHelper.isLowerThan(Build.VERSION_CODES.LOLLIPOP)) {
            return;
        }
        if (w > 0 && h > 0) {
// Path: AndroidClient/app/src/main/java/com/hufeiya/SignIn/helper/ApiLevelHelper.java
// public class ApiLevelHelper {
// 
//     private ApiLevelHelper() {
//         //no instance
//     }
// 
//     /**
//      * Checks if the current api level is at least the provided value.
//      *
//      * @param apiLevel One of the values within {@link Build.VERSION_CODES}.
//      * @return <code>true</code> if the calling version is at least <code>apiLevel</code>.
//      * Else <code>false</code> is returned.
//      */
//     public static boolean isAtLeast(int apiLevel) {
//         return Build.VERSION.SDK_INT >= apiLevel;
//     }
// 
//     /**
//      * Checks if the current api level is at lower than the provided value.
//      *
//      * @param apiLevel One of the values within {@link Build.VERSION_CODES}.
//      * @return <code>true</code> if the calling version is lower than <code>apiLevel</code>.
//      * Else <code>false</code> is returned.
//      */
//     public static boolean isLowerThan(int apiLevel) {
//         return Build.VERSION.SDK_INT < apiLevel;
//     }
// }
// 
// Path: AndroidClient/app/src/main/java/com/hufeiya/SignIn/widget/outlineprovider/RoundOutlineProvider.java
// @TargetApi(Build.VERSION_CODES.LOLLIPOP)
// public class RoundOutlineProvider extends ViewOutlineProvider {
// 
//     private final int mSize;
// 
//     public RoundOutlineProvider(int size) {
//         if (0 > size) {
//             throw new IllegalArgumentException("size needs to be > 0. Actually was " + size);
//         }
//         mSize = size;
//     }
// 
//     @Override
//     public final void getOutline(View view, Outline outline) {
//         outline.setOval(0, 0, mSize, mSize);
//     }
// 
// }


// Path: AndroidClient/app/src/main/java/com/hufeiya/SignIn/widget/AvatarView.java
import android.widget.ImageView;
import com.hufeiya.SignIn.R;
import com.hufeiya.SignIn.helper.ApiLevelHelper;
import com.hufeiya.SignIn.widget.outlineprovider.RoundOutlineProvider;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.util.AttributeSet;
import android.widget.Checkable;


    private void setAvatarPreLollipop(@DrawableRes int resId) {
        Drawable drawable = ResourcesCompat.getDrawable(getResources(), resId,
                getContext().getTheme());
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        @SuppressWarnings("ConstantConditions")
        RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(getResources(),
                bitmapDrawable.getBitmap());
        roundedDrawable.setCircular(true);
        setImageDrawable(roundedDrawable);
    }

    @Override
    protected void onDraw(@NonNull Canvas canvas) {
        super.onDraw(canvas);
        if (mChecked) {
            Drawable border = ContextCompat.getDrawable(getContext(), R.drawable.selector_avatar);
            border.setBounds(0, 0, getWidth(), getHeight());
            border.draw(canvas);
        }
    }

    @Override
    @SuppressLint("NewApi")
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        if (ApiLevelHelper.isLowerThan(Build.VERSION_CODES.LOLLIPOP)) {
            return;
        }
        if (w > 0 && h > 0) {
            setOutlineProvider(new RoundOutlineProvider(Math.min(w, h)));