Exemplo n.º 1
0
  public void testFileSize() throws IOException {
    for (int i = 0; i < 2; i++) {
      UtilFile.saveFileToProject(
          "testDirectory",
          i + "testsound.mp3",
          org.catrobat.catroid.test.R.raw.longtestsound,
          getInstrumentation().getContext(),
          UtilFile.FileType.TYPE_SOUND_FILE);
    }

    double expectedSizeInKilobytes = 84.2;
    assertEquals(
        "Unexpected file size String",
        String.format("%.1f KB", expectedSizeInKilobytes),
        UtilFile.getSizeAsString(testDirectory));

    for (int i = 2; i < 48; i++) {
      UtilFile.saveFileToProject(
          "testDirectory",
          i + "testsound.mp3",
          org.catrobat.catroid.test.R.raw.longtestsound,
          getInstrumentation().getContext(),
          UtilFile.FileType.TYPE_SOUND_FILE);
    }
    DecimalFormat decimalFormat = new DecimalFormat("#.0");
    String expected = decimalFormat.format(2.0) + " MB";
    assertEquals("Unexpected file size String", expected, UtilFile.getSizeAsString(testDirectory));

    PrintWriter printWriter = null;

    File testFile = new File(Utils.buildPath(testDirectory.getAbsolutePath(), "catroid.txt"));

    try {
      testFile.createNewFile();

      printWriter = new PrintWriter(testFile);
      printWriter.print("catroid");
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (printWriter != null) {
        printWriter.close();
      }
    }

    assertEquals("Unexpected Filesize!", "7 Byte", UtilFile.getSizeAsString(testFile));

    UtilFile.deleteDirectory(testDirectory);
  }
Exemplo n.º 2
0
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
      convertView = View.inflate(context, R.layout.fragment_costume_costumelist_item, null);
    }

    convertView.findViewById(R.id.btn_costume_copy).setTag(position);
    convertView.findViewById(R.id.btn_costume_delete).setTag(position);
    convertView.findViewById(R.id.btn_costume_edit).setTag(position);
    convertView.findViewById(R.id.costume_name).setTag(position);
    convertView.findViewById(R.id.costume_image).setTag(position);

    CostumeData costumeData = costumeDataItems.get(position);

    if (costumeData != null) {
      ImageView costumeImage = (ImageView) convertView.findViewById(R.id.costume_image);
      TextView costumeNameTextField = (TextView) convertView.findViewById(R.id.costume_name);
      TextView costumeResolution = (TextView) convertView.findViewById(R.id.costume_res);
      TextView costumeSize = (TextView) convertView.findViewById(R.id.costume_size);
      Button costumeEditButton = (Button) convertView.findViewById(R.id.btn_costume_edit);
      Button costumeCopyButton = (Button) convertView.findViewById(R.id.btn_costume_copy);
      Button costumeDeleteButton = (Button) convertView.findViewById(R.id.btn_costume_delete);

      costumeImage.setImageBitmap(costumeData.getThumbnailBitmap());
      costumeNameTextField.setText(costumeData.getCostumeName());

      // setting resolution and costume size:
      {
        int[] resolution = costumeData.getResolution();
        costumeResolution.setText(resolution[0] + " x " + resolution[1]);

        // setting size
        if (costumeData.getAbsolutePath() != null) {
          costumeSize.setText(UtilFile.getSizeAsString(new File(costumeData.getAbsolutePath())));
        }
      }

      costumeImage.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (onCostumeEditListener != null) {
                onCostumeEditListener.onCostumeEdit(v);
              }
            }
          });

      costumeNameTextField.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (onCostumeEditListener != null) {
                onCostumeEditListener.onCostumeRename(v);
              }
            }
          });

      costumeEditButton.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (onCostumeEditListener != null) {
                onCostumeEditListener.onCostumeEdit(v);
              }
            }
          });

      costumeCopyButton.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (onCostumeEditListener != null) {
                onCostumeEditListener.onCostumeCopy(v);
              }
            }
          });

      costumeDeleteButton.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (onCostumeEditListener != null) {
                onCostumeEditListener.onCostumeDelete(v);
              }
            }
          });
    }

    return convertView;
  }