Example #1
0
 protected boolean validate(View v) {
   YParamList requiredResult = new YParamList();
   int viewsCount = requiredContainer.getChildCount();
   for (int i = 0; i < viewsCount; ++i) {
     ParamField view = (ParamField) requiredContainer.getChildAt(i);
     if (!view.isParamFilled()) {
       return false;
     }
   }
   YParamList optionalResult = new YParamList();
   viewsCount = optionalContainer.getChildCount();
   for (int i = 0; i < viewsCount; ++i) {
     ParamField view = (ParamField) optionalContainer.getChildAt(i);
     if (!view.isParamFilled()) {
       return false;
     }
   }
   return true;
 }
Example #2
0
 @Override
 public void onClick(View v) {
   if (validate(v)) {
     YParamList requiredResult = new YParamList();
     int viewsCount = requiredContainer.getChildCount();
     for (int i = 0; i < viewsCount; ++i) {
       ParamField view = (ParamField) requiredContainer.getChildAt(i);
       requiredResult.add(view.getName(), view.getFilledParam());
     }
     YParamList optionalResult = new YParamList();
     viewsCount = optionalContainer.getChildCount();
     for (int i = 0; i < viewsCount; ++i) {
       ParamField view = (ParamField) optionalContainer.getChildAt(i);
       optionalResult.add(view.getName(), view.getFilledParam());
     }
     if (mListener != null) {
       mListener.onParamsProvided(requiredResult, optionalResult, mRecipeName);
     }
     getDialog().cancel();
   } else {
     Toast.makeText(getActivity(), "Fill fields to proceed", Toast.LENGTH_SHORT).show();
   }
 }
Example #3
0
  private View initField(Entry<String, YParam> entry, LayoutInflater inflater) {
    ParamField v = null;
    String name = entry.getKey();
    YParam value = entry.getValue();
    TextView nameTextView;
    switch (value.getType()) {
      case Integer:
        v = (ParamField) inflater.inflate(R.layout.field_integer, null);
        EditText integerET = (EditText) v.findViewById(R.id.field_integer);
        if (value.getValue() != null) {
          integerET.setText(value.getValue() + "");
        }

        break;
      case Group:
      case String:
        v = (ParamField) inflater.inflate(R.layout.field_string, null);
        EditText stringET = (EditText) v.findViewById(R.id.field_string);
        if (value.getValue() != null) {
          stringET.setText(value.getValue() + "");
        }
        break;
      case Position:
        v = (ParamField) inflater.inflate(R.layout.field_position, null);
        v.findViewById(R.id.field_button_showmap)
            .setOnClickListener(
                new View.OnClickListener() {

                  @Override
                  public void onClick(View v) {
                    FragmentTransaction ft = getFragmentManager().beginTransaction();
                    PositionMapDialog d = new PositionMapDialog();
                    ft.add(d, "MAP");
                    ft.commit();
                    ((PositionParamField) v.getParent()).setPositionMapDialog(d);
                  }
                });
        break;
      case Boolean:
        v = (ParamField) inflater.inflate(R.layout.field_boolean, null);
        RadioButton trueButton = (RadioButton) v.findViewById(R.id.field_boolean_yes);
        RadioButton falseButton = (RadioButton) v.findViewById(R.id.field_boolean_no);
        boolean defaultBool = (Boolean) value.getValue();
        if (defaultBool) {
          trueButton.setChecked(true);
          falseButton.setChecked(false);
        } else {
          falseButton.setChecked(true);
          trueButton.setChecked(false);
        }
        break;
      case Number:
        v = (ParamField) inflater.inflate(R.layout.field_number, null);
        EditText numberET = (EditText) v.findViewById(R.id.field_number);
        if (value.getValue() != null) {
          numberET.setText(value.getValue() + "");
        }
        v.findViewById(R.id.field_pick_number)
            .setOnClickListener(
                new View.OnClickListener() {

                  @Override
                  public void onClick(View v) {
                    FragmentTransaction ft = getFragmentManager().beginTransaction();
                    NumberDialogFragment d = new NumberDialogFragment();
                    ft.add(d, "NUMBER_PICKER");
                    ft.commit();
                    ((NumberParamField) v.getParent()).setNumberPickerFragment(d);
                  }
                });
        break;
      default:
        break;
    }
    nameTextView = (TextView) v.findViewById(R.id.field_name);
    nameTextView.setText(name);
    v.setYParam(value);
    v.setName(name);
    return v;
  }