use of com.cloudrail.si.types.SpaceAllocation in project AmazeFileManager by TeamAmaze.
the class HybridFile method getUsableSpace.
/**
* Gets usable i.e. free space of a device
* @return
*/
public long getUsableSpace() {
long size = 0L;
switch(mode) {
case SMB:
try {
size = (new SmbFile(path).getDiskFreeSpace());
} catch (MalformedURLException e) {
size = 0L;
e.printStackTrace();
} catch (SmbException e) {
size = 0L;
e.printStackTrace();
}
break;
case FILE:
case ROOT:
size = new File(path).getUsableSpace();
break;
case DROPBOX:
case BOX:
case GDRIVE:
case ONEDRIVE:
SpaceAllocation spaceAllocation = dataUtils.getAccount(mode).getAllocation();
size = spaceAllocation.getTotal() - spaceAllocation.getUsed();
break;
case SFTP:
size = SshClientUtils.execute(new SFtpClientTemplate(path) {
@Override
public Long execute(@NonNull SFTPClient client) throws IOException {
try {
Statvfs.Response response = new Statvfs.Response(path, client.getSFTPEngine().request(Statvfs.request(client, SshClientUtils.extractRemotePathFrom(path))).retrieve());
return response.diskFreeSpace();
} catch (SFTPException e) {
Log.e(TAG, "Error querying server", e);
return 0L;
} catch (Buffer.BufferException e) {
Log.e(TAG, "Error parsing reply", e);
return 0L;
}
}
});
break;
case OTG:
// TODO: Get free space from OTG when {@link DocumentFile} API adds support
break;
}
return size;
}
use of com.cloudrail.si.types.SpaceAllocation in project cloudrail-si-android-sdk by CloudRail.
the class Files method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_files, container, false);
TextView tv = (TextView) v.findViewById(R.id.service_name);
switch(this.currentService) {
case 1:
{
tv.setText("My Dropbox:");
break;
}
case 2:
{
tv.setText("My Box:");
break;
}
case 3:
{
tv.setText("My GoogleDrive:");
break;
}
case 4:
{
tv.setText("My OneDrive:");
break;
}
case 5:
{
tv.setText("My Egnyte:");
break;
}
case 6:
{
tv.setText("My OneDrive Business:");
break;
}
}
final TextView tv2 = (TextView) v.findViewById(R.id.allocation);
new Thread(new Runnable() {
@Override
public void run() {
final SpaceAllocation alloc = getService().getAllocation();
getOwnActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
String used = getSizeString(alloc.getUsed());
String total = getSizeString(alloc.getTotal());
tv2.setText(used + " used of " + total);
}
});
}
}).start();
this.list = (ListView) v.findViewById(R.id.listView);
this.list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startSpinner();
LinearLayout ll = (LinearLayout) view;
TextView tv = (TextView) ll.findViewById(R.id.list_item);
final String name = (String) tv.getText();
new Thread(new Runnable() {
@Override
public void run() {
String next = currentPath;
if (!currentPath.equals("/")) {
next += "/";
}
next += name;
CloudMetaData info = getService().getMetadata(next);
if (info.getFolder()) {
setNewPath(next);
} else {
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
InputStream data = getService().download(next);
File file = new File(path, name);
try {
FileOutputStream stream = new FileOutputStream(file, true);
pipe(data, stream);
data.close();
stream.close();
} catch (Exception e) {
stopSpinner();
e.printStackTrace();
}
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
getOwnActivity().sendBroadcast(intent);
String ext = getMimeType(name);
String mime = null;
stopSpinner();
if (ext != null && isDisplayable(ext)) {
mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), mime);
startActivity(intent);
} else {
getOwnActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Download complete! Stored to download folder.", Toast.LENGTH_SHORT).show();
}
});
}
}
}
}).start();
}
});
this.list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
selectedItem = view;
PopupMenu popupMenu = new PopupMenu(getOwnActivity(), view);
MenuInflater menuInflater = getOwnActivity().getMenuInflater();
menuInflater.inflate(R.menu.selected_item_bar, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_delete:
{
removeItem();
return true;
}
case R.id.action_copy:
{
copyItem();
return true;
}
case R.id.action_create_share_link:
{
createShareLink();
return true;
}
case R.id.action_cut:
{
cutItem();
return true;
}
default:
return false;
}
}
});
popupMenu.show();
return true;
}
});
this.spinner = (ProgressBar) v.findViewById(R.id.spinner);
this.spinner.setVisibility(View.GONE);
this.currentPath = "/";
this.updateList();
return v;
}
use of com.cloudrail.si.types.SpaceAllocation in project AmazeFileManager by TeamAmaze.
the class HybridFile method getTotal.
/**
* Gets total size of the disk
* @param context
* @return
*/
public long getTotal(Context context) {
long size = 0l;
switch(mode) {
case SMB:
// TODO: Find total storage space of SMB when JCIFS adds support
try {
size = new SmbFile(path).getDiskFreeSpace();
} catch (SmbException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
break;
case FILE:
case ROOT:
size = new File(path).getTotalSpace();
break;
case DROPBOX:
case BOX:
case ONEDRIVE:
case GDRIVE:
SpaceAllocation spaceAllocation = dataUtils.getAccount(mode).getAllocation();
size = spaceAllocation.getTotal();
break;
case SFTP:
size = SshClientUtils.execute(new SFtpClientTemplate(path) {
@Override
public Long execute(@NonNull SFTPClient client) throws IOException {
try {
Statvfs.Response response = new Statvfs.Response(path, client.getSFTPEngine().request(Statvfs.request(client, SshClientUtils.extractRemotePathFrom(path))).retrieve());
return response.diskSize();
} catch (SFTPException e) {
Log.e(TAG, "Error querying server", e);
return 0L;
} catch (Buffer.BufferException e) {
Log.e(TAG, "Error parsing reply", e);
return 0L;
}
}
});
break;
case OTG:
// TODO: Find total storage space of OTG when {@link DocumentFile} API adds support
DocumentFile documentFile = OTGUtil.getDocumentFile(path, context, false);
documentFile.length();
break;
}
return size;
}
Aggregations