Example usage for android.graphics Paint ANTI_ALIAS_FLAG

List of usage examples for android.graphics Paint ANTI_ALIAS_FLAG

Introduction

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

Prototype

int ANTI_ALIAS_FLAG

To view the source code for android.graphics Paint ANTI_ALIAS_FLAG.

Click Source Link

Document

Paint flag that enables antialiasing when drawing.

Usage

From source file:de.treichels.hott.ui.android.html.AndroidCurveImageGenerator.java

private Bitmap getBitmap(final Curve curve, final float scale, final boolean description) {
    final boolean pitchCurve = curve.getPoint()[0].getPosition() == 0;
    final float scale1 = scale * 0.75f; // smaller images on the android
    // platform/*w w w . jav a2  s.  c  o m*/

    final Bitmap image = Bitmap.createBitmap((int) (10 + 200 * scale1), (int) (10 + 250 * scale1),
            Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(image);

    final Paint backgroundPaint = new Paint();
    backgroundPaint.setColor(Color.WHITE);
    backgroundPaint.setStyle(Style.FILL);

    final Paint forgroundPaint = new Paint();
    forgroundPaint.setColor(Color.BLACK);
    forgroundPaint.setStyle(Style.STROKE);
    forgroundPaint.setStrokeWidth(1.0f);
    forgroundPaint.setStrokeCap(Cap.BUTT);
    forgroundPaint.setStrokeJoin(Join.ROUND);
    forgroundPaint.setStrokeMiter(0.0f);

    final Paint curvePaint = new Paint(forgroundPaint);
    curvePaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    curvePaint.setStrokeWidth(2.0f);

    final Paint pointPaint = new Paint(curvePaint);
    pointPaint.setStrokeWidth(5.0f);
    pointPaint.setStyle(Style.FILL_AND_STROKE);

    final Paint helpLinePaint = new Paint(forgroundPaint);
    helpLinePaint.setColor(Color.GRAY);
    helpLinePaint.setPathEffect(new DashPathEffect(new float[] { 5.0f, 5.0f }, 2.5f));

    final Paint textPaint = new Paint(forgroundPaint);
    textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
    textPaint.setTextSize(12.0f);
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setStyle(Style.FILL);

    canvas.drawRect(0, 0, 10 + 200 * scale1, 10 + 250 * scale1, backgroundPaint);
    canvas.drawRect(5, 5, 5 + 200 * scale1, 5 + 250 * scale1, forgroundPaint);

    canvas.drawLine(5, 5 + 25 * scale1, 5 + 200 * scale1, 5 + 25 * scale1, helpLinePaint);
    canvas.drawLine(5, 5 + 225 * scale1, 5 + 200 * scale1, 5 + 225 * scale1, helpLinePaint);
    if (!pitchCurve) {
        canvas.drawLine(5, 5 + 125 * scale1, 5 + 200 * scale1, 5 + 125 * scale1, helpLinePaint);
        canvas.drawLine(5 + 100 * scale1, 5, 5 + 100 * scale1, 5 + 250 * scale1, helpLinePaint);
    }

    if (curve.getPoint() != null) {
        int numPoints = 0;
        for (final CurvePoint p : curve.getPoint()) {
            if (p.isEnabled()) {
                numPoints++;
            }
        }

        final double[] xVals = new double[numPoints];
        final double[] yVals = new double[numPoints];

        int i = 0;
        for (final CurvePoint p : curve.getPoint()) {
            if (p.isEnabled()) {
                if (i == 0) {
                    xVals[i] = pitchCurve ? 0 : -100;
                } else if (i == numPoints - 1) {
                    xVals[i] = 100;
                } else {
                    xVals[i] = p.getPosition();
                }
                yVals[i] = p.getValue();

                if (description) {
                    float x0;
                    float y0;
                    if (pitchCurve) {
                        x0 = (float) (5 + xVals[i] * 2 * scale1);
                        y0 = (float) (5 + (225 - yVals[i] * 2) * scale1);
                    } else {
                        x0 = (float) (5 + (100 + xVals[i]) * scale1);
                        y0 = (float) (5 + (125 - yVals[i]) * scale1);
                    }

                    canvas.drawPoint(x0, y0, pointPaint);
                    if (y0 < 5 + 125 * scale1) {
                        canvas.drawRect(x0 - 4, y0 + 5, x0 + 3, y0 + 18, backgroundPaint);
                        canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 + 16, textPaint);
                    } else {
                        canvas.drawRect(x0 - 4, y0 - 5, x0 + 3, y0 - 18, backgroundPaint);
                        canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 - 7, textPaint);
                    }
                }

                i++;
            }
        }

        if (numPoints > 2 && curve.isSmoothing()) {
            final SplineInterpolator s = new SplineInterpolator();
            final PolynomialSplineFunction function = s.interpolate(xVals, yVals);

            float x0 = 5;
            float y0;
            if (pitchCurve) {
                y0 = (float) (5 + (225 - yVals[0] * 2) * scale1);
            } else {
                y0 = (float) (5 + (125 - yVals[0]) * scale1);
            }

            while (x0 < 4 + 200 * scale1) {
                final float x1 = x0 + 1;
                float y1;
                if (pitchCurve) {
                    y1 = (float) (5 + (225 - function.value((x1 - 5) / scale1 / 2) * 2) * scale1);
                } else {
                    y1 = (float) (5 + (125 - function.value((x1 - 5) / scale1 - 100)) * scale1);
                }

                canvas.drawLine(x0, y0, x1, y1, curvePaint);

                x0 = x1;
                y0 = y1;
            }
        } else {
            for (i = 0; i < numPoints - 1; i++) {
                float x0, y0, x1, y1;

                if (pitchCurve) {
                    x0 = (float) (5 + xVals[i] * 2 * scale1);
                    y0 = (float) (5 + (225 - yVals[i] * 2) * scale1);

                    x1 = (float) (5 + xVals[i + 1] * 2 * scale1);
                    y1 = (float) (5 + (225 - yVals[i + 1] * 2) * scale1);
                } else {
                    x0 = (float) (5 + (100 + xVals[i]) * scale1);
                    y0 = (float) (5 + (125 - yVals[i]) * scale1);

                    x1 = (float) (5 + (100 + xVals[i + 1]) * scale1);
                    y1 = (float) (5 + (125 - yVals[i + 1]) * scale1);
                }

                canvas.drawLine(x0, y0, x1, y1, curvePaint);
            }
        }
    }

    return image;
}

From source file:com.example.hemantsaini.my_notes.DividerItemDecoration.java

private void init() {
    padding = mContext.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);
    updatePaddint();//from  w  ww  .  j av  a 2  s.com
    dividerHeight = DEFAULT_DIVIDER_HEIGHT;

    mPaddingPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaddingPaint.setColor(ContextCompat.getColor(mContext, android.R.color.white));
    mPaddingPaint.setStyle(Paint.Style.FILL);

    mDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDividerPaint.setColor(ContextCompat.getColor(mContext, android.R.color.darker_gray));
    mDividerPaint.setStyle(Paint.Style.FILL);
}

From source file:com.loopeer.codereader.ui.decoration.DividerItemDecoration.java

private void init() {
    padding = mContext.getResources().getDimensionPixelSize(R.dimen.medium_padding);
    updatePaddint();//  www  . jav  a 2s. c  om
    dividerHeight = DEFAULT_DIVIDER_HEIGHT;

    mPaddingPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaddingPaint.setColor(ContextCompat.getColor(mContext, R.color.item_background));
    mPaddingPaint.setStyle(Paint.Style.FILL);

    mDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDividerPaint.setColor(ContextCompat.getColor(mContext, R.color.color_divider));
    mDividerPaint.setStyle(Paint.Style.FILL);
}

From source file:cn.bingoogolapple.refreshlayout.BGAStickinessRefreshView.java

private void initPaint() {
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPath = new Path();
}

From source file:com.Duo.music.player.Dialogs.CustomizeScreensDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    parentActivity = getActivity();//from  w  w w . j  a v  a2  s.  c o  m
    dialogFragment = (DialogFragment) getFragmentManager().findFragmentByTag("customizeScreensDialog");

    sharedPreferences = parentActivity.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE);

    rootView = (View) parentActivity.getLayoutInflater().inflate(R.layout.customize_screens_layout, null);

    customizeScreensText = (TextView) rootView.findViewById(R.id.customize_screens_text);
    customizeScreensText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    customizeScreensText.setPaintFlags(
            customizeScreensText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    //Populate the arraylists with the settings saved in SharedPreferences.
    page1 = sharedPreferences.getString("PAGE_1", getResources().getString(R.string.artists_caps));
    page2 = sharedPreferences.getString("PAGE_2", getResources().getString(R.string.albums_caps));
    page3 = sharedPreferences.getString("PAGE_3", getResources().getString(R.string.songs_caps));
    page4 = sharedPreferences.getString("PAGE_4", getResources().getString(R.string.playlists_caps));
    page5 = sharedPreferences.getString("PAGE_5", getResources().getString(R.string.genres_caps));
    page6 = sharedPreferences.getString("PAGE_6", getResources().getString(R.string.folders_caps));

    if (!page1.equals("null") || !page1.equals(null)) {
        screenTitlesList.add(page1);
    }

    if (!page2.equals("null") || !page2.equals(null)) {
        screenTitlesList.add(page2);
    }

    if (!page3.equals("null") || !page3.equals(null)) {
        screenTitlesList.add(page3);
    }

    if (!page4.equals("null") || !page4.equals(null)) {
        screenTitlesList.add(page4);
    }

    if (!page5.equals("null") || !page5.equals(null)) {
        screenTitlesList.add(page5);
    }

    if (!page6.equals("null") || !page6.equals(null)) {
        screenTitlesList.add(page6);
    }

    listView = (DragSortListView) rootView.findViewById(R.id.customize_screens_listview);
    adapter = new CustomizeScreensListAdapter(parentActivity, screenTitlesList);
    listView.setAdapter(adapter);
    listView.setDropListener(onDrop);
    SimpleFloatViewManager simpleFloatViewManager = new SimpleFloatViewManager(listView);
    simpleFloatViewManager.setBackgroundColor(Color.TRANSPARENT);
    listView.setFloatViewManager(simpleFloatViewManager);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    //Set the dialog title.
    builder.setTitle(R.string.customize_screens);
    builder.setView(rootView);
    builder.setPositiveButton(R.string.done, new OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            dialogFragment.dismiss();

            //adapter.getItem(i) will get us the order for the screens.
            sharedPreferences.edit().putString("PAGE_1", adapter.getItem(0).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_2", adapter.getItem(1).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_3", adapter.getItem(2).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_4", adapter.getItem(3).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_5", adapter.getItem(4).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_6", adapter.getItem(5).toString().toUpperCase()).commit();

            Toast.makeText(parentActivity, R.string.changes_saved, Toast.LENGTH_SHORT).show();

            //Restart the app.
            Intent i = parentActivity.getBaseContext().getPackageManager()
                    .getLaunchIntentForPackage(parentActivity.getBaseContext().getPackageName());

            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            dialogFragment.dismiss();
            getActivity().finish();
            startActivity(i);

        }

    });

    return builder.create();
}

From source file:com.jelly.music.player.Dialogs.CustomizeScreensDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    parentActivity = getActivity();// ww w .  j a  v a  2  s.  c  om
    dialogFragment = (DialogFragment) getFragmentManager().findFragmentByTag("customizeScreensDialog");

    sharedPreferences = parentActivity.getSharedPreferences("com.jelly.music.player", Context.MODE_PRIVATE);

    rootView = (View) parentActivity.getLayoutInflater().inflate(R.layout.customize_screens_layout, null);

    customizeScreensText = (TextView) rootView.findViewById(R.id.customize_screens_text);
    customizeScreensText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    customizeScreensText.setPaintFlags(
            customizeScreensText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    //Populate the arraylists with the settings saved in SharedPreferences.
    page1 = sharedPreferences.getString("PAGE_1", getResources().getString(R.string.artists_caps));
    page2 = sharedPreferences.getString("PAGE_2", getResources().getString(R.string.albums_caps));
    page3 = sharedPreferences.getString("PAGE_3", getResources().getString(R.string.songs_caps));
    page4 = sharedPreferences.getString("PAGE_4", getResources().getString(R.string.playlists_caps));
    page5 = sharedPreferences.getString("PAGE_5", getResources().getString(R.string.genres_caps));
    page6 = sharedPreferences.getString("PAGE_6", getResources().getString(R.string.folders_caps));

    if (!page1.equals("null") || !page1.equals(null)) {
        screenTitlesList.add(page1);
    }

    if (!page2.equals("null") || !page2.equals(null)) {
        screenTitlesList.add(page2);
    }

    if (!page3.equals("null") || !page3.equals(null)) {
        screenTitlesList.add(page3);
    }

    if (!page4.equals("null") || !page4.equals(null)) {
        screenTitlesList.add(page4);
    }

    if (!page5.equals("null") || !page5.equals(null)) {
        screenTitlesList.add(page5);
    }

    if (!page6.equals("null") || !page6.equals(null)) {
        screenTitlesList.add(page6);
    }

    listView = (DragSortListView) rootView.findViewById(R.id.customize_screens_listview);
    adapter = new CustomizeScreensListAdapter(parentActivity, screenTitlesList);
    listView.setAdapter(adapter);
    listView.setDropListener(onDrop);
    SimpleFloatViewManager simpleFloatViewManager = new SimpleFloatViewManager(listView);
    simpleFloatViewManager.setBackgroundColor(Color.TRANSPARENT);
    listView.setFloatViewManager(simpleFloatViewManager);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    //Set the dialog title.
    builder.setTitle(R.string.customize_screens);
    builder.setView(rootView);
    builder.setPositiveButton(R.string.done, new OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            dialogFragment.dismiss();

            //adapter.getItem(i) will get us the order for the screens.
            sharedPreferences.edit().putString("PAGE_1", adapter.getItem(0).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_2", adapter.getItem(1).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_3", adapter.getItem(2).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_4", adapter.getItem(3).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_5", adapter.getItem(4).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_6", adapter.getItem(5).toString().toUpperCase()).commit();

            Toast.makeText(parentActivity, R.string.changes_saved, Toast.LENGTH_SHORT).show();

            //Restart the app.
            Intent i = parentActivity.getBaseContext().getPackageManager()
                    .getLaunchIntentForPackage(parentActivity.getBaseContext().getPackageName());

            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            dialogFragment.dismiss();
            getActivity().finish();
            startActivity(i);

        }

    });

    return builder.create();
}

From source file:com.beijing.fun.view.refreshLayout.BGAStickinessRefreshView.java

private void initPaint() {
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(mStickinessColor);
    mPath = new Path();
}

From source file:com.github.kubatatami.RoundedView.java

private void drawText(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size));

    Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());
    RectF bounds = new RectF(areaRect);

    bounds.right = paint.measureText(text, 0, text.length());
    bounds.bottom = paint.descent() - paint.ascent();
    bounds.left += (areaRect.width() - bounds.right) / 2.0f;
    bounds.top += (areaRect.height() - bounds.bottom) / 2.0f;

    paint.setColor(Color.WHITE);//from  ww  w .j  av  a  2  s.co m

    canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint);
}

From source file:com.artioml.practice.activities.LicenseActivity.java

public BitmapDrawable drawParallelogramLine(int width) {
    Matrix matrix = new Matrix();
    Path path = new Path();
    path.addRect(0, 0, (4 * width) / 40, (4 * width) / 200, Path.Direction.CW);
    Path pathStamp = new Path();
    Paint p;/*  w w w.  j a  v  a 2  s  .  c  o m*/
    Bitmap bitmap;

    p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setStyle(Paint.Style.FILL);

    bitmap = Bitmap.createBitmap(width / 4, width / 80 * 2 + (4 * width) / 200, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    p.setColor(ContextCompat.getColor(this, R.color.colorPrimaryLight));

    matrix.reset();
    matrix.setTranslate(0, 0);
    matrix.postSkew(-1f, 0.0f, 0, (4 * width) / 200);
    path.transform(matrix, pathStamp);
    canvas.drawPath(pathStamp, p);

    p.setColor(ContextCompat.getColor(this, R.color.colorAccent));

    matrix.reset();
    matrix.setTranslate(width / 8, 0);
    matrix.postSkew(-1f, 0.0f, width / 8, (4 * width) / 200);
    path.transform(matrix, pathStamp);
    canvas.drawPath(pathStamp, p);

    BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
    bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);

    return bitmapDrawable;
}

From source file:com.aniruddhc.acemusic.player.Dialogs.CustomizeScreensDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    parentActivity = getActivity();/*  w  ww. j  a  v a  2  s.  c  o m*/
    dialogFragment = (DialogFragment) getFragmentManager().findFragmentByTag("customizeScreensDialog");

    sharedPreferences = parentActivity.getSharedPreferences("com.aniruddhc.acemusic.player",
            Context.MODE_PRIVATE);

    rootView = (View) parentActivity.getLayoutInflater().inflate(R.layout.customize_screens_layout, null);

    customizeScreensText = (TextView) rootView.findViewById(R.id.customize_screens_text);
    customizeScreensText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    customizeScreensText.setPaintFlags(
            customizeScreensText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    //Populate the arraylists with the settings saved in SharedPreferences.
    page1 = sharedPreferences.getString("PAGE_1", getResources().getString(R.string.artists_caps));
    page2 = sharedPreferences.getString("PAGE_2", getResources().getString(R.string.albums_caps));
    page3 = sharedPreferences.getString("PAGE_3", getResources().getString(R.string.songs_caps));
    page4 = sharedPreferences.getString("PAGE_4", getResources().getString(R.string.playlists_caps));
    page5 = sharedPreferences.getString("PAGE_5", getResources().getString(R.string.genres_caps));
    page6 = sharedPreferences.getString("PAGE_6", getResources().getString(R.string.folders_caps));

    if (!page1.equals("null") || !page1.equals(null)) {
        screenTitlesList.add(page1);
    }

    if (!page2.equals("null") || !page2.equals(null)) {
        screenTitlesList.add(page2);
    }

    if (!page3.equals("null") || !page3.equals(null)) {
        screenTitlesList.add(page3);
    }

    if (!page4.equals("null") || !page4.equals(null)) {
        screenTitlesList.add(page4);
    }

    if (!page5.equals("null") || !page5.equals(null)) {
        screenTitlesList.add(page5);
    }

    if (!page6.equals("null") || !page6.equals(null)) {
        screenTitlesList.add(page6);
    }

    listView = (DragSortListView) rootView.findViewById(R.id.customize_screens_listview);
    adapter = new CustomizeScreensListAdapter(parentActivity, screenTitlesList);
    listView.setAdapter(adapter);
    listView.setDropListener(onDrop);
    SimpleFloatViewManager simpleFloatViewManager = new SimpleFloatViewManager(listView);
    simpleFloatViewManager.setBackgroundColor(Color.TRANSPARENT);
    listView.setFloatViewManager(simpleFloatViewManager);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    //Set the dialog title.
    builder.setTitle(R.string.customize_screens);
    builder.setView(rootView);
    builder.setPositiveButton(R.string.done, new OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            dialogFragment.dismiss();

            //adapter.getItem(i) will get us the order for the screens.
            sharedPreferences.edit().putString("PAGE_1", adapter.getItem(0).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_2", adapter.getItem(1).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_3", adapter.getItem(2).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_4", adapter.getItem(3).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_5", adapter.getItem(4).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_6", adapter.getItem(5).toString().toUpperCase()).commit();

            Toast.makeText(parentActivity, R.string.changes_saved, Toast.LENGTH_SHORT).show();

            //Restart the app.
            Intent i = parentActivity.getBaseContext().getPackageManager()
                    .getLaunchIntentForPackage(parentActivity.getBaseContext().getPackageName());

            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            dialogFragment.dismiss();
            getActivity().finish();
            startActivity(i);

        }

    });

    return builder.create();
}