List of usage examples for android.content.res Resources getIdentifier
public int getIdentifier(String name, String defType, String defPackage)
From source file:com.linkbubble.util.Util.java
public static Integer getSystemNavigationBarHeight(Context context) { Integer result = null;//from w ww . j av a 2 s . co m try { Resources resources = context.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { result = resources.getDimensionPixelSize(resourceId); } } catch (Exception e) { } return result; }
From source file:util.Utils.java
/** * ???/*from w ww. ja v a 2 s.c o m*/ * * @param context * @return ?? */ public static int getStatusBarHeight(Context context) { int result = 0; Resources res = context.getResources(); int resourceId = res.getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = res.getDimensionPixelSize(resourceId); } return result; }
From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java
private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStart(obj); text.removeSpan(obj);/*from ww w. j av a 2 s . co m*/ if (where != len) { Font f = (Font) obj; if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.startsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = res.getColorStateList(colorRes); text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = getHtmlColor(f.mColor); if (c != -1) { text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
From source file:com.android.usbtuner.setup.TunerSetupActivity.java
/** * Sends the recommendation card to start the USB tuner TV input setup activity. * * @param context a {@link Context} instance *//*from ww w . j a v a 2s . c o m*/ private static void sendRecommendationCard(Context context) { Resources resources = context.getResources(); String focusedTitle = resources.getString(R.string.ut_setup_recommendation_card_focused_title); String title = resources.getString(R.string.ut_setup_recommendation_card_title); Bitmap largeIcon = BitmapFactory.decodeResource(resources, R.drawable.recommendation_antenna); // Build and send the notification. Notification notification = new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(context) .setAutoCancel(false).setContentTitle(focusedTitle).setContentText(title).setContentInfo(title) .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(largeIcon) .setSmallIcon(resources.getIdentifier(TAG_ICON, TAG_DRAWABLE, context.getPackageName())) .setContentIntent(createPendingIntentForSetupActivity(context))).build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFY_TAG, NOTIFY_ID, notification); }
From source file:com.linkbubble.util.Util.java
static public void showThemedDialog(Dialog dialog) { dialog.show();//from w ww .j a v a 2 s . c o m Resources resources = dialog.getContext().getResources(); int color = resources.getColor( Settings.get().getDarkThemeEnabled() ? R.color.color_primary_bright : R.color.color_primary); int dividerId = resources.getIdentifier("android:id/titleDivider", null, null); if (dividerId > 0) { View divider = dialog.findViewById(dividerId); if (divider != null) { divider.setBackgroundColor(color); } } int titleTextViewId = resources.getIdentifier("android:id/alertTitle", null, null); if (titleTextViewId > 0) { TextView textView = (TextView) dialog.findViewById(titleTextViewId); if (textView != null) { textView.setTextColor(color); } } }
From source file:com.nttec.everychan.ui.theme.CustomThemeHelper.java
private static void processWindow(Context context, SparseIntArray attrs, int textColorPrimaryOriginal, int textColorPrimaryOverridden) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) return;/*from w w w .ja v a 2 s .c o m*/ boolean isLollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; int materialPrimaryIndex = attrs.indexOfKey(R.attr.materialPrimary); int materialPrimaryDarkIndex = attrs.indexOfKey(R.attr.materialPrimaryDark); int materialNavigationBarIndex = attrs.indexOfKey(R.attr.materialNavigationBar); boolean overrideActionbarColor = materialPrimaryIndex >= 0; boolean overridePanelsColor = Math.max(materialPrimaryDarkIndex, materialNavigationBarIndex) >= 0; boolean overrideTextColor = textColorPrimaryOriginal != textColorPrimaryOverridden; if (!overrideTextColor && !overrideActionbarColor && !overridePanelsColor) return; Window window = ((Activity) context).getWindow(); final View decorView = window.getDecorView(); Resources resources = context.getResources(); if (overrideActionbarColor) { try { Drawable background = new ColorDrawable(attrs.valueAt(materialPrimaryIndex)); Object actionBar = context.getClass().getMethod("getActionBar").invoke(context); actionBar.getClass().getMethod("setBackgroundDrawable", Drawable.class).invoke(actionBar, background); } catch (Exception e) { Logger.e(TAG, e); } } if (overrideTextColor) { int id = resources.getIdentifier("action_bar_title", "id", "android"); if (id != 0) { View v = decorView.findViewById(id); if (v instanceof TextView) ((TextView) v).setTextColor(textColorPrimaryOverridden); } } if (isLollipop && overrideTextColor) { try { int id = resources.getIdentifier("action_bar", "id", "android"); if (id == 0) throw new Exception("'android:id/action_bar' identifier not found"); View v = decorView.findViewById(id); if (v == null) throw new Exception("view with id 'android:id/action_bar' not found"); Class<?> toolbarClass = Class.forName("android.widget.Toolbar"); if (!toolbarClass.isInstance(v)) throw new Exception("view 'android:id/action_bar' is not instance of android.widget.Toolbar"); toolbarClass.getMethod("setTitleTextColor", int.class).invoke(v, textColorPrimaryOverridden); setLollipopMenuOverflowIconColor((ViewGroup) v, textColorPrimaryOverridden); } catch (Exception e) { Logger.e(TAG, e); } } if (isLollipop && overridePanelsColor) { try { if (materialPrimaryDarkIndex >= 0) { window.getClass().getMethod("setStatusBarColor", int.class).invoke(window, attrs.valueAt(materialPrimaryDarkIndex)); } if (materialNavigationBarIndex >= 0) { window.getClass().getMethod("setNavigationBarColor", int.class).invoke(window, attrs.valueAt(materialNavigationBarIndex)); } } catch (Exception e) { Logger.e(TAG, e); } } }
From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java
public static Drawable getDrawableByName(View view, String name) { Resources resources = view.getResources(); return resources.getDrawable(resources.getIdentifier(name, "drawable", view.getContext().getPackageName())); }
From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java
public static int parseColor(View view, String text) { if (text.startsWith("@color/")) { Resources resources = view.getResources(); return resources.getColor(resources.getIdentifier(text.substring("@color/".length()), "color", view.getContext().getPackageName())); }//from w ww . j ava2s . c o m if (text.length() == 4 && text.startsWith("#")) { text = "#" + text.charAt(1) + text.charAt(1) + text.charAt(2) + text.charAt(2) + text.charAt(3) + text.charAt(3); } return Color.parseColor(text); }
From source file:com.aretha.slidemenu.SlideMenu.java
/** * Retrieve the height of status bar that defined in system * //from ww w . j a va 2 s .c om * @param context * @return */ public static float getStatusBarHeight(Context context) { Resources resources = context.getResources(); int statusBarIdentifier = resources.getIdentifier("status_bar_height", "dimen", "android"); if (0 != statusBarIdentifier) { return resources.getDimension(statusBarIdentifier); } return 0; }
From source file:library.slideMenu.SlideMenu.java
public static float getStatusBarHeight(Context context) { Resources resources = context.getResources(); int statusBarIdentifier = resources.getIdentifier("status_bar_height", "dimen", "android"); if (0 != statusBarIdentifier) { return resources.getDimension(statusBarIdentifier); }//from ww w . ja va 2 s . co m return 0; }