Search in sources :

Example 71 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project RecyclerBanner by renjianan.

the class RecyclerViewBannerBase method initView.

protected void initView(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerViewBannerBase);
    showIndicator = a.getBoolean(R.styleable.RecyclerViewBannerBase_showIndicator, true);
    autoPlayDuration = a.getInt(R.styleable.RecyclerViewBannerBase_interval, 4000);
    isAutoPlaying = a.getBoolean(R.styleable.RecyclerViewBannerBase_autoPlaying, true);
    mSelectedDrawable = a.getDrawable(R.styleable.RecyclerViewBannerBase_indicatorSelectedSrc);
    mUnselectedDrawable = a.getDrawable(R.styleable.RecyclerViewBannerBase_indicatorUnselectedSrc);
    if (mSelectedDrawable == null) {
        // 绘制默认选中状态图形
        GradientDrawable selectedGradientDrawable = new GradientDrawable();
        selectedGradientDrawable.setShape(GradientDrawable.OVAL);
        selectedGradientDrawable.setColor(Color.RED);
        selectedGradientDrawable.setSize(dp2px(5), dp2px(5));
        selectedGradientDrawable.setCornerRadius(dp2px(5) / 2);
        mSelectedDrawable = new LayerDrawable(new Drawable[] { selectedGradientDrawable });
    }
    if (mUnselectedDrawable == null) {
        // 绘制默认未选中状态图形
        GradientDrawable unSelectedGradientDrawable = new GradientDrawable();
        unSelectedGradientDrawable.setShape(GradientDrawable.OVAL);
        unSelectedGradientDrawable.setColor(Color.GRAY);
        unSelectedGradientDrawable.setSize(dp2px(5), dp2px(5));
        unSelectedGradientDrawable.setCornerRadius(dp2px(5) / 2);
        mUnselectedDrawable = new LayerDrawable(new Drawable[] { unSelectedGradientDrawable });
    }
    indicatorMargin = a.getDimensionPixelSize(R.styleable.RecyclerViewBannerBase_indicatorSpace, dp2px(4));
    int marginLeft = a.getDimensionPixelSize(R.styleable.RecyclerViewBannerBase_indicatorMarginLeft, dp2px(16));
    int marginRight = a.getDimensionPixelSize(R.styleable.RecyclerViewBannerBase_indicatorMarginRight, dp2px(0));
    int marginBottom = a.getDimensionPixelSize(R.styleable.RecyclerViewBannerBase_indicatorMarginBottom, dp2px(11));
    int g = a.getInt(R.styleable.RecyclerViewBannerBase_indicatorGravity, 0);
    int gravity;
    if (g == 0) {
        gravity = GravityCompat.START;
    } else if (g == 2) {
        gravity = GravityCompat.END;
    } else {
        gravity = Gravity.CENTER;
    }
    int o = a.getInt(R.styleable.RecyclerViewBannerBase_orientation, 0);
    int orientation = 0;
    if (o == 0) {
        orientation = LinearLayoutManager.HORIZONTAL;
    } else if (o == 1) {
        orientation = LinearLayoutManager.VERTICAL;
    }
    a.recycle();
    // recyclerView部分
    mRecyclerView = new RecyclerView(context);
    new PagerSnapHelper().attachToRecyclerView(mRecyclerView);
    mLayoutManager = getLayoutManager(context, orientation);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            onBannerScrolled(recyclerView, dx, dy);
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            onBannerScrollStateChanged(recyclerView, newState);
        }
    });
    LayoutParams vpLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    addView(mRecyclerView, vpLayoutParams);
    // 指示器部分
    indicatorContainer = new RecyclerView(context);
    LinearLayoutManager indicatorLayoutManager = new LinearLayoutManager(context, orientation, false);
    indicatorContainer.setLayoutManager(indicatorLayoutManager);
    indicatorAdapter = new IndicatorAdapter();
    indicatorContainer.setAdapter(indicatorAdapter);
    LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.BOTTOM | gravity;
    params.setMargins(marginLeft, 0, marginRight, marginBottom);
    addView(indicatorContainer, params);
    if (!showIndicator) {
        indicatorContainer.setVisibility(GONE);
    }
}
Also used : TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 72 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project android_frameworks_base by ResurrectionRemix.

the class BatteryMeterDrawable method loadBatteryDrawables.

private void loadBatteryDrawables(Resources res, int style) {
    if (isThemeApplied()) {
        try {
            checkBatteryMeterDrawableValid(res, style);
        } catch (BatteryMeterDrawableException e) {
            Log.w(TAG, "Invalid themed battery meter drawable, falling back to system", e);
        /*              Disable until the theme engine is brought up
                PackageManager pm = mContext.getPackageManager();
                try {
                    res = pm.getThemedResourcesForApplication(mContext.getPackageName(),
                            ThemeConfig.SYSTEM_DEFAULT);
                } catch (PackageManager.NameNotFoundException nnfe) {
                    // Ignore; this should not happen
                }
*/
        }
    }
    final int drawableResId = getBatteryDrawableResourceForStyle(style);
    mBatteryDrawable = (LayerDrawable) res.getDrawable(drawableResId, null);
    mFrameDrawable = mBatteryDrawable.findDrawableByLayerId(R.id.battery_frame);
    mFrameDrawable.setTint(mCurrentBackgroundColor != 0 ? mCurrentBackgroundColor : res.getColor(R.color.batterymeter_frame_color));
    // Set the animated vector drawable we will be stop-animating
    final Drawable levelDrawable = mBatteryDrawable.findDrawableByLayerId(R.id.battery_fill);
    mLevelDrawable = new StopMotionVectorDrawable(levelDrawable);
    mBoltDrawable = mBatteryDrawable.findDrawableByLayerId(R.id.battery_charge_indicator);
}
Also used : StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) Paint(android.graphics.Paint)

Example 73 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project JustAndroid by chinaltz.

the class AbWheelView method initResourcesIfNecessary.

/**
	 * Initializes resources.
	 */
private void initResourcesIfNecessary() {
    if (itemsPaint == null) {
        itemsPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
        // itemsPaint.density = getResources().getDisplayMetrics().density;
        itemsPaint.setTextSize(valueTextSize);
    }
    if (valuePaint == null) {
        valuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG);
        // valuePaint.density = getResources().getDisplayMetrics().density;
        valuePaint.setTextSize(valueTextSize);
    }
    if (labelPaint == null) {
        labelPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG);
        labelPaint.setTextSize(labelTextSize);
        //设置阴影
        labelPaint.setShadowLayer(0.5f, 0, 1, 0xFFFFFFFF);
    }
    //如果没设置中间的选中条用默认的颜色
    if (centerSelectDrawable == null) {
        GradientDrawable mGradientDrawable = new GradientDrawable(Orientation.BOTTOM_TOP, centerSelectGradientColors);
        mGradientDrawable.setStroke(centerSelectStrokeWidth, centerSelectStrokeColor);
        centerSelectDrawable = mGradientDrawable;
    }
    //上边界渐变层
    if (topShadow == null) {
        topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);
    }
    //下边界渐变层
    if (bottomShadow == null) {
        bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
    }
    if (this.getBackground() == null) {
        //原来用颜色渐变实现setBackgroundDrawable(layerDrawable);
        //底部的颜色
        GradientDrawable mGradientDrawable1 = new GradientDrawable(Orientation.TOP_BOTTOM, topGradientColors);
        GradientDrawable mGradientDrawable2 = new GradientDrawable(Orientation.BOTTOM_TOP, bottomGradientColors);
        mGradientDrawable1.setStroke(topStrokeWidth, topStrokeColor);
        mGradientDrawable1.setShape(GradientDrawable.RECTANGLE);
        mGradientDrawable2.setShape(GradientDrawable.RECTANGLE);
        mGradientDrawable1.setGradientType(GradientDrawable.LINEAR_GRADIENT);
        mGradientDrawable2.setGradientType(GradientDrawable.LINEAR_GRADIENT);
        GradientDrawable[] mDrawables = new GradientDrawable[2];
        mDrawables[0] = mGradientDrawable1;
        mDrawables[1] = mGradientDrawable2;
        LayerDrawable layerDrawable = new LayerDrawable(mDrawables);
        //第一个参数0代表数组的第1个元素
        layerDrawable.setLayerInset(0, 0, 0, 0, 0);
        //第一个参数1代表数组的第2个元素
        layerDrawable.setLayerInset(1, 4, 1, 4, 1);
        setBackgroundDrawable(layerDrawable);
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) TextPaint(android.text.TextPaint)

Example 74 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project android-floating-action-button by futuresimple.

the class FloatingActionButton method updateBackground.

void updateBackground() {
    final float strokeWidth = getDimension(R.dimen.fab_stroke_width);
    final float halfStrokeWidth = strokeWidth / 2f;
    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini), createFillDrawable(strokeWidth), createOuterStrokeDrawable(strokeWidth), getIconDrawable() });
    int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2;
    int circleInsetHorizontal = (int) (mShadowRadius);
    int circleInsetTop = (int) (mShadowRadius - mShadowOffset);
    int circleInsetBottom = (int) (mShadowRadius + mShadowOffset);
    layerDrawable.setLayerInset(1, circleInsetHorizontal, circleInsetTop, circleInsetHorizontal, circleInsetBottom);
    layerDrawable.setLayerInset(2, (int) (circleInsetHorizontal - halfStrokeWidth), (int) (circleInsetTop - halfStrokeWidth), (int) (circleInsetHorizontal - halfStrokeWidth), (int) (circleInsetBottom - halfStrokeWidth));
    layerDrawable.setLayerInset(3, circleInsetHorizontal + iconOffset, circleInsetTop + iconOffset, circleInsetHorizontal + iconOffset, circleInsetBottom + iconOffset);
    setBackgroundCompat(layerDrawable);
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 75 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project SmartAndroidSource by jaychou2012.

the class IcsProgressBar method doRefreshProgress.

private synchronized void doRefreshProgress(int id, int progress, boolean fromUser, boolean callBackToApp) {
    float scale = mMax > 0 ? (float) progress / (float) mMax : 0;
    final Drawable d = mCurrentDrawable;
    if (d != null) {
        Drawable progressDrawable = null;
        if (d instanceof LayerDrawable) {
            progressDrawable = ((LayerDrawable) d).findDrawableByLayerId(id);
        }
        final int level = (int) (scale * MAX_LEVEL);
        (progressDrawable != null ? progressDrawable : d).setLevel(level);
    } else {
        invalidate();
    }
    if (callBackToApp && id == android.R.id.progress) {
        onProgressRefresh(scale, fromUser);
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Aggregations

LayerDrawable (android.graphics.drawable.LayerDrawable)133 Drawable (android.graphics.drawable.Drawable)91 BitmapDrawable (android.graphics.drawable.BitmapDrawable)61 StateListDrawable (android.graphics.drawable.StateListDrawable)45 AnimationDrawable (android.graphics.drawable.AnimationDrawable)42 ClipDrawable (android.graphics.drawable.ClipDrawable)42 ShapeDrawable (android.graphics.drawable.ShapeDrawable)39 Paint (android.graphics.Paint)25 SuppressLint (android.annotation.SuppressLint)21 GradientDrawable (android.graphics.drawable.GradientDrawable)19 Bitmap (android.graphics.Bitmap)14 ColorDrawable (android.graphics.drawable.ColorDrawable)14 BitmapShader (android.graphics.BitmapShader)13 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)8 OvalShape (android.graphics.drawable.shapes.OvalShape)8 TypedArray (android.content.res.TypedArray)7 Nullable (android.annotation.Nullable)5 Resources (android.content.res.Resources)5 InsetDrawable (android.graphics.drawable.InsetDrawable)5 TransitionDrawable (android.graphics.drawable.TransitionDrawable)5