android.graphics.drawable.LayerDrawable Java Examples

The following examples show how to use android.graphics.drawable.LayerDrawable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RangeProgressBar.java    From RangeSeekBar with MIT License 6 votes vote down vote up
private void updateDrawableBounds(int w, int h) {
    mPaddingLeft = getPaddingLeft();
    mPaddingRight = getPaddingRight();
    mPaddingTop = getPaddingTop();
    mPaddingBottom = getPaddingBottom();

    w -= mPaddingRight + mPaddingLeft;
    h -= mPaddingTop + mPaddingBottom;

    int right = w;
    int bottom = h;
    int top = 0;
    int left = 0;

    mProgressDrawableIndicator = null;
    mProgressIndicatorBounds = null;
    mComputedWidth = w;

    if (mProgressDrawable != null) {
        mProgressDrawable.setBounds(left, top, right, bottom);
        mProgressDrawableIndicator = ((LayerDrawable) mProgressDrawable).findDrawableByLayerId(android.R.id.progress);
        mProgressIndicatorBounds = mProgressDrawableIndicator.getBounds();
    }
}
 
Example #2
Source File: RoundedImageViewWithBorder.java    From ImageLetterIcon with Apache License 2.0 6 votes vote down vote up
private void updateAttrs(Drawable drawable, boolean background) {
    if (drawable == null) {
        return;
    }
    if (drawable instanceof RoundedDrawable) {
        ((RoundedDrawable) drawable)
                .setScaleType(mScaleType)
                .setCornerRadius(background && !mRoundBackground ? 0 : mCornerRadius)
                .setBorderWidth(mBorderWidth)
                .setBorderColors(mBorderColor)
                .setOval(mOval);
    } else if (drawable instanceof LayerDrawable) {
        // loop through layers to and set drawable attrs
        LayerDrawable ld = ((LayerDrawable) drawable);
        int layers = ld.getNumberOfLayers();
        for (int i = 0; i < layers; i++) {
            updateAttrs(ld.getDrawable(i), background);
        }
    }
}
 
Example #3
Source File: ObservationFormPickerActivity.java    From mage-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    final JsonObject formDefinition = (JsonObject) formDefinitions.get(position);

    String name = formDefinition.get("name").getAsString();
    holder.name.setText(name);

    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onFormClicked(formDefinition);
        }
    });

    String color = formDefinition.get("color").getAsString();
    // Lets add a tiny bit of transparency to soften things up.
    color = "#D7" + color.substring(1, color.length());

    LayerDrawable pickerIcon = (LayerDrawable) holder.icon.getDrawable();
    Drawable background = pickerIcon.findDrawableByLayerId(R.id.background);
    DrawableCompat.setTint(background, Color.parseColor(color));
}
 
Example #4
Source File: FloatingActionButton.java    From TestChat with Apache License 2.0 6 votes vote down vote up
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, halfStrokeWidth, halfStrokeWidth);

        return drawable;
}
 
Example #5
Source File: WXViewUtils.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: PXToggleButtonStyleAdapter.java    From pixate-freestyle-android with Apache License 2.0 6 votes vote down vote up
/**
 * This method is called when the view's background was null, or did not
 * have any states assigned. The call will directly update the views in the
 * context list with the background image generated by each of the contexts.
 * A new StateListDrawable that will be applied as the View's background.
 * Subclasses may overwrite.
 * 
 * @param ruleSets
 * @param contexts
 */
protected void updateWithNewStates(List<PXRuleSet> ruleSets, List<PXStylerContext> contexts) {
    // We should have the same view in all contexts, so grab the first
    // and set it with the new background
    StateListDrawable drawable = PXDrawableUtil.createNewStateListDrawable(this, ruleSets,
            contexts);
    if (drawable != null) {
        // Set the background on the right level of the toggle button
        ToggleButton toggleButton = (ToggleButton) contexts.get(0).getStyleable();
        Drawable background = toggleButton.getBackground();
        if (background instanceof LayerDrawable) {
            LayerDrawable layerDrawable = (LayerDrawable) background;
            layerDrawable.setDrawableByLayerId(android.R.id.background, drawable);
        } else {
            // we don't deal with any other background type (non-default)
            // (TODO: We may need to hack our way to create a new
            // LayerDrawable with the right layers id's)
            PXDrawableUtil.setBackgroundDrawable((View) toggleButton, drawable);
        }
    }
}
 
Example #7
Source File: FloatingActionButton.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
void updateBackground() {
  float circleLeft = mShadowRadius;
  float circleTop = mShadowRadius - mShadowOffset;

  final RectF circleRect = new RectF(circleLeft, circleTop, circleLeft + mCircleSize, circleTop + mCircleSize);

  LayerDrawable layerDrawable = new LayerDrawable(
      new Drawable[] {
          getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.floating_action_button_fab_bg_normal : R.drawable.floating_action_button_fab_bg_mini),
          createFillDrawable(circleRect),
          createStrokesDrawable(circleRect),
          getIconDrawable()
      });

  float iconOffset = (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2f;

  int iconInsetHorizontal = (int) (mShadowRadius + iconOffset);
  int iconInsetTop = (int) (circleTop + iconOffset);
  int iconInsetBottom = (int) (mShadowRadius + mShadowOffset + iconOffset);

  layerDrawable.setLayerInset(3, iconInsetHorizontal, iconInsetTop, iconInsetHorizontal, iconInsetBottom);

  setBackgroundCompat(layerDrawable);
}
 
Example #8
Source File: RoundedImageView.java    From QuickReturn with Apache License 2.0 6 votes vote down vote up
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));
        }
    }
}
 
Example #9
Source File: AppShortcutIconGenerator.java    From Phonograph with GNU General Public License v3.0 6 votes vote down vote up
private static IconCompat generateThemedIcon(Context context, int iconId, int foregroundColor, int backgroundColor) {
    // Get and tint foreground and background drawables
    Drawable vectorDrawable = ImageUtil.getTintedVectorDrawable(context, iconId, foregroundColor);
    Drawable backgroundDrawable = ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_app_shortcut_background, backgroundColor);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        AdaptiveIconDrawable adaptiveIconDrawable = new AdaptiveIconDrawable(backgroundDrawable, vectorDrawable);
        return IconCompat.createWithAdaptiveBitmap(ImageUtil.createBitmap(adaptiveIconDrawable));
    } else {
        // Squash the two drawables together
        LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{backgroundDrawable, vectorDrawable});

        // Return as an Icon
        return IconCompat.createWithBitmap(ImageUtil.createBitmap(layerDrawable));
    }
}
 
Example #10
Source File: CmBatteryBar.java    From Noyze with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the {@link ShapeDrawable} which displays the
 * color of the bar across the screen.
 */
public void setProgressDrawable(Drawable mDrawable, int mNewColor)
{
	if (mDrawable instanceof LayerDrawable &&
		getProgressDrawable() instanceof LayerDrawable)
	{
        final LayerDrawable mDraw = (LayerDrawable) getProgressDrawable();
        final ClipDrawable mShape = (ClipDrawable)
            mDraw.findDrawableByLayerId(android.R.id.progress);

        // Make sure we've got everything.
        if (mShape != null && mProgress != null &&
            mProgress.getPaint() != null)
        {
            mProgress.getPaint().setColor(mNewColor);
            final Rect mBounds = mDraw.getBounds();
            super.setProgressDrawable(mDraw);
            getProgressDrawable().setBounds(mBounds);
            return;
        }
	}
	
	super.setProgressDrawable(mDrawable);
}
 
Example #11
Source File: ArrowButton.java    From hkm-progress-button with MIT License 6 votes vote down vote up
protected LayerDrawable createCommonFace() {
    if (resIcon != -1) {
        LayerDrawable ly = afterProcessLayerDrawable(new LayerDrawable(
                new Drawable[]{
                        createFillDrawable(),
                        getArrow(),
                        getIcon()
                }));
        ly.setLayerInset(2, icon_size_text_padding, 0, 0, 0);
        return ly;
    } else {
        return afterProcessLayerDrawable(new LayerDrawable(
                new Drawable[]{
                        createFillDrawable(),
                        getArrow()
                }));
    }
}
 
Example #12
Source File: Swipe_Button_View.java    From AGIKSwipeButton with MIT License 6 votes vote down vote up
void set_default(AttributeSet attrs, int defStyle) {
    inflate(getContext(), R.layout.sb_swipe_view, this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackground(ContextCompat.getDrawable(getContext(), R.drawable.sb_swipe_view_bg));
    } else {
        setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.sb_swipe_view_bg));
    }

    swipeTextView = findViewById(R.id.sb_text);
    swipe_button_controller = findViewById(R.id.sb_swipe);
    swipe_button_controller.setOnSeekBarChangeListener(this);
    swipe_bg_drawable = getBackground();
    swipeLayers = (LayerDrawable) swipe_button_controller.getThumb();
    thumb_bg_drawable = swipeLayers.findDrawableByLayerId(R.id.thumb_background);

    TypedArray attributes = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeButtonView,
            defStyle, defStyle);
    try {
        getAttributes(attributes);
    } finally {
        attributes.recycle();
    }
}
 
Example #13
Source File: ColorSuggestionListAdapter.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the color button to represent a color suggestion.
 *
 * @param button The button view to set up.
 * @param index The index of the suggestion in mSuggestions.
 */
private void setUpColorButton(View button, int index) {
    if (index >= mSuggestions.length) {
        button.setTag(null);
        button.setContentDescription(null);
        button.setVisibility(View.INVISIBLE);
        return;
    }
    button.setTag(mSuggestions[index]);
    button.setVisibility(View.VISIBLE);
    ColorSuggestion suggestion = mSuggestions[index];
    LayerDrawable layers = (LayerDrawable) button.getBackground();
    GradientDrawable swatch =
            (GradientDrawable) layers.findDrawableByLayerId(R.id.color_button_swatch);
    swatch.setColor(suggestion.mColor);
    String description = suggestion.mLabel;
    if (TextUtils.isEmpty(description)) {
        description = String.format("#%06X", (0xFFFFFF & suggestion.mColor));
    }
    button.setContentDescription(description);
    button.setOnClickListener(this);
}
 
Example #14
Source File: GeneratedContactPhoto.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Drawable asDrawable(Context context, int color, boolean inverted) {
  int targetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
  String character = getAbbreviation(name);

  if (!TextUtils.isEmpty(character)) {
    Drawable base = TextDrawable.builder()
                                .beginConfig()
                                .width(targetSize)
                                .height(targetSize)
                                .useFont(TYPEFACE)
                                .fontSize(ViewUtil.dpToPx(context, 24))
                                .textColor(inverted ? color : Color.WHITE)
                                .endConfig()
                                .buildRound(character, inverted ? Color.WHITE : color);

    Drawable gradient = context.getResources().getDrawable(ThemeUtil.isDarkTheme(context) ? R.drawable.avatar_gradient_dark
                                                                                          : R.drawable.avatar_gradient_light);
    return new LayerDrawable(new Drawable[] { base, gradient });
  }

  return new ResourceContactPhoto(fallbackResId).asDrawable(context, color, inverted);
}
 
Example #15
Source File: ColorPickerAdapter.java    From PhotoEditor with MIT License 6 votes vote down vote up
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, 0, 20, 20));
    biggerCircle.getPaint().setColor(colorCode);

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

    LayerDrawable layerDrawable = new LayerDrawable(drawables);

    view.setBackgroundDrawable(layerDrawable);
}
 
Example #16
Source File: BaseMapLayerDhisTransformation.java    From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Bitmap createTransformedBitmap(Bitmap cropOriginal, Bitmap staticMap) {
    Drawable[] layers = new Drawable[2];

    BitmapDrawable baseMapDrawable = new BitmapDrawable(mContext.getResources(), staticMap);
    baseMapDrawable.setGravity(Gravity.CENTER);

    BitmapDrawable mapDrawable = new BitmapDrawable(mContext.getResources(), cropOriginal);
    mapDrawable.setGravity(Gravity.CENTER);

    layers[0] = baseMapDrawable;
    layers[1] = mapDrawable;
    LayerDrawable layerDrawable = new LayerDrawable(layers);


    Bitmap transformedBitmap = Bitmap.createBitmap(
            staticMap.getWidth(), staticMap.getHeight(), Bitmap.Config.ARGB_8888);
    layerDrawable.setBounds(0, 0, staticMap.getWidth(), staticMap.getHeight());
    layerDrawable.draw(new Canvas(transformedBitmap));

    return transformedBitmap;
}
 
Example #17
Source File: RoundedDrawable.java    From Loop with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #18
Source File: ExampleListActivity.java    From UILibrary with MIT License 6 votes vote down vote up
/**
 * 苹果桌面图标下载风格的进度条
 */
private void addAppStoreStyleDrawableToList(){
    ProgressiveDrawable.DrawContentProvider appStoreProvider = new AppStoreStyleProgressProvider(0x99000000);

    final ProgressiveDrawable drawable = new ProgressiveDrawable(appStoreProvider);
    final Drawable backgroundDrawable = ContextCompat.getDrawable(this, R.drawable.test1);
    final LayerDrawable contentDrawalbe = new LayerDrawable(new Drawable[]{backgroundDrawable, drawable});
    mExampleItemList.add(new ExampleItem("AppStoreStyleDrawable", new ExampleDetailActivity.DetailContentProvider() {
        @Override
        public Object provideInstance() {
            return contentDrawalbe;
        }

        @Override
        public void onGestureMove(float x, float y, int action) {
            if(x >= -1 && x <= 1){
                drawable.setProgress(x);
            }
        }

        @Override
        public void destroy(){

        }
    }));
}
 
Example #19
Source File: ColorPickerAdapter.java    From react-native-photo-editor with Apache License 2.0 6 votes vote down vote up
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, 0, 20, 20));
    biggerCircle.getPaint().setColor(colorCode);

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

    LayerDrawable layerDrawable = new LayerDrawable(drawables);

    view.setBackgroundDrawable(layerDrawable);
}
 
Example #20
Source File: ColorPickerAdapter.java    From photo-editor-android with MIT License 6 votes vote down vote up
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, 0, 20, 20));
    biggerCircle.getPaint().setColor(colorCode);

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

    LayerDrawable layerDrawable = new LayerDrawable(drawables);

    view.setBackgroundDrawable(layerDrawable);
}
 
Example #21
Source File: WorldMapSeekBar.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private void initDrawables(@NonNull Context context)
{
    majorTick = ContextCompat.getDrawable(context, R.drawable.ic_tick);
    minorTick = ContextCompat.getDrawable(context, R.drawable.ic_tick);
    centerTick = ContextCompat.getDrawable(context, R.drawable.ic_tick_center);
    initTick(majorTick, true);
    initTick(minorTick, false);
    initTick(centerTick, true, centerTickColor);

    Drawable background = ContextCompat.getDrawable(context, R.drawable.seekbar_background);
    SuntimesUtils.tintDrawable(background, trackColor, trackColor, 0);

    Drawable secondaryProgress = new ColorDrawable(Color.TRANSPARENT);
    Drawable primaryProgress = new ScaleDrawable(new ColorDrawable(Color.TRANSPARENT), Gravity.START, 1, -1);

    LayerDrawable progressDrawable = new LayerDrawable(new Drawable[] { background, secondaryProgress, primaryProgress });
    progressDrawable.setId(0, android.R.id.background);
    progressDrawable.setId(1, android.R.id.secondaryProgress);
    progressDrawable.setId(2, android.R.id.progress);

    Rect bounds = getProgressDrawable().getBounds();
    setProgressDrawable(progressDrawable);
    getProgressDrawable().setBounds(bounds);
}
 
Example #22
Source File: PasswordGenerator.java    From Passbook with Apache License 2.0 6 votes vote down vote up
private void tintSeekBar(SeekBar sb) {
    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        if( getContext() == null) {
            return;
        }
        LayerDrawable progress = (LayerDrawable)ContextCompat.getDrawable(getContext(),
                R.drawable.progress);
        if (progress == null) {
            return;
        }
        progress.getDrawable(0).setColorFilter(C.ThemedColors[C.colorIconNormal],
                PorterDuff.Mode.SRC_ATOP);
        progress.getDrawable(1).setColorFilter(C.ThemedColors[C.colorAccent],
                PorterDuff.Mode.SRC_ATOP);
        sb.setProgressDrawable(progress);

        Drawable thumb = ContextCompat.getDrawable(getContext(), R.drawable.thumb);
        if (thumb == null) {
            return;
        }
        thumb.setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP);
        sb.setThumb(thumb);
    }
}
 
Example #23
Source File: RoundedDrawable.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #24
Source File: FloatingActionButton.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
protected void updateBackground() {
    float circleLeft = mShadowRadius;
    float circleTop = mShadowRadius - mShadowOffset;
    final RectF circleRect = new RectF(circleLeft, circleTop, circleLeft + mCircleSize, circleTop + mCircleSize);
    final LayerDrawable layerDrawable = generateFinalDrawables(circleRect);
    float iconOffset = (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2f;
    int iconInsetHorizontal = (int) (mShadowRadius + iconOffset);
    int iconInsetTop = (int) (circleTop + iconOffset);
    int iconInsetBottom = (int) (mShadowRadius + mShadowOffset + iconOffset);
    layerDrawable.setLayerInset(layerDrawable.getNumberOfLayers() - 1, iconInsetHorizontal, iconInsetTop, iconInsetHorizontal, iconInsetBottom);
    setBackgroundCompat(layerDrawable);
}
 
Example #25
Source File: FileListAdapter.java    From faceswap with Apache License 2.0 5 votes vote down vote up
private Drawable getFileDrawable(int fileResource) {
    Drawable firstLayer = mContext.getResources().getDrawable(fileResource);
    LayerDrawable drawable = new LayerDrawable(new Drawable[]{
            mContext.getResources().getDrawable(R.drawable.fplib_circle),
            firstLayer
    });

    drawable.setLayerInset(1, (int) iconPadding, (int) iconPadding,
            (int) iconPadding, (int) iconPadding);

    return drawable;
}
 
Example #26
Source File: RangeProgressBar.java    From RangeSeekBar with MIT License 5 votes vote down vote up
private static boolean needsTileify(Drawable dr) {
    if (dr instanceof LayerDrawable) {
        final LayerDrawable orig = (LayerDrawable) dr;
        final int N = orig.getNumberOfLayers();
        for (int i = 0; i < N; i++) {
            if (needsTileify(orig.getDrawable(i))) {
                logger.debug("needsTileify!");
                return true;
            }
        }
        return false;
    }

    if (dr instanceof StateListDrawable) {
        //throw new RuntimeException("StateListDrawable not supported");
        return false;
        //            final StateListDrawable in = (StateListDrawable) dr;
        //            final int N = in.getStateCount();
        //            for (int i = 0; i < N; i++) {
        //                if (needsTileify(in.getStateDrawable(i))) {
        //                    return true;
        //                }
        //            }
        //            return false;
    }

    return dr instanceof BitmapDrawable;

}
 
Example #27
Source File: FButton.java    From Trivia-Knowledge with Apache License 2.0 5 votes vote down vote up
private LayerDrawable createDrawable(int radius, int topColor, int bottomColor) {

        float[] outerRadius = new float[]{radius, radius, radius, radius, radius, radius, radius, radius};

        //Top
        RoundRectShape topRoundRect = new RoundRectShape(outerRadius, null, null);
        ShapeDrawable topShapeDrawable = new ShapeDrawable(topRoundRect);
        topShapeDrawable.getPaint().setColor(topColor);
        //Bottom
        RoundRectShape roundRectShape = new RoundRectShape(outerRadius, null, null);
        ShapeDrawable bottomShapeDrawable = new ShapeDrawable(roundRectShape);
        bottomShapeDrawable.getPaint().setColor(bottomColor);
        //Create array
        Drawable[] drawArray = {bottomShapeDrawable, topShapeDrawable};
        LayerDrawable layerDrawable = new LayerDrawable(drawArray);

        //Set shadow height
        if (isShadowEnabled && topColor != Color.TRANSPARENT) {
            //unpressed drawable
            layerDrawable.setLayerInset(0, 0, 0, 0, 0);  /*index, left, top, right, bottom*/
        } else {
            //pressed drawable
            layerDrawable.setLayerInset(0, 0, mShadowHeight, 0, 0);  /*index, left, top, right, bottom*/
        }
        layerDrawable.setLayerInset(1, 0, 0, 0, mShadowHeight);  /*index, left, top, right, bottom*/

        return layerDrawable;
    }
 
Example #28
Source File: FileRecyclerViewAdapter.java    From faceswap with Apache License 2.0 5 votes vote down vote up
private Drawable getFileDrawable(int fileResource) {
    Drawable firstLayer = context.getResources().getDrawable(fileResource);
    LayerDrawable drawable = new LayerDrawable(new Drawable[]{
            context.getResources().getDrawable(R.drawable.fplib_circle),
            firstLayer
    });

    drawable.setLayerInset(1, (int) iconPadding, (int) iconPadding,
            (int) iconPadding, (int) iconPadding);

    return drawable;
}
 
Example #29
Source File: ZProgressBar.java    From AccountBook with GNU General Public License v3.0 5 votes vote down vote up
private void createDrawable(){
    Drawable[] layers = new Drawable[2];
    Drawable background = makeBackground();
    Drawable progress = makeProgress();
    ClipDrawable clip = new ClipDrawable(progress
            , Gravity.LEFT, ClipDrawable.HORIZONTAL);
    layers[0] = background;
    layers[1] = clip;
    LayerDrawable layer = new LayerDrawable(layers);
    layer.setId(0, android.R.id.background);
    layer.setId(1, android.R.id.progress);
    setProgressDrawable(layer);
}
 
Example #30
Source File: FloatingActionButton.java    From FlowGeek with GNU General Public License v2.0 5 votes vote down vote up
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.mipmap.fab_bg_normal : R.mipmap.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);
}