Java Code Examples for org.chromium.base.ApiCompatibilityUtils#getBlockSize()

The following examples show how to use org.chromium.base.ApiCompatibilityUtils#getBlockSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadManagerUi.java    From delion with Apache License 2.0 6 votes vote down vote up
SpaceDisplay(final ViewGroup parent) {
    mSpaceUsedTextView = (TextView) parent.findViewById(R.id.space_used_display);
    mSpaceTotalTextView = (TextView) parent.findViewById(R.id.space_total_display);
    mSpaceBar = (ProgressBar) parent.findViewById(R.id.space_bar);

    mFileSystemBytesTask = new AsyncTask<Void, Void, Long>() {
        @Override
        protected Long doInBackground(Void... params) {
            StatFs statFs = new StatFs(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_DOWNLOADS).getPath());
            long totalBlocks = ApiCompatibilityUtils.getBlockCount(statFs);
            long blockSize = ApiCompatibilityUtils.getBlockSize(statFs);
            long fileSystemBytes = totalBlocks * blockSize;
            return fileSystemBytes;
        }
    };
    mFileSystemBytesTask.execute();
}
 
Example 2
Source File: SpaceDisplay.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected Long doInBackground(Void... params) {
    File downloadDirectory = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DOWNLOADS);

    // Create the downloads directory, if necessary.
    if (!downloadDirectory.exists()) {
        try {
            // mkdirs() can fail, so we still need to check if the directory exists
            // later.
            downloadDirectory.mkdirs();
        } catch (SecurityException e) {
            Log.e(TAG, "SecurityException when creating download directory.", e);
        }
    }

    // Determine how much space is available on the storage device where downloads
    // reside.  If the downloads directory doesn't exist, it is likely that the user
    // doesn't have an SD card installed.
    long blocks = 0;
    if (downloadDirectory.exists()) {
        StatFs statFs = new StatFs(downloadDirectory.getPath());
        if (mFetchTotalSize) {
            blocks = ApiCompatibilityUtils.getBlockCount(statFs);
        } else {
            blocks = ApiCompatibilityUtils.getAvailableBlocks(statFs);
        }

        return blocks * ApiCompatibilityUtils.getBlockSize(statFs);
    } else {
        Log.e(TAG, "Download directory doesn't exist.");
        return 0L;
    }
}
 
Example 3
Source File: SpaceDisplay.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected Long doInBackground(Void... params) {
    File downloadDirectory = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DOWNLOADS);

    // Create the downloads directory, if necessary.
    if (!downloadDirectory.exists()) {
        try {
            // mkdirs() can fail, so we still need to check if the directory exists
            // later.
            downloadDirectory.mkdirs();
        } catch (SecurityException e) {
            Log.e(TAG, "SecurityException when creating download directory.", e);
        }
    }

    // Determine how much space is available on the storage device where downloads
    // reside.  If the downloads directory doesn't exist, it is likely that the user
    // doesn't have an SD card installed.
    long blocks = 0;
    if (downloadDirectory.exists()) {
        StatFs statFs = new StatFs(downloadDirectory.getPath());
        if (mFetchTotalSize) {
            blocks = ApiCompatibilityUtils.getBlockCount(statFs);
        } else {
            blocks = ApiCompatibilityUtils.getAvailableBlocks(statFs);
        }

        return blocks * ApiCompatibilityUtils.getBlockSize(statFs);
    } else {
        Log.e(TAG, "Download directory doesn't exist.");
        return 0L;
    }
}