Android Open Source - our_days Custom Shape Image View






From Project

Back to project page our_days.

License

The source code is released under:

Apache License

If you think the Android project our_days listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.meg7.widget;
/*from   ww w.  ja v  a2 s  .  co  m*/
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.util.AttributeSet;

/**
 * Created by Mostafa Gazar on 11/2/13.
 */
public class CustomShapeImageView extends BaseImageView {

    public static class Shape {
        public static final int CIRCLE = 1;
        public static final int RECTANGLE = 2;
        public static final int SVG    = 3;
    }

    private int mShape = Shape.CIRCLE;
    private int mSvgRawResourceId;

    public CustomShapeImageView(Context context) {
        super(context);
    }

    public CustomShapeImageView(Context context, int resourceId, int shape, int svgRawResourceId) {
        this(context);

        setImageResource(resourceId);
        mShape = shape;
        mSvgRawResourceId = svgRawResourceId;
    }

    public CustomShapeImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        sharedConstructor(context, attrs);
    }

    public CustomShapeImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        sharedConstructor(context, attrs);
    }

    private void sharedConstructor(Context context, AttributeSet attrs) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomShapeImageView);
        mShape = a.getInt(R.styleable.CustomShapeImageView_shape, Shape.CIRCLE);
        mSvgRawResourceId = a.getResourceId(R.styleable.CustomShapeImageView_svg_raw_resource, 0);
        a.recycle();
    }

    @Override
    public Bitmap getBitmap() {
        switch (mShape) {
            case Shape.CIRCLE:
                return CircleImageView.getBitmap(getWidth(), getHeight());
            case Shape.RECTANGLE:
                return RectangleImageView.getBitmap(getWidth(), getHeight());
            case Shape.SVG:
                return SvgImageView.getBitmap(mContext, getWidth(), getHeight(), mSvgRawResourceId);
        }
        return null;
    }

}




Java Source Code List

com.meg7.widget.BaseImageView.java
com.meg7.widget.CircleImageView.java
com.meg7.widget.CustomShapeImageView.java
com.meg7.widget.CustomShapeSquareImageView.java
com.meg7.widget.RectangleImageView.java
com.meg7.widget.SvgImageView.java
com.svgandroid.ParserHelper.java
com.svgandroid.SVGParseException.java
com.svgandroid.SVGParser.java
com.svgandroid.SVG.java
com.yemyatthu.ourdays.activity.MyConfigActivity.java
com.yemyatthu.ourdays.fragment.MyConfigFragment.java
com.yemyatthu.ourdays.widget.LoveWidgetProvider.java