Exemple #1
0
 public String getAbsolutePathBackPackSound() {
   if (fileName != null) {
     return Utils.buildPath(getPathToBackPackSoundDirectory(), fileName);
   } else {
     return null;
   }
 }
Exemple #2
0
 private String getPathToBackPackSoundDirectory() {
   Log.d("TAG", "getPathToBackPackSoundDirectory() called!");
   return Utils.buildPath(
       Utils.buildProjectPath(
           Constants.DEFAULT_ROOT
               + "/"
               + Constants.BACKPACK_DIRECTORY
               + "/"
               + Constants.BACKPACK_SOUND_DIRECTORY));
 }
Exemple #3
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);
  }
 private synchronized void startRecording() {
   if (soundRecorder != null && soundRecorder.isRecording()) {
     return;
   }
   try {
     String recordPath =
         Utils.buildPath(
             Constants.TMP_PATH,
             getString(R.string.soundrecorder_recorded_filename) + Constants.RECORDING_EXTENTION);
     soundRecorder = new SoundRecorder(recordPath);
     soundRecorder.start();
     setViewsToRecordingState();
   } catch (IOException e) {
     Log.e("CATROID", "Error recording sound.", e);
     Toast.makeText(this, R.string.soundrecorder_error, Toast.LENGTH_SHORT).show();
   }
 }
Exemple #5
0
  public SoundInfo copySoundInfoForSprite(Sprite sprite) {
    SoundInfo cloneSoundInfo = new SoundInfo();

    cloneSoundInfo.name = this.name;

    try {
      cloneSoundInfo.fileName =
          StorageHandler.getInstance()
              .copySoundFile(
                  Utils.buildPath(
                      Utils.buildProjectPath(
                          ProjectManager.getInstance().getCurrentProject().getName()),
                      Constants.SOUND_DIRECTORY,
                      fileName))
              .getName();
    } catch (IOException ioException) {
      Log.e(TAG, Log.getStackTraceString(ioException));
    }

    return cloneSoundInfo;
  }
  @Override
  protected void onHandleIntent(Intent intent) {
    StorageHandler.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());

    receiver = (ResultReceiver) intent.getParcelableExtra("receiver");
    try {
      if (projectPath == null) {
        result = false;
        Log.e(TAG, "project path is null");
        return;
      }

      File directoryPath = new File(projectPath);
      String[] paths = directoryPath.list();

      if (paths == null) {
        result = false;
        Log.e(TAG, "project path is not valid");
        return;
      }

      for (int i = 0; i < paths.length; i++) {
        paths[i] = Utils.buildPath(directoryPath.getAbsolutePath(), paths[i]);
      }

      String zipFileString = Utils.buildPath(Constants.TMP_PATH, UPLOAD_FILE_NAME);
      File zipFile = new File(zipFileString);
      if (!zipFile.exists()) {
        zipFile.getParentFile().mkdirs();
        zipFile.createNewFile();
      }
      if (!UtilZip.writeToZipFile(paths, zipFileString)) {
        zipFile.delete();
        result = false;
        return;
      }

      // String deviceIMEI = UtilDeviceInfo.getDeviceIMEI(context);
      String userEmail = UtilDeviceInfo.getUserEmail(this);
      String language = UtilDeviceInfo.getUserLanguageCode(this);

      Context context = getApplicationContext();
      ServerCalls.getInstance()
          .uploadProject(
              projectName,
              projectDescription,
              zipFileString,
              userEmail,
              language,
              token,
              username,
              receiver,
              notificationId,
              context);

      zipFile.delete();
    } catch (IOException e) {
      e.printStackTrace();
      result = false;
    } catch (WebconnectionException webException) {
      serverAnswer = webException.getMessage();
      Log.e(TAG, serverAnswer);
      result = false;
    }
  }
Exemple #7
0
 private String getPathToBackPackDirectory() {
   Log.d("TAG", "getPathToBackPackDirectory() called!");
   return Utils.buildPath(
       Utils.buildProjectPath(ProjectManager.getInstance().getCurrentProject().getName()),
       Constants.BACKPACK_DIRECTORY);
 }
Exemple #8
0
 private String getPathToSoundDirectory() {
   return Utils.buildPath(
       Utils.buildProjectPath(ProjectManager.getInstance().getCurrentProject().getName()),
       Constants.SOUND_DIRECTORY);
 }