Example usage for android.graphics Paint setTextAlign

List of usage examples for android.graphics Paint setTextAlign

Introduction

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

Prototype

public void setTextAlign(Align align) 

Source Link

Document

Set the paint's text alignment.

Usage

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_text(Paint paint, int x, int y, String text, int size, int dx, int dy, int bgcolor) {
    int oldcolor = paint.getColor();
    Path path = null;//from w w w . ja va2 s  .com

    paint.setTextSize(size / 15);
    paint.setStyle(Paint.Style.FILL);

    if (dx != 0x10000 || dy != 0) {
        path = new Path();
        path.moveTo(x, y);
        path.rLineTo(dx, dy);
        paint.setTextAlign(android.graphics.Paint.Align.LEFT);
    }

    if (bgcolor != 0) {
        paint.setStrokeWidth(3);
        paint.setColor(bgcolor);
        paint.setStyle(Paint.Style.STROKE);
        if (path == null) {
            draw_canvas.drawText(text, x, y, paint);
        } else {
            draw_canvas.drawTextOnPath(text, path, 0, 0, paint);
        }
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(oldcolor);
    }

    if (path == null) {
        draw_canvas.drawText(text, x, y, paint);
    } else {
        draw_canvas.drawTextOnPath(text, path, 0, 0, paint);
    }
    paint.clearShadowLayer();
}

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);//from   w  ww.  java2 s  . c  o m
    if (quoteData != null) {
        try {
            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);//from  w  ww .ja va2  s  . c  o m
    if (quoteData != null) {
        try {
            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.launcher3.Utilities.java

public static Bitmap getNotificationBadgeIcon(Context context, Bitmap appIcon, int number) {
    Paint paint;
    Paint circlePaint;//  w ww  . java 2s  . c  o m
    String text = "" + String.valueOf(number);
    Bitmap canvasBitmap = Bitmap.createBitmap(appIcon.getWidth(), appIcon.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(canvasBitmap);
    paint = new Paint();
    circlePaint = new Paint();

    paint.setColor(Color.WHITE);
    paint.setTextSize(45);
    paint.setAntiAlias(true);
    paint.setTextAlign(Paint.Align.CENTER);

    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);

    circlePaint.setColor(ContextCompat.getColor(context, R.color.colorPrimary));
    circlePaint.setAntiAlias(true);

    canvas.drawCircle(appIcon.getWidth() / 4, appIcon.getHeight() / 4, 45, circlePaint);
    canvas.drawText(text, appIcon.getWidth() / 4, appIcon.getHeight() / 3, paint);

    return overlay(appIcon, canvasBitmap);
}

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

void makeBMP(CalculationResult res) {

    Bitmap bmp = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);

    //canvas.drawARGB(155, 253, 255, 253);
    canvas.drawARGB(255, 255, 255, 255);
    Paint p = new Paint();
    p.setTypeface(Utility.getNazaninFont());
    p.setTextSize(25);/*from  w w  w  .  ja va 2 s  . c o m*/
    p.setAntiAlias(true);

    int y = 20;
    Drawable d = getResources().getDrawable(R.drawable.abfa);
    d.setBounds(100, 10, 300, 210);
    d.draw(canvas);
    p.setTextAlign(Paint.Align.CENTER);
    y += 210;
    canvas.drawText("   ?  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText(":" + Utility.NowDate(), 200, y, p);
    y += 40;
    canvas.drawText("___________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.CustomerNumber, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.Title, 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p);

    y += 40;
    Paint p1 = new Paint();
    p1.setTypeface(Utility.getNazaninFont());
    p1.setARGB(255, 0, 0, 0);
    p1.setAntiAlias(true);
    p1.setStrokeWidth(40);
    p1.setStyle(Paint.Style.STROKE);
    canvas.drawLine(10, y, 390, y, p1);
    p.setARGB(255, 255, 255, 255);
    canvas.drawText("  :" + Seprate3(res.TotalAmount) + " ", 200, y, p);
    p.setARGB(255, 0, 0, 0);

    y += 40;
    canvas.drawText("__________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.BillIdentifier, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p);

    /* Path pth = new Path();
     pth.addArc(10, 20, 390, 790, 0, 360);
            
     p.setColor(Color.argb(20, 10, 10, 10));
     p.setTextSize(30);
     String watermark = "";
     for (int i = 0; i < 15; i++) {
     watermark += "  ";
     }
     canvas.drawTextOnPath(watermark, pth, 0, 0, p);*/
    //File file = new File(getCacheDir()+ "/billing.png");
    File file = new File("/sdcard/billing.png");
    FileOutputStream outfile;
    try {
        outfile = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile);

        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "image/*");
        startActivity(intent);

    } catch (Exception ex) {
        Log.e("error", ex.toString());
    }

}

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

void makePDF(CalculationResult res) {

    PdfDocument doc = new PdfDocument();
    PdfDocument.PageInfo inf = new PdfDocument.PageInfo.Builder(400, 800, 1).create();
    PdfDocument.Page page = doc.startPage(inf);

    Canvas canvas = page.getCanvas();

    //canvas.drawARGB(155, 253, 255, 253);
    canvas.drawARGB(255, 255, 255, 255);
    Paint p = new Paint();
    p.setTypeface(Utility.getNazaninFont());
    p.setTextSize(25);/*  w ww. j a  v  a2 s.  c  o  m*/
    p.setAntiAlias(true);

    int y = 20;
    Drawable d = getResources().getDrawable(R.drawable.abfa);
    d.setBounds(100, 10, 300, 210);
    d.draw(canvas);
    p.setTextAlign(Paint.Align.CENTER);
    y += 210;
    canvas.drawText("   ?  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText(":" + Utility.NowDate(), 200, y, p);
    y += 40;
    canvas.drawText("___________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.CustomerNumber, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.Title, 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p);

    y += 40;
    Paint p1 = new Paint();
    p1.setTypeface(Utility.getNazaninFont());
    p1.setARGB(255, 0, 0, 0);
    p1.setAntiAlias(true);
    p1.setStrokeWidth(40);
    p1.setStyle(Paint.Style.STROKE);
    canvas.drawLine(10, y, 390, y, p1);
    p.setARGB(255, 255, 255, 255);
    canvas.drawText("  :" + Seprate3(res.TotalAmount) + " ", 200, y, p);
    p.setARGB(255, 0, 0, 0);

    y += 40;
    canvas.drawText("__________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.BillIdentifier, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p);

    doc.finishPage(page);
    //File file = new File(getCacheDir()+ "/billing.png");
    File file = new File("/sdcard/billing.pdf");
    FileOutputStream outfile;
    try {
        outfile = new FileOutputStream(file);
        //bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile);
        doc.writeTo(outfile);
        doc.close();

        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_VIEW);
        //intent.setDataAndType(Uri.fromFile(file), "image/*");
        intent.setDataAndType(Uri.fromFile(file), "application/pdf");
        startActivity(intent);
        //new RetrieveFeedTask().execute(bmp);

    } catch (Exception ex) {
        Log.e("error", ex.toString());
        new AlertDialog.Builder(this).setMessage(
                "    ? pdf    ? \n https://cafebazaar.ir/app/com.kdanmobile.android.pdfreader.google.pad/?l=fa   ")
                .show();
    }

}

From source file:com.cssn.samplesdk.MainActivity.java

/**
 *
 *//*from   w w  w  .  j  av a  2s.  c om*/
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (Util.LOG_ENABLED) {
        Utils.appendLog(TAG, "protected void onCreate(Bundle savedInstanceState)");
    }

    // load the model
    if (savedInstanceState == null) {
        if (Util.LOG_ENABLED) {
            Utils.appendLog(TAG, "if (savedInstanceState == null)");
        }
        mainActivityModel = new MainActivityModel();
    } else {
        if (Util.LOG_ENABLED) {
            Utils.appendLog(TAG, "if (savedInstanceState != null)");
        }
        mainActivityModel = DataContext.getInstance().getMainActivityModel();
        // if coming from background and kill the app, restart the model
        if (mainActivityModel == null) {
            mainActivityModel = new MainActivityModel();
        }
    }
    DataContext.getInstance().setContext(getApplicationContext());

    String licenseKey = DataContext.getInstance().getLicenseKey();

    // load the controller instance
    acuantAndroidMobileSdkControllerInstance = AcuantAndroidMobileSDKController.getInstance(this, licenseKey);
    if (!Util.isTablet(this)) {
        acuantAndroidMobileSdkControllerInstance
                .setPdf417BarcodeImageDrawable(getResources().getDrawable(R.drawable.barcode));
    }

    acuantAndroidMobileSdkControllerInstance.setWebServiceListener(this);
    acuantAndroidMobileSdkControllerInstance.setCloudUrl("cssnwebservices.com");
    acuantAndroidMobileSdkControllerInstance.setWatermarkText("Powered By Acuant", 0, 0, 30, 0);
    DisplayMetrics metrics = this.getResources().getDisplayMetrics();

    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int height = displaymetrics.heightPixels;
    int width = displaymetrics.widthPixels;
    int minLength = (int) (Math.min(width, height) * 0.9);
    int maxLength = (int) (minLength * 1.5);
    int left = minLength / 2 - 50;
    int top = maxLength / 2 - 100;
    Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    Typeface currentTypeFace = textPaint.getTypeface();
    Typeface bold = Typeface.create(currentTypeFace, Typeface.BOLD);
    textPaint.setColor(Color.WHITE);
    textPaint.setTextSize(50);
    textPaint.setTextAlign(Paint.Align.LEFT);
    textPaint.setTypeface(bold);
    Paint.FontMetrics metric = textPaint.getFontMetrics();
    acuantAndroidMobileSdkControllerInstance.setInstructionText("Blink Slowly", left, top, textPaint);
    //acuantAndroidMobileSdkControllerInstance.setShowActionBar(false);
    //acuantAndroidMobileSdkControllerInstance.setShowStatusBar(false);
    acuantAndroidMobileSdkControllerInstance.setFlashlight(false);
    //acuantAndroidMobileSdkControllerInstance.setFlashlight(0,0,50,0);
    //acuantAndroidMobileSdkControllerInstance.setFlashlightImageDrawable(getResources().getDrawable(R.drawable.lighton), getResources().getDrawable(R.drawable.lightoff));
    //acuantAndroidMobileSdkControllerInstance.setShowInitialMessage(true);
    //acuantAndroidMobileSdkControllerInstance.setCropBarcode(true);
    //acuantAndroidMobileSdkControllerInstance.setPdf417BarcodeDialogWaitingBarcode("AcuantAndroidMobileSampleSDK","ALIGN AND TAP", 10, "Try Again", "Yes");
    acuantAndroidMobileSdkControllerInstance.setCanShowBracketsOnTablet(true);
    // load several member variables
    setContentView(R.layout.activity_main);

    layoutCards = (LinearLayout) findViewById(R.id.cardImagesLayout);
    layoutBackImage = (RelativeLayout) findViewById(R.id.relativeLayoutBackImage);
    layoutFrontImage = (RelativeLayout) findViewById(R.id.relativeLayoutFrontImage);

    frontImageView = (ImageView) findViewById(R.id.frontImageView);
    backImageView = (ImageView) findViewById(R.id.backImageView);

    editTextLicense = (EditText) findViewById(R.id.editTextLicenceKey);
    editTextLicense.setText(DataContext.getInstance().getLicenseKey());

    txtTapToCaptureFront = (TextView) findViewById(R.id.txtTapToCaptureFront);
    txtTapToCaptureBack = (TextView) findViewById(R.id.txtTapToCaptureBack);

    activateLicenseButton = (Button) findViewById(R.id.activateLicenseButton);

    processCardButton = (Button) findViewById(R.id.processCardButton);
    processCardButton.setVisibility(View.INVISIBLE);

    editTextLicense.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            validateLicenseKey(editTextLicense.getText().toString());
            DataContext.getInstance().setLicenseKey(editTextLicense.getText().toString());
            return true;
        }
    });

    // it is necessary to use a post UI call, because of the previous set text on 'editTextLicense'
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            editTextLicense.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    mainActivityModel.setState(State.NO_VALIDATED);
                    updateActivateLicenseButtonFromModel();
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }
            });
        }
    });

    editTextLicense.setOnFocusChangeListener(new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                hideVirtualKeyboard();
            }
        }
    });

    // update the UI from the model
    updateUI();
    acuantAndroidMobileSdkControllerInstance.setCardCroppingListener(this);
    acuantAndroidMobileSdkControllerInstance.setAcuantErrorListener(this);
    if (Utils.LOG_ENABLED) {
        Utils.appendLog(TAG, "getScreenOrientation()=" + Util.getScreenOrientation(this));
    }
}

From source file:com.chrynan.guitarchords.view.GuitarChordView.java

protected float getVerticalCenterTextPosition(float originalYPosition, String text, int textSizeInPixels) {
    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setTextAlign(Paint.Align.CENTER);
    p.setTextSize(textSizeInPixels);/*from  www . java  2 s .c o m*/
    return getVerticalCenterTextPosition(originalYPosition, text, p);
}

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

public void drawIndex(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);//from w  w w. j  ava2s. co  m
    tPaint.setColor(GlobalColor.clrLine);
    tPaint.setStyle(Paint.Style.STROKE);
    tPaint.setStrokeWidth(1);
    this.x = 0;
    this.y = 0;
    startX = x + tips / 2;
    endX = width - tips / 2;
    canvas.drawRect(startX, DY + DY / 4, endX, height - DY / 4, tPaint);
    canvas.drawLine(startX, DY * 7 + DY / 2, endX, DY * 7 + DY / 2, tPaint);
    canvas.drawLine(startX, DY * 18 + DY / 4, endX, DY * 18 + DY / 4, tPaint);
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

            paint.setTextSize(mTextSize);
            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY * 2);
            canvas.drawText("?", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("???", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x + tips, y, paint);

            canvas.translate(0, DY * 1.5f);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);

            canvas.translate(width, -DY * 15.5f);
            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("a"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("b"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("govbond"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("fund"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("warrant"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("bond"), true), x - tips, y, paint);

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

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

            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint);

            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);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(zhangdie, x - tips, 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(0, DY);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(zhangfu + "%", 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);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), 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);

            canvas.translate(-width, DY * 1.7f);

            paint.setTextSize(mTextSize);
            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);

            canvas.drawText("", x + tips, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(width / 2, 0);
            canvas.drawText(String.valueOf(jo.getInt("zj")), x, y, paint);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.drawText("", x + tips, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(width / 2, 0);
            canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

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

public void drawHKIndex(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);//  w ww. j a va 2 s. c o m
    tPaint.setColor(GlobalColor.clrLine);
    tPaint.setStyle(Paint.Style.STROKE);
    tPaint.setStrokeWidth(1);
    this.x = 0;
    this.y = 0;
    startX = x + tips / 2;
    endX = width - tips / 2;
    canvas.drawRect(startX, DY + DY / 4, endX, height - DY / 4, tPaint);
    canvas.drawLine(startX, DY * 5 + DY / 2, endX, DY * 5 + DY / 2, tPaint);
    canvas.drawLine(startX, DY * 11 + DY / 8, endX, DY * 11 + DY / 8, tPaint);
    //canvas.drawLine(startX, DY*16+DY/4, endX, DY*16+DY/4, tPaint);
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

            paint.setTextSize(mTextSize);
            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY * 2);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);

            canvas.translate(0, DY * 1.5f);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText("??", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x + tips, y, paint);

            canvas.translate(0, DY * 1.5f);
            //            canvas.drawText("?", x + tips, y, paint);
            //            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x + tips, y, paint);

            canvas.translate(width, -DY * 13f);
            paint.setTextAlign(Paint.Align.RIGHT);

            double zjcj = jo.getDouble("zjcj");
            setColor(paint, zjcj, zrsp);

            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x - tips, y, paint);

            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);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(zhangdie, x - tips, 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(0, DY);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x - tips, y, paint);
            else
                canvas.drawText(zhangfu + "%", 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);

            canvas.translate(0, DY * 1.5f);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint);

            canvas.translate(0, DY);
            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.getAmountFormat(jo.getDouble("cjsl"), true), x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint);

            canvas.translate(0, DY * 1.5f);
            //canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1), x - tips, y, paint);

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

            paint.setColor(GlobalColor.colorPriceEqual);
            canvas.translate(0, DY);
            canvas.drawText(String.valueOf(jo.getInt("pj")), x - tips, y, paint);

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}