android.content.res.TypedArray#getPositionDescription()源码实例Demo

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

源代码1 项目: android_9.0.0_r45   文件: AnimatorInflater.java
/**
 * Setup the Animator to achieve path morphing.
 *
 * @param anim The target Animator which will be updated.
 * @param arrayAnimator TypedArray for the ValueAnimator.
 * @return the PathDataEvaluator.
 */
private static TypeEvaluator setupAnimatorForPath(ValueAnimator anim,
         TypedArray arrayAnimator) {
    TypeEvaluator evaluator = null;
    String fromString = arrayAnimator.getString(R.styleable.Animator_valueFrom);
    String toString = arrayAnimator.getString(R.styleable.Animator_valueTo);
    PathParser.PathData pathDataFrom = fromString == null
            ? null : new PathParser.PathData(fromString);
    PathParser.PathData pathDataTo = toString == null
            ? null : new PathParser.PathData(toString);

    if (pathDataFrom != null) {
        if (pathDataTo != null) {
            anim.setObjectValues(pathDataFrom, pathDataTo);
            if (!PathParser.canMorph(pathDataFrom, pathDataTo)) {
                throw new InflateException(arrayAnimator.getPositionDescription()
                        + " Can't morph from " + fromString + " to " + toString);
            }
        } else {
            anim.setObjectValues((Object)pathDataFrom);
        }
        evaluator = new PathDataEvaluator();
    } else if (pathDataTo != null) {
        anim.setObjectValues((Object)pathDataTo);
        evaluator = new PathDataEvaluator();
    }

    if (DBG_ANIMATOR_INFLATER && evaluator != null) {
        Log.v(TAG, "create a new PathDataEvaluator here");
    }

    return evaluator;
}
 
源代码2 项目: java-n-IDE-for-Android   文件: SplitView.java
private void init(Context context, AttributeSet attrs) {

        TypedArray viewAttrs = context.obtainStyledAttributes(attrs, R.styleable.SplitView);

        RuntimeException e = null;
        mHandleId = viewAttrs.getResourceId(R.styleable.SplitView_handle, 0);
        if (mHandleId == 0) {
            e = new IllegalArgumentException(viewAttrs.getPositionDescription() +
                    ": The required attribute handle must refer to a valid child view.");
        }

        mPrimaryContentId = viewAttrs.getResourceId(R.styleable.SplitView_topContent, 0);
        if (mPrimaryContentId == 0) {
            e = new IllegalArgumentException(viewAttrs.getPositionDescription() +
                    ": The required attribute primaryContent must refer to a valid child view.");
        }


        mSecondaryContentId = viewAttrs.getResourceId(R.styleable.SplitView_bottomContent, 0);
        if (mSecondaryContentId == 0) {
            e = new IllegalArgumentException(viewAttrs.getPositionDescription() +
                    ": The required attribute secondaryContent must refer to a valid child view.");
        }

        mMinSizePrimaryContent = viewAttrs.getDimension(R.styleable.SplitView_minSize, 1);
        viewAttrs.recycle();

        if (e != null) {
            throw e;
        }
    }
 
源代码3 项目: CanDialog   文件: PathAnimatorInflater.java
/**
 * Setup the Animator to achieve path morphing.
 *
 * @param anim The target Animator which will be updated.
 * @param arrayAnimator TypedArray for the ValueAnimator.
 * @return the PathDataEvaluator.
 */
private static TypeEvaluator setupAnimatorForPath(ValueAnimator anim,
                                                  TypedArray arrayAnimator) {
    TypeEvaluator evaluator = null;
    String fromString = arrayAnimator.getString(R.styleable.Animator_android_valueFrom);
    String toString = arrayAnimator.getString(R.styleable.Animator_android_valueTo);
    PathParser.PathDataNode[] nodesFrom =PathParser.createNodesFromPathData(fromString);
    PathParser.PathDataNode[] nodesTo = PathParser.createNodesFromPathData(toString);

    if (nodesFrom != null) {
        if (nodesTo != null) {
            anim.setObjectValues(nodesFrom, nodesTo);
            if (!PathParser.canMorph(nodesFrom, nodesTo)) {
                throw new InflateException(arrayAnimator.getPositionDescription()
                        + " Can't morph from " + fromString + " to " + toString);
            }
        } else {
            anim.setObjectValues((Object)nodesFrom);
        }
        evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesFrom));
    } else if (nodesTo != null) {
        anim.setObjectValues((Object)nodesTo);
        evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesTo));
    }

    if (DBG_ANIMATOR_INFLATER && evaluator != null) {
        Log.v(TAG, "create a new PathDataEvaluator here");
    }

    return evaluator;
}
 
源代码4 项目: Carbon   文件: RippleDrawableICS.java
private void verifyRequiredAttributes(TypedArray a) throws XmlPullParserException {
    if (mState.mColor == null && (mState.mTouchThemeAttrs == null
            || mState.mTouchThemeAttrs[R.styleable.RippleDrawable_android_color] == 0)) {
        throw new XmlPullParserException(a.getPositionDescription() +
                ": <ripple> requires a valid color attribute");
    }
}
 
源代码5 项目: ElasticProgressBar   文件: PathAnimatorInflater.java
/**
 * Setup the Animator to achieve path morphing.
 *
 * @param anim          The target Animator which will be updated.
 * @param arrayAnimator TypedArray for the ValueAnimator.
 * @return the PathDataEvaluator.
 */
private static TypeEvaluator setupAnimatorForPath(ValueAnimator anim,
                                                  TypedArray arrayAnimator) {
    TypeEvaluator evaluator = null;
    String fromString = arrayAnimator.getString(R.styleable.Animator_vc_valueFrom);
    String toString = arrayAnimator.getString(R.styleable.Animator_vc_valueTo);
    PathParser.PathDataNode[] nodesFrom = PathParser.createNodesFromPathData(fromString);
    PathParser.PathDataNode[] nodesTo = PathParser.createNodesFromPathData(toString);

    if (nodesFrom != null) {
        if (nodesTo != null) {
            anim.setObjectValues(nodesFrom, nodesTo);
            if (!PathParser.canMorph(nodesFrom, nodesTo)) {
                throw new InflateException(arrayAnimator.getPositionDescription()
                        + " Can't morph from " + fromString + " to " + toString);
            }
        } else {
            anim.setObjectValues((Object) nodesFrom);
        }
        evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesFrom));
    } else if (nodesTo != null) {
        anim.setObjectValues((Object) nodesTo);
        evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesTo));
    }

    if (DBG_ANIMATOR_INFLATER && evaluator != null) {
        Log.v(LOG_TAG, "create a new PathDataEvaluator here");
    }

    return evaluator;
}
 
源代码6 项目: RippleDrawable   文件: RippleDrawable.java
private void verifyRequiredAttributes(TypedArray a) throws XmlPullParserException {
    if (mState.mColor == null && (mState.mTouchThemeAttrs == null
            || mState.mTouchThemeAttrs[R.styleable.RippleDrawable_android_color].data == 0)) {
        throw new XmlPullParserException(a.getPositionDescription() +
                ": <ripple> requires a valid color attribute");
    }
}
 
源代码7 项目: android_9.0.0_r45   文件: AnimatorInflater.java
/**
 * Setup ObjectAnimator's property or values from pathData.
 *
 * @param anim The target Animator which will be updated.
 * @param arrayObjectAnimator TypedArray for the ObjectAnimator.
 * @param getFloats True if the value type is float.
 * @param pixelSize The relative pixel size, used to calculate the
 *                  maximum error for path animations.
 */
private static void setupObjectAnimator(ValueAnimator anim, TypedArray arrayObjectAnimator,
        int valueType, float pixelSize) {
    ObjectAnimator oa = (ObjectAnimator) anim;
    String pathData = arrayObjectAnimator.getString(R.styleable.PropertyAnimator_pathData);

    // Path can be involved in an ObjectAnimator in the following 3 ways:
    // 1) Path morphing: the property to be animated is pathData, and valueFrom and valueTo
    //    are both of pathType. valueType = pathType needs to be explicitly defined.
    // 2) A property in X or Y dimension can be animated along a path: the property needs to be
    //    defined in propertyXName or propertyYName attribute, the path will be defined in the
    //    pathData attribute. valueFrom and valueTo will not be necessary for this animation.
    // 3) PathInterpolator can also define a path (in pathData) for its interpolation curve.
    // Here we are dealing with case 2:
    if (pathData != null) {
        String propertyXName =
                arrayObjectAnimator.getString(R.styleable.PropertyAnimator_propertyXName);
        String propertyYName =
                arrayObjectAnimator.getString(R.styleable.PropertyAnimator_propertyYName);

        if (valueType == VALUE_TYPE_PATH || valueType == VALUE_TYPE_UNDEFINED) {
            // When pathData is defined, we are in case #2 mentioned above. ValueType can only
            // be float type, or int type. Otherwise we fallback to default type.
            valueType = VALUE_TYPE_FLOAT;
        }
        if (propertyXName == null && propertyYName == null) {
            throw new InflateException(arrayObjectAnimator.getPositionDescription()
                    + " propertyXName or propertyYName is needed for PathData");
        } else {
            Path path = PathParser.createPathFromPathData(pathData);
            float error = 0.5f * pixelSize; // max half a pixel error
            PathKeyframes keyframeSet = KeyframeSet.ofPath(path, error);
            Keyframes xKeyframes;
            Keyframes yKeyframes;
            if (valueType == VALUE_TYPE_FLOAT) {
                xKeyframes = keyframeSet.createXFloatKeyframes();
                yKeyframes = keyframeSet.createYFloatKeyframes();
            } else {
                xKeyframes = keyframeSet.createXIntKeyframes();
                yKeyframes = keyframeSet.createYIntKeyframes();
            }
            PropertyValuesHolder x = null;
            PropertyValuesHolder y = null;
            if (propertyXName != null) {
                x = PropertyValuesHolder.ofKeyframes(propertyXName, xKeyframes);
            }
            if (propertyYName != null) {
                y = PropertyValuesHolder.ofKeyframes(propertyYName, yKeyframes);
            }
            if (x == null) {
                oa.setValues(y);
            } else if (y == null) {
                oa.setValues(x);
            } else {
                oa.setValues(x, y);
            }
        }
    } else {
        String propertyName =
                arrayObjectAnimator.getString(R.styleable.PropertyAnimator_propertyName);
        oa.setPropertyName(propertyName);
    }
}
 
源代码8 项目: VectorChildFinder   文件: VectorDrawableCompat.java
private void updateStateFromTypedArray(TypedArray a, XmlPullParser parser)
        throws XmlPullParserException {
    final VectorDrawableCompatState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;

    // Account for any configuration changes.
    // state.mChangingConfigurations |= Utils.getChangingConfigurations(a);

    final int mode = TypedArrayUtils.getNamedInt(a, parser, "tintMode",
            AndroidResources.styleable_VectorDrawable_tintMode, -1);
    state.mTintMode = parseTintModeCompat(mode, PorterDuff.Mode.SRC_IN);

    final ColorStateList tint =
            a.getColorStateList(AndroidResources.styleable_VectorDrawable_tint);
    if (tint != null) {
        state.mTint = tint;
    }

    state.mAutoMirrored = TypedArrayUtils.getNamedBoolean(a, parser, "autoMirrored",
            AndroidResources.styleable_VectorDrawable_autoMirrored, state.mAutoMirrored);

    pathRenderer.mViewportWidth = TypedArrayUtils.getNamedFloat(a, parser, "viewportWidth",
            AndroidResources.styleable_VectorDrawable_viewportWidth,
            pathRenderer.mViewportWidth);

    pathRenderer.mViewportHeight = TypedArrayUtils.getNamedFloat(a, parser, "viewportHeight",
            AndroidResources.styleable_VectorDrawable_viewportHeight,
            pathRenderer.mViewportHeight);

    if (pathRenderer.mViewportWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<vector> tag requires viewportHeight > 0");
    }

    pathRenderer.mBaseWidth = a.getDimension(
            AndroidResources.styleable_VectorDrawable_width, pathRenderer.mBaseWidth);
    pathRenderer.mBaseHeight = a.getDimension(
            AndroidResources.styleable_VectorDrawable_height, pathRenderer.mBaseHeight);
    if (pathRenderer.mBaseWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<vector> tag requires width > 0");
    } else if (pathRenderer.mBaseHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<vector> tag requires height > 0");
    }

    // shown up from API 11.
    final float alphaInFloat = TypedArrayUtils.getNamedFloat(a, parser, "alpha",
            AndroidResources.styleable_VectorDrawable_alpha, pathRenderer.getAlpha());
    pathRenderer.setAlpha(alphaInFloat);

    final String name = a.getString(AndroidResources.styleable_VectorDrawable_name);
    if (name != null) {
        pathRenderer.mRootName = name;
        pathRenderer.mVGTargetsMap.put(name, pathRenderer);
    }
}
 
源代码9 项目: CanDialog   文件: VectorDrawable.java
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;

    // Account for any configuration changes.
    state.mChangingConfigurations |= getChangingConfigurations(a);

    // Extract the theme attributes, if any.
    //TODO: will not support drawable theming yet (applies to tinting mainly)
    //state.mThemeAttrs = a.extractThemeAttrs();

    final int tintMode = a.getInt(R.styleable.VectorDrawable_vc_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = parseTintMode(tintMode, Mode.SRC_IN);
    }

    final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_vc_tint);
    if (tint != null) {
        state.mTint = tint;
    }

    state.mAutoMirrored = a.getBoolean(
            R.styleable.VectorDrawable_vc_autoMirrored, state.mAutoMirrored);

    pathRenderer.mViewportWidth = a.getFloat(
            R.styleable.VectorDrawable_vc_viewportWidth, pathRenderer.mViewportWidth);
    pathRenderer.mViewportHeight = a.getFloat(
            R.styleable.VectorDrawable_vc_viewportHeight, pathRenderer.mViewportHeight);

    if (pathRenderer.mViewportWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<menu_vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<menu_vector> tag requires viewportHeight > 0");
    }

    pathRenderer.mBaseWidth = a.getDimension(
            R.styleable.VectorDrawable_android_width, pathRenderer.mBaseWidth);
    pathRenderer.mBaseHeight = a.getDimension(
            R.styleable.VectorDrawable_android_height, pathRenderer.mBaseHeight);

    if (pathRenderer.mBaseWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<menu_vector> tag requires width > 0");
    } else if (pathRenderer.mBaseHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<menu_vector> tag requires height > 0");
    }

    final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_android_alpha,
            pathRenderer.getAlpha());
    pathRenderer.setAlpha(alphaInFloat);

    final String name = a.getString(R.styleable.VectorDrawable_android_name);
    if (name != null) {
        pathRenderer.mRootName = name;
        pathRenderer.mVGTargetsMap.put(name, pathRenderer);
    }
}
 
源代码10 项目: ElasticProgressBar   文件: VectorDrawable.java
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;

    // Account for any configuration changes.
    state.mChangingConfigurations |= getChangingConfigurations(a);

    // Extract the theme attributes, if any.
    //TODO: will not support drawable theming yet (applies to tinting mainly)
    //state.mThemeAttrs = a.extractThemeAttrs();

    final int tintMode = a.getInt(R.styleable.VectorDrawable_vc_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = parseTintMode(tintMode, PorterDuff.Mode.SRC_IN);
    }

    final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_vc_tint);
    if (tint != null) {
        state.mTint = tint;
    }

    state.mAutoMirrored = a.getBoolean(
            R.styleable.VectorDrawable_vc_autoMirrored, state.mAutoMirrored);

    pathRenderer.mViewportWidth = a.getFloat(
            R.styleable.VectorDrawable_vc_viewportWidth, pathRenderer.mViewportWidth);
    pathRenderer.mViewportHeight = a.getFloat(
            R.styleable.VectorDrawable_vc_viewportHeight, pathRenderer.mViewportHeight);


    if (pathRenderer.mViewportWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<menu_vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<menu_vector> tag requires viewportHeight > 0");
    }

    pathRenderer.mBaseWidth = a.getDimension(
            R.styleable.VectorDrawable_android_width, pathRenderer.mBaseWidth);
    pathRenderer.mBaseHeight = a.getDimension(
            R.styleable.VectorDrawable_android_height, pathRenderer.mBaseHeight);

    if (pathRenderer.mBaseWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<menu_vector> tag requires width > 0");
    } else if (pathRenderer.mBaseHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() +
                "<menu_vector> tag requires height > 0");
    }

    final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_android_alpha,
            pathRenderer.getAlpha());
    pathRenderer.setAlpha(alphaInFloat);

    final String name = a.getString(R.styleable.VectorDrawable_android_name);
    if (name != null) {
        pathRenderer.mRootName = name;
        pathRenderer.mVGTargetsMap.put(name, pathRenderer);
    }
}
 
源代码11 项目: Mover   文件: VectorDrawable.java
private void updateStateFromTypedArray(TypedArray array) throws XmlPullParserException {
  final VectorDrawableState state = mVectorState;
  final VPathRenderer pathRenderer = state.mVPathRenderer;

  // Account for any configuration changes.
  state.mChangingConfigurations |= Utils.getChangingConfigurations(array);

  // Extract the theme attributes, if any.
  state.mThemeAttrs = null; // TODO THEME TINT Not supported yet a.extractThemeAttrs();

  final int tintMode = array.getInt(R.styleable.VectorDrawable_tintMode, -1);
  if (tintMode != -1) {
    state.mTintMode = Utils.parseTintMode(tintMode, DEFAULT_TINT_MODE);
  }

  final ColorStateList tint = array.getColorStateList(R.styleable.VectorDrawable_tint);
  if (tint != null) {
    state.mTint = tint;
  }

  state.mAutoMirrored = array.getBoolean(
      R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored);

  pathRenderer.mViewportWidth = array.getFloat(
      R.styleable.VectorDrawable_viewportWidth, pathRenderer.mViewportWidth);
  pathRenderer.mViewportHeight = array.getFloat(
      R.styleable.VectorDrawable_viewportHeight, pathRenderer.mViewportHeight);

  if (pathRenderer.mViewportWidth <= 0) {
    throw new XmlPullParserException(array.getPositionDescription() +
            String.format(" %s, <vector> tag requires width > 0 (%s)", mResourceName, pathRenderer.mBaseWidth));
  } else if (pathRenderer.mViewportHeight <= 0) {
    throw new XmlPullParserException(array.getPositionDescription() +
            String.format("%s, <vector> tag requires width > 0 (%s)", mResourceName, pathRenderer.mViewportHeight));
  }

    pathRenderer.mBaseHeight = array.getDimension(
            R.styleable.VectorDrawable_height, pathRenderer.mBaseHeight);
    pathRenderer.mBaseWidth = array.getDimension(
            R.styleable.VectorDrawable_width, pathRenderer.mBaseWidth);

  if (pathRenderer.mBaseWidth <= 0) {
    throw new XmlPullParserException(array.getPositionDescription() +
        String.format("%s <vector> tag requires width > 0 (%s)", mResourceName, pathRenderer.mBaseWidth));
  } else if (pathRenderer.mBaseHeight <= 0) {
    throw new XmlPullParserException(array.getPositionDescription() +
            String.format("%s <vector> tag requires width > 0 (%s)",mResourceName, pathRenderer.mBaseHeight));
  }

  final float alphaInFloat = array.getFloat(R.styleable.VectorDrawable_alpha,
      pathRenderer.getAlpha());
  pathRenderer.setAlpha(alphaInFloat);

  final String name = array.getString(R.styleable.VectorDrawable_name);
  if (name != null) {
    pathRenderer.mRootName = name;
    pathRenderer.mVGTargetsMap.put(name, pathRenderer);
  }
}
 
源代码12 项目: MrVector   文件: VectorDrawable.java
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
  final VectorDrawableState state = mVectorState;
  final VPathRenderer pathRenderer = state.mVPathRenderer;

  // Account for any configuration changes.
  state.mChangingConfigurations |= Utils.getChangingConfigurations(a);

  // Extract the theme attributes, if any.
  state.mThemeAttrs = null; // TODO THEME TINT Not supported yet a.extractThemeAttrs();

  final int tintMode = a.getInt(R.styleable.VectorDrawable_mv_tintMode, -1);
  if (tintMode != -1) {
    state.mTintMode = Utils.parseTintMode(tintMode, DEFAULT_TINT_MODE);
  }

  final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_mv_tint);
  if (tint != null) {
    state.mTint = tint;
  }

  state.mAutoMirrored = a.getBoolean(
      R.styleable.VectorDrawable_mv_autoMirrored, state.mAutoMirrored);

  pathRenderer.mViewportWidth = a.getFloat(
      R.styleable.VectorDrawable_mv_viewportWidth, pathRenderer.mViewportWidth);
  pathRenderer.mViewportHeight = a.getFloat(
      R.styleable.VectorDrawable_mv_viewportHeight, pathRenderer.mViewportHeight);

  if (pathRenderer.mViewportWidth <= 0) {
    throw new XmlPullParserException(a.getPositionDescription() +
        "<vector> tag requires viewportWidth > 0");
  } else if (pathRenderer.mViewportHeight <= 0) {
    throw new XmlPullParserException(a.getPositionDescription() +
        "<vector> tag requires viewportHeight > 0");
  }

  pathRenderer.mBaseWidth = a.getDimension(
      R.styleable.VectorDrawable_mv_width, pathRenderer.mBaseWidth);
  pathRenderer.mBaseHeight = a.getDimension(
      R.styleable.VectorDrawable_mv_height, pathRenderer.mBaseHeight);

  if (pathRenderer.mBaseWidth <= 0) {
    throw new XmlPullParserException(a.getPositionDescription() +
        "<vector> tag requires width > 0");
  } else if (pathRenderer.mBaseHeight <= 0) {
    throw new XmlPullParserException(a.getPositionDescription() +
        "<vector> tag requires height > 0");
  }

  final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_mv_alpha,
      pathRenderer.getAlpha());
  pathRenderer.setAlpha(alphaInFloat);

  final String name = a.getString(R.styleable.VectorDrawable_mv_name);
  if (name != null) {
    pathRenderer.mRootName = name;
    pathRenderer.mVGTargetsMap.put(name, pathRenderer);
  }
}
 
源代码13 项目: Androzic   文件: ScrollLayout.java
public ScrollLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.setWillNotDraw(false);
    rightShadow = getContext().getResources().getDrawable(R.drawable.right_shadow);
    leftShadow = getContext().getResources().getDrawable(R.drawable.left_shadow);
    mScroller = new Scroller(getContext());
    setGravity(Gravity.CENTER_VERTICAL);
    setOrientation(HORIZONTAL);
    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    // as mMaximumVelocity does not exist in API<4
    float density = getContext().getResources().getDisplayMetrics().density;
    mMaximumVelocity = (int)(4000 * 0.5f * density);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrollLayout,
            0, 0);

    // Get the labeler class and construct an instance
    String className = a.getNonResourceString(R.styleable.ScrollLayout_labelerClass);
    if (className == null) {
        throw new RuntimeException("Must specify labeler class at " + a.getPositionDescription());
    }

    String labelerFormat = a.getString(R.styleable.ScrollLayout_labelerFormat);
    if (labelerFormat == null) {
        throw new RuntimeException("Must specify labelerFormat at " + a.getPositionDescription());
    }

    try {
        Class<?> klazz = Class.forName(className);
        Constructor<?> ctor = klazz.getConstructor(String.class);
        mLabeler = (Labeler)ctor.newInstance(labelerFormat);
    } catch (Exception e) {
        throw new RuntimeException("Failed to construct labeler at " + a.getPositionDescription(), e);
    }

    // Determine the width and height of our children, using the labelers preferred
    // values as defaults
    objWidth = a.getDimensionPixelSize(R.styleable.ScrollLayout_childWidth,
            mLabeler.getPreferredViewWidth(context));
    objHeight = a.getDimensionPixelSize(R.styleable.ScrollLayout_childHeight,
            mLabeler.getPreferredViewHeight(context));

    a.recycle();
}