Example usage for android.graphics Paint setStyle

List of usage examples for android.graphics Paint setStyle

Introduction

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

Prototype

public void setStyle(Style style) 

Source Link

Document

Set the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes Fill).

Usage

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    int userId = Util.getUserId(Process.myUid());
    boolean mounted = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
    boolean updates = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingUpdates, false);

    menu.findItem(R.id.menu_export).setEnabled(mounted);
    menu.findItem(R.id.menu_import).setEnabled(mounted);

    menu.findItem(R.id.menu_submit).setEnabled(Util.hasValidFingerPrint(this));

    menu.findItem(R.id.menu_pro).setVisible(!Util.isProEnabled() && Util.hasProLicense(this) == null);

    menu.findItem(R.id.menu_dump).setVisible(Util.isDebuggable(this));

    menu.findItem(R.id.menu_update).setVisible(updates);
    menu.findItem(R.id.menu_update).setEnabled(mounted);

    // Update filter count

    // Get settings
    boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false);
    boolean fInternet = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFInternet, false);
    boolean fRestriction = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestriction, false);
    boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, true);
    boolean fOnDemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemand, false);
    boolean fUser = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUser, true);
    boolean fSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFSystem, false);

    // Count number of active filters
    int numberOfFilters = 0;
    if (fUsed)/*from  ww w . ja v a 2  s .c  om*/
        numberOfFilters++;
    if (fInternet)
        numberOfFilters++;
    if (fRestriction)
        numberOfFilters++;
    if (fPermission)
        numberOfFilters++;
    if (fOnDemand)
        numberOfFilters++;
    if (fUser)
        numberOfFilters++;
    if (fSystem)
        numberOfFilters++;

    if (numberOfFilters > 0) {
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_filter)
                .copy(Bitmap.Config.ARGB_8888, true);

        Paint paint = new Paint();
        paint.setStyle(Style.FILL);
        paint.setColor(Color.GRAY);
        paint.setTextSize(bitmap.getWidth() / 3);
        paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));

        String text = Integer.toString(numberOfFilters);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawText(text, bitmap.getWidth() - paint.measureText(text), bitmap.getHeight(), paint);

        MenuItem fMenu = menu.findItem(R.id.menu_filter);
        fMenu.setIcon(new BitmapDrawable(getResources(), bitmap));
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.example.SmartBoard.DrawingView.java

public void onDrawCircle(Canvas canvas) {
    Paint paint = drawPaint;
    if (points[3] == null) //point4 null when user did not touch and move on screen.
        return;//from w  w w  .j  ava  2  s  . co  m
    int left, top, right, bottom;
    left = points[0].x;
    top = points[0].y;
    right = points[0].x;
    bottom = points[0].y;
    for (int i = 1; i < points.length; i++) {
        left = left > points[i].x ? points[i].x : left;
        top = top > points[i].y ? points[i].y : top;
        right = right < points[i].x ? points[i].x : right;
        bottom = bottom < points[i].y ? points[i].y : bottom;
    }

    float cx = (left + right) / 2f;
    float cy = (top + bottom) / 2f;
    float radius = (float) Math.hypot(top - bottom, right - left) / 2f;

    //draw stroke
    paint.setStyle(Paint.Style.STROKE);
    // paint.setColor(Color.parseColor("#AADB1255"));
    paint.setStrokeWidth(5);

    if (finished) {

        JSONObject objectProperties = new JSONObject();
        String key = UUID.randomUUID().toString();

        try {
            objectProperties.put("id", key);
            objectProperties.put("type", "Circle");
            objectProperties.put("color", drawPaint.getColor());
            objectProperties.put("size", 5);
            objectProperties.put("clientId", client.getClientId());
            objectProperties.put("radius", radius);
            objectProperties.put("x", cx);
            objectProperties.put("y", cy);

        } catch (JSONException e) {

        }

        objectDrawables.put(key, objectProperties);

        //  drawCanvas.drawCircle(cx, cy, radius, paint);

        //   drawCanvas.save();
        //  mqtt.publishRectangle(objectProperties);
        mqtt.publishCircle(objectProperties);

        //reset to start drawing again
        points = new Point[4];
        colorballs.clear();
        return;

    }

    canvas.drawCircle(cx, cy, radius, paint);
    // draw the balls on the canvas
    //  paint.setColor(Color.BLUE);
    paint.setTextSize(18);
    paint.setStrokeWidth(0);
    // paint.setColor(Color.BLUE);
    for (int i = 0; i < colorballs.size(); i++) {
        ColorBall ball = colorballs.get(i);
        canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), paint);

        canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint);
    }
}

From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (DEBUG) {/*from  www. ja  va 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 drawScrollLine(Rect r, Canvas canvas, Paint p) {
    final int right = computeDayLeftPosition(mNumDays);
    final int y = mFirstCell - 1;

    p.setAntiAlias(false);/*from   w  ww .jav  a2s . co m*/
    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:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private void init(Context context) {
    setFocusable(true);/*  w w w . j a v a2s . c om*/

    // 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.eveningoutpost.dexdrip.Home.java

private void setupCharts() {
    bgGraphBuilder = new BgGraphBuilder(this);
    updateStuff = false;// w ww  .  ja v  a 2  s  . co m
    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
        }
    }

}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

/**
 * @param r//from  w w  w.java 2s .co  m
 * @param canvas
 * @param p
 */
private void drawBgColors(Rect r, Canvas canvas, Paint p) {
    int todayIndex = mTodayJulianDay - mFirstJulianDay;
    // Draw the hours background color
    r.top = mDestRect.top;
    r.bottom = mDestRect.bottom;
    r.left = 0;
    r.right = mHoursWidth;
    p.setColor(mBgColor);
    p.setStyle(Style.FILL);
    p.setAntiAlias(false);
    canvas.drawRect(r, p);

    // Draw background for grid area
    if (mNumDays == 1 && todayIndex == 0) {
        // Draw a white background for the time later than current time
        int lineY = mCurrentTime.hour * (mCellHeight + HOUR_GAP) + ((mCurrentTime.minute * mCellHeight) / 60)
                + 1;
        if (lineY < mViewStartY + mViewHeight) {
            lineY = Math.max(lineY, mViewStartY);
            r.left = mHoursWidth;
            r.right = mViewWidth;
            r.top = lineY;
            r.bottom = mViewStartY + mViewHeight;
            p.setColor(mFutureBgColor);
            canvas.drawRect(r, p);
        }
    } else if (todayIndex >= 0 && todayIndex < mNumDays) {
        // Draw today with a white background for the time later than current time
        int lineY = mCurrentTime.hour * (mCellHeight + HOUR_GAP) + ((mCurrentTime.minute * mCellHeight) / 60)
                + 1;
        if (lineY < mViewStartY + mViewHeight) {
            lineY = Math.max(lineY, mViewStartY);
            r.left = computeDayLeftPosition(todayIndex) + 1;
            r.right = computeDayLeftPosition(todayIndex + 1);
            r.top = lineY;
            r.bottom = mViewStartY + mViewHeight;
            p.setColor(mFutureBgColor);
            canvas.drawRect(r, p);
        }

        // Paint Tomorrow and later days with future color
        if (todayIndex + 1 < mNumDays) {
            r.left = computeDayLeftPosition(todayIndex + 1) + 1;
            r.right = computeDayLeftPosition(mNumDays);
            r.top = mDestRect.top;
            r.bottom = mDestRect.bottom;
            p.setColor(mFutureBgColor);
            canvas.drawRect(r, p);
        }
    } else if (todayIndex < 0) {
        // Future
        r.left = computeDayLeftPosition(0) + 1;
        r.right = computeDayLeftPosition(mNumDays);
        r.top = mDestRect.top;
        r.bottom = mDestRect.bottom;
        p.setColor(mFutureBgColor);
        canvas.drawRect(r, p);
    }
    p.setAntiAlias(true);
}

From source file:com.acceleratedio.pac_n_zoom.DrawSVG.java

public ArrayList<ImageView> DrawSVG(Context context, ImageView orgnlImageView, RelativeLayout rel_anm_lo) {

    paint.setColor(Color.WHITE);/* w w w .ja va  2  s  .  c  om*/
    paint.setStyle(Paint.Style.FILL);
    LoadSVG.SVGData data = AnimActivity.svg_data;
    ArrayList<ImageView> imgViews = new ArrayList<ImageView>();
    imgViews.add(orgnlImageView);

    if (data.symbl != null) {

        ArrayList<String> sprt_ordr = data.svg.ordr;
        int sym_mbr = 0;
        Bitmap bitmap;
        Canvas canvas;

        // - Loop through the sprites 
        int sprt_nmbr = sprt_ordr.size();
        data.svg.initScl = new float[sprt_nmbr];
        float[] initScl = data.svg.initScl;

        for (int sprt_mbr = 1; sprt_mbr < sprt_nmbr; sprt_mbr += 1) {

            String sprt_id = sprt_ordr.get(sprt_mbr); // e.g., id="g2_0"

            if (Integer.parseInt(sprt_id.substring(sprt_id.indexOf('_') + 1)) > 0) {
                // The symbol is already drawn; replicate the view   
                String init_sprt = sprt_id.substring(0, sprt_id.indexOf('_') + 1) + '0';
                String svg_ordr = data.svg.svg_ordr;
                String cnt_str = svg_ordr.substring(0, svg_ordr.indexOf(init_sprt));
                ImageView init_vw = imgViews.get(StringUtils.countMatches(cnt_str, ","));
                Bitmap initBmp = ((BitmapDrawable) init_vw.getDrawable()).getBitmap();

                bitmap = Bitmap.createBitmap(initBmp.getWidth(), initBmp.getHeight(), initBmp.getConfig());

                canvas = new Canvas(bitmap);
                canvas.save(Canvas.MATRIX_SAVE_FLAG);
                xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id);
                canvas.scale(crt_sprt.scl, crt_sprt.scl);
                initScl[sprt_mbr] = crt_sprt.scl;
                canvas.translate(0, 0);
            } else {
                // The symbol needs to be drawn; a new view   is used
                bitmap = getCreatBmp(rel_anm_lo);
                canvas = new Canvas(bitmap);
                canvas.save(Canvas.MATRIX_SAVE_FLAG);

                // - Set the init values
                xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id);
                canvas.scale(crt_sprt.scl, crt_sprt.scl);
                initScl[sprt_mbr] = crt_sprt.scl;
                canvas.translate(0, 0);

                // - Draw the bitmap
                LoadSVG.symbol crt_sym = data.symbl.get(sym_mbr);
                ArrayList<LoadSVG.path> pths = crt_sym.pths;
                int pth_nmbr = pths.size();

                // Loop through the paths
                for (int pth_mbr = 0; pth_mbr < pth_nmbr; pth_mbr += 1) {

                    LoadSVG.path crt_pth = pths.get(pth_mbr);
                    final Path path = new Path();
                    final Paint paint = new Paint();
                    /* Debug
                    if (pth_mbr + 1 == pth_nmbr) {
                            
                       String log_str = "Paths: pth_mbr = " +
                          String.valueOf(pth_mbr) + "; color = " + crt_pth.clr;
                            
                       Log.d("DrawSVG", log_str);
                    }
                    */
                    paint.setColor(Color.parseColor(crt_pth.clr));
                    paint.setAntiAlias(true);
                    paint.setStyle(Paint.Style.FILL_AND_STROKE);
                    ld_pth_pnts(crt_pth.pth, path);
                    path.close();
                    path.setFillType(Path.FillType.EVEN_ODD);
                    canvas.drawPath(path, paint);
                }

                canvas.restore();
                sym_mbr += 1;
            }

            ImageView iv = new ImageView(context);
            iv.setImageBitmap(bitmap);

            RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);

            iv.draw(canvas);
            iv.setLayoutParams(rlp);
            iv.setBackgroundColor(Color.TRANSPARENT);
            imgViews.add(iv);
        } // sprites
    } // if symbol

    return imgViews;
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private Rect drawEventRect(Event event, Canvas canvas, Paint p, Paint eventTextPaint, int visibleTop,
        int visibleBot) {
    // Draw the Event Rect
    Rect r = mRect;/*from   w w w. j ava2  s.  c o m*/
    r.top = Math.max((int) event.top + EVENT_RECT_TOP_MARGIN, visibleTop);
    r.bottom = Math.min((int) event.bottom - EVENT_RECT_BOTTOM_MARGIN, visibleBot);
    r.left = (int) event.left + EVENT_RECT_LEFT_MARGIN;
    r.right = (int) event.right;

    int color;
    if (event == mClickedEvent) {
        color = mClickedColor;
    } else {
        color = event.color;
    }

    p.setStyle(Style.FILL_AND_STROKE);
    p.setAntiAlias(false);

    int floorHalfStroke = (int) Math.floor(EVENT_RECT_STROKE_WIDTH / 2.0f);
    int ceilHalfStroke = (int) Math.ceil(EVENT_RECT_STROKE_WIDTH / 2.0f);
    r.top = Math.max((int) event.top + EVENT_RECT_TOP_MARGIN + floorHalfStroke, visibleTop);
    r.bottom = Math.min((int) event.bottom - EVENT_RECT_BOTTOM_MARGIN - ceilHalfStroke, visibleBot);
    r.left += floorHalfStroke;
    r.right -= ceilHalfStroke;
    p.setStrokeWidth(EVENT_RECT_STROKE_WIDTH);
    p.setColor(color);
    int alpha = p.getAlpha();
    p.setAlpha(mEventsAlpha);
    canvas.drawRect(r, p);
    p.setAlpha(alpha);
    p.setStyle(Style.FILL);

    // If this event is selected, then use the selection color
    if (mSelectedEvent == event && mClickedEvent != null) {
        boolean paintIt = false;
        color = 0;

        if (paintIt) {
            p.setColor(color);
            canvas.drawRect(r, p);
        }
        p.setAntiAlias(true);
    }

    // Setup rect for drawEventText which follows
    r.top = (int) event.top + EVENT_RECT_TOP_MARGIN;
    r.bottom = (int) event.bottom - EVENT_RECT_BOTTOM_MARGIN;
    r.left = (int) event.left + EVENT_RECT_LEFT_MARGIN;
    r.right = (int) event.right - EVENT_RECT_RIGHT_MARGIN;
    return r;
}

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

public void drawQuoteWin(Canvas canvas, JSONObject quoteData, int idx) throws JSONException {
    Paint mPaint = new Paint();
    mPaint.setTextAlign(Paint.Align.LEFT);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mPaint.setAntiAlias(true);/*from   www . j av  a  2s .com*/

    mPaint.setColor(GlobalColor.colorKlinePopub);
    mPaint.setTextSize(sTextSize);
    canvas.drawText(":", 0, axisLabelHeight, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 3, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 5, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 7, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 9, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 11, mPaint);
    canvas.drawText("??:", 0, axisLabelHeight * 13, mPaint);
    canvas.drawText("??:", 0, axisLabelHeight * 15, mPaint);

    mPaint.setTextAlign(Paint.Align.RIGHT);
    String qt = quoteData.getJSONArray("K").getJSONArray(idx).getString(0);
    double jrkp = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(1);
    double zg = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(2);
    double zd = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(3);
    double sp = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(4);
    double preclose;
    if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) {
        switch (idx) {
        case 0:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(7);
            break;
        default:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx - 1).getDouble(7);
            break;
        }
        if (quoteData.getJSONArray("K").length() == 1) {
            preclose = quoteData.getJSONArray("K").getJSONArray(0).getDouble(7);
        }
    } else {
        switch (idx) {
        case 0:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(4);
            break;
        default:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx - 1).getDouble(4);
            break;
        }
        if (quoteData.getJSONArray("K").length() == 1) {
            preclose = quoteData.getDouble("zrsp");//quoteData.getJSONArray("K").getJSONArray(0).getDouble(4);
        }
    }
    mPaint.setColor(getcolor(jrkp, preclose));
    canvas.drawText(Utils.dataFormation(jrkp, stockdigit), klineX, axisLabelHeight * 2, mPaint);
    mPaint.setColor(getcolor(zg, preclose));
    canvas.drawText(Utils.dataFormation(zg, stockdigit), klineX, axisLabelHeight * 4, mPaint);
    mPaint.setColor(getcolor(zd, preclose));
    canvas.drawText(Utils.dataFormation(zd, stockdigit), klineX, axisLabelHeight * 6, mPaint);
    mPaint.setColor(getcolor(sp, preclose));
    canvas.drawText(Utils.dataFormation(sp, stockdigit), klineX, axisLabelHeight * 8, mPaint);
    double zhangdie = sp - preclose;
    if (zhangdie > 0)
        mPaint.setColor(GlobalColor.colorpriceUp);
    else if (zhangdie < 0)
        mPaint.setColor(GlobalColor.colorPriceDown);
    else
        mPaint.setColor(GlobalColor.colorPriceEqual);
    canvas.drawText(Utils.dataFormation(zhangdie, stockdigit), klineX, axisLabelHeight * 10, mPaint);
    //      if(quoteData.getString("period").equals("min5") || 
    //            quoteData.getString("period").equals("min15") ||
    //            quoteData.getString("period").equals("min30") ||
    //            quoteData.getString("period").equals("min60")){
    //         qt = qt.substring(4,6)+'/'+qt.substring(6,8)+' '+qt.substring(8);
    //      }else{
    //         qt = qt.substring(2,4)+qt.substring(4,6)+qt.substring(6,8);
    //      }
    qt = qt.substring(2, 4) + qt.substring(4, 6) + qt.substring(6, 8);
    mPaint.setColor(GlobalColor.colorLabelName);
    canvas.drawText(qt, klineX, axisLabelHeight * 12, mPaint);

    mPaint.setColor(GlobalColor.colorStockName);
    canvas.drawText(Utils.getAmountFormat(quoteData.getJSONArray("K").getJSONArray(idx).getDouble(5), false),
            klineX, axisLabelHeight * 14, mPaint);
    mPaint.setColor(GlobalColor.colorStockName);
    canvas.drawText(Utils.getAmountFormat(quoteData.getJSONArray("K").getJSONArray(idx).getDouble(6), false),
            klineX, axisLabelHeight * 16, mPaint);
}