Merge changes I020bd406,I85f82b8e into sc-dev
* changes: Support custom content in UsageProgressBarPreference Adjust layout of UsageProgressBarPreference
This commit is contained in:
@@ -6,6 +6,7 @@ android_library {
|
||||
|
||||
static_libs: [
|
||||
"androidx.preference_preference",
|
||||
"androidx-constraintlayout_constraintlayout",
|
||||
],
|
||||
|
||||
sdk_version: "system_current",
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
@@ -26,29 +27,40 @@
|
||||
android:paddingTop="32dp"
|
||||
android:paddingBottom="32dp">
|
||||
|
||||
<RelativeLayout
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/usage_summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignBaseline="@id/total_summary"
|
||||
android:singleLine="true"
|
||||
app:layout_constraintWidth_percent="0.45"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBaseline_toBaselineOf="@id/total_summary"
|
||||
android:ellipsize="marquee"
|
||||
android:fontFamily="@*android:string/config_headlineFontFamily"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Display1"
|
||||
android:textSize="20sp"/>
|
||||
android:textSize="14sp"
|
||||
android:textAlignment="viewStart"/>
|
||||
<TextView
|
||||
android:id="@+id/total_summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:singleLine="true"
|
||||
app:layout_constraintWidth_percent="0.45"
|
||||
app:layout_constraintEnd_toStartOf="@id/custom_content"
|
||||
android:ellipsize="marquee"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1"/>
|
||||
</RelativeLayout>
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1"
|
||||
android:textSize="14sp"
|
||||
android:textAlignment="viewEnd"/>
|
||||
<FrameLayout
|
||||
android:id="@+id/custom_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="@id/total_summary"
|
||||
app:layout_constraintWidth_percent="0.1"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@android:id/progress"
|
||||
|
||||
@@ -22,6 +22,9 @@ import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -41,6 +44,7 @@ public class UsageProgressBarPreference extends Preference {
|
||||
|
||||
private CharSequence mUsageSummary;
|
||||
private CharSequence mTotalSummary;
|
||||
private ImageView mCustomImageView;
|
||||
private int mPercent = -1;
|
||||
|
||||
/**
|
||||
@@ -110,6 +114,15 @@ public class UsageProgressBarPreference extends Preference {
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
/** Set custom ImageView to the right side of total summary. */
|
||||
public <T extends ImageView> void setCustomContent(T imageView) {
|
||||
if (imageView == mCustomImageView) {
|
||||
return;
|
||||
}
|
||||
mCustomImageView = imageView;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds the created View to the data for this preference.
|
||||
*
|
||||
@@ -141,6 +154,15 @@ public class UsageProgressBarPreference extends Preference {
|
||||
progressBar.setIndeterminate(false);
|
||||
progressBar.setProgress(mPercent);
|
||||
}
|
||||
|
||||
final FrameLayout customLayout = (FrameLayout) holder.findViewById(R.id.custom_content);
|
||||
if (mCustomImageView == null) {
|
||||
customLayout.removeAllViews();
|
||||
customLayout.setVisibility(View.GONE);
|
||||
} else {
|
||||
customLayout.addView(mCustomImageView);
|
||||
customLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence enlargeFontOfNumber(CharSequence summary) {
|
||||
|
||||
@@ -18,11 +18,15 @@ package com.android.settingslib.widget;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.SpannedString;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
@@ -97,4 +101,30 @@ public class UsageProgressBarPreferenceTest {
|
||||
.findViewById(android.R.id.progress);
|
||||
assertThat(progressBar.getProgress()).isEqualTo((int) (31.0f / 80 * 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCustomContent_setNullImageView_noChild() {
|
||||
mUsageProgressBarPreference.setCustomContent(null /* imageView */);
|
||||
|
||||
mUsageProgressBarPreference.onBindViewHolder(mViewHolder);
|
||||
|
||||
final FrameLayout customContent =
|
||||
(FrameLayout) mViewHolder.findViewById(R.id.custom_content);
|
||||
assertThat(customContent.getChildCount()).isEqualTo(0);
|
||||
assertThat(customContent.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCustomContent_setImageView_oneChild() {
|
||||
final ImageView imageView = mock(ImageView.class);
|
||||
mUsageProgressBarPreference.setCustomContent(imageView);
|
||||
|
||||
mUsageProgressBarPreference.onBindViewHolder(mViewHolder);
|
||||
|
||||
final FrameLayout customContent =
|
||||
(FrameLayout) mViewHolder.findViewById(R.id.custom_content);
|
||||
assertThat(customContent.getChildCount()).isEqualTo(1);
|
||||
assertThat(customContent.getChildAt(0)).isEqualTo(imageView);
|
||||
assertThat(customContent.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user