예제 #1
0
  @Override
  public View getPrototypeView(Context context) {
    View prototypeView = View.inflate(context, R.layout.brick_change_variable_by, null);
    Spinner variableSpinner = (Spinner) prototypeView.findViewById(R.id.change_variable_spinner);
    variableSpinner.setFocusableInTouchMode(false);
    variableSpinner.setFocusable(false);

    UserBrick currentBrick = ProjectManager.getInstance().getCurrentUserBrick();
    int userBrickId =
        (currentBrick == null ? -1 : currentBrick.getDefinitionBrick().getUserBrickId());

    DataAdapter dataAdapter =
        ProjectManager.getInstance()
            .getCurrentProject()
            .getDataContainer()
            .createDataAdapter(
                context, userBrickId, ProjectManager.getInstance().getCurrentSprite(), inUserBrick);

    UserVariableAdapterWrapper userVariableAdapterWrapper =
        new UserVariableAdapterWrapper(context, dataAdapter);
    userVariableAdapterWrapper.setItemLayout(
        android.R.layout.simple_spinner_item, android.R.id.text1);
    variableSpinner.setAdapter(userVariableAdapterWrapper);
    setSpinnerSelection(variableSpinner, null);

    TextView textChangeVariable =
        (TextView) prototypeView.findViewById(R.id.brick_change_variable_prototype_view);
    textChangeVariable.setText(String.valueOf(BrickValues.CHANGE_VARIABLE));
    return prototypeView;
  }
예제 #2
0
  @Override
  public View getView(final Context context, int brickId, BaseAdapter baseAdapter) {
    if (animationState) {
      return view;
    }

    view = View.inflate(context, R.layout.brick_change_variable_by, null);
    view = getViewWithAlpha(alphaValue);
    setCheckboxView(R.id.brick_change_variable_checkbox);
    final Brick brickInstance = this;

    checkbox.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            checked = isChecked;
            adapter.handleCheck(brickInstance, isChecked);
          }
        });

    TextView prototypeText =
        (TextView) view.findViewById(R.id.brick_change_variable_prototype_view);
    TextView textField = (TextView) view.findViewById(R.id.brick_change_variable_edit_text);
    prototypeText.setVisibility(View.GONE);
    getFormulaWithBrickField(BrickField.VARIABLE_CHANGE)
        .setTextFieldId(R.id.brick_change_variable_edit_text);
    getFormulaWithBrickField(BrickField.VARIABLE_CHANGE).refreshTextField(view);
    textField.setVisibility(View.VISIBLE);
    textField.setOnClickListener(this);

    Spinner variableSpinner = (Spinner) view.findViewById(R.id.change_variable_spinner);

    UserBrick currentBrick = ProjectManager.getInstance().getCurrentUserBrick();
    int userBrickId = (currentBrick == null ? -1 : currentBrick.getUserBrickId());

    DataAdapter dataAdapter =
        ProjectManager.getInstance()
            .getCurrentProject()
            .getDataContainer()
            .createDataAdapter(
                context, userBrickId, ProjectManager.getInstance().getCurrentSprite(), inUserBrick);
    UserVariableAdapterWrapper userVariableAdapterWrapper =
        new UserVariableAdapterWrapper(context, dataAdapter);
    userVariableAdapterWrapper.setItemLayout(
        android.R.layout.simple_spinner_item, android.R.id.text1);

    variableSpinner.setAdapter(userVariableAdapterWrapper);

    if (!(checkbox.getVisibility() == View.VISIBLE)) {
      variableSpinner.setClickable(true);
      variableSpinner.setEnabled(true);
    } else {
      variableSpinner.setClickable(false);
      variableSpinner.setFocusable(false);
    }

    setSpinnerSelection(variableSpinner, null);

    variableSpinner.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP
                && ((Spinner) view).getSelectedItemPosition() == 0
                && ((Spinner) view).getAdapter().getCount() == 1) {
              NewDataDialog dialog =
                  new NewDataDialog((Spinner) view, NewDataDialog.DialogType.USER_VARIABLE);
              dialog.addVariableDialogListener(ChangeVariableBrick.this);
              dialog.show(
                  ((SherlockFragmentActivity) view.getContext()).getSupportFragmentManager(),
                  NewDataDialog.DIALOG_FRAGMENT_TAG);
              return true;
            }
            return false;
          }
        });

    variableSpinner.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0
                && ((UserVariableAdapterWrapper) parent.getAdapter()).isTouchInDropDownView()) {
              NewDataDialog dialog =
                  new NewDataDialog((Spinner) parent, NewDataDialog.DialogType.USER_VARIABLE);
              dialog.addVariableDialogListener(ChangeVariableBrick.this);
              dialog.show(
                  ((SherlockFragmentActivity) view.getContext()).getSupportFragmentManager(),
                  NewDataDialog.DIALOG_FRAGMENT_TAG);
            }
            ((UserVariableAdapterWrapper) parent.getAdapter()).resetIsTouchInDropDownView();
            userVariable = (UserVariable) parent.getItemAtPosition(position);
            adapterView = parent;
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {
            userVariable = null;
          }
        });

    return view;
  }