List of usage examples for android.graphics.drawable ShapeDrawable ShapeDrawable
public ShapeDrawable(Shape s)
From source file:com.justplay1.shoppist.shared.widget.animboxes.SelectBoxView.java
private void init(Context context) { inflate(context, R.layout.view_select_box, this); ButterKnife.bind(this); mainView.setOnClickListener(this); OvalShape ovalShape = new OvalShape(); shapeDrawable = new ShapeDrawable(ovalShape); dimen = getResources().getDimensionPixelSize(R.dimen.select_box_check); selectedStateColor = ContextCompat.getColor(context, R.color.action_mode_toolbar_color); toMiddleAnimation = AnimationUtils.loadAnimation(context, R.anim.to_middle); toMiddleAnimation.setAnimationListener(this); fromMiddleAnimation = AnimationUtils.loadAnimation(context, R.anim.from_middle); zoomAnimation = AnimationUtils.loadAnimation(context, R.anim.zoom); zoomAnimation.setAnimationListener(new Animation.AnimationListener() { @Override/* w w w .j a va 2s.c o m*/ public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); }
From source file:ru.gkpromtech.exhibition.utils.CircleImageView.java
private void sharedConstructor(int color, final float radius) { final float density = getContext().getResources().getDisplayMetrics().density; final int diameter = (int) (radius * density * 2); final int shadowYOffset = (int) (density * Y_OFFSET); final int shadowXOffset = (int) (density * X_OFFSET); mShadowRadius = (int) (density * SHADOW_RADIUS); ShapeDrawable circle;//from w ww . ja va 2s. co m if (elevationSupported()) { circle = new ShapeDrawable(new OvalShape()); ViewCompat.setElevation(this, SHADOW_ELEVATION * density); } else { OvalShape oval = new OvalShadow(mShadowRadius, diameter); circle = new ShapeDrawable(oval); ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint()); circle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR); final int padding = (int) mShadowRadius; // set padding so the inner image sits correctly within the shadow. setPadding(padding, padding, padding, padding); } circle.getPaint().setColor(color); setBackground(circle); }
From source file:gov.sfmta.sfpark.AnnotationsOverlay.java
public AnnotationsOverlay(Drawable defaultMarker, Context context) { super(boundCenterBottom(defaultMarker)); mContext = context;/*www. j ava 2s . c om*/ iconArray = new Drawable[8]; ShapeDrawable invisible = new ShapeDrawable(new RectShape()); invisible.getPaint().setColor(0x00000000); iconArray[0] = invisible; iconArray[1] = mContext.getResources().getDrawable(R.drawable.invalid_garage); iconArray[2] = mContext.getResources().getDrawable(R.drawable.garage_availability_high); iconArray[3] = mContext.getResources().getDrawable(R.drawable.garage_availability_medium); iconArray[4] = mContext.getResources().getDrawable(R.drawable.garage_availability_low); iconArray[5] = mContext.getResources().getDrawable(R.drawable.garage_price_low); iconArray[6] = mContext.getResources().getDrawable(R.drawable.garage_price_medium); iconArray[7] = mContext.getResources().getDrawable(R.drawable.garage_price_high); boundCenterBottom(iconArray[0]); boundCenterBottom(iconArray[1]); boundCenterBottom(iconArray[2]); boundCenterBottom(iconArray[3]); boundCenterBottom(iconArray[4]); boundCenterBottom(iconArray[5]); boundCenterBottom(iconArray[6]); boundCenterBottom(iconArray[7]); action = 0; last_action = 0; }
From source file:com.tiancaicc.springfloatingactionmenu.MenuItemView.java
private void init(Context context, boolean hasMargin) { Resources resources = getResources(); int diameterPX = Utils.dpToPx(mMenuItem.getDiameter(), resources); this.mDiameter = diameterPX; mBtn = new ImageButton(context); mBtn.setScaleType(ImageView.ScaleType.FIT_CENTER); if (hasMargin) { int p = Util.dpToPx(12, getResources()); mBtn.setPadding(p, p, p, p);/*from w w w .j ava 2s . c o m*/ } LayoutParams btnLp = new LayoutParams(diameterPX, diameterPX); btnLp.gravity = Gravity.CENTER_HORIZONTAL; btnLp.bottomMargin = Util.dpToPx(mGapSize, resources); mBtn.setLayoutParams(btnLp); OvalShape ovalShape = new OvalShape(); ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape); shapeDrawable.getPaint().setColor(resources.getColor(mMenuItem.getBgColor())); mBtn.setBackgroundDrawable(shapeDrawable); if (TextUtils.isEmpty(mMenuItem.getIconFilePath())) { mBtn.setImageResource(mMenuItem.getIcon()); } else { mBtn.setImageURI(Uri.fromFile(new File(mMenuItem.getIconFilePath()))); } mBtn.setClickable(false); addView(mBtn); mLabel = (com.github.omadahealth.typefaceview.TypefaceTextView) View.inflate(getContext(), R.layout.c_text_view, null); mLabel.setPaintFlags(mLabel.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); mLabel.setTextIsSelectable(false); LayoutParams labelLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); labelLp.gravity = Gravity.CENTER_HORIZONTAL; mLabel.setLayoutParams(labelLp); if (!TextUtils.isEmpty(mMenuItem.getLabel())) { mLabel.setPadding(0, Util.dpToPx(70, getResources()), 0, 0); Drawable bottomArrow = ContextCompat.getDrawable(getContext(), R.drawable.ic_arrow); mLabel.setCompoundDrawablesWithIntrinsicBounds(null, null, null, bottomArrow); } mLabel.setText(mMenuItem.getLabel()); mLabel.setTextColor(resources.getColor(mMenuItem.getTextColor())); // mLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTextSize); addView(mLabel); setOrientation(LinearLayout.VERTICAL); if (mAlphaAnimation) { setAlpha(0); } getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { getViewTreeObserver().removeGlobalOnLayoutListener(this); applyPressAnimation(); ViewGroup parent = (ViewGroup) getParent(); parent.setClipChildren(false); parent.setClipToPadding(false); setClipChildren(false); setClipToPadding(false); } }); }
From source file:org.opensilk.common.ui.widget.ColorCodedThumbnail.java
public void init(String title) { Integer color = null;/*from w w w . j a v a 2 s.c o m*/ if (!TextUtils.isEmpty(title)) { if (title.equals("..")) { setText(title); color = R.color.red; } else { Character c = title.toUpperCase(Locale.US).charAt(0); setText(c.toString()); if (c.compareTo('A') >= 0 && c.compareTo('Z') <= 0) { color = COLORS.get(c); } else if (c.compareTo('0') >= 0 && c.compareTo('9') <= 0) { color = COLORS.get(COLORS.keyAt(Integer.valueOf(c.toString()))); } } } if (color == null) { color = R.color.gray; } ShapeDrawable bg = new ShapeDrawable(new OvalShape()); bg.getPaint().setColor(getResources().getColor(color)); setBackgroundDrawable(bg); }
From source file:com.justplay1.shoppist.features.search.SearchAdapter.java
@Override public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { SearchViewHolder holder = (SearchViewHolder) viewHolder; ProductViewModel item = getItem(position); holder.text1.setText(item.getName()); OvalShape ovalShape = new OvalShape(); ShapeDrawable drawable = new ShapeDrawable(ovalShape); drawable.getPaint().setColor(item.getCategory().getColor()); ViewUtils.setBackground(holder.typeIcon, drawable); if (!item.getId().equals(SearchView.JUST_NAME)) { holder.text2.setText(item.getCategory().getName()); } else {// w w w.ja v a 2s .co m holder.text2.setVisibility(View.GONE); } switch (contextType) { case Const.CONTEXT_QUICK_ADD_GOODS_TO_LIST: ViewUtils.setBackground(holder.iconEnd, iconEndDrawable); break; case Const.CONTEXT_QUICK_SEARCH_IN_GOODS_LIST: holder.iconEnd.setVisibility(View.GONE); break; } }
From source file:com.wudoumi.battertest.view.CircleImageView.java
private void init(int color, final float radius) { final float density = getContext().getResources().getDisplayMetrics().density; final int diameter = (int) (radius * density * 2); final int shadowYOffset = (int) (density * Y_OFFSET); final int shadowXOffset = (int) (density * X_OFFSET); mShadowRadius = (int) (density * SHADOW_RADIUS); ShapeDrawable circle;// ww w . j av a2 s . com if (elevationSupported()) { circle = new ShapeDrawable(new OvalShape()); ViewCompat.setElevation(this, SHADOW_ELEVATION * density); } else { OvalShape oval = new OvalShadow(mShadowRadius, diameter); circle = new ShapeDrawable(oval); ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint()); circle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR); final int padding = mShadowRadius; // set padding so the inner image sits correctly within the shadow. setPadding(padding, padding, padding, padding); } circle.getPaint().setColor(color); setBackgroundDrawable(circle); }
From source file:android.support.v7.widget.AppCompatProgressBarHelper.java
/** * Converts a drawable to a tiled version of itself. It will recursively * traverse layer and state list drawables. *///from w w w . ja v a 2 s.c o m private Drawable tileify(Drawable drawable, boolean clip) { if (drawable instanceof DrawableWrapper) { Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable(); if (inner != null) { inner = tileify(inner, clip); ((DrawableWrapper) drawable).setWrappedDrawable(inner); } } else if (drawable instanceof LayerDrawable) { LayerDrawable background = (LayerDrawable) drawable; final int N = background.getNumberOfLayers(); Drawable[] outDrawables = new Drawable[N]; for (int i = 0; i < N; i++) { int id = background.getId(i); outDrawables[i] = tileify(background.getDrawable(i), (id == android.R.id.progress || id == android.R.id.secondaryProgress)); } LayerDrawable newBg = new LayerDrawable(outDrawables); for (int i = 0; i < N; i++) { newBg.setId(i, background.getId(i)); } return newBg; } else if (drawable instanceof BitmapDrawable) { final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; final Bitmap tileBitmap = bitmapDrawable.getBitmap(); if (mSampleTile == null) { mSampleTile = tileBitmap; } final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape()); final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP); shapeDrawable.getPaint().setShader(bitmapShader); shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter()); return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable; } return drawable; }
From source file:org.mariotaku.twidere.view.HomeActionButton.java
@Override public void setButtonColor(int color) { if (isInEditMode()) { final ShapeDrawable sd = new ShapeDrawable(new OvalShape()); sd.getPaint().setColor(color);// www . j a v a 2s.c o m ViewSupport.setBackground(this, sd); } else { ViewSupport.setBackground(this, new ColorDrawable(color)); } }
From source file:com.ashlikun.badgeview.BadgeView.java
public void setBackground(int radius, int badgeColor) { if (radius <= 0 || (this.radius == radius && bvColor == badgeColor)) { return;/*ww w .ja va 2 s . c om*/ } bvColor = badgeColor; this.radius = radius; float[] radiusArray = new float[] { radius, radius, radius, radius, radius, radius, radius, radius }; RoundRectShape roundRect = new RoundRectShape(radiusArray, null, null); ShapeDrawable bgDrawable = new ShapeDrawable(roundRect); bgDrawable.getPaint().setColor(badgeColor); setBackgroundDrawable(bgDrawable); }