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

Commit 3d0a59b0 authored by Edgar Wang's avatar Edgar Wang
Browse files

Remove ProgressBar from AppPreference

- There is no one using the progress
- The progressbar is not common usage of AppPreference

Bug: 365506467
Test: atest
Flag: EXEMPT refactor
Change-Id: I14c2309b553a22694b7406cf05b8838a7b09f60c
parent 3b5125b3
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -78,15 +78,6 @@
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"
            android:visibility="gone"/>

        <ProgressBar
            android:id="@android:id/progress"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="4dp"
            android:layout_marginTop="4dp"
            android:max="100"
            android:visibility="gone"/>
    </LinearLayout>

    <LinearLayout
+0 −9
Original line number Diff line number Diff line
@@ -74,15 +74,6 @@
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"
            android:visibility="gone"/>

        <ProgressBar
            android:id="@android:id/progress"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:max="100"
            android:visibility="gone"/>
    </LinearLayout>

    <LinearLayout
+0 −31
Original line number Diff line number Diff line
@@ -18,11 +18,8 @@ package com.android.settingslib.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;

import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;

import com.android.settingslib.widget.preference.app.R;

@@ -31,9 +28,6 @@ import com.android.settingslib.widget.preference.app.R;
 */
public class AppPreference extends Preference {

    private int mProgress;
    private boolean mProgressVisible;

    public AppPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        setLayoutResource(R.layout.preference_app);
@@ -53,29 +47,4 @@ public class AppPreference extends Preference {
        super(context, attrs);
        setLayoutResource(R.layout.preference_app);
    }

    /**
     * Sets the current progress.
     * @param amount the current progress
     *
     * @see ProgressBar#setProgress(int)
     */
    public void setProgress(int amount) {
        mProgress = amount;
        mProgressVisible = true;
        notifyChanged();
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder view) {
        super.onBindViewHolder(view);

        final ProgressBar progress = (ProgressBar) view.findViewById(android.R.id.progress);
        if (mProgressVisible) {
            progress.setProgress(mProgress);
            progress.setVisibility(View.VISIBLE);
        } else {
            progress.setVisibility(View.GONE);
        }
    }
}
+0 −64
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.
 */

package com.android.settingslib.widget;

import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import android.view.View;

import androidx.preference.PreferenceViewHolder;

import com.android.settingslib.widget.preference.app.R;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

@RunWith(RobolectricTestRunner.class)
public class AppPreferenceTest {

    private Context mContext;
    private View mRootView;
    private AppPreference mPref;
    private PreferenceViewHolder mHolder;

    @Before
    public void setUp() {
        mContext = RuntimeEnvironment.application;
        mRootView = View.inflate(mContext, R.layout.preference_app, null /* parent */);
        mHolder = PreferenceViewHolder.createInstanceForTests(mRootView);
        mPref = new AppPreference(mContext);
    }

    @Test
    public void setProgress_showProgress() {
        mPref.setProgress(1);
        mPref.onBindViewHolder(mHolder);

        assertThat(mHolder.findViewById(android.R.id.progress).getVisibility())
                .isEqualTo(View.VISIBLE);
    }

    @Test
    public void foobar_testName() {
        float iconSize = mContext.getResources().getDimension(com.android.settingslib.widget.theme.R.dimen.secondary_app_icon_size);
        assertThat(Float.floatToIntBits(iconSize)).isEqualTo(Float.floatToIntBits(32));
    }
}