Java Code Examples for android.util.TypedValue#complexToDimension()
The following examples show how to use
android.util.TypedValue#complexToDimension() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScaleAnimation.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
float resolveScale(float scale, int type, int data, int size, int psize) { float targetSize; if (type == TypedValue.TYPE_FRACTION) { targetSize = TypedValue.complexToFraction(data, size, psize); } else if (type == TypedValue.TYPE_DIMENSION) { targetSize = TypedValue.complexToDimension(data, mResources.getDisplayMetrics()); } else { return scale; } if (size == 0) { return 1; } return targetSize/(float)size; }
Example 2
Source File: TypedArray.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Retrieve a dimensional unit attribute at <var>index</var>. Unit * conversions are based on the current {@link DisplayMetrics} * associated with the resources this {@link TypedArray} object * came from. * <p> * This method will throw an exception if the attribute is defined but is * not a dimension. * * @param index Index of attribute to retrieve. * @param defValue Value to return if the attribute is not defined or * not a resource. * * @return Attribute dimension value multiplied by the appropriate * metric, or defValue if not defined. * @throws RuntimeException if the TypedArray has already been recycled. * @throws UnsupportedOperationException if the attribute is defined but is * not an integer. * * @see #getDimensionPixelOffset * @see #getDimensionPixelSize */ public float getDimension(@StyleableRes int index, float defValue) { if (mRecycled) { throw new RuntimeException("Cannot make calls to a recycled instance!"); } final int attrIndex = index; index *= STYLE_NUM_ENTRIES; final int[] data = mData; final int type = data[index + STYLE_TYPE]; if (type == TypedValue.TYPE_NULL) { return defValue; } else if (type == TypedValue.TYPE_DIMENSION) { return TypedValue.complexToDimension(data[index + STYLE_DATA], mMetrics); } else if (type == TypedValue.TYPE_ATTRIBUTE) { final TypedValue value = mValue; getValueAt(index, value); throw new UnsupportedOperationException( "Failed to resolve attribute at index " + attrIndex + ": " + value); } throw new UnsupportedOperationException("Can't convert value at index " + attrIndex + " to dimension: type=0x" + Integer.toHexString(type)); }
Example 3
Source File: DefaultNavigationImplementation.java From native-navigation with MIT License | 6 votes |
public float getBarHeight( ReactInterface component, ReactToolbar toolbar, ActionBar actionBar, ReadableMap config, boolean firstCall ) { Activity activity = component.getActivity(); TypedValue typedValue = new TypedValue(); int attributeResourceId = android.R.attr.actionBarSize; if (activity instanceof AppCompatActivity) { attributeResourceId = R.attr.actionBarSize; } if (activity.getTheme().resolveAttribute(attributeResourceId, typedValue, true)) { float px = TypedValue.complexToDimension(typedValue.data, activity.getResources().getDisplayMetrics()); float pixelDensity = Resources.getSystem().getDisplayMetrics().density; return px / pixelDensity; } // if we've made it here, we need to guess... return activity.getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material); }
Example 4
Source File: PushListAdapter.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void configureViewForPosition(View itemView, int position) { TextView dateText = (TextView) itemView.findViewById(R.id.push_date); TextView titleText = (TextView) itemView.findViewById(R.id.push_title); TextView descriptionText = (TextView) itemView.findViewById(R.id.push_description); ImageView iconImage = (ImageView) itemView.findViewById(R.id.push_icon_image); String title = entries.get(position).getTitle(); if (title.equals("")) title = entries.get(position).getService().getName(); String description = entries.get(position).getMessage(); Date pushDate = entries.get(position).getLocalTimestamp(); Bitmap icon = entries.get(position).getService().getIconBitmapOrDefault(context); dateText.setText(this.dateFormat.format(pushDate)); titleText.setText(title); descriptionText.setText(description); iconImage.setImageBitmap(icon); TypedValue value = new TypedValue(); DisplayMetrics metrics = new DisplayMetrics(); context.getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, value, true); ((WindowManager) (context.getSystemService(Context.WINDOW_SERVICE))).getDefaultDisplay().getMetrics(metrics); int lineCount = selectedIndex == position ? descriptionText.getLineCount() : 0; int minHeight = (int) TypedValue.complexToDimension(value.data, metrics); int prefHeight = (lineCount + 2) * descriptionText.getLineHeight(); itemView.getLayoutParams().height = prefHeight > minHeight ? prefHeight : minHeight; }
Example 5
Source File: ParallaxViewPager.java From FamilyChat with Apache License 2.0 | 5 votes |
public ParallaxViewPager(Context context, AttributeSet attrs) { super(context, attrs); mParallaxTransformer = new ParallaxTransformer(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ParallaxViewPager, 0, 0); mMode = Mode.values()[a.getInt(R.styleable.ParallaxViewPager_mode, 0)]; setMode(mMode); if (a.hasValue(R.styleable.ParallaxViewPager_right_shadow)) { mRightShadow = a.getDrawable(R.styleable.ParallaxViewPager_right_shadow); } if (a.hasValue(R.styleable.ParallaxViewPager_left_shadow)) { mLeftShadow = a.getDrawable(R.styleable.ParallaxViewPager_left_shadow); } mShadowWidth = a.getDimensionPixelSize(R.styleable.ParallaxViewPager_shadow_width, (int) dp2px(20, getContext())); TypedValue tv = a.peekValue(R.styleable.ParallaxViewPager_outset); if (tv != null) { if (tv.type == TypedValue.TYPE_FRACTION) { mOutsetFraction = a.getFraction(R.styleable.ParallaxViewPager_outset, 1, 1, 0); setOutsetFraction(mOutsetFraction); } else if (tv.type == TypedValue.TYPE_DIMENSION) { mOutset = (int) TypedValue.complexToDimension(tv.data, getResources().getDisplayMetrics()); setOutset(mOutset); } } final int resID = a.getResourceId(R.styleable.ParallaxViewPager_interpolator, 0); if (resID > 0) { setInterpolator(context, resID); } a.recycle(); }
Example 6
Source File: ScreenUtil.java From android-design-support-lib-sample with Apache License 2.0 | 5 votes |
public static int getActionBarHeight(Context context){ TypedValue typedValue = new TypedValue(); int actionBatHeight = 0; if(context.getTheme().resolveAttribute(android.R.attr.actionBarSize,typedValue,true)){ DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); float actionBar = TypedValue.complexToDimension(typedValue.data,displayMetrics); actionBatHeight = Math.round(actionBar); } return actionBatHeight; }
Example 7
Source File: TypedValueUtil.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
public static float complexToDimension(int data) { return TypedValue.complexToDimension(data, Base.getDisplayMetrics()); }
Example 8
Source File: TextSearchFragment.java From trekarta with GNU General Public License v3.0 | 4 votes |
public float getItemHeight() { TypedValue value = new TypedValue(); getActivity().getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, value, true); return TypedValue.complexToDimension(value.data, getResources().getDisplayMetrics()); }
Example 9
Source File: Resources.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Retrieve a dimensional for a particular resource ID. Unit * conversions are based on the current {@link DisplayMetrics} associated * with the resources. * * @param id The desired resource identifier, as generated by the aapt * tool. This integer encodes the package, type, and resource * entry. The value 0 is an invalid identifier. * * @return Resource dimension value multiplied by the appropriate * metric. * * @throws NotFoundException Throws NotFoundException if the given ID does not exist. * * @see #getDimensionPixelOffset * @see #getDimensionPixelSize */ public float getDimension(@DimenRes int id) throws NotFoundException { final TypedValue value = obtainTempTypedValue(); try { final ResourcesImpl impl = mResourcesImpl; impl.getValue(id, value, true); if (value.type == TypedValue.TYPE_DIMENSION) { return TypedValue.complexToDimension(value.data, impl.getDisplayMetrics()); } throw new NotFoundException("Resource ID #0x" + Integer.toHexString(id) + " type #0x" + Integer.toHexString(value.type) + " is not valid"); } finally { releaseTempTypedValue(value); } }