Search in sources :

Example 21 with OvalShape

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);
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape) Paint(android.graphics.Paint)

Example 22 with OvalShape

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;
}
Also used : LinearGradient(android.graphics.LinearGradient) ShaderFactory(android.graphics.drawable.ShapeDrawable.ShaderFactory) ColorDrawable(android.graphics.drawable.ColorDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape) Shader(android.graphics.Shader) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 23 with OvalShape

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);
}
Also used : FloatingActionsMenu(com.getbase.floatingactionbutton.FloatingActionsMenu) OnClickListener(android.view.View.OnClickListener) FloatingActionButton(com.getbase.floatingactionbutton.FloatingActionButton) ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape) View(android.view.View)

Example 24 with OvalShape

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;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape) Point(com.google.maps.android.geometry.Point) SuppressLint(android.annotation.SuppressLint)

Example 25 with OvalShape

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;
        }
    });
}
Also used : OvalShape(android.graphics.drawable.shapes.OvalShape) Shape(android.graphics.drawable.shapes.Shape) TypedArray(android.content.res.TypedArray) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ImageView(android.widget.ImageView) OvalShape(android.graphics.drawable.shapes.OvalShape) ImageView(android.widget.ImageView) View(android.view.View) MotionEvent(android.view.MotionEvent)

Aggregations

OvalShape (android.graphics.drawable.shapes.OvalShape)44 ShapeDrawable (android.graphics.drawable.ShapeDrawable)40 Paint (android.graphics.Paint)17 SuppressLint (android.annotation.SuppressLint)10 StateListDrawable (android.graphics.drawable.StateListDrawable)8 ColorDrawable (android.graphics.drawable.ColorDrawable)7 LayerDrawable (android.graphics.drawable.LayerDrawable)7 Drawable (android.graphics.drawable.Drawable)5 ImageView (android.widget.ImageView)5 LinearGradient (android.graphics.LinearGradient)3 Shader (android.graphics.Shader)3 ShaderFactory (android.graphics.drawable.ShapeDrawable.ShaderFactory)3 View (android.view.View)3 Bitmap (android.graphics.Bitmap)2 Rect (android.graphics.Rect)2 RectF (android.graphics.RectF)2 RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 LinearInterpolator (android.view.animation.LinearInterpolator)2 RelativeLayout (android.widget.RelativeLayout)2