List of usage examples for java.text DecimalFormat setMinimumFractionDigits
@Override public void setMinimumFractionDigits(int newValue)
From source file:com.eveningoutpost.dexdrip.Home.java
private void handleWordPair() { boolean preserve = false; if ((thisnumber == -1) || (thisword == "")) return;/*from w w w .j a v a2s.c o m*/ Log.d(TAG, "GOT WORD PAIR: " + thisnumber + " = " + thisword); switch (thisword) { case "rapid": if ((insulinset == false) && (thisnumber > 0)) { thisinsulinnumber = thisnumber; textInsulinDose.setText(Double.toString(thisnumber) + " units"); Log.d(TAG, "Rapid dose: " + Double.toString(thisnumber)); insulinset = true; btnInsulinDose.setVisibility(View.VISIBLE); textInsulinDose.setVisibility(View.VISIBLE); } else { Log.d(TAG, "Rapid dose already set"); preserve = true; } break; case "carbs": if ((carbsset == false) && (thisnumber > 0)) { thiscarbsnumber = thisnumber; textCarbohydrates.setText(Integer.toString((int) thisnumber) + " carbs"); carbsset = true; Log.d(TAG, "Carbs eaten: " + Double.toString(thisnumber)); btnCarbohydrates.setVisibility(View.VISIBLE); textCarbohydrates.setVisibility(View.VISIBLE); } else { Log.d(TAG, "Carbs already set"); preserve = true; } break; case "blood": if ((glucoseset == false) && (thisnumber > 0)) { thisglucosenumber = thisnumber; if (prefs.getString("units", "mgdl").equals("mgdl")) { if (textBloodGlucose != null) textBloodGlucose.setText(Double.toString(thisnumber) + " mg/dl"); } else { if (textBloodGlucose != null) textBloodGlucose.setText(Double.toString(thisnumber) + " mmol/l"); } Log.d(TAG, "Blood test: " + Double.toString(thisnumber)); glucoseset = true; if (textBloodGlucose != null) { btnBloodGlucose.setVisibility(View.VISIBLE); textBloodGlucose.setVisibility(View.VISIBLE); } } else { Log.d(TAG, "Blood glucose already set"); preserve = true; } break; case "time": Log.d(TAG, "processing time keyword"); if ((timeset == false) && (thisnumber >= 0)) { final NumberFormat nf = NumberFormat.getNumberInstance(Locale.US); final DecimalFormat df = (DecimalFormat) nf; //DecimalFormat df = new DecimalFormat("#"); df.setMinimumIntegerDigits(2); df.setMinimumFractionDigits(2); df.setMaximumFractionDigits(2); df.setMaximumIntegerDigits(2); final Calendar c = Calendar.getInstance(); final SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("dd/M/yyyy ", Locale.US); final SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("dd/M/yyyy HH.mm", Locale.US); // TODO double check 24 hour 12.00 etc final String datenew = simpleDateFormat1.format(c.getTime()) + df.format(thisnumber); Log.d(TAG, "Time Timing data datenew: " + datenew); final Date datethen; final Date datenow = new Date(); try { datethen = simpleDateFormat2.parse(datenew); double difference = datenow.getTime() - datethen.getTime(); // is it more than 1 hour in the future? If so it must be yesterday if (difference < -(1000 * 60 * 60)) { difference = difference + (86400 * 1000); } else { // - midnight feast pre-bolus nom nom if (difference > (60 * 60 * 23 * 1000)) difference = difference - (86400 * 1000); } Log.d(TAG, "Time Timing data: " + df.format(thisnumber) + " = difference ms: " + JoH.qs(difference)); textTime.setText(df.format(thisnumber)); timeset = true; thistimeoffset = difference; btnTime.setVisibility(View.VISIBLE); textTime.setVisibility(View.VISIBLE); } catch (ParseException e) { // toast to explain? Log.d(TAG, "Got exception parsing date time"); } } else { Log.d(TAG, "Time data already set"); preserve = true; } break; } // end switch if (preserve == false) { Log.d(TAG, "Clearing speech values"); thisnumber = -1; thisword = ""; } else { Log.d(TAG, "Preserving speech values"); } // don't show approve/cancel if we only have time if (insulinset || glucoseset || carbsset) { btnApprove.setVisibility(View.VISIBLE); btnCancel.setVisibility(View.VISIBLE); if (small_screen) { final float button_scale_factor = 0.60f; ((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).leftMargin = 0; ((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).leftMargin = 0; ((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).setMarginStart(0); ((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).setMarginStart(0); ((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).rightMargin = 0; ((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).rightMargin = 0; btnApprove.setScaleX(button_scale_factor); btnApprove.setScaleY(button_scale_factor); btnCancel.setScaleX(button_scale_factor); btnCancel.setScaleY(button_scale_factor); btnInsulinDose.setScaleX(button_scale_factor); btnCarbohydrates.setScaleX(button_scale_factor); btnCarbohydrates.setScaleY(button_scale_factor); btnBloodGlucose.setScaleX(button_scale_factor); btnBloodGlucose.setScaleY(button_scale_factor); btnInsulinDose.setScaleY(button_scale_factor); btnTime.setScaleX(button_scale_factor); btnTime.setScaleY(button_scale_factor); final int small_text_size = 12; textCarbohydrates.setTextSize(small_text_size); textInsulinDose.setTextSize(small_text_size); textBloodGlucose.setTextSize(small_text_size); textTime.setTextSize(small_text_size); } } if (insulinset || glucoseset || carbsset || timeset) { if (chart != null) { chart.setAlpha((float) 0.10); } WatchUpdaterService.sendTreatment(thiscarbsnumber, thisinsulinnumber, thisglucosenumber, thistimeoffset, textTime.getText().toString()); } }
From source file:com.zoffcc.applications.zanavi.Navit.java
public static String logHeap(Class clazz) { Double allocated = Double.valueOf(Debug.getNativeHeapAllocatedSize()) / Double.valueOf((1048576)); Double sum_size = Double.valueOf(Debug.getNativeHeapSize() / Double.valueOf(1048576.0)); Double free = Double.valueOf(Debug.getNativeHeapFreeSize() / Double.valueOf(1048576.0)); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2);/*from w ww . ja v a 2 s .c om*/ df.setMinimumFractionDigits(2); // Log.d("Navit", "MemMem:DEBUG: ================================="); Log.d("Navit", "MemMem:DEBUG:heap native: allc " + df.format(allocated) + "MB sum=" + df.format(sum_size) + "MB (" + df.format(free) + "MB free) in [" + clazz.getName().replaceAll("com.zoffcc.applications.zanavi.", "") + "]"); Log.d("Navit", "MemMem:DEBUG:java memory: allc: " + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "MB sum=" + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "MB (" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)"); calcAvailableMemory(); String mem_type = "NATIVE"; try { if (android.os.Build.VERSION.SDK_INT >= 11) { mem_type = "JAVA"; } } catch (Exception e) { } return ("" + df.format(allocated) + "/" + df.format(sum_size) + "(" + df.format(free) + ")" + ":" + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "/" + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "(" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + ") " + mem_type); }
From source file:com.zoffcc.applications.zanavi.Navit.java
public static String logHeap_for_batch(Class clazz) { try {/*from w w w . j a v a 2 s . c o m*/ Double allocated = Double.valueOf(Debug.getNativeHeapAllocatedSize()) / Double.valueOf((1048576)); Double sum_size = Double.valueOf(Debug.getNativeHeapSize() / Double.valueOf(1048576.0)); Double free = Double.valueOf(Debug.getNativeHeapFreeSize() / Double.valueOf(1048576.0)); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); // Log.d("Navit", "MemMem:DEBUG: ================================="); Log.d("Navit", "MemMem:DEBUG:heap native: allc " + df.format(allocated) + "MB sum=" + df.format(sum_size) + "MB (" + df.format(free) + "MB free) in [" + clazz.getName().replaceAll("com.zoffcc.applications.zanavi.", "") + "]"); Log.d("Navit", "MemMem:DEBUG:java memory: allc: " + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "MB sum=" + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "MB (" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)"); // calcAvailableMemory(); String mem_type = "NATIVE"; try { if (android.os.Build.VERSION.SDK_INT >= 11) { mem_type = "JAVA"; } } catch (Exception e) { } // return ("" + df.format(allocated) + "/" + df.format(sum_size) + "(" + df.format(free) + ")" + ":" + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "/" + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "(" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + ") " + mem_type); return ("==MEM==:" + "J:" + (Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + ":" + (Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + ",N:" + allocated + ":" + sum_size); } catch (Exception e2) { return ("==MEM==:ERROR"); } }