Search in sources :

Example 1 with BytesResult

use of android.text.format.Formatter.BytesResult in project android_frameworks_base by ResurrectionRemix.

the class FormatterTest method checkFormatBytes.

private void checkFormatBytes(long bytes, boolean useShort, String expectedString, long expectedRounded) {
    BytesResult r = Formatter.formatBytes(getContext().getResources(), bytes, Formatter.FLAG_CALCULATE_ROUNDED | (useShort ? Formatter.FLAG_SHORTER : 0));
    assertEquals(expectedString, r.value);
    assertEquals(expectedRounded, r.roundedBytes);
}
Also used : BytesResult(android.text.format.Formatter.BytesResult)

Example 2 with BytesResult

use of android.text.format.Formatter.BytesResult in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ProcessStatsSummary method refreshUi.

@Override
public void refreshUi() {
    Context context = getContext();
    MemInfo memInfo = mStatsManager.getMemInfo();
    double usedRam = memInfo.realUsedRam;
    double totalRam = memInfo.realTotalRam;
    double freeRam = memInfo.realFreeRam;
    BytesResult usedResult = Formatter.formatBytes(context.getResources(), (long) usedRam, Formatter.FLAG_SHORTER);
    String totalString = Formatter.formatShortFileSize(context, (long) totalRam);
    String freeString = Formatter.formatShortFileSize(context, (long) freeRam);
    CharSequence memString;
    CharSequence[] memStatesStr = getResources().getTextArray(R.array.ram_states);
    int memState = mStatsManager.getMemState();
    if (memState >= 0 && memState < memStatesStr.length - 1) {
        memString = memStatesStr[memState];
    } else {
        memString = memStatesStr[memStatesStr.length - 1];
    }
    mSummaryPref.setAmount(usedResult.value);
    mSummaryPref.setUnits(usedResult.units);
    float usedRatio = (float) (usedRam / (freeRam + usedRam));
    mSummaryPref.setRatios(usedRatio, 0, 1 - usedRatio);
    mPerformance.setSummary(memString);
    mTotalMemory.setSummary(totalString);
    mAverageUsed.setSummary(Utils.formatPercentage((long) usedRam, (long) totalRam));
    mFree.setSummary(freeString);
    String durationString = getString(sDurationLabels[mDurationIndex]);
    int numApps = mStatsManager.getEntries().size();
    mAppListPreference.setSummary(getResources().getQuantityString(R.plurals.memory_usage_apps_summary, numApps, numApps, durationString));
}
Also used : Context(android.content.Context) BytesResult(android.text.format.Formatter.BytesResult) MemInfo(com.android.settings.applications.ProcStatsData.MemInfo)

Example 3 with BytesResult

use of android.text.format.Formatter.BytesResult in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class StorageSettings method refresh.

private void refresh() {
    final Context context = getPrefContext();
    getPreferenceScreen().removeAll();
    mInternalCategory.removeAll();
    mExternalCategory.removeAll();
    mInternalCategory.addPreference(mInternalSummary);
    int privateCount = 0;
    long privateUsedBytes = 0;
    long privateTotalBytes = 0;
    final List<VolumeInfo> volumes = mStorageManager.getVolumes();
    Collections.sort(volumes, VolumeInfo.getDescriptionComparator());
    for (VolumeInfo vol : volumes) {
        if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
            final long volumeTotalBytes = PrivateStorageInfo.getTotalSize(vol, sTotalInternalStorage);
            final int color = COLOR_PRIVATE[privateCount++ % COLOR_PRIVATE.length];
            mInternalCategory.addPreference(new StorageVolumePreference(context, vol, color, volumeTotalBytes));
            if (vol.isMountedReadable()) {
                final File path = vol.getPath();
                privateUsedBytes += (volumeTotalBytes - path.getFreeSpace());
                privateTotalBytes += volumeTotalBytes;
            }
        } else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
            StorageVolumePreference ExStorageVolumePreference = new StorageVolumePreference(context, vol, COLOR_PUBLIC, 0);
            //Disable preference when in change
            ExStorageVolumePreference.setEnabled(vol.getState() != VolumeInfo.STATE_CHECKING && vol.getState() != VolumeInfo.STATE_EJECTING);
            mExternalCategory.addPreference(ExStorageVolumePreference);
        }
    }
    // Show missing private volumes
    final List<VolumeRecord> recs = mStorageManager.getVolumeRecords();
    for (VolumeRecord rec : recs) {
        if (rec.getType() == VolumeInfo.TYPE_PRIVATE && mStorageManager.findVolumeByUuid(rec.getFsUuid()) == null) {
            // TODO: add actual storage type to record
            final Drawable icon = context.getDrawable(R.drawable.ic_sim_sd);
            icon.mutate();
            icon.setTint(COLOR_PUBLIC);
            icon.setTintMode(PorterDuff.Mode.SRC_ATOP);
            final Preference pref = new Preference(context);
            pref.setKey(rec.getFsUuid());
            pref.setTitle(rec.getNickname());
            pref.setSummary(com.android.internal.R.string.ext_media_status_missing);
            pref.setIcon(icon);
            mInternalCategory.addPreference(pref);
        }
    }
    // Show unsupported disks to give a chance to init
    final List<DiskInfo> disks = mStorageManager.getDisks();
    for (DiskInfo disk : disks) {
        if (disk.volumeCount == 0 && disk.size > 0) {
            final Preference pref = new Preference(context);
            pref.setKey(disk.getId());
            pref.setTitle(disk.getDescription());
            pref.setSummary(com.android.internal.R.string.ext_media_status_unsupported);
            pref.setIcon(R.drawable.ic_sim_sd);
            mExternalCategory.addPreference(pref);
        }
    }
    final BytesResult result = Formatter.formatBytes(getResources(), privateUsedBytes, 0);
    mInternalSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large), result.value, result.units));
    mInternalSummary.setSummary(getString(R.string.storage_volume_used_total, Formatter.formatFileSize(context, privateTotalBytes)));
    if (mInternalCategory.getPreferenceCount() > 0) {
        getPreferenceScreen().addPreference(mInternalCategory);
    }
    if (mExternalCategory.getPreferenceCount() > 0) {
        getPreferenceScreen().addPreference(mExternalCategory);
    }
    if (mInternalCategory.getPreferenceCount() == 2 && mExternalCategory.getPreferenceCount() == 0) {
        // Only showing primary internal storage, so just shortcut
        final Bundle args = new Bundle();
        args.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
        PrivateVolumeSettings.setVolumeSize(args, sTotalInternalStorage);
        Intent intent = Utils.onBuildStartFragmentIntent(getActivity(), PrivateVolumeSettings.class.getName(), args, null, R.string.apps_storage, null, false);
        intent.putExtra(SettingsDrawerActivity.EXTRA_SHOW_MENU, true);
        getActivity().startActivity(intent);
        finish();
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) Drawable(android.graphics.drawable.Drawable) DiskInfo(android.os.storage.DiskInfo) VolumeInfo(android.os.storage.VolumeInfo) Intent(android.content.Intent) BytesResult(android.text.format.Formatter.BytesResult) VolumeRecord(android.os.storage.VolumeRecord) Preference(android.support.v7.preference.Preference) File(java.io.File)

Example 4 with BytesResult

use of android.text.format.Formatter.BytesResult in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PrivateVolumeSettings method update.

private void update() {
    if (!isVolumeValid()) {
        getActivity().finish();
        return;
    }
    setTitle();
    // Valid options may have changed
    getFragmentManager().invalidateOptionsMenu();
    final Context context = getActivity();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    if (getResources().getBoolean(R.bool.config_storage_manager_settings_enabled)) {
        addPreference(screen, mAutomaticStorageManagement);
    }
    addPreference(screen, mSummary);
    List<UserInfo> allUsers = mUserManager.getUsers();
    final int userCount = allUsers.size();
    final boolean showHeaders = userCount > 1;
    final boolean showShared = (mSharedVolume != null) && mSharedVolume.isMountedReadable();
    mItemPoolIndex = 0;
    mHeaderPoolIndex = 0;
    int addedUserCount = 0;
    // Add current user and its profiles first
    for (int userIndex = 0; userIndex < userCount; ++userIndex) {
        final UserInfo userInfo = allUsers.get(userIndex);
        if (isProfileOf(mCurrentUser, userInfo)) {
            final PreferenceGroup details = showHeaders ? addCategory(screen, userInfo.name) : screen;
            addDetailItems(details, showShared, userInfo.id);
            ++addedUserCount;
        }
    }
    // Add rest of users
    if (userCount - addedUserCount > 0) {
        PreferenceGroup otherUsers = addCategory(screen, getText(R.string.storage_other_users));
        for (int userIndex = 0; userIndex < userCount; ++userIndex) {
            final UserInfo userInfo = allUsers.get(userIndex);
            if (!isProfileOf(mCurrentUser, userInfo)) {
                addItem(otherUsers, /* titleRes */
                0, userInfo.name, userInfo.id);
            }
        }
    }
    addItem(screen, R.string.storage_detail_cached, null, UserHandle.USER_NULL);
    if (showShared) {
        addPreference(screen, mExplore);
    }
    final long freeBytes = mVolume.getPath().getFreeSpace();
    final long usedBytes = mTotalSize - freeBytes;
    if (LOGV)
        Log.v(TAG, "update() freeBytes: " + freeBytes + " usedBytes: " + usedBytes);
    final BytesResult result = Formatter.formatBytes(getResources(), usedBytes, 0);
    mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large), result.value, result.units));
    mSummary.setSummary(getString(R.string.storage_volume_used, Formatter.formatFileSize(context, mTotalSize)));
    mSummary.setPercent((int) ((usedBytes * 100) / mTotalSize));
    mMeasure.forceMeasure();
    mNeedsUpdate = false;
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) UserInfo(android.content.pm.UserInfo) PreferenceGroup(android.support.v7.preference.PreferenceGroup) BytesResult(android.text.format.Formatter.BytesResult)

Example 5 with BytesResult

use of android.text.format.Formatter.BytesResult in project android_frameworks_base by DirtyUnicorns.

the class FormatterTest method checkFormatBytes.

private void checkFormatBytes(long bytes, boolean useShort, String expectedString, long expectedRounded) {
    BytesResult r = Formatter.formatBytes(getContext().getResources(), bytes, Formatter.FLAG_CALCULATE_ROUNDED | (useShort ? Formatter.FLAG_SHORTER : 0));
    assertEquals(expectedString, r.value);
    assertEquals(expectedRounded, r.roundedBytes);
}
Also used : BytesResult(android.text.format.Formatter.BytesResult)

Aggregations

BytesResult (android.text.format.Formatter.BytesResult)14 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 Locale (java.util.Locale)5 Context (android.content.Context)4 PreferenceScreen (android.support.v7.preference.PreferenceScreen)2 File (java.io.File)2 Intent (android.content.Intent)1 UserInfo (android.content.pm.UserInfo)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 DiskInfo (android.os.storage.DiskInfo)1 VolumeInfo (android.os.storage.VolumeInfo)1 VolumeRecord (android.os.storage.VolumeRecord)1 Preference (android.support.v7.preference.Preference)1 PreferenceGroup (android.support.v7.preference.PreferenceGroup)1 MemInfo (com.android.settings.applications.ProcStatsData.MemInfo)1