コード例 #1
0
ファイル: SoundInfo.java プロジェクト: sy1121/thor
 public String getAbsolutePathBackPackSound() {
   if (fileName != null) {
     return Utils.buildPath(getPathToBackPackSoundDirectory(), fileName);
   } else {
     return null;
   }
 }
コード例 #2
0
ファイル: SoundInfo.java プロジェクト: sy1121/thor
 private String getPathToBackPackSoundDirectory() {
   Log.d("TAG", "getPathToBackPackSoundDirectory() called!");
   return Utils.buildPath(
       Utils.buildProjectPath(
           Constants.DEFAULT_ROOT
               + "/"
               + Constants.BACKPACK_DIRECTORY
               + "/"
               + Constants.BACKPACK_SOUND_DIRECTORY));
 }
コード例 #3
0
ファイル: UtilFileTest.java プロジェクト: joe69/Catroid
  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);
  }
コード例 #4
0
 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();
   }
 }
コード例 #5
0
ファイル: SoundInfo.java プロジェクト: sy1121/thor
  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;
  }
コード例 #6
0
  @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;
    }
  }
コード例 #7
0
ファイル: SoundInfo.java プロジェクト: sy1121/thor
 private String getPathToBackPackDirectory() {
   Log.d("TAG", "getPathToBackPackDirectory() called!");
   return Utils.buildPath(
       Utils.buildProjectPath(ProjectManager.getInstance().getCurrentProject().getName()),
       Constants.BACKPACK_DIRECTORY);
 }
コード例 #8
0
ファイル: SoundInfo.java プロジェクト: sy1121/thor
 private String getPathToSoundDirectory() {
   return Utils.buildPath(
       Utils.buildProjectPath(ProjectManager.getInstance().getCurrentProject().getName()),
       Constants.SOUND_DIRECTORY);
 }