List of usage examples for android.graphics Paint setColor
public void setColor(@ColorInt int color)
From source file:com.cssweb.android.view.PriceView.java
private void drawQihuo(Canvas canvas) { //stockdigit = 0; Paint paint = this.mPaint; tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1);/*from w w w. ja va 2 s .co m*/ this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY / 4, endX, height - DY / 4, tPaint); canvas.drawLine(startX, DY * 2 + DY / 4, endX, DY * 2 + DY / 4, tPaint); canvas.drawLine(startX, DY * 8 + DY / 4, endX, DY * 8 + DY / 4, tPaint); canvas.drawLine(startX, DY * 11 + DY / 4, endX, DY * 11 + DY / 4, 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); String str = ""; double zrsp = jo.getDouble("zrsp"); canvas.translate(0, DY); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY); double temp2 = jo.getDouble("sjw1"); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit); canvas.drawText(str, x, y, paint); canvas.translate(0, DY); temp2 = jo.getDouble("bjw1"); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit); canvas.drawText(str, x, y, paint); canvas.translate(0, -DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); paint.setColor(GlobalColor.colorStockName); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl1"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl1"), true), x - tips, y, paint); canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); 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 / 2, -DY * 5); paint.setTextAlign(Paint.Align.RIGHT); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint); canvas.translate(0, DY); 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); } 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(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, 1); if (zhangfu.equals("-")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangfu + "%", x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrjs"), stockdigit), x, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), true), x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), true), x, y, paint); canvas.translate(0, -DY * 5); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); 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 / 2, -DY * 5); paint.setTextAlign(Paint.Align.RIGHT); 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.colorLabelName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("zrjs"), stockdigit), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), true), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint); canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); 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 / 2, -DY * 2); paint.setTextAlign(Paint.Align.RIGHT); double zt = jo.getDouble("zt"); setColor(paint, zt, zrsp); canvas.drawText(Utils.dataFormation(zt, stockdigit), x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrcc"), 0), x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0), x, y, paint); 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(width / 2, -DY * 2); paint.setTextAlign(Paint.Align.RIGHT); double dt = jo.getDouble("dt"); setColor(paint, dt, zrsp); canvas.drawText(Utils.dataFormation(dt, stockdigit), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("zc"), 0), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.cssweb.android.view.PriceView.java
public void drawPrice(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1);// w w w .ja va 2 s .c o m this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY / 4, endX, height - DY / 4, tPaint); canvas.drawLine(startX, DY + DY / 4, endX, DY + DY / 4, tPaint); canvas.drawLine(startX, DY * 6 + DY / 4, endX, DY * 6 + DY / 4, tPaint); canvas.drawLine(startX, DY * 11 + DY / 4, endX, DY * 11 + DY / 4, 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); String str = ""; double zrsp = jo.getDouble("zrsp"); canvas.translate(0, DY); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, 0); if (jo.getDouble("wb") < 0) paint.setColor(GlobalColor.colorPriceDown); else if (jo.getDouble("wb") > 0) paint.setColor(GlobalColor.colorpriceUp); else paint.setColor(GlobalColor.colorPriceEqual); if (jo.getInt("tp") == 1) canvas.drawText("", x, y, paint); else canvas.drawText(Utils.dataFormation(jo.getDouble("wb") * 100, 1) + "%", x, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, 0); if (jo.getDouble("wc") < 0) { paint.setColor(GlobalColor.colorPriceDown); canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x - tips, y, paint); } else if (jo.getDouble("wc") > 0) { paint.setColor(GlobalColor.colorpriceUp); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x - tips, y, paint); } else { paint.setColor(GlobalColor.colorPriceEqual); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), false), x - tips, y, paint); } canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); 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); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 4); for (int i = 5; i >= 1; i--) { double temp2 = jo.getDouble("sjw" + i); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp")); //paint.setTextAlign(Paint.Align.CENTER); canvas.drawText(str, x, y, paint); if (i != 1) canvas.translate(0, DY); } paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); for (int i = 5; i >= 1; i--) { paint.setTextAlign(Paint.Align.RIGHT); canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl" + i), false), x - tips, y, paint); if (i != 1) canvas.translate(0, DY); } canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); 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 / 2, -DY * 4); paint.setTextAlign(Paint.Align.RIGHT); 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, -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); } canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); 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); int syjd = jo.getInt("syjd"); switch (syjd) { case 1: canvas.drawText("()", x + tips, y, paint); break; case 2: canvas.drawText("()", x + tips, y, paint); break; case 3: canvas.drawText("()", x + tips, y, paint); break; case 4: canvas.drawText("()", x + tips, y, paint); break; default: canvas.drawText("()", x + tips, y, paint); break; } canvas.translate(width / 2, -DY * 7); paint.setTextAlign(Paint.Align.RIGHT); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.drawText(Utils.dataFormation(zjcj, stockdigit, jo.getInt("tp")), x, y, paint); canvas.translate(0, DY); 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); } 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(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit, jo.getInt("tp")); if (zhangfu.equals("-") || zhangfu.equals("")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangfu + "%", x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("hs") * 100, 1) + "%", x, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jz"), 1), x, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("mgsy"), 2), x, y, paint); canvas.translate(0, -DY * 7); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); 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); if (NameRule.isBond(type)) canvas.drawText("", x + tips, y, paint); else canvas.drawText("PE()", x + tips, y, paint); canvas.translate(width / 2, -DY * 7); paint.setTextAlign(Paint.Align.RIGHT); 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); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("gb"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("ltsl") * 100, true), x - tips, y, paint); canvas.translate(0, DY); if (NameRule.isBond(type)) { canvas.drawText(Utils.dataFormation(jo.getDouble("fullprice"), 1), x - tips, y, paint); } else { canvas.drawText(Utils.dataFormation(jo.getDouble("sy"), 1), x - tips, y, paint); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
private void setupHourTextPaint(Paint p) { p.setColor(mCalendarHourLabelColor); p.setTextSize(HOURS_TEXT_SIZE);//from ww w . ja v a2 s . c o m p.setTypeface(Typeface.DEFAULT); p.setTextAlign(Align.RIGHT); p.setAntiAlias(true); }
From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (DEBUG) {/*from w w w .j av a 2 s .c o m*/ Paint p = new Paint(); p.setColor(Color.RED); p.setStrokeWidth(2); p.setStyle(Paint.Style.STROKE); canvas.drawLine(0, getMaxPanelHeight(), getWidth(), getMaxPanelHeight(), p); p.setColor(Color.BLUE); canvas.drawLine(0, getExpandedHeight(), getWidth(), getExpandedHeight(), p); p.setColor(Color.GREEN); canvas.drawLine(0, calculatePanelHeightQsExpanded(), getWidth(), calculatePanelHeightQsExpanded(), p); p.setColor(Color.YELLOW); canvas.drawLine(0, calculatePanelHeightShade(), getWidth(), calculatePanelHeightShade(), p); p.setColor(Color.MAGENTA); canvas.drawLine(0, calculateQsTopPadding(), getWidth(), calculateQsTopPadding(), p); p.setColor(Color.CYAN); canvas.drawLine(0, mNotificationStackScroller.getTopPadding(), getWidth(), mNotificationStackScroller.getTopPadding(), p); } }
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
private void drawAmPm(Canvas canvas, Paint p) { p.setColor(mCalendarAmPmLabel); p.setTextSize(AMPM_TEXT_SIZE);//from w w w . j ava 2 s. c om p.setTypeface(mBold); p.setAntiAlias(true); p.setTextAlign(Align.RIGHT); String text = mAmString; if (mFirstHour >= 12) { text = mPmString; } int y = mFirstCell + mFirstHourOffset + 2 * mHoursTextHeight + HOUR_GAP; canvas.drawText(text, HOURS_LEFT_MARGIN, y, p); if (mFirstHour < 12 && mFirstHour + mNumHours > 12) { // Also draw the "PM" text = mPmString; y = mFirstCell + mFirstHourOffset + (12 - mFirstHour) * (mCellHeight + HOUR_GAP) + 2 * mHoursTextHeight + HOUR_GAP; canvas.drawText(text, HOURS_LEFT_MARGIN, y, p); } }
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
private void init(Context context) { setFocusable(true);/*from w ww.jav a 2s . c o m*/ // Allow focus in touch mode so that we can do keyboard shortcuts // even after we've entered touch mode. setFocusableInTouchMode(true); setClickable(true); setOnCreateContextMenuListener(this); mFirstDayOfWeek = Time.MONDAY; mCurrentTime = new Time(DayUtils.getTimeZone(context, mTZUpdater)); long currentTime = System.currentTimeMillis(); mCurrentTime.set(currentTime); mTodayJulianDay = Time.getJulianDay(currentTime, mCurrentTime.gmtoff); mEventTextPaint.setTextSize(EVENT_TEXT_FONT_SIZE); mEventTextPaint.setTextAlign(Align.LEFT); mEventTextPaint.setAntiAlias(true); int gridLineColor = 0xff707070; Paint p = mSelectionPaint; p.setColor(gridLineColor); p.setStyle(Style.FILL); p.setAntiAlias(false); p = mPaint; p.setAntiAlias(true); // Long day names mDayStrsLong = new String[14]; // Allocate space for 2 weeks worth of weekday names so that we can // easily start the week display at any week day. mDayStrs = new String[14]; // Also create an array of 2-letter abbreviations. mDayStrs2Letter = new String[14]; for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) { int index = i - Calendar.SUNDAY; mDayStrsLong[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_LONG).toUpperCase(); mDayStrsLong[index + 7] = mDayStrsLong[index]; // e.g. Tue for Tuesday mDayStrs[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_MEDIUM).toUpperCase(); mDayStrs[index + 7] = mDayStrs[index]; // e.g. Tu for Tuesday mDayStrs2Letter[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_SHORT).toUpperCase(); // If we don't have 2-letter day strings, fall back to 1-letter. if (mDayStrs2Letter[index].equals(mDayStrs[index])) { mDayStrs2Letter[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_SHORTEST); } mDayStrs2Letter[index + 7] = mDayStrs2Letter[index]; } // Figure out how much space we need for the 3-letter abbrev names // in the worst case. p.setTextSize(DATE_HEADER_FONT_SIZE); p.setTypeface(mBold); String[] dateStrs = { " 28", " 30" }; mDateStrWidth = computeMaxStringWidth(0, dateStrs, p); Time time = new Time(); time.setJulianDay(mFirstJulianDay); String s = SimpleDateFormat.getDateInstance().format(new Date(time.toMillis(false))); mDateStrWidthLong = computeMaxStringWidth(0, new String[] { s }, p); p.setTextSize(DAY_HEADER_FONT_SIZE); mDateStrWidth += computeMaxStringWidth(0, mDayStrs, p); mDateStrWidthLong += computeMaxStringWidth(0, mDayStrsLong, p); p.setTextSize(HOURS_TEXT_SIZE); p.setTypeface(null); handleOnResume(); mAmString = DateUtils.getAMPMString(Calendar.AM).toUpperCase(); mPmString = DateUtils.getAMPMString(Calendar.PM).toUpperCase(); String[] ampm = { mAmString, mPmString }; p.setTextSize(AMPM_TEXT_SIZE); mHoursWidth = Math.max(HOURS_MARGIN, computeMaxStringWidth(mHoursWidth, ampm, p) + HOURS_RIGHT_MARGIN); mHoursWidth = Math.max(MIN_HOURS_WIDTH, mHoursWidth); LayoutInflater inflater; inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); Resources.Theme dialogTheme = getResources().newTheme(); dialogTheme.applyStyle(android.R.style.Theme_Dialog, true); TypedArray ta = dialogTheme.obtainStyledAttributes(new int[] { android.R.attr.windowBackground }); // Catch long clicks for creating a new event mBaseDate = new Time(DayUtils.getTimeZone(context, mTZUpdater)); long millis = System.currentTimeMillis(); mBaseDate.set(millis); mEarliestStartHour = new int[mNumDays]; mHasAllDayEvent = new boolean[mNumDays]; // mLines is the array of points used with Canvas.drawLines() in // drawGridBackground() and drawAllDayEvents(). Its size depends // on the max number of lines that can ever be drawn by any single // drawLines() call in either of those methods. final int maxGridLines = (24 + 1) // max horizontal lines we might draw + (mNumDays + 1); // max vertical lines we might draw mLines = new float[maxGridLines * 4]; }
From source file:com.android.mms.ui.MessageUtils.java
public static Bitmap getCircularBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = bitmap.getWidth() / 2; paint.setAntiAlias(true);//from w w w . j a va 2 s . com 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:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
private void drawScrollLine(Rect r, Canvas canvas, Paint p) { final int right = computeDayLeftPosition(mNumDays); final int y = mFirstCell - 1; p.setAntiAlias(false);//from w w w .j ava 2 s . c om p.setStyle(Style.FILL); p.setColor(mCalendarGridLineInnerHorizontalColor); p.setStrokeWidth(GRID_LINE_INNER_WIDTH); canvas.drawLine(GRID_LINE_LEFT_MARGIN, y, right, y, p); p.setAntiAlias(true); }
From source file:fr.magistry.taigime.CandidateView.java
/** * If the canvas is null, then only touch calculations are performed to pick the target * candidate.//from w w w. java 2 s . c o m */ @Override protected void onDraw(Canvas canvas) { if (canvas != null) { super.onDraw(canvas); } mTotalWidth = 0; if (mSuggestions == null) return; if (mBgPadding == null) { mBgPadding = new Rect(0, 0, 0, 0); if (getBackground() != null) { getBackground().getPadding(mBgPadding); } } int x = 0; final int count = mSuggestions.size(); final int height = getHeight(); final Rect bgPadding = mBgPadding; final Paint paint = mPaint; final int touchX = mTouchX; final int scrollX = getScrollX(); final boolean scrolled = mScrolled; final int y; //= (int) ( - mPaint.ascent() + mVerticalPadding); final int y2; //= (int) (height - mPaintTRS.descent()); // (y - mVerticalPadding - mPaint.descent() - mPaintTRS.ascent()) ; final float initialTRSsize = mPaintTRS.getTextSize(); if (mOutputTRS) { y2 = (int) (-mPaintTRS.ascent() + mVerticalPadding); y = (int) (height - mPaint.descent()); } else { y = (int) (-mPaint.ascent() + mVerticalPadding); y2 = (int) (height - mPaintTRS.descent()); } for (int i = 0; i < count; i++) { Candidate suggestion = mSuggestions.get(i); String hanji = suggestion.getWord().getHanji(); String trs = ""; switch (ROMANISATION_OUTPUT_MODE) { case 0: trs = suggestion.getWord().getTailuo(); break; case 1: trs = suggestion.getWord().getPOJ(); break; case 2: trs = suggestion.getWord().getPOJ_safe(); break; default: trs = suggestion.getWord().getTailuo(); } float textWidth; if (i == 0) { hanji = ""; trs = "";//hanji;//TODO: conversion? //if(mOutputTRS){ trs = suggestion.getWord().getBopomo(); if (trs != "") textWidth = mPaintBPM.measureText(trs); else textWidth = 3; //} //else { // hanji = suggestion.getWord().getBopomo(); // textWidth = paint.measureText(hanji); //} } else textWidth = paint.measureText(hanji); if (textWidth == 0.0) textWidth = paint.measureText(" "); final int wordWidth = (int) textWidth + X_GAP * 2; mWordX[i] = x; mWordWidth[i] = wordWidth; mPaintTRS.setTextSize(initialTRSsize); mPaintTRS.setTextSize(reduceTextSizeFromWidth(mPaintTRS, trs, textWidth)); paint.setColor(mColorNormal); if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) { if (canvas != null) { canvas.translate(x, 0); mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height); mSelectionHighlight.draw(canvas); canvas.translate(-x, 0); } mSelectedIndex = i; } if (canvas != null) { Paint activePaint = null; Paint secondPaint = null; if (mOutputTRS) { activePaint = mPaintTRS; secondPaint = paint; } else { activePaint = paint; secondPaint = mPaintTRS; } if (i == 0) { activePaint = mPaintBPM; } secondPaint.setAlpha(150); if ((i == mCursor)) { activePaint.setFakeBoldText(true); activePaint.setColor(mColorRecommended); } else if (i != 0) { activePaint.setColor(mColorOther); } if (i == 0) { canvas.drawText(trs, x + X_GAP, y2, mPaintBPM); } else { canvas.drawText(hanji, x + X_GAP, y, paint); canvas.drawText(trs, x + X_GAP, y2, mPaintTRS); } activePaint.setColor(mColorOther); canvas.drawLine(x + wordWidth + 0.5f, bgPadding.top, x + wordWidth + 0.5f, height + 1, paint); activePaint.setFakeBoldText(false); secondPaint.setAlpha(255); } x += wordWidth; mPaintTRS.setTextSize(initialTRSsize); } mTotalWidth = x; if (mTargetScrollX != getScrollX()) { scrollToTarget(); } }
From source file:com.eveningoutpost.dexdrip.Home.java
private void setupCharts() { bgGraphBuilder = new BgGraphBuilder(this); updateStuff = false;//from ww w.j ava 2 s .com chart = (LineChartView) findViewById(R.id.chart); if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) { ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) chart.getLayoutParams(); params.topMargin = 130; chart.setLayoutParams(params); } chart.setBackgroundColor(getCol(X.color_home_chart_background)); chart.setZoomType(ZoomType.HORIZONTAL); //Transmitter Battery Level final Sensor sensor = Sensor.currentSensor(); if (sensor != null && sensor.latest_battery_level != 0 && sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_LOW && !prefs.getBoolean("disable_battery_warning", false)) { Drawable background = new Drawable() { @Override public void draw(Canvas canvas) { DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics(); int px = (int) (30 * (metrics.densityDpi / 160f)); Paint paint = new Paint(); paint.setTextSize(px); paint.setAntiAlias(true); paint.setColor(Color.parseColor("#FFFFAA")); paint.setStyle(Paint.Style.STROKE); paint.setAlpha(100); canvas.drawText(getString(R.string.transmitter_battery), 10, chart.getHeight() / 3 - (int) (1.2 * px), paint); if (sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_EMPTY) { paint.setTextSize((int) (px * 1.5)); canvas.drawText(getString(R.string.very_low), 10, chart.getHeight() / 3, paint); } else { canvas.drawText(getString(R.string.low), 10, chart.getHeight() / 3, paint); } } @Override public void setAlpha(int alpha) { } @Override public void setColorFilter(ColorFilter cf) { } @Override public int getOpacity() { return 0; // TODO Which pixel format should this be? } }; chart.setBackground(background); } previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview); chart.setLineChartData(bgGraphBuilder.lineData()); chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener(mActivity)); previewChart.setBackgroundColor(getCol(X.color_home_chart_background)); previewChart.setZoomType(ZoomType.HORIZONTAL); previewChart.setLineChartData(bgGraphBuilder.previewLineData(chart.getLineChartData())); updateStuff = true; previewChart.setViewportCalculationEnabled(true); chart.setViewportCalculationEnabled(true); previewChart.setViewportChangeListener(new ViewportListener()); chart.setViewportChangeListener(new ChartViewPortListener()); setViewport(); if (small_height) { previewChart.setVisibility(View.GONE); // quick test Viewport moveViewPort = new Viewport(chart.getMaximumViewport()); float tempwidth = (float) moveViewPort.width() / 4; holdViewport.left = moveViewPort.right - tempwidth; holdViewport.right = moveViewPort.right + (moveViewPort.width() / 24); holdViewport.top = moveViewPort.top; holdViewport.bottom = moveViewPort.bottom; chart.setCurrentViewport(holdViewport); previewChart.setCurrentViewport(holdViewport); } else { previewChart.setVisibility(View.VISIBLE); } if (insulinset || glucoseset || carbsset || timeset) { if (chart != null) { chart.setAlpha((float) 0.10); // TODO also set buttons alpha } } }