Ejemplo n.º 1
0
  private void setSpinnerSelection(Spinner spinner) {
    final ArrayList<Sprite> spriteList =
        (ArrayList<Sprite>) ProjectManager.getInstance().getCurrentProject().getSpriteList();

    if (spriteList.contains(pointedObject)) {
      oldSelectedObject = pointedObject.getName();
      spinner.setSelection(
          ((SpinnerAdapterWrapper) spinner.getAdapter())
              .getAdapter()
              .getPosition(pointedObject.getName()),
          true);
    } else {
      if (oldSelectedObject != null && !oldSelectedObject.equals("")) {
        spinner.setSelection(
            ((SpinnerAdapterWrapper) spinner.getAdapter())
                .getAdapter()
                .getPosition(this.oldSelectedObject),
            true);
      } else {
        if (spinner.getAdapter().getCount() > 1) {
          spinner.setSelection(1, true);
        } else {
          spinner.setSelection(0, true);
        }
      }
    }
  }
Ejemplo n.º 2
0
  private ArrayAdapter<String> getArrayAdapterFromSpriteList(Context context) {
    final ArrayAdapter<String> arrayAdapter =
        new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    arrayAdapter.add(context.getString(R.string.new_broadcast_message));

    final ArrayList<Sprite> spriteList =
        (ArrayList<Sprite>) ProjectManager.getInstance().getCurrentProject().getSpriteList();

    for (Sprite sprite : spriteList) {
      String spriteName = sprite.getName();
      String temp = ProjectManager.getInstance().getCurrentSprite().getName();
      if (!spriteName.equals(temp) && !spriteName.equals(context.getString(R.string.background))) {
        arrayAdapter.add(sprite.getName());
      }
    }

    return arrayAdapter;
  }
Ejemplo n.º 3
0
    public void refreshSpinnerAfterNewSprite(final Context context, final String newSpriteName) {
      Project project = ProjectManager.getInstance().getCurrentProject();
      for (Sprite sprite : project.getSpriteList()) {
        if (sprite.getName().equals(newSpriteName)) {
          pointedObject = sprite;
        }
      }

      setSpinnerSelection(spinner);

      AlertDialog dialog =
          new CustomAlertDialogBuilder(context)
              .setTitle(R.string.dialog_new_object_switch_title)
              .setMessage(R.string.dialog_new_object_switch_message)
              .setPositiveButton(
                  R.string.yes,
                  new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      ProjectManager.getInstance().setCurrentSprite(pointedObject);

                      Intent intent = new Intent(context, ProgramMenuActivity.class);
                      intent.putExtra(
                          ProgramMenuActivity.FORWARD_TO_SCRIPT_ACTIVITY,
                          ScriptActivity.FRAGMENT_SCRIPTS);
                      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                      context.startActivity(intent);

                      dialog.dismiss();
                    }
                  })
              .setNegativeButton(
                  R.string.no,
                  new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      spinnerAdapter.notifyDataSetChanged();
                      dialog.dismiss();
                    }
                  })
              .create();
      dialog.setCanceledOnTouchOutside(true);
      dialog.show();
    }