Java Code Examples for com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder#unitized_string()

The following examples show how to use com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder#unitized_string() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: xDripWidget.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
private static void displayCurrentInfo(AppWidgetManager appWidgetManager, int appWidgetId, Context context, RemoteViews views) {
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context);
    BgReading lastBgreading = BgReading.lastNoSenssor();

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    boolean showLines = settings.getBoolean("widget_range_lines", false);

    if (lastBgreading != null) {
        double estimate = 0;
        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)
                .setHeight(height).setWidth(width).showHighLine(showLines).showLowLine(showLines).build());

        if ((new Date().getTime()) - (60000 * 11) - lastBgreading.timestamp > 0) {
            estimate = lastBgreading.calculated_value;
            Log.d(TAG, "old value, estimate " + estimate);
            views.setTextViewText(R.id.widgetBg, bgGraphBuilder.unitized_string(estimate));
            views.setTextViewText(R.id.widgetArrow, "--");
            views.setInt(R.id.widgetBg, "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        } else {
            estimate = lastBgreading.calculated_value;
            String stringEstimate = bgGraphBuilder.unitized_string(estimate);
            String slope_arrow = lastBgreading.slopeArrow();
            if (lastBgreading.hide_slope) {
                slope_arrow = "--";
            }
            Log.d(TAG, "newish value, estimate " + stringEstimate + slope_arrow);
            views.setTextViewText(R.id.widgetBg, stringEstimate);
            views.setTextViewText(R.id.widgetArrow, slope_arrow);
            views.setInt(R.id.widgetBg, "setPaintFlags", 0);
        }
        List<BgReading> bgReadingList =  BgReading.latest(2);
        if(bgReadingList != null && bgReadingList.size() == 2) {

            views.setTextViewText(R.id.widgetDelta, bgGraphBuilder.unitizedDeltaString(true, true));
        } else {
            views.setTextViewText(R.id.widgetDelta, "--");
        }
        int timeAgo =(int) Math.floor((new Date().getTime() - lastBgreading.timestamp)/(1000*60));
        if (timeAgo == 1) {
            views.setTextViewText(R.id.readingAge, timeAgo + " Minute ago");
        } else {
            views.setTextViewText(R.id.readingAge, timeAgo + " Minutes ago");
        }
        if (timeAgo > 15) {
            views.setTextColor(R.id.readingAge, Color.parseColor("#FFBB33"));
        } else {
            views.setTextColor(R.id.readingAge, Color.WHITE);
        }

        if(settings.getBoolean("extra_status_line", false) && settings.getBoolean("widget_status_line", false)) {
            views.setTextViewText(R.id.widgetStatusLine, Home.extraStatusLine(settings));
            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);
        }
    }
}
 
Example 2
Source File: xDripWidget.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static void displayCurrentInfo() {
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(mContext);
    BgReading lastBgreading = BgReading.lastNoSenssor();
    if (lastBgreading != null) {
        double estimate = 0;
        if ((new Date().getTime()) - (60000 * 11) - lastBgreading.timestamp > 0) {
            estimate = lastBgreading.calculated_value;
            Log.d(TAG, "old value, estimate " + estimate);
            views.setTextViewText(R.id.widgetBg, bgGraphBuilder.unitized_string(estimate));
            views.setTextViewText(R.id.widgetArrow, "--");
            views.setInt(R.id.widgetBg, "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        } else {
            estimate = lastBgreading.calculated_value;
            String stringEstimate = bgGraphBuilder.unitized_string(estimate);
            String slope_arrow = BgReading.slopeArrow((lastBgreading.calculated_value_slope * 60000));
            if (lastBgreading.hide_slope) {
                slope_arrow = "--";
            }
            Log.d(TAG, "newish value, estimate " + stringEstimate + slope_arrow);
            views.setTextViewText(R.id.widgetBg, stringEstimate);
            views.setTextViewText(R.id.widgetArrow, slope_arrow);
            views.setInt(R.id.widgetBg, "setPaintFlags", 0);
        }
        List<BgReading> bgReadingList =  BgReading.latest(2);
        if(bgReadingList != null && bgReadingList.size() == 2) {

            views.setTextViewText(R.id.widgetDelta, bgGraphBuilder.unitizedDeltaString(lastBgreading.calculated_value - bgReadingList.get(1).calculated_value));
        } else {
            views.setTextViewText(R.id.widgetDelta, "--");
        }
        int timeAgo =(int) Math.floor((new Date().getTime() - lastBgreading.timestamp)/(1000*60));
        if (timeAgo == 1) {
            views.setTextViewText(R.id.readingAge, timeAgo + " Minute ago");
        } else {
            views.setTextViewText(R.id.readingAge, timeAgo + " Minutes ago");
        }
        if (timeAgo > 15) {
            views.setTextColor(R.id.readingAge, Color.parseColor("#FFBB33"));
        } else {
            views.setTextColor(R.id.readingAge, Color.WHITE);
        }

        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);
        }
    }
}