Search in sources :

Example 1 with BgGraphBuilder

use of com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder in project xDrip by NightscoutFoundation.

the class ExampleChartPreferenceView method refreshView.

protected void refreshView(View view) {
    LineChartView chart = (LineChartView) view.findViewById(R.id.example_linechart);
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(getContext());
    chart.setLineChartData(bgGraphBuilder.lineData());
    Viewport viewport = chart.getMaximumViewport();
    chart.setViewportCalculationEnabled(false);
    chart.setInteractive(false);
    chart.setCurrentViewport(viewport);
    chart.setPadding(0, 0, 0, 0);
    chart.setLeft(0);
    chart.setTop(0);
    Log.d(TAG, "onBindExampleChart: refreshview " + chart.getHeight());
}
Also used : Viewport(lecho.lib.hellocharts.model.Viewport) LineChartView(lecho.lib.hellocharts.view.LineChartView) BgGraphBuilder(com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder)

Example 2 with BgGraphBuilder

use of com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder in project xDrip by NightscoutFoundation.

the class xDripWidget method displayCurrentInfo.

private static void displayCurrentInfo(AppWidgetManager appWidgetManager, int appWidgetId, Context context, RemoteViews views) {
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context);
    BgReading lastBgreading = BgReading.lastNoSenssor();
    final boolean showLines = Pref.getBoolean("widget_range_lines", false);
    final boolean showExstraStatus = Pref.getBoolean("extra_status_line", false) && Pref.getBoolean("widget_status_line", false);
    if (lastBgreading != null) {
        double estimate = 0;
        double estimated_delta = -9999;
        try {
            int height = appWidgetManager.getAppWidgetOptions(appWidgetId).getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);
            int width = appWidgetManager.getAppWidgetOptions(appWidgetId).getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);
            views.setImageViewBitmap(R.id.widgetGraph, new BgSparklineBuilder(context).setBgGraphBuilder(bgGraphBuilder).setBackgroundColor(ColorCache.getCol(ColorCache.X.color_widget_chart_background)).setHeight(height).setWidth(width).showHighLine(showLines).showLowLine(showLines).build());
            final BestGlucose.DisplayGlucose dg = (use_best_glucose) ? BestGlucose.getDisplayGlucose() : null;
            estimate = (dg != null) ? dg.mgdl : lastBgreading.calculated_value;
            String extrastring = "";
            String slope_arrow = (dg != null) ? dg.delta_arrow : lastBgreading.slopeArrow();
            String stringEstimate;
            if (dg == null) {
                // if not using best glucose helper
                if (BestGlucose.compensateNoise()) {
                    // this needs scaling based on noise intensity
                    estimate = BgGraphBuilder.best_bg_estimate;
                    estimated_delta = BgGraphBuilder.best_bg_estimate - BgGraphBuilder.last_bg_estimate;
                    // delta by minute
                    slope_arrow = BgReading.slopeToArrowSymbol(estimated_delta / (BgGraphBuilder.DEXCOM_PERIOD / 60000));
                    // currentBgValueText.setTypeface(null, Typeface.ITALIC);
                    // warning symbol !
                    extrastring = " \u26A0";
                }
                // TODO functionize this check as it is in multiple places
                if (Pref.getBooleanDefaultFalse("display_glucose_from_plugin") && (PluggableCalibration.getCalibrationPluginFromPreferences() != null)) {
                    extrastring += " " + context.getString(R.string.p_in_circle);
                }
            } else {
                // TODO make a couple of getters in dg for these functions
                extrastring = " " + dg.extra_string + ((dg.from_plugin) ? " " + context.getString(R.string.p_in_circle) : "");
                estimated_delta = dg.delta_mgdl;
                // TODO properly illustrate + standardize warning level
                if (dg.warning > 1)
                    slope_arrow = "";
            }
            // TODO use dg stale calculation and/or preformatted text
            if ((new Date().getTime()) - Home.stale_data_millis() - lastBgreading.timestamp > 0) {
                // estimate = lastBgreading.calculated_value;
                Log.d(TAG, "old value, estimate " + estimate);
                stringEstimate = bgGraphBuilder.unitized_string(estimate);
                // views.setTextViewText(R.id.widgetArrow, "--");
                slope_arrow = "--";
                views.setInt(R.id.widgetBg, "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
            } else {
                // estimate = lastBgreading.calculated_value;
                stringEstimate = bgGraphBuilder.unitized_string(estimate);
                if (lastBgreading.hide_slope) {
                    slope_arrow = "--";
                }
                Log.d(TAG, "newish value, estimate " + stringEstimate + slope_arrow);
                views.setInt(R.id.widgetBg, "setPaintFlags", 0);
            }
            if (Sensor.isActive() || Home.get_follower()) {
                views.setTextViewText(R.id.widgetBg, stringEstimate);
                views.setTextViewText(R.id.widgetArrow, slope_arrow);
            } else {
                views.setTextViewText(R.id.widgetBg, "");
                views.setTextViewText(R.id.widgetArrow, "");
            }
            // is it really necessary to read this data once here and again in unitizedDeltaString?
            // couldn't we just use the unitizedDeltaString to detect the error condition?
            List<BgReading> bgReadingList = BgReading.latest(2, Home.get_follower());
            if (estimated_delta == -9999) {
                // use original delta
                if (bgReadingList != null && bgReadingList.size() == 2) {
                    views.setTextViewText(R.id.widgetDelta, bgGraphBuilder.unitizedDeltaString(true, true, Home.get_follower()));
                } else {
                    views.setTextViewText(R.id.widgetDelta, "--");
                }
            } else {
                // use compensated estimate
                views.setTextViewText(R.id.widgetDelta, bgGraphBuilder.unitizedDeltaStringRaw(true, true, estimated_delta));
            }
            // TODO use dg preformatted localized string
            int timeAgo = (int) Math.floor((new Date().getTime() - lastBgreading.timestamp) / (1000 * 60));
            if (timeAgo == 1) {
                views.setTextViewText(R.id.readingAge, timeAgo + " Minute ago" + extrastring);
            } else {
                views.setTextViewText(R.id.readingAge, timeAgo + " Minutes ago" + extrastring);
            }
            if (timeAgo > 15) {
                views.setTextColor(R.id.readingAge, Color.parseColor("#FFBB33"));
            } else {
                views.setTextColor(R.id.readingAge, Color.WHITE);
            }
            if (showExstraStatus) {
                views.setTextViewText(R.id.widgetStatusLine, Home.extraStatusLine());
                views.setViewVisibility(R.id.widgetStatusLine, View.VISIBLE);
            } else {
                views.setTextViewText(R.id.widgetStatusLine, "");
                views.setViewVisibility(R.id.widgetStatusLine, View.GONE);
            }
            if (bgGraphBuilder.unitized(estimate) <= bgGraphBuilder.lowMark) {
                views.setTextColor(R.id.widgetBg, Color.parseColor("#C30909"));
                views.setTextColor(R.id.widgetDelta, Color.parseColor("#C30909"));
                views.setTextColor(R.id.widgetArrow, Color.parseColor("#C30909"));
            } else if (bgGraphBuilder.unitized(estimate) >= bgGraphBuilder.highMark) {
                views.setTextColor(R.id.widgetBg, Color.parseColor("#FFBB33"));
                views.setTextColor(R.id.widgetDelta, Color.parseColor("#FFBB33"));
                views.setTextColor(R.id.widgetArrow, Color.parseColor("#FFBB33"));
            } else {
                views.setTextColor(R.id.widgetBg, Color.WHITE);
                views.setTextColor(R.id.widgetDelta, Color.WHITE);
                views.setTextColor(R.id.widgetArrow, Color.WHITE);
            }
        } catch (RuntimeException e) {
            Log.e(TAG, "Got exception in displaycurrentinfo: " + e);
        }
    }
}
Also used : BgSparklineBuilder(com.eveningoutpost.dexdrip.UtilityModels.BgSparklineBuilder) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) Paint(android.graphics.Paint) Date(java.util.Date) BgGraphBuilder(com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder)

Example 3 with BgGraphBuilder

use of com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder in project xDrip by NightscoutFoundation.

the class PebbleWatchSync method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    context = getApplicationContext();
    bgGraphBuilder = new BgGraphBuilder(context);
    initPebbleDisplays();
    PebbleUtil.pebbleDisplayType = getCurrentBroadcastToPebbleSetting();
    Log.d(TAG, "onCreate for: " + PebbleUtil.pebbleDisplayType.toString());
    currentWatchFaceUUID = getActivePebbleDisplay().watchfaceUUID();
    init();
}
Also used : BgGraphBuilder(com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder)

Example 4 with BgGraphBuilder

use of com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder in project xDrip by NightscoutFoundation.

the class Home method setupCharts.

private void setupCharts() {
    bgGraphBuilder = new BgGraphBuilder(this);
    updateStuff = false;
    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();
    // ????????? what about tomato here ?????
    if (sensor != null && sensor.latest_battery_level != 0 && !DexCollectionService.getBestLimitterHardwareName().equalsIgnoreCase("BlueReader") && sensor.latest_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_LOW && !Pref.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 <= Dex_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() {
                // TODO Which pixel format should this be?
                return 0;
            }
        };
        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()));
    previewChart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportCalculationEnabled(true);
    chart.setViewportChangeListener(new ChartViewPortListener());
    updateStuff = true;
    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 {
        if (homeShelf.get("time_buttons")) {
            final long which_hour = PersistentStore.getLong("home-locked-hours");
            if (which_hour > 0) {
                hours = which_hour;
                setHoursViewPort();
            } else {
                hours = DEFAULT_CHART_HOURS;
            }
        } else {
            hours = DEFAULT_CHART_HOURS;
        }
        previewChart.setVisibility(homeShelf.get("chart_preview") ? View.VISIBLE : View.GONE);
    }
    if (insulinset || glucoseset || carbsset || timeset) {
        if (chart != null) {
            chart.setAlpha((float) 0.10);
        // TODO also set buttons alpha
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Viewport(lecho.lib.hellocharts.model.Viewport) Paint(android.graphics.Paint) DisplayMetrics(android.util.DisplayMetrics) Paint(android.graphics.Paint) Point(android.graphics.Point) BgGraphBuilder(com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder) ColorFilter(android.graphics.ColorFilter) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 5 with BgGraphBuilder

use of com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder in project xDrip by NightscoutFoundation.

the class BGHistory method setupCharts.

private void setupCharts() {
    dateButton1.setText(dateFormatter.format(date1.getTime()));
    Calendar endDate = (GregorianCalendar) date1.clone();
    endDate.add(Calendar.DATE, noDays);
    // LimiTTer sample rate 1 per 2 minutes
    int numValues = noDays * (60 / 2) * 24;
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(this, date1.getTimeInMillis(), endDate.getTimeInMillis(), numValues, false);
    chart = (LineChartView) findViewById(R.id.chart);
    chart.setZoomType(ZoomType.HORIZONTAL);
    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);
    chart.setLineChartData(bgGraphBuilder.lineData());
    chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener(this));
    previewChart.setLineChartData(bgGraphBuilder.previewLineData(chart.getLineChartData()));
    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());
    setupStatistics(date1.getTimeInMillis(), endDate.getTimeInMillis());
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) BgGraphBuilder(com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder)

Aggregations

BgGraphBuilder (com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder)18 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)6 BgSparklineBuilder (com.eveningoutpost.dexdrip.UtilityModels.BgSparklineBuilder)6 Bitmap (android.graphics.Bitmap)4 Paint (android.graphics.Paint)4 Date (java.util.Date)4 Viewport (lecho.lib.hellocharts.model.Viewport)4 Canvas (android.graphics.Canvas)2 ColorFilter (android.graphics.ColorFilter)2 Point (android.graphics.Point)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 DisplayMetrics (android.util.DisplayMetrics)2 ViewGroup (android.view.ViewGroup)2 Sensor (com.eveningoutpost.dexdrip.Models.Sensor)2 PebbleDictionary (com.getpebble.android.kit.util.PebbleDictionary)2 DataMap (com.google.android.gms.wearable.DataMap)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2