file chooser
This commit is contained in:
parent
600cbc2151
commit
fa26d57dd1
4 changed files with 58 additions and 49 deletions
|
@ -156,8 +156,8 @@ public class BucketSelect extends AppCompatActivity {
|
||||||
// Toast message on menu item clicked
|
// Toast message on menu item clicked
|
||||||
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
|
||||||
if (menuItem.getTitle() == getResources().getString(R.string.upload_file_tobucket)) {
|
if (menuItem.getTitle() == getResources().getString(R.string.upload_file_tobucket)) {
|
||||||
Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||||
//upload(Name.get(position).toString(), false);
|
upload(Name.get(position).toString(), false);
|
||||||
|
|
||||||
} else if (menuItem.getTitle() == getResources().getString(R.string.create_bucket)) {
|
} else if (menuItem.getTitle() == getResources().getString(R.string.create_bucket)) {
|
||||||
//upload();
|
//upload();
|
||||||
|
|
|
@ -258,8 +258,8 @@ public class ObjectSelect extends AppCompatActivity {
|
||||||
// Toast message on menu item clicked
|
// Toast message on menu item clicked
|
||||||
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
|
||||||
if (menuItem.getTitle() == getResources().getString(R.string.upload_file_here)) {
|
if (menuItem.getTitle() == getResources().getString(R.string.upload_file_here)) {
|
||||||
Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||||
//upload(Name.get(position).toString(), false);
|
upload(false);
|
||||||
} else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
|
} else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) {
|
||||||
if (Name.size() == 1 && treelevel >= 1) {
|
if (Name.size() == 1 && treelevel >= 1) {
|
||||||
Toast.makeText(ObjectSelect.this, getResources().getString(R.string.only_item_onlist), Toast.LENGTH_SHORT).show();
|
Toast.makeText(ObjectSelect.this, getResources().getString(R.string.only_item_onlist), Toast.LENGTH_SHORT).show();
|
||||||
|
@ -284,8 +284,8 @@ public class ObjectSelect extends AppCompatActivity {
|
||||||
// Toast message on menu item clicked
|
// Toast message on menu item clicked
|
||||||
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
|
||||||
if (menuItem.getTitle() == getResources().getString(R.string.upload_file_here)) {
|
if (menuItem.getTitle() == getResources().getString(R.string.upload_file_here)) {
|
||||||
Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(ObjectSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||||
//upload(Name.get(position).toString(), false);
|
upload(false);
|
||||||
} else if (menuItem.getTitle() == getResources().getString(R.string.file_external)) {
|
} else if (menuItem.getTitle() == getResources().getString(R.string.file_external)) {
|
||||||
try {
|
try {
|
||||||
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString());
|
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString());
|
||||||
|
@ -469,13 +469,13 @@ public class ObjectSelect extends AppCompatActivity {
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void upload(String object, boolean isfolder) {
|
private void upload(boolean isfolder) {
|
||||||
Intent intent = new Intent(this, Uploader.class);
|
Intent intent = new Intent(this, Uploader.class);
|
||||||
intent.putExtra("endpoint", endpoint);
|
intent.putExtra("endpoint", endpoint);
|
||||||
intent.putExtra("username", username);
|
intent.putExtra("username", username);
|
||||||
intent.putExtra("password", password);
|
intent.putExtra("password", password);
|
||||||
intent.putExtra("bucket", bucket);
|
intent.putExtra("bucket", bucket);
|
||||||
intent.putExtra("prefix", prefix + object);
|
intent.putExtra("prefix", prefix);
|
||||||
intent.putExtra("region", location);
|
intent.putExtra("region", location);
|
||||||
intent.putExtra("isfolder", isfolder);
|
intent.putExtra("isfolder", isfolder);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
|
@ -33,6 +33,7 @@ public class Uploader extends AppCompatActivity {
|
||||||
AWSCredentials myCredentials;
|
AWSCredentials myCredentials;
|
||||||
AmazonS3 s3client;
|
AmazonS3 s3client;
|
||||||
ProgressBar simpleProgressBar;
|
ProgressBar simpleProgressBar;
|
||||||
|
String[] filename;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -45,6 +46,7 @@ public class Uploader extends AppCompatActivity {
|
||||||
location = getIntent().getStringExtra("region");
|
location = getIntent().getStringExtra("region");
|
||||||
prefix = getIntent().getStringExtra("prefix");
|
prefix = getIntent().getStringExtra("prefix");
|
||||||
isfolder = getIntent().getBooleanExtra("isfolder", false);
|
isfolder = getIntent().getBooleanExtra("isfolder", false);
|
||||||
|
fprefix = (EditText)findViewById(R.id.fprefix);
|
||||||
region = Region.getRegion(location);
|
region = Region.getRegion(location);
|
||||||
s3ClientOptions = S3ClientOptions.builder().build();
|
s3ClientOptions = S3ClientOptions.builder().build();
|
||||||
if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
|
if (!endpoint.contains(getResources().getString(R.string.aws_endpoint))) {
|
||||||
|
@ -54,10 +56,11 @@ public class Uploader extends AppCompatActivity {
|
||||||
s3client = new AmazonS3Client(myCredentials, region);
|
s3client = new AmazonS3Client(myCredentials, region);
|
||||||
s3client.setEndpoint(endpoint);
|
s3client.setEndpoint(endpoint);
|
||||||
s3client.setS3ClientOptions(s3ClientOptions);
|
s3client.setS3ClientOptions(s3ClientOptions);
|
||||||
fprefix = (EditText)findViewById(R.id.fprefix);
|
|
||||||
Button fileUpload = (Button)findViewById(R.id.fileupload);
|
Button fileUpload = (Button)findViewById(R.id.fileupload);
|
||||||
simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
|
simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
|
||||||
Toast.makeText(Uploader.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(Uploader.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||||
|
performFileSearch("Select file to upload");
|
||||||
|
//fprefix.setText(prefix);
|
||||||
/*if (isfolder) {
|
/*if (isfolder) {
|
||||||
folder = uploadFolder();
|
folder = uploadFolder();
|
||||||
} else {
|
} else {
|
||||||
|
@ -71,7 +74,8 @@ public class Uploader extends AppCompatActivity {
|
||||||
Toast.makeText(Uploader.this, getResources().getString(R.string.no_file_selected), Toast.LENGTH_SHORT).show();
|
Toast.makeText(Uploader.this, getResources().getString(R.string.no_file_selected), Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
//Toast.makeText(CreateBucket.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(CreateBucket.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||||
System.out.println(file.getPath());
|
//System.out.println(file.getPath());
|
||||||
|
System.out.println(filename[filename.length-1]);
|
||||||
Thread uploadFile = new Thread(new Runnable() {
|
Thread uploadFile = new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -112,46 +116,49 @@ public class Uploader extends AppCompatActivity {
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
private Uri uploadFolder() {
|
|
||||||
StorageManager sm = (StorageManager) this.getSystemService(Context.STORAGE_SERVICE);
|
|
||||||
|
|
||||||
Intent intent = sm.getPrimaryStorageVolume().createOpenDocumentTreeIntent();
|
private void performFileSearch(String messageTitle) {
|
||||||
String startDir = "Documents";
|
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||||
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
|
||||||
|
intent.setType("*/*");
|
||||||
|
/*String[] mimeTypes = new String[]{"application/x-binary,application/octet-stream"};
|
||||||
|
if (mimeTypes.length > 0) {
|
||||||
|
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
|
||||||
|
}*/
|
||||||
|
|
||||||
Uri uri = intent.getParcelableExtra("android.provider.extra.INITIAL_URI");
|
if (intent.resolveActivity(getPackageManager()) != null) {
|
||||||
|
startActivityForResult(Intent.createChooser(intent, messageTitle), 100);
|
||||||
String scheme = uri.toString();
|
} else {
|
||||||
|
Toast.makeText(Uploader.this, getResources().getString(R.string.file_choose_fail), Toast.LENGTH_SHORT).show();
|
||||||
scheme = scheme.replace("/root/", "/document/");
|
finish();
|
||||||
|
}
|
||||||
scheme += "%3A" + startDir;
|
|
||||||
|
|
||||||
uri = Uri.parse(scheme);
|
|
||||||
|
|
||||||
intent.putExtra("android.provider.extra.INITIAL_URI", uri);
|
|
||||||
((Activity) this).startActivityForResult(intent,100);
|
|
||||||
return uri;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Uri uploadFile() {
|
@Override
|
||||||
StorageManager sm = (StorageManager) this.getSystemService(Context.STORAGE_SERVICE);
|
public void onActivityResult(int requestCode, int resultCode, final Intent resultData) {
|
||||||
|
// The ACTION_OPEN_DOCUMENT intent was sent with the request code OPEN_DIRECTORY_REQUEST_CODE.
|
||||||
Intent intent = sm.getPrimaryStorageVolume().createOpenDocumentTreeIntent();
|
// If the request code seen here doesn't match, it's the response to some other intent,
|
||||||
String startDir = "Documents";
|
// and the below code shouldn't run at all.
|
||||||
|
super.onActivityResult(requestCode, resultCode, resultData);
|
||||||
Uri uri = intent.getParcelableExtra("android.provider.extra.INITIAL_URI");
|
if (requestCode == 100) {
|
||||||
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
String scheme = uri.toString();
|
// The document selected by the user won't be returned in the intent.
|
||||||
|
// Instead, a URI to that document will be contained in the return intent
|
||||||
scheme = scheme.replace("/root/", "/document/");
|
// provided to this method as a parameter. Pull that uri using "resultData.getData()"
|
||||||
|
if (resultData != null && resultData.getData() != null) {
|
||||||
scheme += "%3A" + startDir;
|
file = resultData.getData();
|
||||||
|
filename = file.getPath().split("/");
|
||||||
uri = Uri.parse(scheme);
|
System.out.println("File selected successfully");
|
||||||
|
System.out.println("Prefix "+prefix);
|
||||||
intent.putExtra("android.provider.extra.INITIAL_URI", uri);
|
} else {
|
||||||
((Activity) this).startActivityForResult(intent,100);
|
Toast.makeText(Uploader.this, getResources().getString(R.string.file_path_fail), Toast.LENGTH_SHORT).show();
|
||||||
return uri;
|
finish();
|
||||||
}*/
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("User cancelled file browsing {}");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -16,6 +16,8 @@
|
||||||
<string name="file_external">Open in</string>
|
<string name="file_external">Open in</string>
|
||||||
<string name="upload_file_tobucket">Upload file to this bucket</string>
|
<string name="upload_file_tobucket">Upload file to this bucket</string>
|
||||||
<string name="upload_folder_tobucket">Upload folder to this bucket</string>
|
<string name="upload_folder_tobucket">Upload folder to this bucket</string>
|
||||||
|
<string name="file_choose_fail">Could not open file choose screen</string>
|
||||||
|
<string name="file_path_fail">File uri not found</string>
|
||||||
<string name="upload_button">Upload file</string>
|
<string name="upload_button">Upload file</string>
|
||||||
<string name="upload_prefix">Upload prefix</string>
|
<string name="upload_prefix">Upload prefix</string>
|
||||||
<string name="no_file_selected">Please select a file</string>
|
<string name="no_file_selected">Please select a file</string>
|
||||||
|
|
Loading…
Reference in a new issue