当前位置: 首页>>代码示例>>Java>>正文


Java ScaleDrawable类代码示例

本文整理汇总了Java中android.graphics.drawable.ScaleDrawable的典型用法代码示例。如果您正苦于以下问题:Java ScaleDrawable类的具体用法?Java ScaleDrawable怎么用?Java ScaleDrawable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ScaleDrawable类属于android.graphics.drawable包,在下文中一共展示了ScaleDrawable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    findViewById(R.id.tv_transition).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            TransitionDrawable drawable = (TransitionDrawable) v.getBackground();
            drawable.startTransition(3000);
        }
    });

    ScaleDrawable scaleDrawable = (ScaleDrawable) findViewById(R.id.v_scale).getBackground();
    scaleDrawable.setLevel(10);      //lever默认为0,无法显示。level范围为0~10000。level越大,显示的越大

    ClipDrawable clipDrawable = (ClipDrawable) findViewById(R.id.v_clip).getBackground();
    clipDrawable.setLevel(5000);

    View vCustom = findViewById(R.id.v_custom);
    CustomDrawable customDrawable = new CustomDrawable(getResources().getColor(R.color.colorAccent));
    vCustom.setBackground(customDrawable);
}
 
开发者ID:DysaniazzZ,项目名称:ArtOfAndroid,代码行数:24,代码来源:MainActivity.java

示例2: assertEquals

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
public static void assertEquals(ScaleDrawable a,ScaleDrawable b)
{
    assertEqualsDrawableWrapper(a, b);

    assertEquals(a.isStateful(), b.isStateful());

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

    Class classScaleState = TestUtil.resolveClass(ScaleDrawable.class.getName() + "$ScaleState");
    assertEquals((Float) TestUtil.getField(a_state, classScaleState, "mScaleWidth"), (Float) TestUtil.getField(b_state, classScaleState, "mScaleWidth"));
    assertEquals((Float) TestUtil.getField(a_state, classScaleState, "mScaleHeight"), (Float) TestUtil.getField(b_state, classScaleState, "mScaleHeight"));
    assertEquals((Integer) TestUtil.getField(a_state, classScaleState, "mGravity"), (Integer) TestUtil.getField(b_state, classScaleState, "mGravity"));

    // android:drawable
    if (Build.VERSION.SDK_INT < TestUtil.MARSHMALLOW) // 23
    {
        assertEquals((Drawable) TestUtil.getField(a_state, classScaleState, "mDrawable"), (Drawable) TestUtil.getField(b_state, classScaleState, "mDrawable"));
    }
}
 
开发者ID:jmarranz,项目名称:itsnat_droid,代码行数:21,代码来源:Assert.java

示例3: onWindowFocusChanged

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        // test transition
        View v = findViewById(R.id.test_transition);
        TransitionDrawable drawable = (TransitionDrawable) v.getBackground();
        drawable.startTransition(1000);

        // test scale
        View testScale = findViewById(R.id.test_scale);
        ScaleDrawable testScaleDrawable = (ScaleDrawable) testScale.getBackground();
        testScaleDrawable.setLevel(10);

        // test clip
        ImageView testClip = (ImageView) findViewById(R.id.test_clip);
        ClipDrawable testClipDrawable = (ClipDrawable) testClip.getDrawable();
        testClipDrawable.setLevel(8000);
        
        // test custom drawable
        View testCustomDrawable = findViewById(R.id.test_custom_drawable);
        CustomDrawable customDrawable = new CustomDrawable(Color.parseColor("#0ac39e"));
        testCustomDrawable.setBackgroundDrawable(customDrawable);
    }
}
 
开发者ID:singwhatiwanna,项目名称:android-art-res,代码行数:26,代码来源:MainActivity.java

示例4: applyThumbTint

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
/**
 * Applies current thumb tint from {@link Decorator#mTintInfo} to the current thumb drawable.
 * <p>
 * <b>Note</b>, that for post {@link android.os.Build.VERSION_CODES#LOLLIPOP LOLLIPOP} this
 * method does nothing.
 */
@SuppressWarnings("ConstantConditions")
private void applyThumbTint() {
	this.ensureDecorator();
	if (UiConfig.MATERIALIZED || mThumb == null || !mDecorator.hasTintInfo()) {
		return;
	}
	final Drawable thumb = mThumb instanceof ScaleDrawable ? ((ScaleDrawable) mThumb).getDrawable() : mThumb;
	final SeekBarTintInfo tintInfo = mDecorator.getTintInfo();
	if ((!tintInfo.hasTintList && !tintInfo.hasTintMode)) {
		return;
	}
	final boolean isTintDrawable = thumb instanceof TintDrawable;
	final TintDrawable tintDrawable = isTintDrawable ? (TintDrawable) thumb : new TintDrawable(thumb);
	if (tintInfo.hasTintList) {
		tintDrawable.setTintList(tintInfo.tintList);
	}
	if (tintInfo.hasTintMode) {
		tintDrawable.setTintMode(tintInfo.tintMode);
	}
	if (tintDrawable.isStateful()) {
		tintDrawable.setState(getDrawableState());
	}
	if (isTintDrawable) {
		return;
	}
	final int thumbOffset = getThumbOffset();
	this.mThumb = mDecorator.hasPrivateFlag(PFLAG_DISCRETE) ?
			mAnimations.makeThumbScaleable(tintDrawable, Gravity.CENTER) :
			tintDrawable;

	super.setThumb(mThumb);
	tintDrawable.attachCallback();
	setThumbOffset(thumbOffset);
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:41,代码来源:SeekBarWidget.java

示例5: setThumbScale

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
/**
 * Updates a scale level of the thumb's drawable.
 *
 * @param scale The scale value from the range {@code [0.0, 1.0]}.
 */
@SuppressWarnings("Range")
void setThumbScale(float scale) {
	if (view.mThumb instanceof ScaleDrawable) {
		final int scaleLevel = Math.round(scale * MAX_LEVEL);
		view.mThumb.setLevel(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN ?
				scaleLevel :
				// Correct scale level for pre JELLY_BEAN Android versions.
				// scaleLevel(10000) = scale(1.0) [expected scale(1.0)]
				// scaleLevel(5000)  = scale(0.0) [expected scale(0.5)]
				// scaleLevel(0)     = scale(1.0) [expected scale(0.0)]
				scaleLevel + (int) ((10000 - scaleLevel) / 10000f * 5000)
		);
	}
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:20,代码来源:SeekBarWidget.java

示例6: setupDrawables

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
private void setupDrawables() {
    parts = new ArrayList<>();
    parts.add(ContextCompat.getDrawable(getContext(), R.drawable.carriage_part1));
    parts.add(ContextCompat.getDrawable(getContext(), R.drawable.carriage_part2));
    parts.add(ContextCompat.getDrawable(getContext(), R.drawable.carriage_part3));

    carriageOffset = (int) getContext().getResources().getDimension(R.dimen.carriage_offset);
    pageOffset = (int) getContext().getResources().getDimension(R.dimen.page_offset);
    offset = (int) getContext().getResources().getDimension(R.dimen.offset);

    button = ContextCompat.getDrawable(getContext(), R.drawable.button);
    buttonPressed = ContextCompat.getDrawable(getContext(), R.drawable.button_pressed);

    page = new ScaleDrawable(ContextCompat.getDrawable(getContext(), R.drawable.page),
            TOP, -1, 1);
    page.setLevel(10000);
    pageBack =
            new ScaleDrawable(ContextCompat.getDrawable(getContext(), R.drawable.page_revers),
                    TOP, -1, 1);
    pageBack.setLevel(0);

    keyboard = ContextCompat.getDrawable(getContext(), R.drawable.keyboard_bg);
    typewriter = ContextCompat.getDrawable(getContext(), R.drawable.machine);
    space = ContextCompat.getDrawable(getContext(), R.drawable.space);
    spacePressed = ContextCompat.getDrawable(getContext(), R.drawable.space_pressed);
    letter = ContextCompat.getDrawable(getContext(), R.drawable.letter);
}
 
开发者ID:Ilya-Gh,项目名称:Typewriter,代码行数:28,代码来源:TypewriterRefreshDrawable.java

示例7: canSafelyMutateDrawable

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
/**
 * Some drawable implementations have problems with mutation. This method returns false if
 * there is a known issue in the given drawable's implementation.
 */
public static boolean canSafelyMutateDrawable(@NonNull Drawable drawable) {
    if (Build.VERSION.SDK_INT < 15 && drawable instanceof InsetDrawable) {
        return false;
    }  else if (Build.VERSION.SDK_INT < 15 && drawable instanceof GradientDrawable) {
        // GradientDrawable has a bug pre-ICS which results in mutate() resulting
        // in loss of color
        return false;
    } else if (Build.VERSION.SDK_INT < 17 && drawable instanceof LayerDrawable) {
        return false;
    }

    if (drawable instanceof DrawableContainer) {
        // If we have a DrawableContainer, let's traverse its child array
        final Drawable.ConstantState state = drawable.getConstantState();
        if (state instanceof DrawableContainer.DrawableContainerState) {
            final DrawableContainer.DrawableContainerState containerState =
                    (DrawableContainer.DrawableContainerState) state;
            for (final Drawable child : containerState.getChildren()) {
                if (!canSafelyMutateDrawable(child)) {
                    return false;
                }
            }
        }
    } else if (drawable instanceof android.support.v4.graphics.drawable.DrawableWrapper) {
        return canSafelyMutateDrawable(
                ((android.support.v4.graphics.drawable.DrawableWrapper) drawable)
                        .getWrappedDrawable());
    } /*else if (drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) {
        return canSafelyMutateDrawable(
                ((android.support.v7.graphics.drawable.DrawableWrapper) drawable)
                        .getWrappedDrawable());
    }*/ else if (drawable instanceof ScaleDrawable) {
        return canSafelyMutateDrawable(((ScaleDrawable) drawable).getDrawable());
    }

    return true;
}
 
开发者ID:commonsguy,项目名称:cwac-crossport,代码行数:42,代码来源:DrawableUtils.java

示例8: setEventsIcon

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
public void setEventsIcon(@DrawableRes int drawableRes) {
    Drawable drawable = ContextCompat.getDrawable(getContext(), drawableRes);
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    drawable.setBounds(0, 0, width / 2, height / 2);
    ScaleDrawable sd = new ScaleDrawable(drawable, Gravity.CENTER, 0.6f, 0.6f);
    sd.setLevel(8000);
    ViewHelper.tintDrawable(drawable, ViewHelper.getTertiaryTextColor(getContext()));
    setCompoundDrawablesWithIntrinsicBounds(sd, null, null, null);
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:11,代码来源:FontTextView.java

示例9: setSeekBarBg

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
private void setSeekBarBg(){
    try {
        int progressColor = CustomAttrValueUtil.getAttrColorValue(R.attr.colorPrimary,R.color.colorAccent,this);
        LayerDrawable layerDrawable = (LayerDrawable) seekBar.getProgressDrawable();
        ScaleDrawable scaleDrawable = (ScaleDrawable)layerDrawable.findDrawableByLayerId(android.R.id.progress);
        GradientDrawable drawable = (GradientDrawable) scaleDrawable.getDrawable();
        drawable.setColor(progressColor);
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:lijunyandev,项目名称:MeetMusic,代码行数:12,代码来源:PlayActivity.java

示例10: canSafelyMutateDrawable

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
/**
 * Some drawable implementations have problems with mutation. This method returns false if
 * there is a known issue in the given drawable's implementation.
 */
public static boolean canSafelyMutateDrawable(@NonNull Drawable drawable) {
    if (Build.VERSION.SDK_INT < 15 && drawable instanceof InsetDrawable) {
        return false;
    }  else if (Build.VERSION.SDK_INT < 15 && drawable instanceof GradientDrawable) {
        // GradientDrawable has a bug pre-ICS which results in mutate() resulting
        // in loss of color
        return false;
    } else if (Build.VERSION.SDK_INT < 17 && drawable instanceof LayerDrawable) {
        return false;
    }

    if (drawable instanceof DrawableContainer) {
        // If we have a DrawableContainer, let's traverse it's child array
        final Drawable.ConstantState state = drawable.getConstantState();
        if (state instanceof DrawableContainer.DrawableContainerState) {
            final DrawableContainer.DrawableContainerState containerState =
                    (DrawableContainer.DrawableContainerState) state;
            for (final Drawable child : containerState.getChildren()) {
                if (!canSafelyMutateDrawable(child)) {
                    return false;
                }
            }
        }
    } else if (drawable instanceof android.support.v4.graphics.drawable.DrawableWrapper) {
        return canSafelyMutateDrawable(
                ((android.support.v4.graphics.drawable.DrawableWrapper) drawable)
                        .getWrappedDrawable());
    } else if (drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) {
        return canSafelyMutateDrawable(
                ((android.support.v7.graphics.drawable.DrawableWrapper) drawable)
                        .getWrappedDrawable());
    } else if (drawable instanceof ScaleDrawable) {
        return canSafelyMutateDrawable(((ScaleDrawable) drawable).getDrawable());
    }

    return true;
}
 
开发者ID:ximsfei,项目名称:Android-skin-support,代码行数:42,代码来源:SkinCompatDrawableUtils.java

示例11: m2634b

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
public static boolean m2634b(Drawable drawable) {
    if (drawable instanceof LayerDrawable) {
        return VERSION.SDK_INT >= 16;
    } else if (drawable instanceof InsetDrawable) {
        return VERSION.SDK_INT >= 14;
    } else {
        if (drawable instanceof StateListDrawable) {
            return VERSION.SDK_INT >= 8;
        } else {
            if (drawable instanceof GradientDrawable) {
                return VERSION.SDK_INT >= 14;
            } else {
                if (!(drawable instanceof DrawableContainer)) {
                    return drawable instanceof C0063q ? m2634b(((C0063q) drawable).m469a()) : drawable instanceof C0244a ? m2634b(((C0244a) drawable).m1984a()) : drawable instanceof ScaleDrawable ? m2634b(((ScaleDrawable) drawable).getDrawable()) : true;
                } else {
                    ConstantState constantState = drawable.getConstantState();
                    if (!(constantState instanceof DrawableContainerState)) {
                        return true;
                    }
                    for (Drawable b : ((DrawableContainerState) constantState).getChildren()) {
                        if (!m2634b(b)) {
                            return false;
                        }
                    }
                    return true;
                }
            }
        }
    }
}
 
开发者ID:Qwaz,项目名称:solved-hacking-problem,代码行数:31,代码来源:bt.java

示例12: setupProgressColor

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
/***
 * Method called from APIs below 21 to setup Progress Color
 */
private void setupProgressColor() {
    //load up the drawable and apply color
    LayerDrawable ld = (LayerDrawable) getProgressDrawable();
    ScaleDrawable shape = (ScaleDrawable) (ld.findDrawableByLayerId(android.R.id.progress));
    shape.setColorFilter(mProgressColor, PorterDuff.Mode.SRC_IN);

    //set the background to transparent
    NinePatchDrawable ninePatchDrawable = (NinePatchDrawable) (ld.findDrawableByLayerId(android.R.id.background));
    ninePatchDrawable.setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN);
}
 
开发者ID:goodev,项目名称:droidddle,代码行数:14,代码来源:SeekBarCompat.java

示例13: setEnabled

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
@Override
public void setEnabled(final boolean enabled) {
    mIsEnabled = enabled;
    triggerMethodOnceViewIsDisplayed(this, new Callable<Void>() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public Void call() throws Exception {
            if (!lollipopAndAbove()) {
                gradientDrawable = new GradientDrawable();
                gradientDrawable.setShape(GradientDrawable.OVAL);
                gradientDrawable.setSize(mOriginalThumbHeight / 3, mOriginalThumbHeight / 3);
                gradientDrawable.setColor(mIsEnabled ? mThumbColor : Color.LTGRAY);
                gradientDrawable.setDither(true);
                gradientDrawable.setAlpha(mThumbAlpha);
                setThumb(gradientDrawable);
                //load up the drawable and apply color
                LayerDrawable ld = (LayerDrawable) getProgressDrawable();
                ScaleDrawable shape = (ScaleDrawable) (ld.findDrawableByLayerId(android.R.id.progress));
                shape.setColorFilter(mIsEnabled ? mProgressColor : Color.LTGRAY, PorterDuff.Mode.SRC_IN);
                //set the background to transparent
                NinePatchDrawable ninePatchDrawable = (NinePatchDrawable) (ld.findDrawableByLayerId(android.R.id.background));
                ninePatchDrawable.setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN);
                //background
                //load up the drawable and apply color
                SeekBarBackgroundDrawable seekBarBackgroundDrawable = new SeekBarBackgroundDrawable(getContext(),
                        mIsEnabled ? mProgressBackgroundColor : Color.LTGRAY, mActualBackgroundColor, getPaddingLeft(), getPaddingRight());
                if (belowJellybean())
                    setBackgroundDrawable(seekBarBackgroundDrawable);
                else
                    setBackground(seekBarBackgroundDrawable);
            }
            SeekBarCompat.super.setEnabled(enabled);
            return null;
        }
    });

}
 
开发者ID:goodev,项目名称:droidddle,代码行数:38,代码来源:SeekBarCompat.java

示例14: setupProgressColor

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
/***
 * Method called from APIs below 21 to setup Progress Color
 */
private void setupProgressColor() {
    try {
        //load up the drawable and apply color
        LayerDrawable ld = (LayerDrawable) getProgressDrawable();
        ScaleDrawable shape = (ScaleDrawable) (ld.findDrawableByLayerId(android.R.id.progress));
        shape.setColorFilter(mProgressColor, PorterDuff.Mode.SRC_IN);

        //set the background to transparent
        NinePatchDrawable ninePatchDrawable = (NinePatchDrawable) (ld.findDrawableByLayerId(android.R.id.background));
        ninePatchDrawable.setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN);
    } catch (NullPointerException e) {
        //TODO: Handle exception
    }
}
 
开发者ID:Minitour,项目名称:crofis-android-uikit,代码行数:18,代码来源:SeekBarCompat.java

示例15: setEnabled

import android.graphics.drawable.ScaleDrawable; //导入依赖的package包/类
/***
 * Enables or disables the whole seekBar!
 *
 * @param enabled
 */
@Override
public void setEnabled(final boolean enabled) {
    mIsEnabled = enabled;
    triggerMethodOnceViewIsDisplayed(this, new Callable<Void>() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public Void call() throws Exception {
            if (!lollipopAndAbove()) {
                gradientDrawable = new GradientDrawable();
                gradientDrawable.setShape(GradientDrawable.OVAL);
                gradientDrawable.setSize(mOriginalThumbHeight / 3, mOriginalThumbHeight / 3);
                gradientDrawable.setColor(mIsEnabled ? mThumbColor : Color.LTGRAY);
                gradientDrawable.setDither(true);
                gradientDrawable.setAlpha(mThumbAlpha);
                setThumb(gradientDrawable);
                //load up the drawable and apply color
                LayerDrawable ld = (LayerDrawable) getProgressDrawable();
                ScaleDrawable shape = (ScaleDrawable) (ld.findDrawableByLayerId(android.R.id.progress));
                shape.setColorFilter(mIsEnabled ? mProgressColor : Color.LTGRAY, PorterDuff.Mode.SRC_IN);
                //set the background to transparent
                NinePatchDrawable ninePatchDrawable = (NinePatchDrawable) (ld.findDrawableByLayerId(android.R.id.background));
                ninePatchDrawable.setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN);
                //background
                //load up the drawable and apply color
                SeekBarBackgroundDrawable seekBarBackgroundDrawable = new SeekBarBackgroundDrawable(getContext(),
                        mIsEnabled ? mProgressBackgroundColor : Color.LTGRAY, mActualBackgroundColor, getPaddingLeft(), getPaddingRight());
                if (belowJellybean())
                    setBackgroundDrawable(seekBarBackgroundDrawable);
                else
                    setBackground(seekBarBackgroundDrawable);
            }
            SeekBarCompat.super.setEnabled(enabled);
            return null;
        }
    });

}
 
开发者ID:Minitour,项目名称:crofis-android-uikit,代码行数:43,代码来源:SeekBarCompat.java


注:本文中的android.graphics.drawable.ScaleDrawable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。