Example usage for android.graphics Paint setAntiAlias

List of usage examples for android.graphics Paint setAntiAlias

Introduction

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

Prototype

public void setAntiAlias(boolean aa) 

Source Link

Document

Helper for setFlags(), setting or clearing the ANTI_ALIAS_FLAG bit AntiAliasing smooths out the edges of what is being drawn, but is has no impact on the interior of the shape.

Usage

From source file:edumsg.edumsg_android_app.MainActivity.java

/**
 *
 * The onCreate method first retrieves the sessionId and username from the parent {@link android.content.Intent},
 * which is either created from a {@link LoginFragment} or a {@link RegisterFragment}. Afterwards,
 * it configures the action bar and performs view look-ups for the action bar buttons, followed
 * by setting the onClick listeners for the action bar buttons. Finally, it initializes the
 * properties, sets the onRefresh listener for the swipe refresh layout, and calls the method
 * {@link MainActivity#getFeed()}./*  w  ww  .  ja va2s.c om*/
 *
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sessionId = getIntent().getExtras().getString("sessionId");
    username = getIntent().getExtras().getString("username");
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    setSupportActionBar(toolbar);
    final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.menu_main, null);
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(actionBarLayout);
    ImageButton homeButton = ButterKnife.findById(actionBarLayout, R.id.btn_home);
    final ImageButton searchButton = ButterKnife.findById(actionBarLayout, R.id.btn_search);
    ImageButton createButton = ButterKnife.findById(actionBarLayout, R.id.btn_create);
    ImageButton navButton = ButterKnife.findById(actionBarLayout, R.id.btn_nav);

    final ViewGroup searchLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.menu_search, null);
    final SearchView searchView = ButterKnife.findById(searchLayout, R.id.search);
    final ImageButton backBtn = ButterKnife.findById(searchLayout, R.id.btn_back);

    homeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

    searchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            actionBar.setCustomView(searchLayout);
            SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            searchView.setSearchableInfo(searchManager
                    .getSearchableInfo(new ComponentName(MainActivity.this, SearchResultsActivity.class)));
            searchView.setQuery("", false);
            searchView.setIconified(false);
            searchView.setFocusable(true);
            searchView.requestFocusFromTouch();
        }
    });

    backBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            actionBar.setCustomView(actionBarLayout);
            InputMethodManager imm = (InputMethodManager) getApplicationContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(
                    MainActivity.this.getWindow().getDecorView().getRootView().getWindowToken(), 0);
        }
    });

    createButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

            final EditText input = new EditText(MainActivity.this);
            input.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
            input.setLines(4);
            input.setSingleLine(false);
            input.setBackgroundDrawable(null);
            builder.setView(input);
            builder.setPositiveButton("Tweet", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    createTweet(input.getText().toString());
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            final AlertDialog dialog = builder.create();

            dialog.setOnShowListener(new DialogInterface.OnShowListener() {
                @Override
                public void onShow(DialogInterface dialogInterface) {
                    Button posBtn = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
                    posBtn.setBackgroundColor(cPrimary);
                    posBtn.setTextColor(Color.WHITE);
                    final float scale = getApplicationContext().getResources().getDisplayMetrics().density;
                    int pixels = (int) (10 * scale + 0.5f);
                    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    layoutParams.setMargins(0, 0, pixels, 0);
                    posBtn.setLayoutParams(layoutParams);
                    Button negBtn = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
                    negBtn.setBackgroundColor(cPrimary);
                    negBtn.setTextColor(Color.WHITE);
                }
            });
            dialog.show();
        }
    });

    navButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getSupportFragmentManager();
            List<Fragment> fragments = fragmentManager.getFragments();
            if (fragments != null) {
                for (Fragment fragment : fragments) {
                    if (fragment instanceof NavigationFragment)
                        return;
                }
            }
            NavigationFragment navigationFragment = new NavigationFragment();
            //                Bundle bundle = new_user Bundle();
            //                bundle.putInt("userId", userId);
            //                mainActivityFragment.setArguments(bundle);
            fragmentManager.beginTransaction().add(android.R.id.content, navigationFragment)
                    .addToBackStack("nav").commit();
            //                logout();
            //                launchMessages();
            //                Intent intent = new_user Intent(MainActivity.this, ProfileActivity.class);
            //                intent.putExtra("username", getUsername());
            //                intent.putExtra("name", getName());
            //                intent.putExtra("avatar_url", getAvatar_url());
            //                intent.putExtra("bio", getBio());
            //                intent.putExtra("creatorId", getUserId());
            //                intent.putExtra("userId", getUserId());
            //                startActivity(intent);
        }
    });

    recyclerView.setHasFixedSize(true);
    final float scale = getApplicationContext().getResources().getDisplayMetrics().density;
    int pixels = (int) (160 * scale + 0.5f);
    Paint paint = new Paint();
    paint.setStrokeWidth(3.0f);
    paint.setColor(Color.rgb(220, 220, 220));
    paint.setAntiAlias(true);
    recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).paint(paint).build());
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);

    tweetObjects = new ArrayList<>();
    rvAdapter = new RVAdapter(this, tweetObjects, sessionId);
    recyclerView.setAdapter(rvAdapter);

    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            tweetObjects.clear();
            getFeed();
        }
    });

    getFeed();
}

From source file:ch.ethz.dcg.jukefox.manager.libraryimport.AndroidAlbumCoverFetcherThread.java

private void drawTextOnBitmap(CompleteAlbum album, Bitmap bitmapHigh, int bitmapSize, float textHeight) {
    Canvas canvas = new Canvas(bitmapHigh);
    canvas.drawARGB(0, 125, 125, 125);/* www. j a  va  2 s .  c om*/
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setTypeface(Typeface.SERIF);
    paint.setSubpixelText(true);
    paint.setTextSize(textHeight);
    paint.setAntiAlias(true);
    String artist = album.getArtists().get(0).getName();
    String shortenedText = new String(artist);

    int textLength = artist.length();
    if (textLength > 18) {
        shortenedText = artist.substring(0, 15) + "...";
        textLength = 18;
    } else if (textLength < 8) {
        while (shortenedText.length() < 8) {
            shortenedText = " " + shortenedText + " ";
        }
    }
    float pixelLength = paint.measureText(shortenedText);
    paint.setTextSize(textHeight * (bitmapSize * 2 / 3) / pixelLength);

    canvas.drawText(shortenedText, bitmapSize / 6, bitmapSize / 3, paint);

    shortenedText = album.getName();
    textLength = album.getName().length();
    if (textLength > 18) {
        shortenedText = album.getName().substring(0, 15) + "...";
        textLength = 18;
    } else if (textLength < 8) {
        while (shortenedText.length() < 8) {
            shortenedText = " " + shortenedText + " ";
        }
    }
    paint.setTextSize(bitmapSize / 10f);
    pixelLength = paint.measureText(shortenedText);
    textHeight = textHeight * bitmapSize * 2f / 3f / pixelLength;
    paint.setTextSize(textHeight);

    canvas.drawText(shortenedText, bitmapSize / 6f, bitmapSize * 2 / 3f + textHeight, paint);
}

From source file:org.mdc.chess.ChessBoard.java

public ChessBoard(Context context, AttributeSet attrs) {
    super(context, attrs);
    pos = new Position();
    selectedSquare = -1;/*  w  w  w .j  a v  a  2s  .  com*/
    userSelectedSquare = false;
    cursorX = cursorY = 0;
    cursorVisible = false;
    x0 = y0 = sqSize = 0;
    pieceXDelta = pieceYDelta = -1;
    flipped = false;
    drawSquareLabels = false;
    toggleSelection = false;
    highlightLastMove = true;
    blindMode = false;

    darkPaint = new Paint();
    brightPaint = new Paint();

    selectedSquarePaint = new Paint();
    selectedSquarePaint.setStyle(Paint.Style.STROKE);
    selectedSquarePaint.setAntiAlias(true);

    cursorSquarePaint = new Paint();
    cursorSquarePaint.setStyle(Paint.Style.STROKE);
    cursorSquarePaint.setAntiAlias(true);

    whitePiecePaint = new Paint();
    whitePiecePaint.setAntiAlias(true);

    blackPiecePaint = new Paint();
    blackPiecePaint.setAntiAlias(true);

    labelPaint = new Paint();
    labelPaint.setAntiAlias(true);

    decorationPaint = new Paint();
    decorationPaint.setAntiAlias(true);

    moveMarkPaint = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
        Paint p = new Paint();
        p.setStyle(Paint.Style.FILL);
        p.setAntiAlias(true);
        moveMarkPaint.add(p);
    }

    if (isInEditMode()) {
        return;
    }

    Typeface chessFont = Typeface.createFromAsset(getContext().getAssets(), "fonts/ChessCases.ttf");
    whitePiecePaint.setTypeface(chessFont);
    blackPiecePaint.setTypeface(chessFont);

    setColors();
}

From source file:com.cssweb.android.view.PriceMini.java

public void drawHKIndex(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);
    if (quoteData != null) {
        try {/*w w  w  .  j  a v a  2 s  .  co  m*/
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX * 0.5f, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(0, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 3.5f, 0);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);

            canvas.translate(-DX * 4f, DY * 1.2f);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);

            canvas.translate(width / 2, -DY * 1);
            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(0, -DY * 4);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 3);
            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x - tips, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit), x - tips, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit), x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 3, DY * 1.2f);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2, -DY * 4);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
    }
}

From source file:jp.gr.java_conf.piropiroping.bluetoothcommander.MainActivity.java

private void convertBitmapCommand(String command, int start, int stop) {
    //???/*  ww  w. j av a  2 s.co  m*/
    Paint objPaint = new Paint();
    Bitmap objBitmap;
    Canvas objCanvas;
    int textSize = 40;
    int textWidth = textSize * command.length(), textHeight = textSize;

    objPaint.setAntiAlias(true);
    objPaint.setColor(Color.BLUE);
    objPaint.setTextSize(textSize);
    Paint.FontMetrics fm = objPaint.getFontMetrics();
    objPaint.getTextBounds(command, 0, command.length(), new Rect(0, 0, textWidth, textHeight));

    //?
    textWidth = (int) objPaint.measureText(command);
    textHeight = (int) (Math.abs(fm.top) + fm.bottom);
    objBitmap = Bitmap.createBitmap(textWidth, textHeight, Bitmap.Config.ARGB_8888);

    //???
    objCanvas = new Canvas(objBitmap);
    objCanvas.drawText(command, 0, Math.abs(fm.top), objPaint);

    Editable editable = mOutEditText.getText();
    SpannableStringBuilder ssb = (SpannableStringBuilder) editable;
    ImageSpan is = new ImageSpan(getApplicationContext(), objBitmap);
    ssb.setSpan(is, start, stop + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * /*from ww  w .  ja v a 2 s  .  c  om*/
 * 
 * @param bitmap
 *            ?Bitmap
 * @param roundPx
 *            ?
 * @return Bitmap
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {

    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());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

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

    return output;
}

From source file:com.cssweb.android.view.PriceMini.java

public void drawIndex(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);
    if (quoteData != null) {
        try {/*  w  w w  .ja v  a2s  .c  om*/
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX * 0.5f, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(0, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 3.5f, 0);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(-DX * 3.5f, DY * 1.2f);
            //canvas.translate(-DX*0.5f, DY*2f);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(width / 2 - DX, -DY * 7);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, 0);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x, y, paint);

            canvas.translate(width / 2, -DY * 3);
            paint.setTextAlign(Paint.Align.RIGHT);

            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit), x, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit), x, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            double amp = jo.getDouble("amp");
            if (amp == 0)
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x, y, paint);

            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.drawText(String.valueOf(jo.getInt("zj")), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.drawText(String.valueOf(jo.getInt("dj")), x, y, paint);

        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 2.5f, DY * 1.2f);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2 - DX, -DY * 7);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
    }
}

From source file:com.cssweb.android.view.PriceMini.java

public void drawQihuo(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);
    if (quoteData != null) {
        try {//from   w w w .j  a v  a  2  s. co m
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            String str = "";
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(-DX / 2, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit, jo.getInt("tp"));
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 2.5f, 0);
            String zhangfu = Utils.dataFormation(zhangf * 100, 1);
            if (zhangfu.equals("-") || zhangfu.equals(""))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);

            canvas.translate(-DX * 3, DY * 1.2f);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(" ", x, y, paint);

            canvas.translate(width / 2, -DY * 2);
            paint.setTextAlign(Paint.Align.RIGHT);
            double temp2 = jo.getDouble("sjw1");
            setColor(paint, temp2, zrsp);
            str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
            canvas.drawText(str, x - tips, y, paint);

            canvas.translate(0, DY);
            temp2 = jo.getDouble("bjw1");
            setColor(paint, temp2, zrsp);
            str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
            canvas.drawText(str, x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0, jo.getInt("tp")), x - tips, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(0, -DY * 5);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(" ", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 5);
            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit, jo.getInt("tp")), x - tips, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit, jo.getInt("tp")), x - tips, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit, jo.getInt("tp")), x - tips, y, paint);

            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl1"), false), x - tips, y, paint);

            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl1"), false), x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0, jo.getInt("tp")), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 3, DY * 1.2f);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText(" ", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2, -DY * 5);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText(" ", x, y, paint);
    }
}

From source file:com.cssweb.android.view.PriceMini.java

public void drawPrice(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);
    if (quoteData != null) {
        try {/*from ww w .  j  av  a2  s . c  om*/
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            String str = "";
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(-DX / 2, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit, jo.getInt("tp"));
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 2.5f, 0);
            //String zhangfu = Utils.dataFormation(zhangf*100, stockdigit);
            //?????2?
            String zhangfu = Utils.dataFormation(zhangf * 100, 1, jo.getInt("tp"));
            if (zhangfu.equals("-") || zhangfu.equals(""))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(-DX * 3, DY * 1.2f);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);

            canvas.translate(DX * 2, -DY * 4);
            for (int i = 1; i <= 5; i++) {
                double temp2 = jo.getDouble("sjw" + i);
                setColor(paint, temp2, zrsp);
                str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
                canvas.drawText(str, x, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2 - DX * 2, -DY * 4);
            for (int i = 1; i <= 5; i++) {
                paint.setTextAlign(Paint.Align.RIGHT);
                canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl" + i), false), x - tips, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(0, -DY * 7);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            //paint.setTextAlign(Paint.Align.CENTER);
            canvas.translate(DX * 2, -DY * 7);
            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit, jo.getInt("tp")), x, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit, jo.getInt("tp")), x, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit, jo.getInt("tp")), x, y, paint);

            canvas.translate(0, DY);
            for (int i = 1; i <= 5; i++) {
                double temp2 = jo.getDouble("bjw" + i);
                setColor(paint, temp2, zrsp);
                str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
                canvas.drawText(str, x, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2 - DX * 2, -DY * 4);
            for (int i = 1; i <= 5; i++) {
                paint.setTextAlign(Paint.Align.RIGHT);
                canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl" + i), false), x - tips, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 3, DY * 1.2f);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2, -DY * 7);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
    }
}

From source file:com.android.contacts.common.ContactPhotoManager.java

/**
 * If necessary, decodes bytes stored in the holder to Bitmap.  As long as the
 * bitmap is held either by {@link #mBitmapCache} or by a soft reference in
 * the holder, it will not be necessary to decode the bitmap.
 *///w w  w.  j  a va2 s  .c  o m
private static void inflateBitmap(BitmapHolder holder, int requestedExtent) {
    final int sampleSize = BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent, requestedExtent);
    byte[] bytes = holder.bytes;
    if (bytes == null || bytes.length == 0) {
        return;
    }

    if (sampleSize == holder.decodedSampleSize) {
        // Check the soft reference.  If will be retained if the bitmap is also
        // in the LRU cache, so we don't need to check the LRU cache explicitly.
        if (holder.bitmapRef != null) {
            holder.bitmap = holder.bitmapRef.get();
            if (holder.bitmap != null) {
                return;
            }
        }
    }

    try {
        Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(bytes, sampleSize);

        // TODO: As a temporary workaround while framework support is being added to
        // clip non-square bitmaps into a perfect circle, manually crop the bitmap into
        // into a square if it will be displayed as a thumbnail so that it can be cropped
        // into a circle.
        final int height = bitmap.getHeight();
        final int width = bitmap.getWidth();

        // The smaller dimension of a scaled bitmap can range from anywhere from 0 to just
        // below twice the length of a thumbnail image due to the way we calculate the optimal
        // sample size.
        if (height != width && Math.min(height, width) <= mThumbnailSize * 2) {
            final int dimension = Math.min(height, width);
            bitmap = ThumbnailUtils.extractThumbnail(bitmap, dimension, dimension);
        }
        // make bitmap mutable and draw size onto it
        if (DEBUG_SIZES) {
            Bitmap original = bitmap;
            bitmap = bitmap.copy(bitmap.getConfig(), true);
            original.recycle();
            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.setTextSize(16);
            paint.setColor(Color.BLUE);
            paint.setStyle(Style.FILL);
            canvas.drawRect(0.0f, 0.0f, 50.0f, 20.0f, paint);
            paint.setColor(Color.WHITE);
            paint.setAntiAlias(true);
            canvas.drawText(bitmap.getWidth() + "/" + sampleSize, 0, 15, paint);
        }

        holder.decodedSampleSize = sampleSize;
        holder.bitmap = bitmap;
        holder.bitmapRef = new SoftReference<Bitmap>(bitmap);
        if (DEBUG) {
            Log.d(TAG, "inflateBitmap " + btk(bytes.length) + " -> " + bitmap.getWidth() + "x"
                    + bitmap.getHeight() + ", " + btk(bitmap.getByteCount()));
        }
    } catch (OutOfMemoryError e) {
        // Do nothing - the photo will appear to be missing
    }
}