Status Update
Comments
we...@gmail.com <we...@gmail.com> #2
vk...@gmail.com <vk...@gmail.com> #3
pano.setZoom(1);
So we don't need to rely on users to perform an action.
we...@gmail.com <we...@gmail.com> #4
vk...@gmail.com <vk...@gmail.com> #5
we...@gmail.com <we...@gmail.com> #6
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch(item.getItemId()) { // Handle action bar item clicks here
case R.id.menu_save: // Save as MIDI music, MPEG audio, or WAVE sound file
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(this);
mBuilder.setTitle(R.string.menu_output).setItems(R.array.entry_output, (dialog, which)->{
iSaveOutput = which; // Range [0, 2] for three output file types
saveOutputFile();
});
mBuilder.create();
mBuilder.show();
return true;
case R.id.menu_open: // Open a file with supported format
startOpenActivity(OPEN_REQUEST_CODE);
return true;
case R.id.menu_delete: // Open multiple files to delete
startOpenActivity(DELETE_REQUEST_CODE);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent resultData) {
super.onActivityResult(requestCode, resultCode, resultData);
if(resultCode != Activity.RESULT_OK || resultData == null) {
renderGraph(MyRender.IsGraphReady()); // Need to redraw plot correctly
return;
}
final ClipData mClipData = resultData.getClipData(); // Multiple selections
Uri mUri = mClipData != null ? mClipData.getItemAt(0).getUri() : resultData.getData(); // The first or single selection
if(requestCode == DELETE_REQUEST_CODE) {
MyPacket.deleteFile(this, mUri, mClipData, mClipData != null ? mClipData.getItemCount() : 1);
} else {
MyPacket.processFile(this, myRender, mUri, requestCode);
}
}
static void deleteFile(final MyApp myApp, final Uri mUri, final ClipData mClipData, final int iTotal) {
final String mFile = getUriDisplayName(mUri);
final String mExtra = iTotal > 1 ? " "+String.format(myApp.getString(R.string.text_delete), iTotal-1) : "?";
final AlertDialog.Builder mBuilder = CreateAlertBuilder(myApp, myApp.getString(R.string.menu_delete)+" "+mFile+mExtra, true);
mBuilder.setPositiveButton(R.string.button_yes, (dialog, id)->{
try {
DocumentsContract.deleteDocument(mContentResolver, mUri);
} catch(FileNotFoundException e) {
e.printStackTrace();
}
for(int i = 1; i < iTotal; i++) { // Delete other selected files
ClipData.Item item = mClipData.getItemAt(i);
try {
DocumentsContract.deleteDocument(mContentResolver, item.getUri());
} catch(FileNotFoundException e) {
e.printStackTrace();
}
}
dialog.dismiss();
});
CreateAlertDialog(mBuilder);
}
sa...@gmail.com <sa...@gmail.com> #7
For me (at least on API 29+) the ACTION_CREATE_DOCUMENT intent does allow to overwrite existing files. It's not exactly intuitive, the user must click one of the existing files, the name is reflected on the prompt, and pressing "SAVE" will ask something like "Overwrite transcode.aac?/Cancel/OK"
. If the user types a name that matches one of the existing files, a new copy will be created instead of overwrite.
And here is where it becomes <s>interesting</s> annoying: the new file will be called "transcode.aac (1)"
(then … (2)
, and so on). The file that is produced is not recognized by the platform as an audio file anymore. Instead of a well-known extension "aac"
it now considered BIN with extension "aac (1)"
.
PS: this all applies to API 21, except then the "Overwrite" prompt does not pop up.
Description
Storage Access Framework ACTION_CREATE_DOCUMENT has no option to overwrite an existing file.
A file such as "filename.ext (1)" will be created if "filename.ext" already exists in folder.
To minimize required work and to reuse existing code, the following method can be used:
1. Allow putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true) for ACTION_CREATE_DOCUMENT intent;
2. No change to picker UI (only a single filename as input in startActivityForResult);
3. If desired filename does not exist, onActivityResult returns Uri with getData();
4. If filename already exists, onActivityResult returns Uri with getClipData();
5. In the latter case, getClipData() has two items (new Uri and existing Uri).
Benefit:
1. Proposed method can reuse code for ACTION_OPEN_DOCUMENT (EXTRA_ALLOW_MULTIPLE tag);
2. Developer can offer (via dialog) to overwrite an existing file or create a new one;
3. ACTION_CREATE_DOCUMENT intent works the old way (without EXTRA_ALLOW_MULTIPLE tag).