android.util.TypedValue#complexToDimension ( )源码实例Demo

下面列出了android.util.TypedValue#complexToDimension ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: ScaleAnimation.java
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;
}
 
源代码2 项目: android_9.0.0_r45   文件: TypedArray.java
/**
 * 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));
}
 
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);
}
 
源代码4 项目: pushfish-android   文件: PushListAdapter.java
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;
}
 
源代码5 项目: FamilyChat   文件: ParallaxViewPager.java
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();
}
 
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;
}
 
源代码7 项目: PowerFileExplorer   文件: TypedValueUtil.java
public static float complexToDimension(int data) {
    return TypedValue.complexToDimension(data, Base.getDisplayMetrics());
}
 
源代码8 项目: trekarta   文件: TextSearchFragment.java
public float getItemHeight() {
    TypedValue value = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, value, true);
    return TypedValue.complexToDimension(value.data, getResources().getDisplayMetrics());
}
 
源代码9 项目: android_9.0.0_r45   文件: Resources.java
/**
 * 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);
    }
}