ambilwarna icon indicating copy to clipboard operation
ambilwarna copied to clipboard

Deprecated method

Open YanMESS opened this issue 6 years ago • 1 comments

Hi there,

Gradle build indicates this:

warning: [deprecation] removeGlobalOnLayoutListener(OnGlobalLayoutListener) in ViewTreeObserver has been deprecated view.getViewTreeObserver().removeGlobalOnLayoutListener(this);

After some research i came across this solution: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } else { //noinspection deprecation mView.getViewTreeObserver().removeGlobalOnLayoutListener(this); }

https://developer.android.com/reference/android/view/ViewTreeObserver.html#removeGlobalOnLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener)

Another one I found later is: MyView.setBackgroundDrawable(viewAlphaOverlay,gd);

Should be turned into: SetBackground(viewAlphaOverlay,gd);

@SuppressWarnings("deprecation")
private void SetBackground(View MyView, GradientDrawable gd) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN){
        MyView.setBackgroundDrawable(gd);
    } else {
        MyView.setBackground(gd);
    }
}

Thanks!

YanMESS avatar Mar 17 '18 07:03 YanMESS

Thank you for the suggestions! Feel free to open a pull request.

denisk20 avatar Mar 20 '18 13:03 denisk20