use of android.graphics.drawable.shapes.OvalShape in project RecyclerRefreshLayout by dinuscxj.
the class MaterialRefreshView method initBackground.
private void initBackground(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);
final int color = Color.parseColor("#FFFAFAFA");
mShadowRadius = (int) (density * SHADOW_RADIUS);
ShapeDrawable circle;
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);
}
use of android.graphics.drawable.shapes.OvalShape in project android-floating-action-button by futuresimple.
the class FloatingActionButton method createInnerStrokesDrawable.
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
if (!mStrokeVisible) {
return new ColorDrawable(Color.TRANSPARENT);
}
ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
final int bottomStrokeColor = darkenColor(color);
final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
final int topStrokeColor = lightenColor(color);
final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
final Paint paint = shapeDrawable.getPaint();
paint.setAntiAlias(true);
paint.setStrokeWidth(strokeWidth);
paint.setStyle(Style.STROKE);
shapeDrawable.setShaderFactory(new ShaderFactory() {
@Override
public Shader resize(int width, int height) {
return new LinearGradient(width / 2, 0, width / 2, height, new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor }, new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }, TileMode.CLAMP);
}
});
return shapeDrawable;
}
use of android.graphics.drawable.shapes.OvalShape in project android-floating-action-button by futuresimple.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.pink_icon).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Clicked pink Floating Action Button", Toast.LENGTH_SHORT).show();
}
});
FloatingActionButton button = (FloatingActionButton) findViewById(R.id.setter);
button.setSize(FloatingActionButton.SIZE_MINI);
button.setColorNormalResId(R.color.pink);
button.setColorPressedResId(R.color.pink_pressed);
button.setIcon(R.drawable.ic_fab_star);
button.setStrokeVisible(false);
final View actionB = findViewById(R.id.action_b);
FloatingActionButton actionC = new FloatingActionButton(getBaseContext());
actionC.setTitle("Hide/Show Action above");
actionC.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
actionB.setVisibility(actionB.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
}
});
final FloatingActionsMenu menuMultipleActions = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
menuMultipleActions.addButton(actionC);
final FloatingActionButton removeAction = (FloatingActionButton) findViewById(R.id.button_remove);
removeAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
((FloatingActionsMenu) findViewById(R.id.multiple_actions_down)).removeButton(removeAction);
}
});
ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
drawable.getPaint().setColor(getResources().getColor(R.color.white));
((FloatingActionButton) findViewById(R.id.setter_drawable)).setIconDrawable(drawable);
final FloatingActionButton actionA = (FloatingActionButton) findViewById(R.id.action_a);
actionA.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
actionA.setTitle("Action A clicked");
}
});
// Test that FAMs containing FABs with visibility GONE do not cause crashes
findViewById(R.id.button_gone).setVisibility(View.GONE);
final FloatingActionButton actionEnable = (FloatingActionButton) findViewById(R.id.action_enable);
actionEnable.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
menuMultipleActions.setEnabled(!menuMultipleActions.isEnabled());
}
});
FloatingActionsMenu rightLabels = (FloatingActionsMenu) findViewById(R.id.right_labels);
FloatingActionButton addedOnce = new FloatingActionButton(this);
addedOnce.setTitle("Added once");
rightLabels.addButton(addedOnce);
FloatingActionButton addedTwice = new FloatingActionButton(this);
addedTwice.setTitle("Added twice");
rightLabels.addButton(addedTwice);
rightLabels.removeButton(addedTwice);
rightLabels.addButton(addedTwice);
}
use of android.graphics.drawable.shapes.OvalShape in project android-maps-utils by googlemaps.
the class DefaultClusterRenderer method makeClusterBackground.
private LayerDrawable makeClusterBackground() {
mColoredCircleBackground = new ShapeDrawable(new OvalShape());
ShapeDrawable outline = new ShapeDrawable(new OvalShape());
// Transparent white.
outline.getPaint().setColor(0x80ffffff);
LayerDrawable background = new LayerDrawable(new Drawable[] { outline, mColoredCircleBackground });
int strokeWidth = (int) (mDensity * 3);
background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
return background;
}
use of android.graphics.drawable.shapes.OvalShape in project uk.co.jasonfry.android.tools by jsonfry.
the class PageControl method initPageControl.
private void initPageControl() {
Log.i("uk.co.jasonfry.android.tools.ui.PageControl", "Initialising PageControl");
indicators = new ArrayList<ImageView>();
activeDrawable = new ShapeDrawable();
inactiveDrawable = new ShapeDrawable();
activeDrawable.setBounds(0, 0, mIndicatorSize, mIndicatorSize);
inactiveDrawable.setBounds(0, 0, mIndicatorSize, mIndicatorSize);
Shape s1 = new OvalShape();
s1.resize(mIndicatorSize, mIndicatorSize);
Shape s2 = new OvalShape();
s2.resize(mIndicatorSize, mIndicatorSize);
int[] i = new int[2];
i[0] = android.R.attr.textColorSecondary;
i[1] = android.R.attr.textColorSecondaryInverse;
TypedArray a = mContext.getTheme().obtainStyledAttributes(i);
((ShapeDrawable) activeDrawable).getPaint().setColor(a.getColor(0, Color.DKGRAY));
((ShapeDrawable) inactiveDrawable).getPaint().setColor(a.getColor(1, Color.LTGRAY));
((ShapeDrawable) activeDrawable).setShape(s1);
((ShapeDrawable) inactiveDrawable).setShape(s2);
mIndicatorSize = (int) (mIndicatorSize * getResources().getDisplayMetrics().density);
setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (mOnPageControlClickListener != null) {
switch(event.getAction()) {
case MotionEvent.ACTION_UP:
if (PageControl.this.getOrientation() == LinearLayout.HORIZONTAL) {
if (//if on left of view
event.getX() < (PageControl.this.getWidth() / 2)) {
if (mCurrentPage > 0) {
mOnPageControlClickListener.goBackwards();
}
} else //if on right of view
{
if (mCurrentPage < (mPageCount - 1)) {
mOnPageControlClickListener.goForwards();
}
}
} else {
if (//if on top half of view
event.getY() < (PageControl.this.getHeight() / 2)) {
if (mCurrentPage > 0) {
mOnPageControlClickListener.goBackwards();
}
} else //if on bottom half of view
{
if (mCurrentPage < (mPageCount - 1)) {
mOnPageControlClickListener.goForwards();
}
}
}
return false;
}
}
return true;
}
});
}
Aggregations