public FlyInMenu(Context context, AttributeSet attrs) { super(context, attrs); myContext = context; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FlyInMenu); duration = a.getInteger(R.styleable.FlyInMenu_animationDuration, 200); RuntimeException e = null; menuId = a.getResourceId(R.styleable.FlyInMenu_menu, 0); if (menuId == 0) { e = new IllegalArgumentException( a.getPositionDescription() + ": The handle attribute is required and must refer to a valid child."); } rightLayoutId = a.getResourceId(R.styleable.FlyInMenu_content, 0); if (rightLayoutId == 0) { e = new IllegalArgumentException( a.getPositionDescription() + ": The content attribute is required and must refer to a valid child."); } a.recycle(); if (e != null) { throw e; } myHandler = new Handler(); mState = State.READY; }
/** * 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; }
public Panel(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Panel); mDuration = a.getInteger(R.styleable.Panel_animationDuration, 750); // duration defaults to 750 ms mPosition = a.getInteger(R.styleable.Panel_position, BOTTOM); // position defaults to BOTTOM mLinearFlying = a.getBoolean(R.styleable.Panel_linearFlying, false); // linearFlying defaults to false mWeight = a.getFraction(R.styleable.Panel_weight, 0, 1, 0.0f); // weight defaults to 0.0 if (mWeight < 0 || mWeight > 1) { mWeight = 0.0f; Log.w(TAG, a.getPositionDescription() + ": weight must be > 0 and <= 1"); } mOpenedHandle = a.getDrawable(R.styleable.Panel_openedHandle); mClosedHandle = a.getDrawable(R.styleable.Panel_closedHandle); RuntimeException e = null; mHandleId = a.getResourceId(R.styleable.Panel_handle, 0); if (mHandleId == 0) { e = new IllegalArgumentException( a.getPositionDescription() + ": The handle attribute is required and must refer to a valid child."); } mContentId = a.getResourceId(R.styleable.Panel_content, 0); if (mContentId == 0) { e = new IllegalArgumentException( a.getPositionDescription() + ": The content attribute is required and must refer to a valid child."); } a.recycle(); if (e != null) { throw e; } mOrientation = (mPosition == TOP || mPosition == BOTTOM) ? VERTICAL : HORIZONTAL; setOrientation(mOrientation); mState = State.READY; mGestureListener = new PanelOnGestureListener(); mGestureDetector = new GestureDetector(mGestureListener); mGestureDetector.setIsLongpressEnabled(false); // i DON'T really know why i need this... setBaselineAligned(false); }
/** Updates the constant state from the values in the typed array. */ private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException { final Resources r = a.getResources(); final NinePatchState state = mNinePatchState; // Account for any configuration changes. state.mChangingConfigurations |= a.getChangingConfigurations(); // Extract the theme attributes, if any. state.mThemeAttrs = a.extractThemeAttrs(); state.mDither = a.getBoolean(R.styleable.NinePatchDrawable_dither, state.mDither); final int srcResId = a.getResourceId(R.styleable.NinePatchDrawable_src, 0); if (srcResId != 0) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inDither = !state.mDither; options.inScreenDensity = r.getDisplayMetrics().noncompatDensityDpi; final Rect padding = new Rect(); final Rect opticalInsets = new Rect(); Bitmap bitmap = null; try { final TypedValue value = new TypedValue(); final InputStream is = r.openRawResource(srcResId, value); bitmap = BitmapFactory.decodeResourceStream(r, value, is, padding, options); is.close(); } catch (IOException e) { // Ignore } if (bitmap == null) { throw new XmlPullParserException( a.getPositionDescription() + ": <nine-patch> requires a valid src attribute"); } else if (bitmap.getNinePatchChunk() == null) { throw new XmlPullParserException( a.getPositionDescription() + ": <nine-patch> requires a valid 9-patch source image"); } bitmap.getOpticalInsets(opticalInsets); state.mNinePatch = new NinePatch(bitmap, bitmap.getNinePatchChunk()); state.mPadding = padding; state.mOpticalInsets = Insets.of(opticalInsets); } state.mAutoMirrored = a.getBoolean(R.styleable.NinePatchDrawable_autoMirrored, state.mAutoMirrored); state.mBaseAlpha = a.getFloat(R.styleable.NinePatchDrawable_alpha, state.mBaseAlpha); final int tintMode = a.getInt(R.styleable.NinePatchDrawable_tintMode, -1); if (tintMode != -1) { state.mTintMode = Drawable.parseTintMode(tintMode, Mode.SRC_IN); } final ColorStateList tint = a.getColorStateList(R.styleable.NinePatchDrawable_tint); if (tint != null) { state.mTint = tint; } // Update local properties. initializeWithState(state, r); // Push density applied by setNinePatchState into state. state.mTargetDensity = mTargetDensity; }