-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeprecatedMethods.java
57 lines (51 loc) · 1.42 KB
/
DeprecatedMethods.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.project.myv.calculator;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.view.View;
public class DeprecatedMethods
{
@TargetApi(16)
@SuppressWarnings("deprecation")
public void setBackground(Drawable drawable, View v)
{
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk > android.os.Build.VERSION_CODES.JELLY_BEAN)
{
v.setBackground(drawable);
}
else
{
v.setBackgroundDrawable(drawable);
}
}
@TargetApi(21)
@SuppressWarnings("deprecation")
public Drawable getDrawable(Context context, int id)
{
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk >= Build.VERSION_CODES.LOLLIPOP)
{
return context.getResources().getDrawable(id, context.getTheme());
}
else
{
return context.getResources().getDrawable(id);
}
}
@SuppressWarnings("deprecation")
public int getColor(Context context, int colorId)
{
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk >= Build.VERSION_CODES.M)
{
return ContextCompat.getColor(context, colorId);
}
else
{
return context.getResources().getColor(colorId);
}
}
}