List of usage examples for android.graphics Paint setColor
public void setColor(@ColorInt int color)
From source file:com.cssn.samplesdk.MainActivity.java
/** * *//*from w w w.j av a2s .c o m*/ @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.cssweb.android.view.PriceMini.java
public void drawIndex(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);//from w w w.ja v a 2s . c om if (quoteData != null) { try { 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);/*from www .j a v a2 s .com*/ 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.almalence.opencam.SavingService.java
protected void drawTextWithBackground(Canvas canvas, Paint paint, String text, int foreground, int background, int imageWidth, int imageHeight) { Rect text_bounds = new Rect(); paint.setColor(foreground); String[] resText = text.split("\n"); String maxLengthText = ""; if (resText.length > 1) { maxLengthText = resText[0].length() > resText[1].length() ? resText[0] : resText[1]; } else if (resText.length > 0) { maxLengthText = resText[0];//from www. ja va2s .c o m } final float scale = getResources().getDisplayMetrics().density; paint.setStyle(Paint.Style.FILL); paint.setColor(background); paint.setAlpha(64); paint.getTextBounds(text, 0, maxLengthText.length(), text_bounds); final int padding = (int) (2 * scale + 0.5f); // convert dps to pixels int textWidth = 0; int textHeight = text_bounds.bottom - text_bounds.top; if (paint.getTextAlign() == Paint.Align.RIGHT || paint.getTextAlign() == Paint.Align.CENTER) { float width = paint.measureText(maxLengthText); // n.b., need to use // measureText // rather than // getTextBounds // here textWidth = (int) width; } text_bounds.left = imageWidth - textWidth - resText.length * padding; text_bounds.right = imageWidth - padding; if (resText.length > 1) { text_bounds.top = imageHeight - resText.length * padding - resText.length * textHeight - textHeight; } else { text_bounds.top = imageHeight - 2 * padding - textHeight; textHeight /= 3; } text_bounds.bottom = imageHeight - padding; paint.setColor(foreground); if (resText.length > 0) { canvas.drawText(resText[0], imageWidth - 5 * padding, imageHeight - resText.length * textHeight - textHeight / 2, paint); } if (resText.length > 1) { canvas.drawText(resText[1], imageWidth - 5 * padding, imageHeight - (resText.length - 1) * textHeight, paint); } if (resText.length > 2) { canvas.drawText(resText[2], imageWidth - 5 * padding, imageHeight - (resText.length - 2) * textHeight + textHeight / 2, paint); } if (resText.length > 3) { canvas.drawText(resText[3], imageWidth - 5 * padding, imageHeight - textHeight / 4, 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 www. 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, 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.gm.common.ui.widget.pageindicator.PageIndicatorView.java
private void drawWithNoEffect(@NonNull Canvas canvas, int position, int x, int y) { float radius = radiusPx; if (animationType == AnimationType.SCALE) { radius *= scaleFactor;/*from ww w. ja v a 2 s . c om*/ } int color = unselectedColor; if (position == selectedPosition) { color = selectedColor; } Paint paint; if (animationType == AnimationType.FILL) { paint = strokePaint; paint.setStrokeWidth(strokePx); } else { paint = fillPaint; } paint.setColor(color); canvas.drawCircle(x, y, radius, paint); }
From source file:io.doist.datetimepicker.time.RadialTimePickerView.java
private void drawSelector(Canvas canvas, int index) { // Calculate the current radius at which to place the selection circle. mLineLength[index] = (int) (mCircleRadius[index] * mNumbersRadiusMultiplier[index] * mAnimationRadiusMultiplier[index]); double selectionRadians = Math.toRadians(mSelectionDegrees[index]); int pointX = mXCenter + (int) (mLineLength[index] * Math.sin(selectionRadians)); int pointY = mYCenter - (int) (mLineLength[index] * Math.cos(selectionRadians)); int color;// w w w . jav a 2 s . c o m int alpha; Paint paint; // Draw the selection circle color = mColorSelector[index % 2][SELECTOR_CIRCLE]; alpha = mAlphaSelector[index % 2][SELECTOR_CIRCLE].getValue(); paint = mPaintSelector[index % 2][SELECTOR_CIRCLE]; paint.setColor(color); paint.setAlpha(getMultipliedAlpha(color, alpha)); canvas.drawCircle(pointX, pointY, mSelectionRadius[index], paint); // Draw the dot if needed if (mSelectionDegrees[index] % 30 != 0) { // We're not on a direct tick color = mColorSelector[index % 2][SELECTOR_DOT]; alpha = mAlphaSelector[index % 2][SELECTOR_DOT].getValue(); paint = mPaintSelector[index % 2][SELECTOR_DOT]; paint.setColor(color); paint.setAlpha(getMultipliedAlpha(color, alpha)); canvas.drawCircle(pointX, pointY, (mSelectionRadius[index] * 2 / 7), paint); } else { // We're not drawing the dot, so shorten the line to only go as far as the edge of the // selection circle int lineLength = mLineLength[index] - mSelectionRadius[index]; pointX = mXCenter + (int) (lineLength * Math.sin(selectionRadians)); pointY = mYCenter - (int) (lineLength * Math.cos(selectionRadians)); } // Draw the line color = mColorSelector[index % 2][SELECTOR_LINE]; alpha = mAlphaSelector[index % 2][SELECTOR_LINE].getValue(); paint = mPaintSelector[index % 2][SELECTOR_LINE]; paint.setColor(color); paint.setAlpha(getMultipliedAlpha(color, alpha)); canvas.drawLine(mXCenter, mYCenter, pointX, pointY, paint); }
From source file:org.telegram.ui.SettingsActivity.java
@Override public View createView(Context context) { actionBar.setBackgroundColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue)); actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_avatar_actionBarSelectorBlue), false); actionBar.setItemsColor(Theme.getColor(Theme.key_avatar_actionBarIconBlue), false); actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAddToContainer(false);//from ww w. ja v a 2s.c om extraHeight = 88; if (AndroidUtilities.isTablet()) { actionBar.setOccupyStatusBar(false); } actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == edit_name) { presentFragment(new ChangeNameActivity()); } else if (id == logout) { presentFragment(new LogoutActivity()); } } }); ActionBarMenu menu = actionBar.createMenu(); ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other); item.addSubItem(edit_name, LocaleController.getString("EditName", R.string.EditName)); item.addSubItem(logout, LocaleController.getString("LogOut", R.string.LogOut)); int scrollTo; int scrollToPosition = 0; Object writeButtonTag = null; if (listView != null) { scrollTo = layoutManager.findFirstVisibleItemPosition(); View topView = layoutManager.findViewByPosition(scrollTo); if (topView != null) { scrollToPosition = topView.getTop(); } else { scrollTo = -1; } writeButtonTag = writeButton.getTag(); } else { scrollTo = -1; } listAdapter = new ListAdapter(context); fragmentView = new FrameLayout(context) { @Override protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) { if (child == listView) { boolean result = super.drawChild(canvas, child, drawingTime); if (parentLayout != null) { int actionBarHeight = 0; int childCount = getChildCount(); for (int a = 0; a < childCount; a++) { View view = getChildAt(a); if (view == child) { continue; } if (view instanceof ActionBar && view.getVisibility() == VISIBLE) { if (((ActionBar) view).getCastShadows()) { actionBarHeight = view.getMeasuredHeight(); } break; } } parentLayout.drawHeaderShadow(canvas, actionBarHeight); } return result; } else { return super.drawChild(canvas, child, drawingTime); } } }; fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray)); FrameLayout frameLayout = (FrameLayout) fragmentView; listView = new RecyclerListView(context); listView.setVerticalScrollBarEnabled(false); listView.setLayoutManager( layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }); listView.setGlowColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue)); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); listView.setAdapter(listAdapter); listView.setItemAnimator(null); listView.setLayoutAnimation(null); listView.setOnItemClickListener((view, position) -> { if (position == notificationRow) { presentFragment(new NotificationsSettingsActivity()); } else if (position == privacyRow) { presentFragment(new PrivacySettingsActivity()); } else if (position == dataRow) { presentFragment(new DataSettingsActivity()); } else if (position == chatRow) { presentFragment(new ThemeActivity(ThemeActivity.THEME_TYPE_BASIC)); } else if (position == helpRow) { BottomSheet.Builder builder = new BottomSheet.Builder(context); builder.setApplyTopPadding(false); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); HeaderCell headerCell = new HeaderCell(context, true, 23, 15, false); headerCell.setHeight(47); headerCell.setText(LocaleController.getString("SettingsHelp", R.string.SettingsHelp)); linearLayout.addView(headerCell); LinearLayout linearLayoutInviteContainer = new LinearLayout(context); linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); int count = 6; for (int a = 0; a < count; a++) { if (a >= 3 && a <= 4 && !BuildVars.LOGS_ENABLED || a == 5 && !BuildVars.DEBUG_VERSION) { continue; } TextCell textCell = new TextCell(context); String text; switch (a) { case 0: text = LocaleController.getString("AskAQuestion", R.string.AskAQuestion); break; case 1: text = LocaleController.getString("TelegramFAQ", R.string.TelegramFAQ); break; case 2: text = LocaleController.getString("PrivacyPolicy", R.string.PrivacyPolicy); break; case 3: text = LocaleController.getString("DebugSendLogs", R.string.DebugSendLogs); break; case 4: text = LocaleController.getString("DebugClearLogs", R.string.DebugClearLogs); break; case 5: default: text = "Switch Backend"; break; } textCell.setText(text, BuildVars.LOGS_ENABLED || BuildVars.DEBUG_VERSION ? a != count - 1 : a != 2); textCell.setTag(a); textCell.setBackgroundDrawable(Theme.getSelectorDrawable(false)); linearLayoutInviteContainer.addView(textCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); textCell.setOnClickListener(v2 -> { Integer tag = (Integer) v2.getTag(); switch (tag) { case 0: { showDialog(AlertsCreator.createSupportAlert(SettingsActivity.this)); break; } case 1: Browser.openUrl(getParentActivity(), LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl)); break; case 2: Browser.openUrl(getParentActivity(), LocaleController.getString("PrivacyPolicyUrl", R.string.PrivacyPolicyUrl)); break; case 3: sendLogs(); break; case 4: FileLog.cleanupLogs(); break; case 5: { if (getParentActivity() == null) { return; } AlertDialog.Builder builder1 = new AlertDialog.Builder(getParentActivity()); builder1.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder1.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder1.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> { SharedConfig.pushAuthKey = null; SharedConfig.pushAuthKeyId = null; SharedConfig.saveConfig(); ConnectionsManager.getInstance(currentAccount).switchBackend(); }); builder1.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder1.create()); break; } } builder.getDismissRunnable().run(); }); } builder.setCustomView(linearLayout); showDialog(builder.create()); } else if (position == languageRow) { presentFragment(new LanguageSelectActivity()); } else if (position == usernameRow) { presentFragment(new ChangeUsernameActivity()); } else if (position == bioRow) { if (userInfo != null) { presentFragment(new ChangeBioActivity()); } } else if (position == numberRow) { presentFragment(new ChangePhoneHelpActivity()); } }); listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { private int pressCount = 0; @Override public boolean onItemClick(View view, int position) { if (position == versionRow) { pressCount++; if (pressCount >= 2 || BuildVars.DEBUG_PRIVATE_VERSION) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("DebugMenu", R.string.DebugMenu)); CharSequence[] items; items = new CharSequence[] { LocaleController.getString("DebugMenuImportContacts", R.string.DebugMenuImportContacts), LocaleController.getString("DebugMenuReloadContacts", R.string.DebugMenuReloadContacts), LocaleController.getString("DebugMenuResetContacts", R.string.DebugMenuResetContacts), LocaleController.getString("DebugMenuResetDialogs", R.string.DebugMenuResetDialogs), BuildVars.LOGS_ENABLED ? LocaleController.getString("DebugMenuDisableLogs", R.string.DebugMenuDisableLogs) : LocaleController.getString("DebugMenuEnableLogs", R.string.DebugMenuEnableLogs), SharedConfig.inappCamera ? LocaleController.getString("DebugMenuDisableCamera", R.string.DebugMenuDisableCamera) : LocaleController.getString("DebugMenuEnableCamera", R.string.DebugMenuEnableCamera), LocaleController.getString("DebugMenuClearMediaCache", R.string.DebugMenuClearMediaCache), LocaleController.getString("DebugMenuCallSettings", R.string.DebugMenuCallSettings), null, BuildVars.DEBUG_PRIVATE_VERSION ? "Check for app updates" : null }; builder.setItems(items, (dialog, which) -> { if (which == 0) { UserConfig.getInstance(currentAccount).syncContacts = true; UserConfig.getInstance(currentAccount).saveConfig(false); ContactsController.getInstance(currentAccount).forceImportContacts(); } else if (which == 1) { ContactsController.getInstance(currentAccount).loadContacts(false, 0); } else if (which == 2) { ContactsController.getInstance(currentAccount).resetImportedContacts(); } else if (which == 3) { MessagesController.getInstance(currentAccount).forceResetDialogs(); } else if (which == 4) { BuildVars.LOGS_ENABLED = !BuildVars.LOGS_ENABLED; SharedPreferences sharedPreferences = ApplicationLoader.applicationContext .getSharedPreferences("systemConfig", Context.MODE_PRIVATE); sharedPreferences.edit().putBoolean("logsEnabled", BuildVars.LOGS_ENABLED).commit(); } else if (which == 5) { SharedConfig.toggleInappCamera(); } else if (which == 6) { MessagesStorage.getInstance(currentAccount).clearSentMedia(); SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit(); SharedConfig.setNoSoundHintShowed(false); } else if (which == 7) { VoIPHelper.showCallDebugSettings(getParentActivity()); } else if (which == 8) { SharedConfig.toggleRoundCamera16to9(); } else if (which == 9) { ((LaunchActivity) getParentActivity()).checkAppUpdate(true); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else { try { Toast.makeText(getParentActivity(), "\\_()_/", Toast.LENGTH_SHORT).show(); } catch (Exception e) { FileLog.e(e); } } return true; } return false; } }); frameLayout.addView(actionBar); extraHeightView = new View(context); extraHeightView.setPivotY(0); extraHeightView.setBackgroundColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue)); frameLayout.addView(extraHeightView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 88)); shadowView = new View(context); shadowView.setBackgroundResource(R.drawable.header_shadow); frameLayout.addView(shadowView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3)); avatarContainer = new FrameLayout(context); avatarContainer.setPivotX(LocaleController.isRTL ? AndroidUtilities.dp(42) : 0); avatarContainer.setPivotY(0); frameLayout.addView(avatarContainer, LayoutHelper.createFrame(42, 42, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), (LocaleController.isRTL ? 0 : 64), 0, (LocaleController.isRTL ? 64 : 0), 0)); avatarContainer.setOnClickListener(v -> { if (avatar != null) { return; } TLRPC.User user = MessagesController.getInstance(currentAccount) .getUser(UserConfig.getInstance(currentAccount).getClientUserId()); if (user != null && user.photo != null && user.photo.photo_big != null) { PhotoViewer.getInstance().setParentActivity(getParentActivity()); PhotoViewer.getInstance().openPhoto(user.photo.photo_big, provider); } }); avatarImage = new BackupImageView(context); avatarImage.setRoundRadius(AndroidUtilities.dp(21)); avatarContainer.addView(avatarImage, LayoutHelper.createFrame(42, 42)); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(0x55000000); avatarProgressView = new RadialProgressView(context) { @Override protected void onDraw(Canvas canvas) { if (avatarImage != null && avatarImage.getImageReceiver().hasNotThumb()) { paint.setAlpha((int) (0x55 * avatarImage.getImageReceiver().getCurrentAlpha())); canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, AndroidUtilities.dp(21), paint); } super.onDraw(canvas); } }; avatarProgressView.setSize(AndroidUtilities.dp(26)); avatarProgressView.setProgressColor(0xffffffff); avatarContainer.addView(avatarProgressView, LayoutHelper.createFrame(42, 42)); showAvatarProgress(false, false); nameTextView = new TextView(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); setPivotX(LocaleController.isRTL ? getMeasuredWidth() : 0); } }; nameTextView.setTextColor(Theme.getColor(Theme.key_profile_title)); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); nameTextView.setLines(1); nameTextView.setMaxLines(1); nameTextView.setSingleLine(true); nameTextView.setEllipsize(TextUtils.TruncateAt.END); nameTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); nameTextView.setPivotY(0); frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 48 : 118, 0, LocaleController.isRTL ? 118 : 48, 0)); onlineTextView = new TextView(context); onlineTextView.setTextColor(Theme.getColor(Theme.key_avatar_subtitleInProfileBlue)); onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); onlineTextView.setLines(1); onlineTextView.setMaxLines(1); onlineTextView.setSingleLine(true); onlineTextView.setEllipsize(TextUtils.TruncateAt.END); onlineTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); frameLayout.addView(onlineTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 48 : 118, 0, LocaleController.isRTL ? 118 : 48, 0)); writeButton = new ImageView(context); Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_profile_actionBackground), Theme.getColor(Theme.key_profile_actionPressedBackground)); if (Build.VERSION.SDK_INT < 21) { Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow_profile) .mutate(); shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY)); CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0); combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56)); drawable = combinedDrawable; } writeButton.setBackgroundDrawable(drawable); writeButton.setImageResource(R.drawable.menu_camera_av); writeButton.setColorFilter( new PorterDuffColorFilter(Theme.getColor(Theme.key_profile_actionIcon), PorterDuff.Mode.MULTIPLY)); writeButton.setScaleType(ImageView.ScaleType.CENTER); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator .ofFloat(writeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)) .setDuration(200)); animator.addState(new int[] {}, ObjectAnimator .ofFloat(writeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)) .setDuration(200)); writeButton.setStateListAnimator(animator); writeButton.setOutlineProvider(new ViewOutlineProvider() { @SuppressLint("NewApi") @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); } frameLayout.addView(writeButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP, LocaleController.isRTL ? 16 : 0, 0, LocaleController.isRTL ? 0 : 16, 0)); writeButton.setOnClickListener(v -> { TLRPC.User user = MessagesController.getInstance(currentAccount) .getUser(UserConfig.getInstance(currentAccount).getClientUserId()); if (user == null) { user = UserConfig.getInstance(currentAccount).getCurrentUser(); } if (user == null) { return; } imageUpdater.openMenu( user.photo != null && user.photo.photo_big != null && !(user.photo instanceof TLRPC.TL_userProfilePhotoEmpty), () -> MessagesController.getInstance(currentAccount).deleteUserPhoto(null)); }); if (scrollTo != -1) { layoutManager.scrollToPositionWithOffset(scrollTo, scrollToPosition); if (writeButtonTag != null) { writeButton.setTag(0); writeButton.setScaleX(0.2f); writeButton.setScaleY(0.2f); writeButton.setAlpha(0.0f); writeButton.setVisibility(View.GONE); } } needLayout(); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (layoutManager.getItemCount() == 0) { return; } int height = 0; View child = recyclerView.getChildAt(0); if (child != null) { if (layoutManager.findFirstVisibleItemPosition() == 0) { height = AndroidUtilities.dp(88) + (child.getTop() < 0 ? child.getTop() : 0); } if (extraHeight != height) { extraHeight = height; needLayout(); } } } }); return fragmentView; }
From source file:com.nextgis.mobile.fragment.MapFragment.java
protected void drawScaleRuler() { int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 10, getResources().getDisplayMetrics()); int notch = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1, getResources().getDisplayMetrics()); Bitmap ruler = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(ruler); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(ContextCompat.getColor(getActivity(), R.color.primary_dark)); paint.setStrokeWidth(4);/* ww w . j av a 2 s . co m*/ paint.setStyle(Paint.Style.STROKE); canvas.drawLine(0, px, px, px, paint); canvas.drawLine(0, px, 0, 0, paint); canvas.drawLine(0, 0, notch, 0, paint); canvas.drawLine(px, px, px, px - notch, paint); mScaleRuler.setImageBitmap(ruler); }
From source file:com.example.SmartBoard.DrawingView.java
@Override protected void onDraw(Canvas canvas) { drawCanvas.drawPath(drawPath, drawPaint); drawCanvas.drawPath(drawPathRecv, drawPaintSender); if (rectMode) { //draw rectangle drawPaint.setXfermode(null);/* w ww. jav a2 s . co m*/ onDrawRectangle(canvas); } else if (circleMode) { drawPaint.setXfermode(null); onDrawCircle(canvas); } else if (lineMode) { drawPaint.setXfermode(null); onDrawLine(canvas); } else if (textMode) { drawPaint.setXfermode(null); onDrawText(canvas); } else if (dragMode && !dragFinished) { drawPaint.setXfermode(null); onDragDraw(canvas, dragX, dragY); } else if (colorDropperMode) { drawPaint.setXfermode(null); onDrawColorDropper(canvas, dropperX, dropperY); } else if (textSizeMode) { drawPaint.setXfermode(null); } canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint); //redraw objects Paint tempPaint = new Paint(); tempPaint.setStyle(Paint.Style.STROKE); for (String key : textObjects.keySet()) { if (key.compareTo("") == 0) { continue; } JSONObject o = textObjects.get(key); tempPaint.setColor(o.optInt("color")); tempPaint.setStrokeWidth(o.optInt("size")); canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"), tempPaint); } for (String key : objectDrawables.keySet()) { //hashtable problems no time to explain. But it creates a duplicate of last item I add to the table. //So dont print duplicates which have empty string key values if (key.compareTo("") == 0) { continue; } JSONObject o = objectDrawables.get(key); String objectType = o.optString("type"); tempPaint.setColor(o.optInt("color")); tempPaint.setStrokeWidth(o.optInt("size")); if (objectType.compareTo("Circle") == 0) { canvas.drawCircle(o.optInt("x"), o.optInt("y"), o.optInt("radius"), tempPaint); } else if (objectType.compareTo("Line") == 0) { canvas.drawLine(o.optInt("startx"), o.optInt("starty"), o.optInt("stopx"), o.optInt("stopy"), tempPaint); } else if (objectType.compareTo("Rectangle") == 0) { canvas.drawRect(Rect.unflattenFromString(o.optString("dimens")), tempPaint); } else if (objectType.compareTo("Text") == 0) { //canvas.drawRect(Rect.unflattenFromString(o.optString("region")), drawPaint); canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"), tempPaint); } } }