Java 类android.graphics.drawable.RotateDrawable 实例源码

项目:BlackList    文件:Utils.java   
/**
 * Sets the background color of the drawable
 **/
public static void setDrawableColor(Context context, Drawable drawable, @AttrRes int colorAttrRes) {
    int colorRes = getResourceId(context, colorAttrRes);
    int color = ContextCompat.getColor(context, colorRes);
    if (drawable instanceof ShapeDrawable) {
        ((ShapeDrawable) drawable).getPaint().setColor(color);
    } else if (drawable instanceof GradientDrawable) {
        ((GradientDrawable) drawable).setColor(color);
    } else if (drawable instanceof ColorDrawable) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            ((ColorDrawable) drawable).setColor(color);
        }
    } else if (drawable instanceof RotateDrawable) {
        setDrawableColor(context, ((RotateDrawable) drawable).getDrawable(), colorAttrRes);
    }
}
项目:InstaTag    文件:InstaTag.java   
private void setColor(Drawable drawable, int color) {
    if (drawable instanceof ShapeDrawable) {
        ((ShapeDrawable) drawable).getPaint().setColor(color);
    } else if (drawable instanceof GradientDrawable) {
        ((GradientDrawable) drawable).setColor(color);
    } else if (drawable instanceof ColorDrawable) {
        ((ColorDrawable) drawable).setColor(color);
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        RotateDrawable rotateDrawable =
                (RotateDrawable) layerDrawable.findDrawableByLayerId(R.id.carrot_shape_top);
        setColor(rotateDrawable.getDrawable(), color);
    } else if (drawable instanceof RotateDrawable) {
        setColor(((RotateDrawable) drawable).getDrawable(), color);
    }
}
项目:itsnat_droid    文件:ClassDescRotateDrawable.java   
public ClassDescRotateDrawable(ClassDescDrawableMgr classMgr,ClassDescElementDrawableBased<? super RotateDrawable> parent)
{
    super(classMgr,"rotate",parent);

    this.rotateStateField = new FieldContainer<Drawable.ConstantState>(RotateDrawable.class, "mState");
    Class rotateStateClass = MiscUtil.resolveClass(RotateDrawable.class.getName() + "$RotateState");

    if (Build.VERSION.SDK_INT >= MiscUtil.MARSHMALLOW) // level 23, v6.0
        this.mDrawableField = new FieldContainer<Drawable>("android.graphics.drawable.DrawableWrapper", "mDrawable");
    else
        this.mDrawableField = new FieldContainer<Drawable>(rotateStateClass, "mDrawable");

    this.mPivotXRelField = new FieldContainer<Boolean>(rotateStateClass, "mPivotXRel");
    this.mPivotXField = new FieldContainer<Float>(rotateStateClass, "mPivotX");
    this.mPivotYRelField = new FieldContainer<Boolean>(rotateStateClass, "mPivotYRel");
    this.mPivotYField = new FieldContainer<Float>(rotateStateClass, "mPivotY");
    this.mFromDegreesField = new FieldContainer<Float>(rotateStateClass, "mFromDegrees");
    this.mCurrentDegreesField = new FieldContainer<Float>(rotateStateClass, "mCurrentDegrees");
    this.mToDegreesField = new FieldContainer<Float>(rotateStateClass, "mToDegrees");
}
项目:FirebaseUI-Android    文件:ChatHolder.java   
private void setIsSender(boolean isSender) {
    final int color;
    if (isSender) {
        color = mGreen300;
        mLeftArrow.setVisibility(View.GONE);
        mRightArrow.setVisibility(View.VISIBLE);
        mMessageContainer.setGravity(Gravity.END);
    } else {
        color = mGray300;
        mLeftArrow.setVisibility(View.VISIBLE);
        mRightArrow.setVisibility(View.GONE);
        mMessageContainer.setGravity(Gravity.START);
    }

    ((GradientDrawable) mMessage.getBackground()).setColor(color);
    ((RotateDrawable) mLeftArrow.getBackground()).getDrawable()
            .setColorFilter(color, PorterDuff.Mode.SRC);
    ((RotateDrawable) mRightArrow.getBackground()).getDrawable()
            .setColorFilter(color, PorterDuff.Mode.SRC);
}
项目:InstaBadge    文件:InstaBadgeView.java   
private void setupBadgeBackgroundColors(String BADGE_COLOR) {

        GradientDrawable gd = (GradientDrawable) outer_container.getBackground();
        gd.setColor(Color.parseColor(BADGE_COLOR));

        LayerDrawable layers = (LayerDrawable) bottom_arrow.getBackground();
        RotateDrawable rotate = (RotateDrawable) layers.findDrawableByLayerId(R.id.grad);
        GradientDrawable drawable = (GradientDrawable) rotate.getDrawable();
        drawable.setColor(Color.parseColor(BADGE_COLOR));

    }
项目:itsnat_droid    文件:ClassDescRotateDrawable.java   
@Override
public boolean isAttributeIgnored(RotateDrawable resource, String namespaceURI, String name)
{
    if (super.isAttributeIgnored(resource,namespaceURI,name))
        return true;

    if (NamespaceUtil.XMLNS_ANDROID.equals(namespaceURI))
    {
        // Se usan en tiempo de construcción
        return ("drawable".equals(name) || "pivotX".equals(name) || "pivotY".equals(name) || "fromDegrees".equals(name) || "toDegrees".equals(name));
    }
    return false;
}
项目:itsnat_droid    文件:Assert.java   
public static void assertEquals(RotateDrawable a,RotateDrawable b)
{
    assertEqualsDrawableWrapper(a, b);

    //assertEquals(a.getDrawable(), b.getDrawable());

    Class classState = TestUtil.resolveClass(RotateDrawable.class.getName() + "$RotateState");

    Drawable.ConstantState a_state;
    Drawable.ConstantState b_state;

    if (Build.VERSION.SDK_INT < TestUtil.MARSHMALLOW) // 23
    {
        a_state = a.getConstantState();
        b_state = b.getConstantState();
    }
    else // >= 23
    {
        a_state = (Drawable.ConstantState)TestUtil.getField(a, RotateDrawable.class, "mState");
        b_state = (Drawable.ConstantState)TestUtil.getField(b, RotateDrawable.class, "mState"); // Devuelve null no se porqué con b.getConstantState()
    }


    assertEquals((Boolean) TestUtil.getField(a_state, classState, "mPivotXRel"), (Boolean) TestUtil.getField(b_state, classState, "mPivotXRel"));
    assertEquals((Float) TestUtil.getField(a_state, classState, "mPivotX"), (Float) TestUtil.getField(b_state, classState, "mPivotX"));
    assertEquals((Boolean) TestUtil.getField(a_state, classState, "mPivotYRel"), (Boolean) TestUtil.getField(b_state, classState, "mPivotYRel"));
    assertEquals((Float) TestUtil.getField(a_state, classState, "mPivotY"), (Float) TestUtil.getField(b_state, classState, "mPivotY"));
    assertEquals((Float) TestUtil.getField(a_state, classState, "mFromDegrees"), (Float) TestUtil.getField(b_state, classState, "mFromDegrees"));
    assertEquals((Float) TestUtil.getField(a_state, classState, "mToDegrees"), (Float) TestUtil.getField(b_state, classState, "mToDegrees"));

    // android:drawable
    if (Build.VERSION.SDK_INT < TestUtil.MARSHMALLOW) // 23
    {
        assertEquals((Drawable) TestUtil.getField(a_state, classState, "mDrawable"), (Drawable) TestUtil.getField(b_state, classState, "mDrawable"));
    }
}
项目:AshaNetApp    文件:RespondFragment.java   
void connectWidgets(View v) {
    dgRespondBg = (GradientDrawable)
        ((RotateDrawable)
         ((LayerDrawable) v.getBackground())
         .findDrawableByLayerId(R.id.drRespondBg))
        .getDrawable();
    btnContinue = (Button) v.findViewById(R.id.btnContinue);
    if (isDonate)
        connectDonateWidgets(v);
    else
        connectRsvpWidgets(v);
}
项目:AshaNetApp    文件:StreamActivity.java   
void connectWidgets() {
    lvStream = (ListView) findViewById(R.id.lvStream);
    tvTitle = (TextView) findViewById(R.id.tvTitle);
    tvWhen = (TextView) findViewById(R.id.tvWhen);
    ivBottomGradient = (ImageView) findViewById(R.id.ivBottomGradient);
    tvSubtitle = (TextView) findViewById(R.id.tvSubtitle);
    tvDescription = (TextView) findViewById(R.id.tvDescription);
    flRespond = (FrameLayout) findViewById(R.id.flRespond);

    ivRespondSlotBg = (ImageView) findViewById(R.id.ivRespondSlotBg);
    ivRespondSlotBg.setOnClickListener(this);
    LayerDrawable ldRespondSlotBg = (LayerDrawable)
        ivRespondSlotBg.getDrawable();
    Log.d("DEBUG", "ldrsb = " + ldRespondSlotBg);
    dgRespondSlotBg = (GradientDrawable)
        ((RotateDrawable)
         ldRespondSlotBg.findDrawableByLayerId(R.id.drRespondSlotBg))
        .getDrawable();
    dgRespondSlot = (GradientDrawable)
        ((RotateDrawable)
         ldRespondSlotBg.findDrawableByLayerId(R.id.drRespondSlot))
        .getDrawable();

    dgStream = (GradientDrawable) ivBottomGradient.getDrawable();

    tvRespondIcon = (TextView) findViewById(R.id.tvRespondIcon);
    tvRespondIcon.setOnClickListener(this);
    ivRespondSlotFg = (ImageView) findViewById(R.id.ivRespondSlotFg);
    dgRespondSlotFg = (GradientDrawable)
        ((RotateDrawable)
         ((LayerDrawable) ivRespondSlotFg.getDrawable())
         .findDrawableByLayerId(R.id.drRespondSlotFg))
        .getDrawable();

    Log.d("DEBUG", "Drawables: " + 
          "dgRespondSlot=" + dgRespondSlot
          + ", dgRespondSlotFg=" + dgRespondSlotFg
          + ", dgRespondSlotBg=" + dgRespondSlotBg
          + ", dgStream=" + dgStream);
}
项目:Orpheus    文件:PlayingIndicator.java   
public PlayingIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);
    setImageResource(R.drawable.now_playing_animated);
    mRotateDrawable = (RotateDrawable) getDrawable();
    if (!VersionUtils.hasLollipop()) {
        mRotateDrawable.setColorFilter(ThemeUtils.getColorAccent(getContext()), PorterDuff.Mode.SRC_IN);
    }
}
项目:Orpheus    文件:PlayingIndicator.java   
public PlayingIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);
    setImageResource(R.drawable.now_playing_indicator);
    mRotateDrawable = (RotateDrawable) getDrawable();
    if (!VersionUtils.hasLollipop()) {
        mRotateDrawable.setColorFilter(ThemeUtils.getColorAccent(getContext()), PorterDuff.Mode.SRC_IN);
    }
}
项目:ColorProgressBar    文件:ColorProgressBar.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
protected void applySingleMode(TypedArray array){

    RotateDrawable d = (RotateDrawable) getResources().getDrawable(R.drawable.spinner_single);
    GradientDrawable gradient = (GradientDrawable) d.getDrawable();

    int startColor = array.getColor(R.styleable.ColorProgressBar_startColor, -1);
    int middleColor = array.getColor(R.styleable.ColorProgressBar_middleColor, -1);
    int endColor = array.getColor(R.styleable.ColorProgressBar_endColor, -1);


    if (startColor == -1){
        throw new IllegalArgumentException("You have not specified a start color");
    }

    if (endColor == -1){
        endColor = getResources().getColor(R.color.spinner_single_default_end);
    }

    if (middleColor == -1){
        middleColor = getResources().getColor(R.color.spinner_single_default_middle);
    }

   gradient.setColors(new int[]{startColor, endColor, middleColor});
    setIndeterminateDrawable(d);

}
项目:Shortcuts    文件:SettingGUI.java   
@Override
public void onResume(){
    super.onResume();

    getPreferenceScreen().getSharedPreferences()
       .registerOnSharedPreferenceChangeListener(this);

    LayerDrawable drawPref = (LayerDrawable)getResources().getDrawable(R.drawable.draw_pref);
    GradientDrawable backPref = (GradientDrawable) drawPref.findDrawableByLayerId(R.id.backtemp);

    LayerDrawable drawWifi = (LayerDrawable)getResources().getDrawable(R.drawable.draw_wifi);
    GradientDrawable backWifi = (GradientDrawable) drawWifi.findDrawableByLayerId(R.id.backtemp);

    LayerDrawable drawBluetooth = (LayerDrawable)getResources().getDrawable(R.drawable.draw_bluetooth);
    GradientDrawable backBluetooth = (GradientDrawable) drawBluetooth.findDrawableByLayerId(R.id.backtemp);

    LayerDrawable drawGPS = (LayerDrawable)getResources().getDrawable(R.drawable.draw_gps);
    GradientDrawable backGPS = (GradientDrawable) drawGPS.findDrawableByLayerId(R.id.backtemp);

    LayerDrawable drawTime = (LayerDrawable)getResources().getDrawable(R.drawable.draw_time);
    GradientDrawable backTime = (GradientDrawable) drawTime.findDrawableByLayerId(R.id.backtemp);

    LayerDrawable drawGeekyLauncher = (LayerDrawable)getResources().getDrawable(R.drawable.draw_geekylauncher);
    RotateDrawable backGL = (RotateDrawable) drawGeekyLauncher.findDrawableByLayerId(R.id.backtemp);

    LayerDrawable drawPro = (LayerDrawable)getResources().getDrawable(R.drawable.draw_pref_pro);
    GradientDrawable backPro = (GradientDrawable) drawPro.findDrawableByLayerId(R.id.backtemp);
    GradientDrawable backPro2 = (GradientDrawable) drawPro.findDrawableByLayerId(R.id.backtemp2);

    backPref.setColor(themeColor);
    backWifi.setColor(themeColor);
    backBluetooth.setColor(themeColor);
    backGPS.setColor(themeColor);
    backTime.setColor(themeColor);
    backPro.setColor(themeColor);   backPro2.setColor(themeColor);
    backGL.setDrawable(new ColorDrawable(themeColor));

    stable.setIcon(drawPref);
    widget.setIcon(drawPref);
    autoremove.setIcon(drawPref);
    autorecovs.setIcon(drawPref);
    autotrans.setIcon(drawPref);
    style.setIcon(drawPref);
    colortext.setIcon(drawPref);
    sizes.setIcon(drawPref);
    overview.setIcon(drawPref);
    prefwifi.setIcon(drawWifi);
    prefbluetooth.setIcon(drawBluetooth);
    prefgps.setIcon(drawGPS);
    preftime.setIcon(drawTime);
    launcher.setIcon(drawGeekyLauncher);
    ad.setIcon(drawPro);
}
项目:itsnat_droid    文件:ClassDescRotateDrawable.java   
@Override
public ElementDrawableChildRoot createElementDrawableChildRoot(DOMElemDrawable rootElem, AttrDrawableContext attrCtx)
{
    ElementDrawableChildRoot elementDrawableRoot = new ElementDrawableChildRoot();

    RotateDrawable drawable = new RotateDrawable();

    XMLInflaterContext xmlInflaterContext = attrCtx.getXMLInflaterContext();
    XMLInflaterDrawable xmlInflaterDrawable = attrCtx.getXMLInflaterDrawable();

    xmlInflaterDrawable.processChildElements(rootElem, elementDrawableRoot,attrCtx);
    ArrayList<ElementDrawableChildBase> childList = elementDrawableRoot.getElementDrawableChildList();

    XMLInflaterRegistry xmlInflaterRegistry = classMgr.getXMLInflaterRegistry();
    Drawable.ConstantState rotateState = rotateStateField.get(drawable);

    Drawable childDrawable = getDrawableChild("drawable", rootElem, xmlInflaterContext, childList);
    if (Build.VERSION.SDK_INT >= MiscUtil.MARSHMALLOW) // level 23, v6.0
        mDrawableField.set(drawable,childDrawable);
    else
        mDrawableField.set(rotateState,childDrawable);

    DOMAttr pivotXAttr = rootElem.getDOMAttribute(NamespaceUtil.XMLNS_ANDROID, "pivotX");
    PercFloatImpl pivotXObj = pivotXAttr != null ? xmlInflaterRegistry.getDimensionPercFloat(pivotXAttr.getResourceDesc(),xmlInflaterContext) : null;
    boolean pivotXRel;
    float pivotX;
    if (pivotXObj == null)
    {
        pivotXRel = true;
        pivotX = 0.5f;
    }
    else
    {
        pivotXRel = pivotXObj.getDataType() == TypedValue.TYPE_FRACTION;
        pivotX = pivotXObj.toFloatBasedOnDataType();
    }
    mPivotXRelField.set(rotateState,pivotXRel);
    mPivotXField.set(rotateState,pivotX);

    DOMAttr pivotYAttr = rootElem.getDOMAttribute(NamespaceUtil.XMLNS_ANDROID, "pivotY");
    PercFloatImpl pivotYObj = pivotYAttr != null ? xmlInflaterRegistry.getDimensionPercFloat(pivotYAttr.getResourceDesc(),xmlInflaterContext) : null;
    boolean pivotYRel;
    float pivotY;
    if (pivotYObj == null)
    {
        pivotYRel = true;
        pivotY = 0.5f;
    }
    else
    {
        pivotYRel = pivotYObj.getDataType() == TypedValue.TYPE_FRACTION;
        pivotY = pivotYObj.toFloatBasedOnDataType();
    }
    mPivotYRelField.set(rotateState,pivotYRel);
    mPivotYField.set(rotateState,pivotY);


    DOMAttr fromDegreesAttr = rootElem.getDOMAttribute(NamespaceUtil.XMLNS_ANDROID, "fromDegrees");
    float fromDegrees = fromDegreesAttr != null ? xmlInflaterRegistry.getFloat(fromDegreesAttr.getResourceDesc(),xmlInflaterContext) : 0.0f;
    mFromDegreesField.set(rotateState,fromDegrees);
    mCurrentDegreesField.set(rotateState,fromDegrees);

    DOMAttr toDegreesAttr = rootElem.getDOMAttribute(NamespaceUtil.XMLNS_ANDROID, "toDegrees");
    float toDegrees = toDegreesAttr != null ? xmlInflaterRegistry.getFloat(toDegreesAttr.getResourceDesc(),xmlInflaterContext) : 360.0f;
    mToDegreesField.set(rotateState,toDegrees);

    setCallback(childDrawable,drawable); // childDrawable no puede ser nulo

    elementDrawableRoot.setDrawable(drawable);

    return elementDrawableRoot;
}
项目:itsnat_droid    文件:ClassDescRotateDrawable.java   
@Override
public Class<RotateDrawable> getDrawableOrElementDrawableClass()
{
    return RotateDrawable.class;
}
项目:itsnat_droid    文件:Assert.java   
public static void assertEquals(Drawable a,Drawable b)
{
    if (!a.getClass().equals(b.getClass())) throw new ItsNatDroidException("Not equal: \"" + a + "\" - \"" + b + "\"");

    if (a instanceof AnimationDrawable)
    {
        assertEquals((AnimationDrawable) a, (AnimationDrawable) b);
    }
    else if (a instanceof BitmapDrawable)
    {
        assertEquals((BitmapDrawable)a,(BitmapDrawable)b);
    }
    else if (a instanceof ClipDrawable)
    {
        assertEquals((ClipDrawable)a,(ClipDrawable)b);
    }
    else if (a instanceof ColorDrawable)
    {
        assertEquals(((ColorDrawable) a).getColor(), ((ColorDrawable) b).getColor());
    }
    else if (a instanceof GradientDrawable)
    {
        assertEquals((GradientDrawable)a,(GradientDrawable)b);
    }
    else if (a instanceof InsetDrawable)
    {
        assertEquals((InsetDrawable)a,(InsetDrawable)b);
    }
    else if (a instanceof LayerDrawable)
    {
        assertEquals((LayerDrawable)a,(LayerDrawable)b);
    }
    else if (a instanceof LevelListDrawable)
    {
        assertEquals((LevelListDrawable)a,(LevelListDrawable)b);
    }
    else if (a instanceof NinePatchDrawable)
    {
        assertEquals((NinePatchDrawable)a,(NinePatchDrawable)b);
    }
    else if (a instanceof RotateDrawable)
    {
        assertEquals((RotateDrawable)a,(RotateDrawable)b);
    }
    else if (a instanceof ScaleDrawable)
    {
        assertEquals((ScaleDrawable)a,(ScaleDrawable)b);
    }
    else if (a instanceof StateListDrawable)
    {
        assertEquals((StateListDrawable)a,(StateListDrawable)b);
    }
    else if (a instanceof TransitionDrawable)
    {
        assertEquals((TransitionDrawable)a,(TransitionDrawable)b);
    }
    else
        throw new ItsNatDroidException("Cannot test drawable " + a);
}
项目:vdb-android    文件:TagArrowUtils.java   
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static Drawable createTag(String color) {

        ShapeDrawable shapeDrawableM = new ShapeDrawable(new RectShape());
//        shapeDrawableM.getShape().resize(100, 100);
        shapeDrawableM.setBounds(0, 0, 100, 20);
        shapeDrawableM.getPaint().setColor(Color.parseColor(color));

//        <size android:width="100dp" android:height="20dp"/>
//        <corners android:radius="0dp"/>


        RotateDrawable rotateDrawable = new RotateDrawable();
        ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape());
        shapeDrawable.getPaint().setColor(Color.parseColor("#ffffff"));

        rotateDrawable.setFromDegrees(45.0f);
        rotateDrawable.setDrawable(shapeDrawable);


        RotateDrawable rotateDrawable1 = new RotateDrawable();
        ShapeDrawable shapeDrawable1 = new ShapeDrawable(new RectShape());
        shapeDrawable1.getPaint().setColor(Color.parseColor("#ffffff"));


        rotateDrawable1.setFromDegrees(-45.0f);
        rotateDrawable1.setDrawable(shapeDrawable1);

        Drawable[] layers = {shapeDrawableM, rotateDrawable, rotateDrawable1};
        LayerDrawable layerDrawable = new LayerDrawable(layers);


        layerDrawable.setLayerInset(1, 0, -40, -20, 38);
        layerDrawable.setLayerInset(2, 0, 40, -20, -50);


        return layerDrawable;

    }