List of usage examples for android.content.res Resources getValue
public void getValue(String name, TypedValue outValue, boolean resolveRefs) throws NotFoundException
From source file:Main.java
public static float getFloatConstant(final Resources res, final int constant) { TypedValue outValue = new TypedValue(); res.getValue(constant, outValue, true); return outValue.getFloat(); }
From source file:android.support.v7.content.res.AppCompatResources.java
private static boolean isColorInt(@NonNull Context context, @ColorRes int resId) { final Resources r = context.getResources(); final TypedValue value = getTypedValue(); r.getValue(resId, value, true); return value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT; }
From source file:uk.ac.ucl.excites.sapelli.collector.ui.items.ImageItem.java
/** * Creates a new ImageItem based on a drawable resource. * /*from www. j av a2s .c o m*/ * @param id the {@link Item} id (may be null) * @param resources a {@link Resources} object which provides access to a drawable resources with id {@code drawableResourceId} * @param drawableResourceId the id of a drawable that is accessible through {@code resources} */ public ImageItem(Integer id, Resources resources, int drawableResourceId) { super(id); this.file = null; this.drawableResourceID = drawableResourceId; TypedValue value = new TypedValue(); resources.getValue(drawableResourceId, value, true); this.vectorBased = MediaHelpers.isVectorImageFileName(value.string.toString()); }
From source file:android.support.v7.widget.AppCompatDrawableManager.java
private Drawable loadDrawableFromDelegates(@NonNull Context context, @DrawableRes int resId) { if (mDelegates != null && !mDelegates.isEmpty()) { if (mKnownDrawableIdTags != null) { final String cachedTagName = mKnownDrawableIdTags.get(resId); if (SKIP_DRAWABLE_TAG.equals(cachedTagName) || (cachedTagName != null && mDelegates.get(cachedTagName) == null)) { // If we don't have a delegate for the drawable tag, or we've been set to // skip it, fail fast and return null if (DEBUG) { Log.d(TAG, "[loadDrawableFromDelegates] Skipping drawable: " + context.getResources().getResourceName(resId)); }/*from www.j a v a 2 s.c o m*/ return null; } } else { // Create an id cache as we'll need one later mKnownDrawableIdTags = new SparseArray<>(); } if (mTypedValue == null) { mTypedValue = new TypedValue(); } final TypedValue tv = mTypedValue; final Resources res = context.getResources(); res.getValue(resId, tv, true); final long key = createCacheKey(tv); Drawable dr = getCachedDrawable(context, key); if (dr != null) { if (DEBUG) { Log.i(TAG, "[loadDrawableFromDelegates] Returning cached drawable: " + context.getResources().getResourceName(resId)); } // We have a cached drawable, return it! return dr; } if (tv.string != null && tv.string.toString().endsWith(".xml")) { // If the resource is an XML file, let's try and parse it try { final XmlPullParser parser = res.getXml(resId); final AttributeSet attrs = Xml.asAttributeSet(parser); int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty loop } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } final String tagName = parser.getName(); // Add the tag name to the cache mKnownDrawableIdTags.append(resId, tagName); // Now try and find a delegate for the tag name and inflate if found final InflateDelegate delegate = mDelegates.get(tagName); if (delegate != null) { dr = delegate.createFromXmlInner(context, parser, attrs, context.getTheme()); } if (dr != null) { // Add it to the drawable cache dr.setChangingConfigurations(tv.changingConfigurations); if (addDrawableToCache(context, key, dr) && DEBUG) { Log.i(TAG, "[loadDrawableFromDelegates] Saved drawable to cache: " + context.getResources().getResourceName(resId)); } } } catch (Exception e) { Log.e(TAG, "Exception while inflating drawable", e); } } if (dr == null) { // If we reach here then the delegate inflation of the resource failed. Mark it as // bad so we skip the id next time mKnownDrawableIdTags.append(resId, SKIP_DRAWABLE_TAG); } return dr; } return null; }
From source file:android.support.v7ox.widget.AppCompatDrawableManager.java
private Drawable loadDrawableFromDelegates(@NonNull Context context, @DrawableRes int resId) { if (mDelegates != null && !mDelegates.isEmpty()) { if (mKnownDrawableIdTags != null) { final String cachedTagName = mKnownDrawableIdTags.get(resId); if (SKIP_DRAWABLE_TAG.equals(cachedTagName) || (cachedTagName != null && mDelegates.get(cachedTagName) == null)) { // If we don't have a delegate for the drawable tag, or we've been set to // skip it, fail fast and return null if (DEBUG) { Log.d(TAG, "[loadDrawableFromDelegates] Skipping drawable: " + context.getResources().getResourceName(resId)); }//from w w w.j a v a2 s . c o m return null; } } else { // Create an id cache as we'll need one later mKnownDrawableIdTags = new SparseArray<>(); } if (mTypedValue == null) { mTypedValue = new TypedValue(); } final TypedValue tv = mTypedValue; final Resources res = context.getResources(); res.getValue(resId, tv, true); final long key = (((long) tv.assetCookie) << 32) | tv.data; Drawable dr = getCachedDelegateDrawable(context, key); if (dr != null) { if (DEBUG) { Log.i(TAG, "[loadDrawableFromDelegates] Returning cached drawable: " + context.getResources().getResourceName(resId)); } // We have a cached drawable, return it! return dr; } if (tv.string != null && tv.string.toString().endsWith(".xml")) { // If the resource is an XML file, let's try and parse it try { final XmlPullParser parser = res.getXml(resId); final AttributeSet attrs = Xml.asAttributeSet(parser); int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty loop } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } final String tagName = parser.getName(); // Add the tag name to the cache mKnownDrawableIdTags.append(resId, tagName); // Now try and find a delegate for the tag name and inflate if found final InflateDelegate delegate = mDelegates.get(tagName); if (delegate != null) { dr = delegate.createFromXmlInner(context, parser, attrs, context.getTheme()); } if (dr != null) { // Add it to the drawable cache dr.setChangingConfigurations(tv.changingConfigurations); if (addCachedDelegateDrawable(context, key, dr) && DEBUG) { Log.i(TAG, "[loadDrawableFromDelegates] Saved drawable to cache: " + context.getResources().getResourceName(resId)); } } } catch (Exception e) { Log.e(TAG, "Exception while inflating drawable", e); } } if (dr == null) { // If we reach here then the delegate inflation of the resource failed. Mark it as // bad so we skip the id next time mKnownDrawableIdTags.append(resId, SKIP_DRAWABLE_TAG); } return dr; } return null; }
From source file:me.lizheng.deckview.helpers.DeckViewConfig.java
/** * Updates the state, given the specified context *//*from w ww . j a v a 2 s. co m*/ void update(Context context) { Resources res = context.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); // Debug mode debugModeEnabled = false; // Layout isLandscape = res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; // Insets displayRect.set(0, 0, dm.widthPixels, dm.heightPixels); // Animations animationPxMovementPerSecond = res.getDimensionPixelSize(R.dimen.animation_movement_in_dps_per_second); // Filtering filteringCurrentViewsAnimDuration = res.getInteger(R.integer.filter_animate_current_views_duration); filteringNewViewsAnimDuration = res.getInteger(R.integer.filter_animate_new_views_duration); // Task stack taskStackScrollDuration = res.getInteger(R.integer.animate_deck_scroll_duration); TypedValue widthPaddingPctValue = new TypedValue(); res.getValue(R.dimen.deck_width_padding_percentage, widthPaddingPctValue, true); taskStackWidthPaddingPct = widthPaddingPctValue.getFloat(); TypedValue stackOverscrollPctValue = new TypedValue(); res.getValue(R.dimen.deck_overscroll_percentage, stackOverscrollPctValue, true); taskStackOverscrollPct = stackOverscrollPctValue.getFloat(); taskStackMaxDim = res.getInteger(R.integer.max_deck_view_dim); taskStackTopPaddingPx = res.getDimensionPixelSize(R.dimen.deck_top_padding); // Transition transitionEnterFromAppDelay = res.getInteger(R.integer.enter_from_app_transition_duration); transitionEnterFromHomeDelay = res.getInteger(R.integer.enter_from_home_transition_duration); // Task view animation and styles taskViewEnterFromAppDuration = res.getInteger(R.integer.task_enter_from_app_duration); taskViewEnterFromHomeDuration = res.getInteger(R.integer.task_enter_from_home_duration); taskViewEnterFromHomeStaggerDelay = res.getInteger(R.integer.task_enter_from_home_stagger_delay); taskViewExitToAppDuration = res.getInteger(R.integer.task_exit_to_app_duration); taskViewExitToHomeDuration = res.getInteger(R.integer.task_exit_to_home_duration); taskViewRemoveAnimDuration = res.getInteger(R.integer.animate_task_view_remove_duration); taskViewRemoveAnimTranslationXPx = res.getDimensionPixelSize(R.dimen.task_view_remove_anim_translation_x); taskViewRoundedCornerRadiusPx = res.getDimensionPixelSize(R.dimen.task_view_rounded_corners_radius); taskViewHighlightPx = res.getDimensionPixelSize(R.dimen.task_view_highlight); taskViewTranslationZMinPx = res.getDimensionPixelSize(R.dimen.task_view_z_min); taskViewTranslationZMaxPx = res.getDimensionPixelSize(R.dimen.task_view_z_max); taskViewAffiliateGroupEnterOffsetPx = res .getDimensionPixelSize(R.dimen.task_view_affiliate_group_enter_offset); TypedValue thumbnailAlphaValue = new TypedValue(); res.getValue(R.dimen.task_view_thumbnail_alpha, thumbnailAlphaValue, true); taskViewThumbnailAlpha = thumbnailAlphaValue.getFloat(); // Task bar colors taskBarViewDefaultBackgroundColor = ContextCompat.getColor(context, R.color.task_bar_default_background_color); taskBarViewLightTextColor = ContextCompat.getColor(context, R.color.task_bar_light_text_color); taskBarViewDarkTextColor = ContextCompat.getColor(context, R.color.task_bar_dark_text_color); taskBarViewHighlightColor = ContextCompat.getColor(context, R.color.task_bar_highlight_color); TypedValue affMinAlphaPctValue = new TypedValue(); res.getValue(R.dimen.task_affiliation_color_min_alpha_percentage, affMinAlphaPctValue, true); taskBarViewAffiliationColorMinAlpha = affMinAlphaPctValue.getFloat(); // Task bar size & animations taskBarHeight = res.getDimensionPixelSize(R.dimen.deck_child_header_bar_height); taskBarDismissDozeDelaySeconds = res.getInteger(R.integer.task_bar_dismiss_delay_seconds); // Nav bar scrim navBarScrimEnterDuration = res.getInteger(R.integer.nav_bar_scrim_enter_duration); // Misc useHardwareLayers = res.getBoolean(R.bool.config_use_hardware_layers); altTabKeyDelay = res.getInteger(R.integer.deck_alt_tab_key_delay); fakeShadows = res.getBoolean(R.bool.config_fake_shadows); svelteLevel = res.getInteger(R.integer.deck_svelte_level); }
From source file:ac.robinson.mediaphone.MediaPhoneActivity.java
private void loadAllPreferences() { SharedPreferences mediaPhoneSettings = PreferenceManager .getDefaultSharedPreferences(MediaPhoneActivity.this); Resources res = getResources(); // bluetooth observer configureBluetoothObserver(mediaPhoneSettings, res); // importing confirmation boolean confirmImporting = res.getBoolean(R.bool.default_confirm_importing); try {//from ww w . j ava 2 s . c o m confirmImporting = mediaPhoneSettings.getBoolean(getString(R.string.key_confirm_importing), confirmImporting); } catch (Exception e) { confirmImporting = res.getBoolean(R.bool.default_confirm_importing); } MediaPhone.IMPORT_CONFIRM_IMPORTING = confirmImporting; // delete after import boolean deleteAfterImport = res.getBoolean(R.bool.default_delete_after_importing); try { deleteAfterImport = mediaPhoneSettings.getBoolean(getString(R.string.key_delete_after_importing), deleteAfterImport); } catch (Exception e) { deleteAfterImport = res.getBoolean(R.bool.default_delete_after_importing); } MediaPhone.IMPORT_DELETE_AFTER_IMPORTING = deleteAfterImport; // minimum frame duration TypedValue resourceValue = new TypedValue(); res.getValue(R.attr.default_minimum_frame_duration, resourceValue, true); float minimumFrameDuration; try { minimumFrameDuration = mediaPhoneSettings.getFloat(getString(R.string.key_minimum_frame_duration), resourceValue.getFloat()); if (minimumFrameDuration <= 0) { throw new NumberFormatException(); } } catch (Exception e) { minimumFrameDuration = resourceValue.getFloat(); } MediaPhone.PLAYBACK_EXPORT_MINIMUM_FRAME_DURATION = Math.round(minimumFrameDuration * 1000); // word duration res.getValue(R.attr.default_word_duration, resourceValue, true); float wordDuration; try { wordDuration = mediaPhoneSettings.getFloat(getString(R.string.key_word_duration), resourceValue.getFloat()); if (wordDuration <= 0) { throw new NumberFormatException(); } } catch (Exception e) { wordDuration = resourceValue.getFloat(); } MediaPhone.PLAYBACK_EXPORT_WORD_DURATION = Math.round(wordDuration * 1000); // screen orientation int requestedOrientation = res.getInteger(R.integer.default_screen_orientation); try { String requestedOrientationString = mediaPhoneSettings .getString(getString(R.string.key_screen_orientation), null); requestedOrientation = Integer.valueOf(requestedOrientationString); } catch (Exception e) { requestedOrientation = res.getInteger(R.integer.default_screen_orientation); } setRequestedOrientation(requestedOrientation); // other preferences loadPreferences(mediaPhoneSettings); }