Esempio n. 1
0
 @Override
 public void onDismiss(DialogInterface dialog) {
   super.onDismiss(dialog);
   if (spinnerAdapter != null) {
     spinnerAdapter.updateSpinner();
   }
 }
Esempio n. 2
0
  private boolean handleOkButton() {
    EditText editText = (EditText) dialogView.findViewById(R.id.dialog_new_object_name_edit_text);
    String newSpriteName;
    if (editText.length() == 0) {
      newSpriteName = editText.getHint().toString();
    } else {
      newSpriteName = editText.getText().toString().trim();
    }
    if (newSpriteName.contains(".")) {
      int fileExtensionPosition = newSpriteName.indexOf(".");
      newSpriteName = newSpriteName.substring(0, fileExtensionPosition);
    }

    ProjectManager projectManager = ProjectManager.getInstance();

    if (newSpriteName.equalsIgnoreCase("")) {
      Utils.showErrorDialog(getActivity(), R.string.spritename_invalid);
      return false;
    }

    if (projectManager.spriteExists(newSpriteName)) {
      Utils.showErrorDialog(getActivity(), R.string.spritename_already_exists);
      return false;
    }

    Sprite sprite = new Sprite(newSpriteName);
    projectManager.addSprite(sprite);

    LookData lookData;
    try {
      File newLookFile =
          StorageHandler.getInstance()
              .copyImage(projectManager.getCurrentProject().getName(), lookUri.getPath(), null);

      String imageFileName = newLookFile.getName();
      Utils.rewriteImageFileForStage(getActivity(), newLookFile);

      lookData = new LookData();
      lookData.setLookFilename(imageFileName);
      lookData.setLookName(newSpriteName);
    } catch (IOException exception) {
      Utils.showErrorDialog(getActivity(), R.string.error_load_image);
      exception.printStackTrace();

      return false;
    }

    sprite.getLookDataList().add(lookData);

    if (requestedAction == ActionAfterFinished.ACTION_UPDATE_SPINNER && spinnerAdapter != null) {
      Intent broadcastIntent;
      broadcastIntent = new Intent(ScriptActivity.ACTION_BRICK_LIST_CHANGED);
      getActivity().sendBroadcast(broadcastIntent);
      spinnerAdapter.refreshSpinnerAfterNewSprite(getActivity(), newSpriteName);
    } else {
      Intent broadcastIntent;
      broadcastIntent = new Intent(ScriptActivity.ACTION_SPRITES_LIST_CHANGED);
      getActivity().sendBroadcast(broadcastIntent);
    }

    if (requestedAction == ActionAfterFinished.ACTION_FORWARD_TO_NEW_OBJECT) {
      projectManager.setCurrentSprite(sprite);

      Intent intent = new Intent(getActivity(), ProgramMenuActivity.class);
      intent.putExtra(
          ProgramMenuActivity.FORWARD_TO_SCRIPT_ACTIVITY, ScriptActivity.FRAGMENT_SCRIPTS);
      startActivity(intent);
    }
    dismiss();
    return true;
  }