Example usage for android.graphics Paint Paint

List of usage examples for android.graphics Paint Paint

Introduction

In this page you can find the example usage for android.graphics Paint Paint.

Prototype

public Paint() 

Source Link

Document

Create a new paint with default settings.

Usage

From source file:app.geochat.ui.widgets.BezelImageView.java

public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, 0);

    mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }/*from   w  w w  .ja v a  2s .  co  m*/

    mBorderDrawable = a.getDrawable(R.styleable.BezelImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress, mDesaturateOnPress);

    a.recycle();

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}

From source file:com.arisprung.tailgate.utilities.FacebookImageLoader.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);//from  ww  w .  j a  v  a2 s. c o  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    int dens = mContext.getResources().getDisplayMetrics().densityDpi;
    Bitmap _bmp = Bitmap.createScaledBitmap(output, dens / 2, dens / 2, false);
    // return _bmp;
    Bitmap bit = TailGateUtility.drawWhiteFrame(_bmp);
    return bit;
}

From source file:ee.ioc.phon.android.speak.Utils.java

/**
 * <p>Returns a bitmap that visualizes the given waveform (byte array),
 * i.e. a sequence of 16-bit integers.</p>
 *
 * TODO: show to high/low points in other color
 * TODO: show end pause data with another color
 *//*  w  ww  . j  a va  2  s.  co  m*/
public static Bitmap drawWaveform(byte[] waveBuffer, int w, int h, int start, int end) {
    final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    final Canvas c = new Canvas(b);
    final Paint paint = new Paint();
    paint.setColor(0xFFFFFFFF); // 0xRRGGBBAA
    paint.setAntiAlias(true);
    paint.setStrokeWidth(0);

    final Paint redPaint = new Paint();
    redPaint.setColor(0xFF000080);
    redPaint.setAntiAlias(true);
    redPaint.setStrokeWidth(0);

    final ShortBuffer buf = ByteBuffer.wrap(waveBuffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
    buf.position(0);

    final int numSamples = waveBuffer.length / 2;
    //final int delay = (SAMPLING_RATE * 100 / 1000);
    final int delay = 0;
    int endIndex = end / 2 + delay;
    if (end == 0 || endIndex >= numSamples) {
        endIndex = numSamples;
    }
    int index = start / 2 - delay;
    if (index < 0) {
        index = 0;
    }
    final int size = endIndex - index;
    int numSamplePerPixel = 32;
    int delta = size / (numSamplePerPixel * w);
    if (delta == 0) {
        numSamplePerPixel = size / w;
        delta = 1;
    }

    final float scale = 3.5f / 65536.0f;
    // do one less column to make sure we won't read past
    // the buffer.
    try {
        for (int i = 0; i < w - 1; i++) {
            final float x = i;
            for (int j = 0; j < numSamplePerPixel; j++) {
                final short s = buf.get(index);
                final float y = (h / 2) - (s * h * scale);
                if (s > Short.MAX_VALUE - 10 || s < Short.MIN_VALUE + 10) {
                    // TODO: make it work
                    c.drawPoint(x, y, redPaint);
                } else {
                    c.drawPoint(x, y, paint);
                }
                index += delta;
            }
        }
    } catch (IndexOutOfBoundsException e) {
        // this can happen, but we don't care
    }

    return b;
}

From source file:Main.java

/**
 * Load the image at {@code imagePath} as a {@link Bitmap}, scaling it to
 * the specified size and preserving the aspect ratio.
 * @param imagePath Path of the image to load.
 * @param width Required width of the resulting {@link Bitmap}.
 * @param height Required height of the resulting {@link Bitmap}.
 * @param fill {@code true} to fill the empty space with transparent color.
 * @param crop {@code true} to crop the image, {@code false} to resize without cutting the image.
 * @return {@link Bitmap} representing the image at {@code imagePath}.
 */// w ww . j  a v a 2  s.  c o m
public static Bitmap loadResizedBitmap(String imagePath, int width, int height, boolean fill, boolean crop) {
    Bitmap retVal;

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inSampleSize = getScale(imagePath, width, height);
    opts.inJustDecodeBounds = false;

    Bitmap image = BitmapFactory.decodeFile(imagePath, opts);

    if (image == null) {
        return null;
    }

    if (image.getWidth() != width || image.getHeight() != height) {
        //Image need to be resized.
        //         int scaledWidth = image.getWidth();
        //         int scaledHeight = image.getHeight();
        //         final float factorWidth = scaledWidth / width;
        //         final float factorHeight = scaledHeight / height;
        //final float factor = (scaledWidth / width) - (scaledHeight / height);
        //         final long factor = (scaledWidth * height) - (scaledHeight * width);
        //         if ((crop && factor > 0) || (factor < 0)) {
        //            scaledHeight = (scaledHeight * width) / scaledWidth;
        //            scaledWidth = width;
        //         } else {
        //            scaledWidth = (scaledWidth * height) / scaledHeight;
        //            scaledHeight = height;
        //         }
        int scaledWidth = (image.getWidth() * height) / image.getHeight();
        int scaledHeight; // = (image.getHeight() * width) / image.getWidth();
        if ((crop && scaledWidth > width) || (!crop && scaledWidth < width)) {
            scaledHeight = height;
        } else {
            scaledWidth = width;
            scaledHeight = (image.getHeight() * width) / image.getWidth();
        }
        //image = Bitmap.createScaledBitmap(image, scaledWidth, scaledHeight, true);

        Rect src = new Rect(0, 0, image.getWidth(), image.getHeight());
        Rect dst = new Rect(0, 0, scaledWidth, scaledHeight);

        if (fill) {
            retVal = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            dst.offset((width - scaledWidth) / 2, (height - scaledHeight) / 2);
        } else {
            retVal = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
        }
        retVal.eraseColor(Color.TRANSPARENT);

        synchronized (canvas) {
            if (antiAliasPaint == null) {
                antiAliasPaint = new Paint();
                antiAliasPaint.setAntiAlias(true);
                antiAliasPaint.setFilterBitmap(true);
                antiAliasPaint.setDither(true);
            }
            canvas.setBitmap(retVal);
            canvas.drawBitmap(image, src, dst, antiAliasPaint);
        }

        image.recycle();
    } else {
        //No need to scale.
        retVal = image;
    }

    return retVal;
}

From source file:arun.com.chromer.browsing.article.view.ElasticDragDismissFrameLayout.java

private void init() {
    dragDismissDistance = getResources().getDimensionPixelSize(R.dimen.article_drag_down_dismiss_distance);

    shouldScale = dragDismissScale != 1f;

    draggingBackgroundPaint = new Paint();
    draggingBackgroundPaint/*  ww w . j a  va 2s  . c om*/
            .setColor(getContext().getResources().getColor(R.color.article_transparentSideBackground));
    draggingBackgroundPaint.setStyle(Paint.Style.FILL);
}

From source file:com.graphics.FingerPaint.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // /////////////
    aChatApp = (MyaChatApplication) getApplication();
    xmppManager = aChatApp.getXmppManager();
    connection = xmppManager.returnConnection();
    secondUser = getIntent().getExtras().getString("username").toString();
    Log.d(TAG, "got user is:" + secondUser);
    // start listening to new msg

    mPaint = new Paint();
    mPaint.setAntiAlias(true);//from   www .  j a  v  a  2 s  .c o  m
    mPaint.setDither(true);
    mPaint.setColor(0xFFFF0000);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(12);

    mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);

    mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
    // setContentView(new MyView(this));
    myView = new MyView(this);
    // final MyView myView = new MyView(this);
    // myView.fingerPaintMsgListener();
    setContentView(myView);

    // startListenter();

    localCoArray = new LocalCoArray(mPaint.getColor());

    // //////////////////

}

From source file:foam.jellyfish.StarwispCanvas.java

@Override
public void onDraw(Canvas canvas) {
    float sx = getWidth() / 320.0f;
    float sy = getHeight() / 200.0f;

    Paint myPaint = new Paint();
    myPaint.setStrokeWidth(0);//from  www  .ja v  a  2  s. c om
    myPaint.setColor(Color.rgb(127, 127, 127));
    canvas.drawRect(0, 0, getWidth(), getHeight(), myPaint);

    try {
        for (int i = 0; i < m_Drawlist.length(); i++) {
            JSONArray prim = m_Drawlist.getJSONArray(i);
            if (prim.getString(0).equals("line")) {
                DrawLine(canvas, prim, sx, sy);
            }
            if (prim.getString(0).equals("text")) {
                DrawText(canvas, prim, sx, sy);
            }
        }
    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing data " + e.toString());
    }
}

From source file:ar.uba.fi.splitapp.MockServer.java

private static Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.RED;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);// ww w  .j  a va  2 s . c o  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    bitmap.recycle();

    return output;
}

From source file:com.example.google.maps.dataviz.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // The gradient for colouring the markers.
    Shader shader = new LinearGradient(0, 0, 0, MARKER_HEIGHT - 1, new int[] { Color.BLUE, Color.RED }, null,
            TileMode.CLAMP);/*from  ww w  .j ava  2  s  .  c  o  m*/
    mPaint = new Paint();
    mPaint.setShader(shader);

    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    if (mMap != null) {
        setUpMap();
    }
}

From source file:angeloid.dreamnarae.SwipeyTabs.java

/**
 * Initialize the SwipeyTabs {@link ViewGroup}
 *//* w  w w  . j av  a  2s. c om*/
private void init() {
    // enable the horizontal fading edges which will be drawn by the parent
    // View
    setHorizontalFadingEdgeEnabled(true);
    setFadingEdgeLength((int) (getResources().getDisplayMetrics().density * 35.0f + 0.5f));
    setWillNotDraw(false);

    mCachedTabPaint = new Paint();
    mCachedTabPaint.setColor(mBottomBarColor);
}