Пример #1
0
 private void set12HourShown(boolean shown) {
   if (shown) {
     mAMPMSpinner.setVisibility(VISIBLE);
   } else {
     mAMPMSpinner.setVisibility(GONE);
   }
 }
Пример #2
0
 private void setDayShown(boolean shown) {
   if (shown) {
     toggleCalendar(false);
     mDaySpinner.setVisibility(VISIBLE);
     mDayEnabled = true;
   } else {
     mDaySpinner.setVisibility(GONE);
     mDayEnabled = false;
   }
 }
Пример #3
0
 private void setMinuteShown(boolean shown) {
   if (shown) {
     mMinuteSpinner.setVisibility(VISIBLE);
     mTimeSpinners.findViewById(R.id.mincolon).setVisibility(VISIBLE);
     mMinuteEnabled = true;
   } else {
     mMinuteSpinner.setVisibility(GONE);
     mTimeSpinners.findViewById(R.id.mincolon).setVisibility(GONE);
     mMinuteEnabled = false;
   }
 }
Пример #4
0
 private void setHourShown(boolean shown) {
   if (shown) {
     mHourSpinner.setVisibility(VISIBLE);
     mHourEnabled = true;
   } else {
     mHourSpinner.setVisibility(GONE);
     mAMPMSpinner.setVisibility(GONE);
     mTimeSpinners.setVisibility(GONE);
     mHourEnabled = false;
   }
 }
Пример #5
0
  private void updateSpinners() {
    updateDaySpinner();

    mYearToggle.setChecked(mHasYear);
    mYearToggle.setVisibility(mYearOptional ? View.VISIBLE : View.GONE);
    mYearPicker.setCurrent(mYear);
    mYearPicker.setVisibility(mHasYear ? View.VISIBLE : View.GONE);

    /* The month display uses 1-12 but our internal state stores it
     * 0-11 so add one when setting the display.
     */
    mMonthPicker.setCurrent(mMonth + 1);
  }
Пример #6
0
  void displayStatus() {
    ActiveBgAlert aba = ActiveBgAlert.getOnly();
    AlertType activeBgAlert = ActiveBgAlert.alertTypegetOnly();

    // aba and activeBgAlert should both either exist ot not exist. all other cases are a bug in
    // another place
    if (aba == null && activeBgAlert != null) {
      UserError.Log.wtf(
          TAG, "ERRRO displayStatus: aba == null, but activeBgAlert != null exiting...");
      return;
    }
    if (aba != null && activeBgAlert == null) {
      UserError.Log.wtf(
          TAG, "ERRRO displayStatus: aba != null, but activeBgAlert == null exiting...");
      return;
    }
    String status;
    if (activeBgAlert == null) {
      status = "No active alert exists";
      alertStatus.setText(status);
      buttonSnooze.setVisibility(View.GONE);
      snoozeValue.setVisibility(View.GONE);
    } else {
      if (!aba.ready_to_alarm()) {
        status =
            "Active alert exists named \""
                + activeBgAlert.name
                + "\" Alert snoozed until "
                + DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date(aba.next_alert_at))
                + " ("
                + (aba.next_alert_at - new Date().getTime()) / 60000
                + " minutes left)";
      } else {
        status = "Active alert exists named \"" + activeBgAlert.name + "\" (not snoozed)";
      }
      SetSnoozePickerValues(snoozeValue, activeBgAlert.above, activeBgAlert.default_snooze);
      alertStatus.setText(status);
    }
  }
  public MultiFieldTimePickerDialog(
      Context context,
      int theme,
      int hour,
      int minute,
      int second,
      int milli,
      int min,
      int max,
      int step,
      boolean is24hourFormat,
      OnMultiFieldTimeSetListener listener) {
    super(context, theme);
    mListener = listener;
    mStep = step;
    mIs24hourFormat = is24hourFormat;

    if (min >= max) {
      min = 0;
      max = 24 * HOUR_IN_MILLIS - 1;
    }
    if (step < 0 || step >= 24 * HOUR_IN_MILLIS) {
      step = MINUTE_IN_MILLIS;
    }

    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.multi_field_time_picker_dialog, null);
    setView(view);

    mHourSpinner = (NumberPicker) view.findViewById(R.id.hour);
    mMinuteSpinner = (NumberPicker) view.findViewById(R.id.minute);
    mSecSpinner = (NumberPicker) view.findViewById(R.id.second);
    mMilliSpinner = (NumberPicker) view.findViewById(R.id.milli);
    mAmPmSpinner = (NumberPicker) view.findViewById(R.id.ampm);

    int minHour = min / HOUR_IN_MILLIS;
    int maxHour = max / HOUR_IN_MILLIS;
    min -= minHour * HOUR_IN_MILLIS;
    max -= maxHour * HOUR_IN_MILLIS;

    if (minHour == maxHour) {
      mHourSpinner.setEnabled(false);
      hour = minHour;
    }

    if (is24hourFormat) {
      mAmPmSpinner.setVisibility(View.GONE);
    } else {
      int minAmPm = minHour / 12;
      int maxAmPm = maxHour / 12;
      int amPm = hour / 12;
      mAmPmSpinner.setMinValue(minAmPm);
      mAmPmSpinner.setMaxValue(maxAmPm);
      mAmPmSpinner.setDisplayedValues(
          new String[] {
            context.getString(R.string.time_picker_dialog_am),
            context.getString(R.string.time_picker_dialog_pm)
          });

      hour %= 12;
      if (hour == 0) {
        hour = 12;
      }
      if (minAmPm == maxAmPm) {
        mAmPmSpinner.setEnabled(false);
        amPm = minAmPm;

        minHour %= 12;
        maxHour %= 12;
        if (minHour == 0 && maxHour == 0) {
          minHour = 12;
          maxHour = 12;
        } else if (minHour == 0) {
          minHour = maxHour;
          maxHour = 12;
        } else if (maxHour == 0) {
          maxHour = 12;
        }
      } else {
        minHour = 1;
        maxHour = 12;
      }
      mAmPmSpinner.setValue(amPm);
    }

    if (minHour == maxHour) {
      mHourSpinner.setEnabled(false);
    }
    mHourSpinner.setMinValue(minHour);
    mHourSpinner.setMaxValue(maxHour);
    mHourSpinner.setValue(hour);

    NumberFormatter twoDigitPaddingFormatter = new NumberFormatter("%02d");

    int minMinute = min / MINUTE_IN_MILLIS;
    int maxMinute = max / MINUTE_IN_MILLIS;
    min -= minMinute * MINUTE_IN_MILLIS;
    max -= maxMinute * MINUTE_IN_MILLIS;

    if (minHour == maxHour) {
      mMinuteSpinner.setMinValue(minMinute);
      mMinuteSpinner.setMaxValue(maxMinute);
      if (minMinute == maxMinute) {
        // Set this otherwise the box is empty until you stroke it.
        mMinuteSpinner.setDisplayedValues(
            new String[] {twoDigitPaddingFormatter.format(minMinute)});
        mMinuteSpinner.setEnabled(false);
        minute = minMinute;
      }
    } else {
      mMinuteSpinner.setMinValue(0);
      mMinuteSpinner.setMaxValue(59);
    }

    if (step >= HOUR_IN_MILLIS) {
      mMinuteSpinner.setEnabled(false);
    }

    mMinuteSpinner.setValue(minute);
    mMinuteSpinner.setFormatter(twoDigitPaddingFormatter);

    if (step >= MINUTE_IN_MILLIS) {
      // Remove the ':' in front of the second spinner as well.
      view.findViewById(R.id.second_colon).setVisibility(View.GONE);
      mSecSpinner.setVisibility(View.GONE);
    }

    int minSecond = min / SECOND_IN_MILLIS;
    int maxSecond = max / SECOND_IN_MILLIS;
    min -= minSecond * SECOND_IN_MILLIS;
    max -= maxSecond * SECOND_IN_MILLIS;

    if (minHour == maxHour && minMinute == maxMinute) {
      mSecSpinner.setMinValue(minSecond);
      mSecSpinner.setMaxValue(maxSecond);
      if (minSecond == maxSecond) {
        // Set this otherwise the box is empty until you stroke it.
        mSecSpinner.setDisplayedValues(new String[] {twoDigitPaddingFormatter.format(minSecond)});
        mSecSpinner.setEnabled(false);
        second = minSecond;
      }
    } else {
      mSecSpinner.setMinValue(0);
      mSecSpinner.setMaxValue(59);
    }

    mSecSpinner.setValue(second);
    mSecSpinner.setFormatter(twoDigitPaddingFormatter);

    if (step >= SECOND_IN_MILLIS) {
      // Remove the '.' in front of the milli spinner as well.
      view.findViewById(R.id.second_dot).setVisibility(View.GONE);
      mMilliSpinner.setVisibility(View.GONE);
    }

    // Round to the nearest step.
    milli = ((milli + step / 2) / step) * step;
    if (step == 1 || step == 10 || step == 100) {
      if (minHour == maxHour && minMinute == maxMinute && minSecond == maxSecond) {
        mMilliSpinner.setMinValue(min / step);
        mMilliSpinner.setMaxValue(max / step);

        if (min == max) {
          mMilliSpinner.setEnabled(false);
          milli = min;
        }
      } else {
        mMilliSpinner.setMinValue(0);
        mMilliSpinner.setMaxValue(999 / step);
      }

      if (step == 1) {
        mMilliSpinner.setFormatter(new NumberFormatter("%03d"));
      } else if (step == 10) {
        mMilliSpinner.setFormatter(new NumberFormatter("%02d"));
      } else if (step == 100) {
        mMilliSpinner.setFormatter(new NumberFormatter("%d"));
      }
      mMilliSpinner.setValue(milli / step);
      mBaseMilli = 0;
    } else if (step < SECOND_IN_MILLIS) {
      // Non-decimal step value.
      ArrayList<String> strValue = new ArrayList<String>();
      for (int i = min; i < max; i += step) {
        strValue.add(String.format("%03d", i));
      }
      mMilliSpinner.setMinValue(0);
      mMilliSpinner.setMaxValue(strValue.size() - 1);
      mMilliSpinner.setValue((milli - min) / step);
      mMilliSpinner.setDisplayedValues(strValue.toArray(new String[strValue.size()]));
      mBaseMilli = min;
    } else {
      mBaseMilli = 0;
    }
  }
  /**
   * 显示剂量编辑框的dialog
   *
   * @param view1 显示剂量编辑框
   * @param viewheshu1 显示剂量单位编辑框
   * @param view2 显示盒数的编辑框
   * @param viewheshu2 显示规格的编辑框
   * @param nextView 下一个要弹出的spinner
   */
  public void showEditDialog(
      final View view1,
      final View viewheshu1,
      final View view2,
      final View viewheshu2,
      final View nextView) {
    if (!(view1 instanceof TextView) || !(viewheshu1 instanceof TextView)) {
      return;
    }
    if (!(view2 instanceof TextView) || !(viewheshu2 instanceof TextView)) {
      return;
    }
    View rootView = getActivity().getLayoutInflater().inflate(R.layout.dialog_number_complex, null);
    final NumberPicker np1 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex1);
    final NumberPicker np2 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex2);
    final NumberPicker np3 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex3);
    final NumberPicker np4 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex4);
    final TextView tvDian = (TextView) rootView.findViewById(R.id.tv_dialog_complex_dian);
    final NumberPicker little = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex_little);
    final EditText et = (EditText) rootView.findViewById(R.id.et_dialog_complex);
    IllnessInfo illnessInfo = (IllnessInfo) spinnerTellMedical3.getSelectedItem();
    // 诺和力剂量需要小数点
    if (illnessInfo.getId().equals("1022")) {
      tvDian.setVisibility(View.VISIBLE);
      little.setVisibility(View.VISIBLE);
    }

    final TextView tv = (TextView) rootView.findViewById(R.id.tv_dialog_dost);
    final NumberPicker np5 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex5);
    final NumberPicker np6 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex6);
    final NumberPicker np7 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex7);
    np1.setMaxValue(5);
    np1.setMinValue(0);
    np2.setMaxValue(9);
    np2.setMinValue(0);
    np3.setMaxValue(9);
    np3.setMinValue(0);
    little.setMinValue(0);
    little.setMaxValue(9);
    np5.setMaxValue(5);
    np5.setMinValue(0);
    np6.setMaxValue(9);
    np6.setMinValue(0);
    np7.setMaxValue(9);
    np7.setMinValue(0);
    // 设置规格的数据
    if (!TextUtils.isEmpty(((TextView) viewheshu2).getText())) {
      tv.setText(((TextView) viewheshu2).getText());
    }
    // 如果剂量数值是double类型
    if (CommonUtil.isStr2Num(((TextView) view1).getText().toString())) {
      final double defaultValues1 =
          TextUtils.isEmpty(((TextView) view1).getText())
              ? 000.00
              : Double.parseDouble(((TextView) view1).getText().toString());
      np1.setValue((int) (defaultValues1 / 100));
      np2.setValue((int) (defaultValues1 * 100 % 10000 / 1000));
      np3.setValue((int) (defaultValues1 * 100 % 1000 / 100));
      little.setValue((int) (defaultValues1 * 100 % 100 / 10));
    } else {
      et.setText(((TextView) view1).getText());
    }
    // 如果固定单位数组中没有新的,则添加
    if (!defaultDost.contains(((TextView) viewheshu1).getText())) {
      defaultDost.add(((TextView) viewheshu1).getText().toString());
    }
    // 默认的索引
    int index = defaultDost.indexOf(((TextView) viewheshu1).getText().toString());
    np4.setDisplayedValues(defaultDost.toArray(new String[defaultDost.size()]));
    np4.setMinValue(0);
    np4.setMaxValue(defaultDost.size() - 1);
    np4.setValue(index);

    final double defaultValues2 =
        TextUtils.isEmpty(((TextView) view2).getText())
            ? 000.00
            : Double.parseDouble(((TextView) view2).getText().toString());
    np5.setValue((int) (defaultValues2 / 100));
    np6.setValue((int) (defaultValues2 * 100 % 10000 / 1000));
    np7.setValue((int) (defaultValues2 * 100 % 1000 / 100));
    MaterialDialog dialog =
        new MaterialDialog.Builder(getActivity())
            .customView(rootView, false)
            .autoDismiss(false)
            .cancelable(false)
            .positiveText("确定")
            .negativeText("取消")
            .neutralText("重置")
            .onPositive(
                new MaterialDialog.SingleButtonCallback() {
                  @Override
                  public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    String aValue1, aValue1_dian = "", aValue2;
                    if (view1 instanceof TextView && view2 instanceof TextView) {
                      // 格式化小数点之前的数
                      if (np1.getValue() == 0) {
                        if (np2.getValue() == 0) {
                          aValue1 = String.valueOf(np3.getValue());
                        } else {
                          aValue1 = String.valueOf(np2.getValue()) + String.valueOf(np3.getValue());
                        }
                      } else {
                        aValue1 =
                            String.valueOf(np1.getValue())
                                + String.valueOf(np2.getValue())
                                + String.valueOf(np3.getValue());
                      }
                      // 格式化小数点之后的数
                      if (little.getValue() != 0) {
                        aValue1_dian = "." + little.getValue();
                      }
                      // 格式化小数点之前的数
                      if (np5.getValue() == 0) {
                        if (np6.getValue() == 0) {
                          aValue2 = String.valueOf(np7.getValue());
                        } else {
                          aValue2 = String.valueOf(np6.getValue()) + String.valueOf(np7.getValue());
                        }
                      } else {
                        aValue2 =
                            String.valueOf(np5.getValue())
                                + String.valueOf(np6.getValue())
                                + String.valueOf(np7.getValue());
                      }
                      ((TextView) view1).setText(aValue1 + aValue1_dian);
                      ((TextView) view2).setText(aValue2);
                      CommonUtil.hideSoftInputView(getActivity(), np1);
                      CommonUtil.hideSoftInputView(getActivity(), np2);
                      CommonUtil.hideSoftInputView(getActivity(), np3);
                      CommonUtil.hideSoftInputView(getActivity(), np4);
                      CommonUtil.hideSoftInputView(getActivity(), np5);
                      CommonUtil.hideSoftInputView(getActivity(), np6);
                      CommonUtil.hideSoftInputView(getActivity(), np7);
                      dialog.dismiss();
                      if (!TextUtils.isEmpty(et.getText())) {
                        ((TextView) view1).setText(et.getText());
                      } else {
                        spinnerTellMedical6.setAdapter(
                            new ArrayAdapter<>(
                                getActivity(),
                                R.layout.spinner_list_item,
                                getResources().getStringArray(R.array.medic_blfy)));
                        nextView.performClick();
                      }
                    }
                  }
                })
            .onNeutral(
                new MaterialDialog.SingleButtonCallback() {
                  @Override
                  public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    np1.setValue(0);
                    np2.setValue(0);
                    np3.setValue(0);
                    np5.setValue(0);
                    np6.setValue(0);
                    np7.setValue(0);
                    et.setText("");
                  }
                })
            .onNegative(
                new MaterialDialog.SingleButtonCallback() {
                  @Override
                  public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    CommonUtil.hideSoftInputView(getActivity(), np1);
                    CommonUtil.hideSoftInputView(getActivity(), np2);
                    CommonUtil.hideSoftInputView(getActivity(), np3);
                    CommonUtil.hideSoftInputView(getActivity(), np4);
                    CommonUtil.hideSoftInputView(getActivity(), np5);
                    CommonUtil.hideSoftInputView(getActivity(), np6);
                    CommonUtil.hideSoftInputView(getActivity(), np7);
                    CommonUtil.hideSoftInputView(getActivity(), et);
                    dialog.dismiss();
                  }
                })
            .build();
    dialog.show();
    // 关闭自动弹出输入法
    CommonUtil.resetDialogParam(getActivity(), dialog);
  }