コード例 #1
0
  /**
   * The action will take after another activity reply to this one
   *
   * @param requestCode -- the key to get result
   * @param resultCode -- result state
   * @param data -- intent to get data
   */
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.i(thisClass, "in FileChooser result");
    if (resultCode == RESULT_OK) {
      switch (requestCode) {
        case PICK_FILE_REQUEST_CODE:
          Uri fileUri = data.getData();

          //                    if (BuildConfig.DEBUG) {
          //                FileUtility.deleteAllFiles(currentSelectedDir());
          //                    }

          // create a file save the content under the related folder
          String path = UriUtility.getPath(this, fileUri);
          String name = FileUtility.getNameFromPath(path);
          FileEncryption file;
          File saveFile;
          try {
            saveFile = fileChooserBL.getEncryptedFilePath(currentSelectedDir(), name);
            file = new FileEncryption(saveFile, path, fileUri.toString(), password);
          } catch (IOException | NoSuchAlgorithmException e) {
            Log.e(thisClass, "File write failed: " + e.toString());
            return;
          }
          try {
            boolean succ = file.encrypt();
            if (!succ) {
              Toast.makeText(
                      getApplicationContext(), getString(R.string.encryptFail), Toast.LENGTH_SHORT)
                  .show();
              return;
            } else {
              Toast.makeText(
                      getApplicationContext(), getString(R.string.encryptSucc), Toast.LENGTH_SHORT)
                  .show();
            }
            if (!file.deleteOriginal()) {
              throw new EncryptionException("fail to delete original file");
            }
          } catch (IOException e) {
            Log.e(thisClass, "File encrypt failed: " + e.toString());
          } catch (NoSuchAlgorithmException | UnrecoverableEntryException | InvalidKeyException e) {
            Log.e(thisClass, " failed: " + e.toString());
          }
          // update the view as if it is clicked
          folderFragmentClick(fatherIndex);
          break;
      }
    } else {
      Log.e(thisClass, " fail to start activity " + data);
    }
  }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_fragment);

    Intent intent = getIntent();
    if (password == null) {
      password = intent.getStringExtra(FirstActivity.PASSWORD);
    }
    if (password == null) {
      showPasswordDialog();
    }

    // set the secretKey for this fragment to encrypt/decrypt
    fileChooserBL = new FileChooserBL(this);
    fileChooserBL.createAndInitDir(Category.values(), fatherDirInfos);
    // Check that the activity is using the layout version with
    // the fragment_container FrameLayout
    if (findViewById(R.id.folder_fragment_container) != null
        && findViewById(R.id.file_fragment_container) != null) {

      // However, if we're being restored from a previous state,
      // then we don't need to do anything and should return or else
      // we could end up with overlapping fragments.
      if (savedInstanceState != null) {
        return;
      }

      folderFragment =
          FolderFragment.newInstance(
              fatherDirInfos,
              R.layout.with_icon,
              new String[] {UIFileInfo.LOGO, UIFileInfo.NAME},
              new int[] {R.id.logo, R.id.desc1});
      detailFragment =
          DetailFileFragment.newInstance(
              UIFileInfo.addFileFrom(currentSelectedDir()), currentSelectedDir().getName());
      // In case this activity was started with special instructions from an
      // Intent, pass the Intent's extras to the fragment as arguments
      folderFragment.setArguments(getIntent().getExtras());
      detailFragment.setArguments(getIntent().getExtras());

      // Add the fragment to the '#fragment_container' FrameLayout
      FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
      fragmentTransaction.add(R.id.folder_fragment_container, folderFragment);
      fragmentTransaction.add(R.id.file_fragment_container, detailFragment).commit();
    }
  }
コード例 #3
0
 @Override
 protected void onDestroy() {
   // TODO: 12/13/15 delete file here?
   fileChooserBL.deleteFile();
   super.onDestroy();
 }