@SuppressWarnings("deprecation") public static int getColor(@NonNull Context context, @ColorRes int colorId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return context.getColor(colorId); } return context.getResources().getColor(colorId); }
private int getColor(Context context, int id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return context.getColor(id); } else { return context.getResources().getColor(id); } } }
private int getColor(int id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return getContext().getColor(id); } else { //noinspection deprecation return getResources().getColor(id); } }
private int getColor(int id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return getContext().getColor(id); } else { return getResources().getColor(id); } } }
private void addTabDivider() { View divider = new View(getContext()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { mViewPager.setBackgroundColor(getContext().getResources().getColor(R.color.horizontal_vertical)); } else { mViewPager.setBackgroundColor(getContext().getColor(R.color.horizontal_vertical)); } LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1, LinearLayout.LayoutParams.MATCH_PARENT); mTabsContainer.addView(divider, mTabsContainer.getChildCount() - 2, params); }
public void update(String e, Boolean success){ errorText.setText(e); if(success){ errorText.setTextColor(getContext().getColor(R.color.dark_bg)); triggerSuccess(); } } }
public static int getColor(Context context, int id) { return context.getColor(id); } }
private static int getColor(Context context, int id) { if (Build.VERSION.SDK_INT >= 23) { return context.getColor(id); } else { //noinspection deprecation return context.getResources().getColor(id); } }
@SuppressWarnings("deprecation") private static int getColor(Context context, int colorResourceId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return context.getColor(colorResourceId); } else { return context.getResources().getColor(colorResourceId); } } }
public static int getColor(Context context,int color ){ if(Build.VERSION.SDK_INT >= 23){ return context.getColor(color); } return context.getResources().getColor(color); }
static public int getColor(Context context, int resourceId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return context.getColor(resourceId); } else { //noinspection deprecation return context.getResources().getColor(resourceId); } } }
public static int getColor(Context context, @ColorRes int colorId) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { //noinspection deprecation return context.getResources().getColor(colorId); } else { return context.getColor(colorId); } }
@Override public void run() { imageFingerprintIcon.setImageResource(R.mipmap.ic_fp_40px); textFingerprintStatus.setText(R.string.fingerprint_hint); textFingerprintStatus.setTextColor(context.getColor(R.color.hint)); } };
/** * You can simulate the use of this method with by calling {@link #setColor(int)} with ContextCompat: * setBackgroundColor(ContextCompat.getColor(resId)); */ @RequiresApi(api = Build.VERSION_CODES.M) public void setColorResource(@ColorRes int resId) { setColor(getContext().getColor(resId)); }
private int getColor(int id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return getContext().getColor(id); } else { return getResources().getColor(id); } } }
private int getColor(int id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return getContext().getColor(id); } else { //noinspection deprecation return getResources().getColor(id); } }
public ForumListAdapter(Context context, List<ForumsListModel.Forum> list) { mContext = context; mLayoutInflater = LayoutInflater.from(mContext); mList = list; mColor = mContext.getColor(ThemeManager.getInstance().getForegroundColor()); }
@RequiresApi(api = Build.VERSION_CODES.O) private static void createNotificationChannel(Context context) { NotificationManager notificationManager = context.getSystemService(NotificationManager.class); NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, context.getString(R.string.notification_events_channel_name), NotificationManager.IMPORTANCE_HIGH); channel.setShowBadge(false); channel.setLightColor(context.getColor(R.color.color_primary)); channel.enableVibration(true); channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); notificationManager.createNotificationChannel(channel); }
private void initLayout(ViewGroup viewGroup, @LayoutRes int layout, @StringRes int title, boolean nextButtonEnable) { View inflate = LayoutInflater.from(this).inflate(layout, viewGroup, false); viewGroup.addView(inflate); getSetupWizardLayout().setHeaderText(title); getSetupWizardLayout().getHeaderTextView().setTextColor(viewGroup.getContext().getColor(R.color.colorAccent)); setNavigationBarNextButtonEnabled(nextButtonEnable); } }
@Test public void handleNotificationWithDefaultColor() { int resourceId = 42; int color = 0x424242; Bundle bundle = mock(Bundle.class); when(bundle.getInt(DEFAULT_COLOR_METADATA_NAME)).thenReturn(resourceId); mApplicationInfoMock.metaData = bundle; when(mContextMock.getColor(eq(resourceId))).thenReturn(color); PushNotifier.handleNotification(mContextMock, new Intent()); verify(mNotificationBuilderMock).setColor(eq(color)); verify(mNotificationManagerMock).notify(mDummyGoogleMessageId.hashCode(), mNotificationMock); }