java类android.graphics.drawable.DrawableContainer的实例源码

ClassDescStateListDrawable.java 文件源码 项目:itsnat_droid 阅读 15 收藏 0 点赞 0 评论 0
public ClassDescStateListDrawable(ClassDescDrawableMgr classMgr, ClassDescElementDrawableContainer parent)
{
    super(classMgr, "selector", parent);

    this.methodGetStateListState = new MethodContainer<DrawableContainer.DrawableContainerState>(StateListDrawable.class,"getStateListState");
    this.methodGetStateListStateIsConstantSize =
            new MethodContainer<Void>(DrawableContainer.class.getName() + "$DrawableContainerState","setConstantSize",boolean.class);
}
ClassDescAnimationDrawable.java 文件源码 项目:itsnat_droid 阅读 14 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
protected void init()
{
    super.init();

    // https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
    // https://developer.android.com/guide/topics/resources/animation-resource.html
    // https://developer.android.com/guide/topics/graphics/drawable-animation.html

    addAttrDescAN(new AttrDescReflecMethodBoolean(this, "oneshot", "setOneShot", false));
    addAttrDescAN(new AttrDescReflecFieldMethodBoolean(this, "variablePadding", "mAnimationState", MiscUtil.resolveClass(DrawableContainer.class.getName() + "$DrawableContainerState"), "setVariablePadding", false));
    // está arriba:  addAttrDescAN(new AttrDescDrawable_Drawable_visible<AnimationDrawable>(this));
}
Assert.java 文件源码 项目:itsnat_droid 阅读 28 收藏 0 点赞 0 评论 0
public static void assertEquals(AnimationDrawable a,AnimationDrawable b)
{
    assertEqualsDrawableContainer(a, b);

    // android:oneshot
    assertEquals(a.isOneShot(), b.isOneShot());
    // android:visible
    assertEquals(a.isVisible(), b.isVisible());

    Drawable.ConstantState a_state = a.getConstantState();
    Drawable.ConstantState b_state = b.getConstantState();

    // android:variablePadding
    Class classDrawableContainerState = TestUtil.resolveClass(DrawableContainer.class.getName() + "$DrawableContainerState");
    assertEquals(TestUtil.getField(a_state, classDrawableContainerState, "mVariablePadding"), TestUtil.getField(b_state, classDrawableContainerState, "mVariablePadding"));

    // <item>

    // android:drawable (o child element drawable) se testea en assertEqualsDrawableContainer
    // android:duration
    Class classState = TestUtil.resolveClass(AnimationDrawable.class.getName() + "$AnimationState");

    int[] a_durations = (int[])TestUtil.getField(a_state, classState, "mDurations");
    int[] b_durations = (int[])TestUtil.getField(b_state, classState, "mDurations");

    assertEquals(a_durations,b_durations);
}
Assert.java 文件源码 项目:itsnat_droid 阅读 31 收藏 0 点赞 0 评论 0
private static void assertEqualsDrawableContainer(DrawableContainer a,DrawableContainer b)
{
    assertEqualsDrawable(a, b);

    Drawable.ConstantState a_state = a.getConstantState();
    Drawable.ConstantState b_state = b.getConstantState();

    // <item>

    // android:drawable (o child element drawable)
    Class classState = TestUtil.resolveClass(DrawableContainer.class.getName() + "$DrawableContainerState");

    Drawable[] a_drawables = (Drawable[])TestUtil.getField(a_state, classState, "mDrawables");
    Drawable[] b_drawables = (Drawable[])TestUtil.getField(b_state, classState, "mDrawables");
    assertEquals(a_drawables.length,b_drawables.length);
    for(int i = 0; i < a_drawables.length; i++)
    {
        // No se porqué a veces no coinciden en número de imágenes en a (el compilado) hay más que en b, al menos chequeamos que los comunes coinciden (los índices con data en b deben coincidir con el dato en a)
        if (a_drawables[i] != null && b_drawables[i] != null)
                assertEquals(a_drawables[i], b_drawables[i]);
        /*
        Falla curiosamente cuando se testea dos veces, el compilado CAMBIA
        if (b_drawables[i] != null && a_drawables[i] == null) // Si b (dinámico) está definido DEBE estarlo a (compilado)
                assertTrue(false);
                */
    }
}
TextInputLayout.java 文件源码 项目:iosched 阅读 36 收藏 0 点赞 0 评论 0
private void ensureBackgroundDrawableStateWorkaround() {
  final int sdk = Build.VERSION.SDK_INT;
  if (sdk != 21 && sdk != 22) {
    // The workaround is only required on API 21-22
    return;
  }
  final Drawable bg = mEditText.getBackground();
  if (bg == null) {
    return;
  }

  if (!mHasReconstructedEditTextBackground) {
    // This is gross. There is an issue in the platform which affects container Drawables
    // where the first drawable retrieved from resources will propagate any changes
    // (like color filter) to all instances from the cache. We'll try to workaround it...

    final Drawable newBg = bg.getConstantState().newDrawable();

    if (bg instanceof DrawableContainer) {
      // If we have a Drawable container, we can try and set it's constant state via
      // reflection from the new Drawable
      mHasReconstructedEditTextBackground =
          DrawableUtils.setContainerConstantState(
              (DrawableContainer) bg, newBg.getConstantState());
    }

    if (!mHasReconstructedEditTextBackground) {
      // If we reach here then we just need to set a brand new instance of the Drawable
      // as the background. This has the unfortunate side-effect of wiping out any
      // user set padding, but I'd hope that use of custom padding on an EditText
      // is limited.
      ViewCompat.setBackground(mEditText, newBg);
      mHasReconstructedEditTextBackground = true;
    }
  }
}
DrawableUtils.java 文件源码 项目:cwac-crossport 阅读 34 收藏 0 点赞 0 评论 0
static boolean setContainerConstantState(DrawableContainer drawable,
          Drawable.ConstantState constantState) {
  // We can use getDeclaredMethod() on v9+
  return setContainerConstantStateV9(drawable, constantState);
}
DrawableUtils.java 文件源码 项目:boohee_v5.6 阅读 33 收藏 0 点赞 0 评论 0
static boolean canSafelyMutateDrawable(@NonNull Drawable drawable) {
    if (drawable instanceof LayerDrawable) {
        if (VERSION.SDK_INT >= 16) {
            return true;
        }
        return false;
    } else if (drawable instanceof InsetDrawable) {
        if (VERSION.SDK_INT < 14) {
            return false;
        }
        return true;
    } else if (drawable instanceof StateListDrawable) {
        if (VERSION.SDK_INT < 8) {
            return false;
        }
        return true;
    } else if (drawable instanceof GradientDrawable) {
        if (VERSION.SDK_INT < 14) {
            return false;
        }
        return true;
    } else if (drawable instanceof DrawableContainer) {
        ConstantState state = drawable.getConstantState();
        if (!(state instanceof DrawableContainerState)) {
            return true;
        }
        for (Drawable child : ((DrawableContainerState) state).getChildren()) {
            if (!canSafelyMutateDrawable(child)) {
                return false;
            }
        }
        return true;
    } else if (drawable instanceof DrawableWrapper) {
        return canSafelyMutateDrawable(((DrawableWrapper) drawable).getWrappedDrawable());
    } else {
        if (drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) {
            return canSafelyMutateDrawable(((android.support.v7.graphics.drawable.DrawableWrapper) drawable).getWrappedDrawable());
        }
        return true;
    }
}
DrawableUtils.java 文件源码 项目:boohee_v5.6 阅读 30 收藏 0 点赞 0 评论 0
static boolean setContainerConstantState(DrawableContainer drawable, ConstantState constantState) {
    if (VERSION.SDK_INT >= 9) {
        return setContainerConstantStateV9(drawable, constantState);
    }
    return setContainerConstantStateV7(drawable, constantState);
}
CustomToggleButton.java 文件源码 项目:Custom-Toggle-Button 阅读 14 收藏 0 点赞 0 评论 0
public void initialize(Context context, AttributeSet attrs) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            this.setBackground(getResources().getDrawable(R.drawable.toggle_background, null));
        } else {
            this.setBackground(getResources().getDrawable(R.drawable.toggle_background));
        }

        StateListDrawable stateListDrawable = (StateListDrawable) this.getBackground();
        DrawableContainer.DrawableContainerState dcs = (DrawableContainer.DrawableContainerState) stateListDrawable.getConstantState();
        Drawable[] drawableItems = dcs.getChildren();
        GradientDrawable unChecked = (GradientDrawable) drawableItems[0];
        GradientDrawable checked = (GradientDrawable) drawableItems[1];
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomToggleButton);

//        getting all the attributes values set from the typed array i.e from user
        int toggleOnColor = typedArray.getColor(R.styleable.CustomToggleButton_checkedColor, Color.parseColor("#FF4081"));
        int toggleOffColor = typedArray.getColor(R.styleable.CustomToggleButton_uncheckedColor, Color.parseColor("#FF4081"));
        float borderWidth = typedArray.getDimension(R.styleable.CustomToggleButton_borderWidth, 4.0f);
        float radius = typedArray.getDimension(R.styleable.CustomToggleButton_radius, 15.0f);
        int checkedTextColor = typedArray.getColor(R.styleable.CustomToggleButton_checkedTextColor, getResources().getColor(R.color.CheckedTextColor));
        int uncheckedTextColor = typedArray.getColor(R.styleable.CustomToggleButton_uncheckedTextColor, getResources().getColor(R.color.uncheckedTextColor));
        Log.d(TAG, "initialize: " + borderWidth);
        ColorStateList colorStateList = new ColorStateList(
                new int[][]{
                        new int[]{android.R.attr.state_checked},
                        new int[]{-android.R.attr.state_checked}
                },
                new int[]{
                        checkedTextColor,
                        uncheckedTextColor
                }
        );

        this.setTextColor(colorStateList);


        checked.setStroke(Math.round(borderWidth), toggleOnColor);
        checked.setColor(toggleOnColor);
        checked.setCornerRadius(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, getResources().getDisplayMetrics()));

        unChecked.setStroke(Math.round(borderWidth), toggleOffColor);
        unChecked.setCornerRadius(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, getResources().getDisplayMetrics()));


    }
ProgressHorizontal.java 文件源码 项目:CuiMarket 阅读 14 收藏 0 点赞 0 评论 0
@Override
protected void onDraw(Canvas canvas) {
    float factor;
    if (mProgress == 0 || mProgress == 1) {
        factor = 1;
    } else {
        long elapsed = System.currentTimeMillis() - mProgressSetTime;
        if (elapsed < 0) {
            factor = 0;
        } else if (elapsed > mSmoothAnimDuration) {
            factor = 1;
        } else {
            factor = elapsed / (float) mSmoothAnimDuration;
        }
    }
    mSmoothProgress = mStartProgress + factor * (mProgress - mStartProgress);

    // Draw background
    if (null != mDrbBackground) {
        mDrbBackground.draw(canvas);
    }

    // Draw progress
    if (null != mDrbProgress) {
        if (mDrbProgress instanceof NinePatchDrawable
                || (mDrbProgress instanceof DrawableContainer && ((DrawableContainer) mDrbProgress).getCurrent() instanceof NinePatchDrawable)) {
            if (mSmoothProgress == 0) {
                mDrbProgress.setBounds(0, 0, 0, 0);
            } else {
                mDrbProgress.setBounds(0, mRawProgressBounds.top,
                        (int) (mRawProgressBounds.left + (mRawProgressBounds.width() - mProgressDrbMinWidth)
                                * mSmoothProgress)
                                + mProgressDrbMinWidth, mRawProgressBounds.bottom);
            }
        }
        mDrbProgress.draw(canvas);
    }

    // Draw progress text
    if (mProgressTextVisible) {
        mSb.delete(0, mSb.length());
        if (StringUtils.isEmpty(mText)) {
            mSb.append((int) (mSmoothProgress * 100));
            mSb.append('%');
        } else {
            mSb.append(mText);
        }
        String text = mSb.toString();

        mTextPaint.setAntiAlias(true);
        mTextPaint.setColor(mProgressTextColor);
        mTextPaint.setTextSize(mProgressTextSize);
        mTextPaint.setTypeface(mTypeface);
        mTextPaint.setTextAlign(Align.CENTER);
        FontMetrics fm = mTextPaint.getFontMetrics();
        int fontH = (int) (Math.abs(fm.descent - fm.ascent));
        canvas.drawText(text, getWidth() >> 1, ((getHeight() - getPaddingTop() - getPaddingBottom()) >> 1) + (fontH >> 1), mTextPaint);

    }

    if (factor != 1) {
        invalidate();
    }
    notifyProgressChange(mSmoothProgress, mProgress);
}


问题


面经


文章

微信
公众号

扫码关注公众号