微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android.graphics.drawable.LayerDrawable的实例源码

项目:Cable-Android    文件BubbleDrawableBuilder.java   
public Drawable create(Context context) {
  final GradientDrawable bubble = new GradientDrawable();
  final int              radius = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius);
  final float[]          radii  = cornerBooleansToRadii(corners,radius);

  bubble.setColor(color);
  bubble.setCornerRadii(radii);

  if (!hasShadow) {
    return bubble;
  } else {
    final GradientDrawable shadow   = new GradientDrawable();
    final int              distance = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_shadow_distance);

    shadow.setColor(shadowColor);
    shadow.setCornerRadii(radii);

    final LayerDrawable layers = new LayerDrawable(new Drawable[]{shadow,bubble});
    layers.setLayerInset(1,distance);
    return layers;
  }
}
项目:GitHub    文件FloatingActionButton.java   
protected LayerDrawable generateFinalDrawables(RectF circleRect) {
    if (mSize == SIZE_NOSHADOW) {
        return new LayerDrawable(
                new Drawable[]{
                        createFillDrawable(circleRect),createstrokesDrawable(circleRect),getIconDrawable()
                });
    } else {
        return new LayerDrawable(
                new Drawable[]{
                        getResources().getDrawable(getDrawableBySize(mSize)),createFillDrawable(circleRect),getIconDrawable()
                });
    }
}
项目:android_ui    文件TintLayerDrawable.java   
/**
 * Updates tint of a layer with the specified <var>layerId</var> of the wrapped drawable
 * depends on the specified <var>stateSet</var>.
 *
 * @param layerId  Id of the desired layer of which tint to update.
 * @param stateSet State set to properly resolve tint color.
 * @return {@code True} if tint has ben updated,{@code false} otherwise.
 */
private boolean updateDrawableLayerTint(int layerId,int[] stateSet) {
    if ((mPrivateFlags & PFLAG_HAS_COLOR_FILTER) == 0) {
        final Drawable drawable = ((LayerDrawable) mDrawable).findDrawableByLayerId(layerId);
        if (drawable == null) {
            return false;
        }

        final DrawableLayerTint layerTint = mDrawableLayerTints != null ? mDrawableLayerTints.get(layerId) : null;
        if (layerTint != null && layerTint.tintList != null && layerTint.tintMode != null) {
            final int tintColor = layerTint.tintList.getColorForState(stateSet,layerTint.currentTint);

            if (tintColor != layerTint.currentTint || (mPrivateFlags & PFLAG_TINT_COLOR_CACHING_ENABLED) == 0) {
                drawable.setColorFilter(new PorterDuffColorFilter(tintColor,layerTint.tintMode));
                layerTint.currentTint = tintColor;
            }
        } else {
            drawable.clearColorFilter();
        }
        return true;
    }
    return false;
}
项目:Rxjava2.0Demo    文件UploadFileActivity.java   
@Override
public void initView() {
    mRefreshLayout = findViewById(R.id.refreshLayout);

    int deta = new Random().nextInt(7 * 24 * 60 * 60 * 1000);
    mClassicsHeader = (ClassicsHeader)mRefreshLayout.getRefreshHeader();
    mClassicsHeader.setLastUpdateTime(new Date(System.currentTimeMillis()-deta));
    mClassicsHeader.setTimeFormat(new SimpleDateFormat("更新于 MM-dd HH:mm",Locale.CHINA));
    mClassicsHeader.setTimeFormat(new DynamicTimeFormat("更新于 %s"));
    mClassicsHeader.setSpinnerStyle(SpinnerStyle.Translate);
    mDrawableProgress = mClassicsHeader.getProgressView().getDrawable();
    if (mDrawableProgress instanceof LayerDrawable) {
        mDrawableProgress = ((LayerDrawable) mDrawableProgress).getDrawable(0);
    }

    if (isFirstEnter) {
        isFirstEnter = false;
        //触发自动刷新
        mRefreshLayout.autoRefresh();
    }
}
项目:mapBox-navigation-android    文件AlertView.java   
private void initBackground() {
  if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
    int progressColor = ThemeSwitcher.retrieveNavigationViewThemeColor(getContext(),R.attr.navigationViewProgress);
    int progressBackgroundColor = ThemeSwitcher.retrieveNavigationViewThemeColor(getContext(),R.attr.navigationViewProgressBackground);

    LayerDrawable progressBarDrawable = (LayerDrawable) alertProgressBar.getProgressDrawable();
    // ProgressBar progress color
    Drawable progressBackgroundDrawable = progressBarDrawable.getDrawable(0);
    progressBackgroundDrawable.setColorFilter(progressBackgroundColor,PorterDuff.Mode.SRC_IN);


    // ProgressBar background color
    Drawable progressDrawable = progressBarDrawable.getDrawable(1);
    progressDrawable.setColorFilter(progressColor,PorterDuff.Mode.SRC_IN);

    // Hide the background
    getBackground().setAlpha(0);
  } else {
    setBackgroundColor(ContextCompat.getColor(getContext(),android.R.color.transparent));
  }
}
项目:RNLearn_Project1    文件Reacthorizontalscrollview.java   
private ReactViewBackgroundDrawable getorCreateReactViewBackground() {
  if (mReactBackgroundDrawable == null) {
    mReactBackgroundDrawable = new ReactViewBackgroundDrawable();
    Drawable backgroundDrawable = getBackground();
    super.setBackground(null);  // required so that drawable callback is cleared before we add the
    // drawable back as a part of LayerDrawable
    if (backgroundDrawable == null) {
      super.setBackground(mReactBackgroundDrawable);
    } else {
      LayerDrawable layerDrawable =
          new LayerDrawable(new Drawable[]{mReactBackgroundDrawable,backgroundDrawable});
      super.setBackground(layerDrawable);
    }
  }
  return mReactBackgroundDrawable;
}
项目:PeSanKita-android    文件BubbleDrawableBuilder.java   
public Drawable create(Context context) {
  final GradientDrawable bubble = new GradientDrawable();
  final int              radius = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius);
  final float[]          radii  = cornerBooleansToRadii(corners,distance);
    return layers;
  }
}
项目:RNLearn_Project1    文件ReactTextView.java   
private ReactViewBackgroundDrawable getorCreateReactViewBackground() {
  if (mReactBackgroundDrawable == null) {
    mReactBackgroundDrawable = new ReactViewBackgroundDrawable();
    Drawable backgroundDrawable = getBackground();
    super.setBackground(null);  // required so that drawable callback is cleared before we add the
    // drawable back as a part of LayerDrawable
    if (backgroundDrawable == null) {
      super.setBackground(mReactBackgroundDrawable);
    } else {
      LayerDrawable layerDrawable =
              new LayerDrawable(new Drawable[]{mReactBackgroundDrawable,backgroundDrawable});
      super.setBackground(layerDrawable);
    }
  }
  return mReactBackgroundDrawable;
}
项目:RNLearn_Project1    文件ReactEditText.java   
private ReactViewBackgroundDrawable getorCreateReactViewBackground() {
  if (mReactBackgroundDrawable == null) {
    mReactBackgroundDrawable = new ReactViewBackgroundDrawable();
    Drawable backgroundDrawable = getBackground();
    super.setBackground(null);  // required so that drawable callback is cleared before we add the
    // drawable back as a part of LayerDrawable
    if (backgroundDrawable == null) {
      super.setBackground(mReactBackgroundDrawable);
    } else {
      LayerDrawable layerDrawable =
          new LayerDrawable(new Drawable[]{mReactBackgroundDrawable,backgroundDrawable});
      super.setBackground(layerDrawable);
    }
  }
  return mReactBackgroundDrawable;
}
项目:MyCalendar    文件FloatingActionButtonLibrary.java   
private Drawable createCircleDrawable(int color,float strokeWidth) {
  int alpha = Color.alpha(color);
  int opaqueColor = opaque(color);

  ShapeDrawable fillDrawable = new ShapeDrawable(new ovalShape());

  final Paint paint = fillDrawable.getPaint();
  paint.setAntiAlias(true);
  paint.setColor(opaqueColor);

  Drawable[] layers = {
      fillDrawable,createInnerstrokesDrawable(opaqueColor,strokeWidth)
  };

  LayerDrawable drawable = alpha == 255 || !mstrokeVisible
      ? new LayerDrawable(layers)
      : new TranslucentLayerDrawable(alpha,layers);

  int halfstrokeWidth = (int) (strokeWidth / 2f);
  drawable.setLayerInset(1,halfstrokeWidth,halfstrokeWidth);

  return drawable;
}
项目:Quran    文件SeekBarPreference.java   
private void styleSeekBar() {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    final Drawable progressDrawable = mSeekBar.getProgressDrawable();
    if (progressDrawable != null) {
      if (progressDrawable instanceof LayerDrawable) {
        LayerDrawable ld = (LayerDrawable) progressDrawable;
        int layers = ld.getNumberOfLayers();
        for (int i = 0; i < layers; i++) {
          ld.getDrawable(i).mutate().setColorFilter(mTintColor,PorterDuff.Mode.SRC_ATOP);
        }
      } else {
        progressDrawable.mutate().setColorFilter(mTintColor,PorterDuff.Mode.SRC_ATOP);
      }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      final Drawable thumb = mSeekBar.getThumb();
      if (thumb != null) {
        thumb.mutate().setColorFilter(mTintColor,PorterDuff.Mode.SRC_ATOP);
      }
    }
  }
}
项目:XERUNG    文件Switch.java   
public void changeBackground() {
    if (iSchecked) {
        if (!isInEditMode()) {
            setBackgroundResource(R.drawable.background_checkBox);
            LayerDrawable layer = (LayerDrawable) getBackground();
            GradientDrawable shape = (GradientDrawable) layer
                    .findDrawableByLayerId(R.id.shape_bacground);
            shape.setColor(backgroundColor);
        }

    } else {
        if (!isInEditMode()) {
            setBackgroundResource(R.drawable.background_switch_ball_uncheck);
        }
    }
}
项目:XERUNG    文件Button.java   
@Override
public void setBackgroundColor(int color) {
    backgroundColor = color;
    if (isEnabled()) {
        beforeBackground = backgroundColor;
    }
    try {
        LayerDrawable layer = (LayerDrawable) getBackground();
        // 每个按钮的框架都是由drawable中的xml文件制定的,xml文件中都有一个item的id叫:shape_bacground
        GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
        /**
         * 给这个图片设置背景色,因为图片的主体是透明的所以可以直接显示背景色
         * 效果就是一个透明但有阴影的框架下有了背景色,这样的方式可以方便的设置不同颜色的按钮,让按钮看起来还是浑然一体
         */
        shape.setColor(backgroundColor);
        /**
         * 当重新设定背景色后,要检查涟漪颜色。如果已经设定了涟漪颜色,那么就用之前的。如果没设定就重新生成
         */
        if (!settedRippleColor) {
            rippleColor = makePressColor(255);
        }
    } catch (Exception ex) {
        // Without bacground
    }
}
项目:TestChat    文件FloatingActionButton.java   
private Drawable createCircleDrawable(int color,float strokeWidth) {
        int alpha = Color.alpha(color);
        int opaqueColor = opaque(color);

        ShapeDrawable fillDrawable = new ShapeDrawable(new ovalShape());

        final Paint paint = fillDrawable.getPaint();
        paint.setAntiAlias(true);
        paint.setColor(opaqueColor);

        Drawable[] layers = {
                fillDrawable,strokeWidth)
        };

        LayerDrawable drawable = alpha == 255 || !mstrokeVisible
                ? new LayerDrawable(layers)
                : new TranslucentLayerDrawable(alpha,layers);

        int halfstrokeWidth = (int) (strokeWidth / 2f);
        drawable.setLayerInset(1,halfstrokeWidth);

        return drawable;
}
项目:qmui    文件QMUIDrawableHelper.java   
/**
 * 动态创建带上分隔线或下分隔线的Drawable
 *
 * @param separatorColor
 * @param bgColor
 * @param top
 * @return
 */
public static LayerDrawable createItemSeparatorBg(@ColorInt int separatorColor,@ColorInt int bgColor,int separatorHeight,boolean top) {

    ShapeDrawable separator = new ShapeDrawable();
    separator.getPaint().setStyle(Paint.Style.FILL);
    separator.getPaint().setColor(separatorColor);

    ShapeDrawable bg = new ShapeDrawable();
    bg.getPaint().setStyle(Paint.Style.FILL);
    bg.getPaint().setColor(bgColor);

    Drawable[] layers = {separator,bg};
    LayerDrawable layerDrawable = new LayerDrawable(layers);

    layerDrawable.setLayerInset(1,top ? separatorHeight : 0,top ? 0 : separatorHeight);
    return layerDrawable;
}
项目:Nird2    文件StrengthMeter.java   
public StrengthMeter(Context context,AttributeSet attrs) {
    super(context,attrs,android.R.attr.progressBarStyleHorizontal);
    bar = new ShapeDrawable();
    bar.getPaint().setColor(RED);
    ClipDrawable clip = new ClipDrawable(bar,LEFT,HORIZONTAL);
    ShapeDrawable background = new ShapeDrawable();
    Paint p = background.getPaint();
    p.setStyle(FILL);
    p.setColor(getResources().getColor(android.R.color.transparent));
    p.setStyle(stroke);
    p.setstrokeWidth(1);
    p.setColor(BLACK);
    Drawable[] layers = new Drawable[] { clip,background };
    setProgressDrawable(new LayerDrawable(layers));
    setIndeterminate(false);
}
项目:weex-3d-map    文件WXViewUtils.java   
public static @Nullable
BorderDrawable getBorderDrawable(@NonNull View view){
  Drawable drawable=view.getBackground();
  if(drawable instanceof BorderDrawable){
    return (BorderDrawable) drawable;
  }
  else if(drawable instanceof LayerDrawable){
    if(((LayerDrawable) drawable).getNumberOfLayers()>1) {
      Drawable innerDrawable=((LayerDrawable) drawable).getDrawable(0);
      if(innerDrawable instanceof BorderDrawable){
        return (BorderDrawable) innerDrawable;
      }
    }
  }
  return null;
}
项目:ucar-weex-core    文件WXViewUtils.java   
public static @Nullable
BorderDrawable getBorderDrawable(@NonNull View view){
  Drawable drawable=view.getBackground();
  if(drawable instanceof BorderDrawable){
    return (BorderDrawable) drawable;
  }
  else if(drawable instanceof LayerDrawable){
    if(((LayerDrawable) drawable).getNumberOfLayers()>1) {
      Drawable innerDrawable=((LayerDrawable) drawable).getDrawable(0);
      if(innerDrawable instanceof BorderDrawable){
        return (BorderDrawable) innerDrawable;
      }
    }
  }
  return null;
}
项目:Mix    文件OrderDialogFragment.java   
private Drawable createProductimageDrawable(Product product) {
    final ShapeDrawable background = new ShapeDrawable();
    background.setShape(new ovalShape());
    background.getPaint().setColor(ContextCompat.getColor(getContext(),product.color));

    final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),BitmapFactory.decodeResource(getResources(),product.image));

    final LayerDrawable layerDrawable = new LayerDrawable
            (new Drawable[]{background,bitmapDrawable});

    final int padding = (int) getResources().getDimension(R.dimen.spacing_huge);
    layerDrawable.setLayerInset(1,padding,padding);

    return layerDrawable;
}
项目:Mix    文件ThemeUtils.java   
public static boolean containsNinePatch(Drawable drawable) {
    drawable = getWrapperDrawable(drawable);
    if (drawable instanceof NinePatchDrawable
            || drawable instanceof InsetDrawable
            || drawable instanceof LayerDrawable) {
        return true;
    } else if (drawable instanceof StateListDrawable) {
        final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState());
        //can't getBaseApplication containState from drawable which is containing DrawableWrapperDonut
        //https://code.google.com/p/android/issues/detail?id=169920
        if (containerState == null) {
            return true;
        }
        for (Drawable dr : containerState.getChildren()) {
            dr = getWrapperDrawable(dr);
            if (dr instanceof NinePatchDrawable
                    || dr instanceof InsetDrawable
                    || dr instanceof LayerDrawable) {
                return true;
            }
        }
    }
    return false;
}
项目:BBSSDK-for-Android    文件SelectableRoundedImageView.java   
public static Drawable fromDrawable(Drawable drawable,Resources r) {
    if (drawable != null) {
        if (drawable instanceof SelectableRoundedCornerDrawable) {
            return drawable;
        } else if (drawable instanceof LayerDrawable) {
            LayerDrawable ld = (LayerDrawable) drawable;
            final int num = ld.getNumberOfLayers();
            for (int i = 0; i < num; i++) {
                Drawable d = ld.getDrawable(i);
                ld.setDrawableByLayerId(ld.getId(i),fromDrawable(d,r));
            }
            return ld;
        }

        Bitmap bm = drawabletoBitmap(drawable);
        if (bm != null) {
            return new SelectableRoundedCornerDrawable(bm,r);
        } else {
        }
    }
    return drawable;
}
项目:AvatarView    文件RoundedImageView.java   
private void updateAttrs(Drawable drawable) {
    if (drawable == null) {
        return;
    }

    if (drawable instanceof RoundedDrawable) {
        ((RoundedDrawable) drawable).setScaleType(mScaleType).setCornerRadius(cornerRadius)
                .setBorderWidth(borderWidth).setBorderColor(borderColor).setoval(isoval);
    } else if (drawable instanceof LayerDrawable) {
        // loop through layers to and set drawable attrs
        LayerDrawable ld = ((LayerDrawable) drawable);
        for (int i = 0,layers = ld.getNumberOfLayers(); i < layers; i++) {
            updateAttrs(ld.getDrawable(i));
        }
    }
}
项目:letv    文件RoundedPagerDrawable.java   
public static Drawable fromDrawable(Drawable drawable) {
    if (drawable == null || (drawable instanceof RoundedPagerDrawable)) {
        return drawable;
    }
    if (drawable instanceof LayerDrawable) {
        Drawable ld = (LayerDrawable) drawable;
        int num = ld.getNumberOfLayers();
        for (int i = 0; i < num; i++) {
            ld.setDrawableByLayerId(ld.getId(i),fromDrawable(ld.getDrawable(i)));
        }
        return ld;
    }
    Bitmap bm = drawabletoBitmap(drawable);
    if (bm != null) {
        return new RoundedPagerDrawable(bm);
    }
    return drawable;
}
项目:letv    文件RoundedImageView.java   
private void updateAttrs(Drawable drawable) {
    if (drawable != null) {
        if (drawable instanceof RoundedPagerDrawable) {
            ((RoundedPagerDrawable) drawable).setScaleType(this.mScaleType).setBorderWidth(this.mBorderWidth).setBorderColor(this.mBorderColor).setoval(this.mIsoval).setTileModeX(this.mTileModeX).setTileModeY(this.mTileModeY);
            if (this.mCornerRadii != null) {
                ((RoundedPagerDrawable) drawable).setCornerRadius(this.mCornerRadii[0],this.mCornerRadii[1],this.mCornerRadii[2],this.mCornerRadii[3]);
            }
            applyColorMod();
        } else if (drawable instanceof LayerDrawable) {
            LayerDrawable ld = (LayerDrawable) drawable;
            int layers = ld.getNumberOfLayers();
            for (int i = 0; i < layers; i++) {
                updateAttrs(ld.getDrawable(i));
            }
        }
    }
}
项目: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);
    }
}
项目:android-mvp-interactor-architecture    文件RateUsDialog.java   
@Override
protected void setUp(View view) {

    mratingMessageView.setVisibility(View.GONE);
    mPlayStoreratingView.setVisibility(View.GONE);

    LayerDrawable stars = (LayerDrawable) mratingBar.getProgressDrawable();
    stars.getDrawable(2)
            .setColorFilter(ContextCompat.getColor(getContext(),R.color.yellow),PorterDuff.Mode.SRC_ATOP);
    stars.getDrawable(0)
            .setColorFilter(ContextCompat.getColor(getContext(),R.color.shadow),PorterDuff.Mode.SRC_ATOP);
    stars.getDrawable(1)
            .setColorFilter(ContextCompat.getColor(getContext(),PorterDuff.Mode.SRC_ATOP);

    mSubmitButton.setonClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mPresenter.onratingSubmitted(mratingBar.getrating(),mMessage.getText().toString());
        }
    });

}
项目:shortstories    文件BitmapUtil.java   
private static Bitmap getCircleIcon(
        Context context,@ColorInt int backgroundColor,int backgroundInset,@DrawableRes int iconResId,@ColorInt int iconColor,int iconInset) {
    Drawable[] layers = new Drawable[2];
    ShapeDrawable background = new ShapeDrawable(new ovalShape());
    background.getPaint().setColor(backgroundColor);
    Drawable icon = ContextCompat.getDrawable(context,iconResId);
    Drawable tintedIcon = DrawableCompat.wrap(icon.mutate());
    DrawableCompat.setTint(tintedIcon,iconColor);
    layers[0] = background;
    layers[1] = tintedIcon;
    LayerDrawable layerDrawable = new LayerDrawable(layers);
    layerDrawable.setLayerInset(1,iconInset,iconInset);
    layerDrawable.setLayerInset(0,backgroundInset,backgroundInset);
    return drawabletoBitmap(layerDrawable);
}
项目:photo-editor-android    文件ColorPickerAdapter.java   
private void buildColorPickerView(View view,int colorCode) {
    view.setVisibility(View.VISIBLE);

    ShapeDrawable biggerCircle = new ShapeDrawable(new ovalShape());
    biggerCircle.setIntrinsicHeight(20);
    biggerCircle.setIntrinsicWidth(20);
    biggerCircle.setBounds(new Rect(0,20,20));
    biggerCircle.getPaint().setColor(colorCode);

    ShapeDrawable smallerCircle = new ShapeDrawable(new ovalShape());
    smallerCircle.setIntrinsicHeight(5);
    smallerCircle.setIntrinsicWidth(5);
    smallerCircle.setBounds(new Rect(0,5,5));
    smallerCircle.getPaint().setColor(Color.WHITE);
    smallerCircle.setPadding(10,10,10);
    Drawable[] drawables = {smallerCircle,biggerCircle};

    LayerDrawable layerDrawable = new LayerDrawable(drawables);

    view.setBackgroundDrawable(layerDrawable);
}
项目:RLibrary    文件ImagePickerImageView.java   
private void setColor(Drawable drawable,@ColorInt int color) {
        if (drawable != null) {
            if (drawable instanceof LayerDrawable) {
//                LayerDrawable layerDrawable = (LayerDrawable) drawable;
//                int numberOfLayers = layerDrawable.getNumberOfLayers();
////                if (numberOfLayers > 0) {
////                    setColor((layerDrawable).getDrawable(numberOfLayers - 1),color);
////                }
//                for (int i = 0; i < numberOfLayers; i++) {
//                    setColor((layerDrawable).getDrawable(i),color);
//                }

                mShowMask = true;
                postInvalidate();
//                layerDrawable.setColorFilter(color,PorterDuff.Mode.MULTIPLY);
            } else {
                drawable.mutate().setColorFilter(color,PorterDuff.Mode.MULTIPLY);
            }
        }
    }
项目:From-design-to-Android-part1    文件OrderDialogFragment.java   
private Drawable createProductimageDrawable(Product product) {
    final ShapeDrawable background = new ShapeDrawable();
    background.setShape(new ovalShape());
    background.getPaint().setColor(ContextCompat.getColor(getContext(),product.image));

    final LayerDrawable layerDrawable = new LayerDrawable
        (new Drawable[]{background,padding);

    return layerDrawable;
}
项目:android-mvp-architecture    文件RateUsDialog.java   
@Override
protected void setUp(View view) {

    mratingMessageView.setVisibility(View.GONE);
    mPlayStoreratingView.setVisibility(View.GONE);

    LayerDrawable stars = (LayerDrawable) mratingBar.getProgressDrawable();
    stars.getDrawable(2)
            .setColorFilter(ContextCompat.getColor(getContext(),mMessage.getText().toString());
        }
    });

}
项目:FloatingApps    文件PopupMenu.java   
public void showAtLocation(final View v,int x,int y) {
    final PopupMenu that = this;
    this.window.setondismissListener(new PopupWindow.OndismissListener() {
        public void ondismiss() {
            that.main_layout.removeAllViews();
        }
    });

    this.main_layout = new LinearLayout(this.ctx);
    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { (NinePatchDrawable)this.ctx.getResources().getDrawable(android.R.drawable.dialog_frame),new ColorDrawable(Color.WHITE) });
    layerDrawable.setLayerInset(0,Utils.dip2px(this.ctx,5),5) + 3,5));
    this.main_layout.setBackgroundDrawable(layerDrawable);
    this.main_layout.addView(this.contentViewLayout);
    this.window.setContentView(this.main_layout);
    this.window.setWidth(this.width);
    this.window.setHeight(this.height);
    this.window.showAsDropDown(v,x,y);
}
项目:StarchWindow    文件rippledrawable.java   
public static void drawCircle(MaterialButton view,int width,int height,float x,float y,int color,int _color,float radius,int alpha,Drawable drawable) {
    Bitmap bm = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bm);
    final Paint paint = new Paint();

    paint.setColor(_color);
    paint.setAlpha(alpha);
    paint.setAntiAlias(true);

    canvas.drawCircle(x,y,radius,paint);

    if(drawable != null) {
           view.setBackgroundDrawable(new LayerDrawable(new Drawable[] {drawable,new BitmapDrawable(bm)}));
       }
       if(drawable == null) {
           view.setBackgroundDrawable(new LayerDrawable(new Drawable[] {new ColorDrawable(color),new BitmapDrawable(bm)}));
       }
}
项目:MaterialAbout    文件RoundedDrawable.java   
public static Drawable fromDrawable(Drawable drawable) {
  if (drawable != null) {
    if (drawable instanceof RoundedDrawable) {
      // just return if it's already a RoundedDrawable
      return drawable;
    } else if (drawable instanceof LayerDrawable) {
      LayerDrawable ld = (LayerDrawable) drawable;
      int num = ld.getNumberOfLayers();

      // loop through layers to and change to RoundedDrawables if possible
      for (int i = 0; i < num; i++) {
        Drawable d = ld.getDrawable(i);
        ld.setDrawableByLayerId(ld.getId(i),fromDrawable(d));
      }
      return ld;
    }

    // try to get a bitmap from the drawable and
    Bitmap bm = drawabletoBitmap(drawable);
    if (bm != null) {
      return new RoundedDrawable(bm);
    }
  }
  return drawable;
}
项目:boohee_v5.6    文件FloatingActionButtonEclairMr1.java   
void setBackgroundDrawable(ColorStateList backgroundTint,Mode backgroundTintMode,int rippleColor,int borderWidth) {
    Drawable[] layers;
    this.mShapeDrawable = DrawableCompat.wrap(createShapeDrawable());
    DrawableCompat.setTintList(this.mShapeDrawable,backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(this.mShapeDrawable,backgroundTintMode);
    }
    this.mrippledrawable = DrawableCompat.wrap(createShapeDrawable());
    DrawableCompat.setTintList(this.mrippledrawable,createColorStateList(rippleColor));
    if (borderWidth > 0) {
        this.mBorderDrawable = createBorderDrawable(borderWidth,backgroundTint);
        layers = new Drawable[]{this.mBorderDrawable,this.mShapeDrawable,this.mrippledrawable};
    } else {
        this.mBorderDrawable = null;
        layers = new Drawable[]{this.mShapeDrawable,this.mrippledrawable};
    }
    this.mContentBackground = new LayerDrawable(layers);
    this.mShadowDrawable = new ShadowDrawableWrapper(this.mView.getResources(),this.mContentBackground,this.mShadowViewDelegate.geTradius(),this.mElevation,this.mElevation + this.mpressedTranslationZ);
    this.mShadowDrawable.setAddPaddingForCorners(false);
    this.mShadowViewDelegate.setBackgroundDrawable(this.mShadowDrawable);
}
项目:FullSizePopupSpinner    文件ViewUtil.java   
static Drawable getRotateDrawable(final Drawable d,final int angle) {
    return new LayerDrawable(new Drawable[]{d}) {
        @Override
        public void draw(final Canvas canvas) {
            canvas.save();
            canvas.rotate(angle,d.getBounds().width() / 2,d.getBounds().height() / 2);
            super.draw(canvas);
            canvas.restore();
        }
    };
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。