Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf0e659a authored by Daniel Nishi's avatar Daniel Nishi
Browse files

Re-add the progress bar for storage preferences.

This re-adds the progress bar and unifies the
StorageItemPreference and its alternate.

Change-Id: Iefc12b4b554306c706c83be232175dd2b84227b7
Fixes: 36223433
Test: Settings robotest
parent 9392681a
Loading
Loading
Loading
Loading
+0 −56
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:minHeight="?android:attr/listPreferredItemHeightSmall"
              android:gravity="center_vertical"
              android:paddingStart="@dimen/preference_no_icon_padding_start"
              android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
              android:paddingTop="16dip"
              android:paddingBottom="16dip"
              android:background="?android:attr/selectableItemBackground">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@android:id/title"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:singleLine="true"
            android:textAppearance="@android:style/TextAppearance.Material.Subhead"
            android:textAlignment="viewStart"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView
            android:id="@android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAlignment="viewStart"
            android:textAppearance="@android:style/TextAppearance.Material.Body1"
            android:textColor="?android:attr/textColorSecondaryNoDisable"
            android:maxLines="10" />

    </LinearLayout>

</LinearLayout>
+8 −8
Original line number Diff line number Diff line
@@ -30,28 +30,28 @@
        android:order="1"
        settings:allowDividerAbove="true"
        settings:allowDividerBelow="true"/>
    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
    <com.android.settings.deviceinfo.StorageItemPreference
        android:key="pref_photos_videos"
        android:title="@string/storage_photos_videos"
        android:order="2"
        settings:allowDividerAbove="true" />
    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
        settings:allowDividerAbove="true"
        android:order="2" />
    <com.android.settings.deviceinfo.StorageItemPreference
        android:key="pref_music_audio"
        android:title="@string/storage_music_audio"
        android:order="3" />
    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
    <com.android.settings.deviceinfo.StorageItemPreference
        android:key="pref_games"
        android:title="@string/storage_games"
        android:order="4" />
    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
    <com.android.settings.deviceinfo.StorageItemPreference
        android:key="pref_other_apps"
        android:title="@string/storage_other_apps"
        android:order="5" />
    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
    <com.android.settings.deviceinfo.StorageItemPreference
        android:key="pref_files"
        android:title="@string/storage_files"
        android:order="6" />
    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
    <com.android.settings.deviceinfo.StorageItemPreference
        android:key="pref_system"
        android:title="@string/storage_detail_system"
        android:order="100" />
+10 −10
Original line number Diff line number Diff line
@@ -18,24 +18,24 @@
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:title="@string/storage_settings">
    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
    <com.android.settings.deviceinfo.StorageItemPreference
        android:key="pref_photos_videos"
        android:title="@string/storage_photos_videos">
    </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
    </com.android.settings.deviceinfo.StorageItemPreference>
    <com.android.settings.deviceinfo.StorageItemPreference
        android:key="pref_music_audio"
        android:title="@string/storage_music_audio">
    </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
    </com.android.settings.deviceinfo.StorageItemPreference>
    <com.android.settings.deviceinfo.StorageItemPreference
        android:key="pref_games"
        android:title="@string/storage_games">
    </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
    </com.android.settings.deviceinfo.StorageItemPreference>
    <com.android.settings.deviceinfo.StorageItemPreference
        android:key="pref_other_apps"
        android:title="@string/storage_other_apps">
    </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
    <com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
    </com.android.settings.deviceinfo.StorageItemPreference>
    <com.android.settings.deviceinfo.StorageItemPreference
        android:key="pref_files"
        android:title="@string/storage_files">
    </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
    </com.android.settings.deviceinfo.StorageItemPreference>
</PreferenceScreen>
+10 −0
Original line number Diff line number Diff line
@@ -114,6 +114,16 @@ public class StorageDashboardFragment extends DashboardFragment
        mSummaryController.updateBytes(usedBytes, totalSize);
        mPreferenceController.setVolume(mVolume);
        mPreferenceController.setSystemSize(systemSize);

        mPreferenceController.setTotalSize(totalSize);
        for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
            PreferenceController controller = mSecondaryUsers.get(i);
            if (controller instanceof SecondaryUserController) {
                SecondaryUserController userController = (SecondaryUserController) controller;
                userController.setTotalSize(totalSize);

            }
        }
    }

    @Override
+18 −12
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.format.Formatter;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;

@@ -28,13 +29,18 @@ import com.android.settings.R;
public class StorageItemPreference extends Preference {
    public int userHandle;

    private ProgressBar progressBar;
    private ProgressBar mProgressBar;
    private static final int PROGRESS_MAX = 100;
    private int progress = -1;
    private int mProgressPercent = -1;

    public StorageItemPreference(Context context) {
        super(context);
        this(context, null);
    }

    public StorageItemPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        setLayoutResource(R.layout.storage_item);
        setSummary(R.string.memory_calculating_size);
    }

    public void setStorageSize(long size, long total) {
@@ -42,30 +48,30 @@ public class StorageItemPreference extends Preference {
                ? String.valueOf(0)
                : Formatter.formatFileSize(getContext(), size));
        if (total == 0) {
            progress = 0;
            mProgressPercent = 0;
        } else {
            progress = (int)(size * PROGRESS_MAX / total);
            mProgressPercent = (int)(size * PROGRESS_MAX / total);
        }
        updateProgressBar();
    }

    protected void updateProgressBar() {
        if (progressBar == null)
        if (mProgressBar == null)
            return;

        if (progress == -1) {
            progressBar.setVisibility(View.GONE);
        if (mProgressPercent == -1) {
            mProgressBar.setVisibility(View.GONE);
            return;
        }

        progressBar.setVisibility(View.VISIBLE);
        progressBar.setMax(PROGRESS_MAX);
        progressBar.setProgress(progress);
        mProgressBar.setVisibility(View.VISIBLE);
        mProgressBar.setMax(PROGRESS_MAX);
        mProgressBar.setProgress(mProgressPercent);
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder view) {
        progressBar = (ProgressBar) view.findViewById(android.R.id.progress);
        mProgressBar = (ProgressBar) view.findViewById(android.R.id.progress);
        updateProgressBar();
        super.onBindViewHolder(view);
    }
Loading