Add 12dp padding above the first slice item
-Add an extra padding in adapter for dedicated panels -Add test cases Bug: 154181365 Test: manual test make -j50 RunSettingsRoboTests "adb shell am start -a android.settings.panel.action.INTERNET_CONNECTIVITY" Change-Id: I65bc26c23ca5a7f1b433c36ac7ddf1a658793719
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
-->
|
-->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/slice_slider_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
@@ -427,4 +427,7 @@
|
|||||||
|
|
||||||
<!-- Developer options shared data screens related dimensions -->
|
<!-- Developer options shared data screens related dimensions -->
|
||||||
<dimen name="list_preferred_item_padding">16dp</dimen>
|
<dimen name="list_preferred_item_padding">16dp</dimen>
|
||||||
|
|
||||||
|
<!-- Output switcher panel related dimensions -->
|
||||||
|
<dimen name="output_switcher_slice_padding_top">12dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.panel;
|
package com.android.settings.panel;
|
||||||
|
|
||||||
|
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_GROUP_SLICE_URI;
|
||||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
|
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
|
||||||
|
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -24,6 +26,7 @@ import android.net.Uri;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
@@ -81,7 +84,7 @@ public class PanelSlicesAdapter
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull SliceRowViewHolder sliceRowViewHolder, int position) {
|
public void onBindViewHolder(@NonNull SliceRowViewHolder sliceRowViewHolder, int position) {
|
||||||
sliceRowViewHolder.onBind(mSliceLiveData.get(position));
|
sliceRowViewHolder.onBind(mSliceLiveData.get(position), position);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,15 +119,21 @@ public class PanelSlicesAdapter
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final SliceView sliceView;
|
final SliceView sliceView;
|
||||||
|
@VisibleForTesting
|
||||||
|
final LinearLayout mSliceSliderLayout;
|
||||||
|
|
||||||
public SliceRowViewHolder(View view) {
|
public SliceRowViewHolder(View view) {
|
||||||
super(view);
|
super(view);
|
||||||
sliceView = view.findViewById(R.id.slice_view);
|
sliceView = view.findViewById(R.id.slice_view);
|
||||||
sliceView.setMode(SliceView.MODE_LARGE);
|
sliceView.setMode(SliceView.MODE_LARGE);
|
||||||
sliceView.setShowTitleItems(true);
|
sliceView.setShowTitleItems(true);
|
||||||
|
mSliceSliderLayout = view.findViewById(R.id.slice_slider_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBind(LiveData<Slice> sliceLiveData) {
|
/**
|
||||||
|
* Called when the view is displayed.
|
||||||
|
*/
|
||||||
|
public void onBind(LiveData<Slice> sliceLiveData, int position) {
|
||||||
sliceLiveData.observe(mPanelFragment.getViewLifecycleOwner(), sliceView);
|
sliceLiveData.observe(mPanelFragment.getViewLifecycleOwner(), sliceView);
|
||||||
|
|
||||||
// Do not show the divider above media devices switcher slice per request
|
// Do not show the divider above media devices switcher slice per request
|
||||||
@@ -133,6 +142,16 @@ public class PanelSlicesAdapter
|
|||||||
mDividerAllowedAbove = false;
|
mDividerAllowedAbove = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Customize output switcher slice top padding
|
||||||
|
if (position == 0 && (slice.getUri().equals(MEDIA_OUTPUT_SLICE_URI)
|
||||||
|
|| slice.getUri().equals(MEDIA_OUTPUT_GROUP_SLICE_URI))) {
|
||||||
|
final int paddingTop = mPanelFragment.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.output_switcher_slice_padding_top);
|
||||||
|
mSliceSliderLayout.setPadding(mSliceSliderLayout.getPaddingLeft(), paddingTop,
|
||||||
|
mSliceSliderLayout.getPaddingRight(),
|
||||||
|
mSliceSliderLayout.getPaddingBottom());
|
||||||
|
}
|
||||||
|
|
||||||
// Log Panel interaction
|
// Log Panel interaction
|
||||||
sliceView.setOnSliceActionListener(
|
sliceView.setOnSliceActionListener(
|
||||||
((eventInfo, sliceItem) -> {
|
((eventInfo, sliceItem) -> {
|
||||||
|
@@ -18,7 +18,9 @@ package com.android.settings.panel;
|
|||||||
|
|
||||||
import static com.android.settings.panel.PanelContent.VIEW_TYPE_SLIDER;
|
import static com.android.settings.panel.PanelContent.VIEW_TYPE_SLIDER;
|
||||||
import static com.android.settings.panel.PanelSlicesAdapter.MAX_NUM_OF_SLICES;
|
import static com.android.settings.panel.PanelSlicesAdapter.MAX_NUM_OF_SLICES;
|
||||||
|
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_GROUP_SLICE_URI;
|
||||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
|
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
|
||||||
|
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -139,6 +141,58 @@ public class PanelSlicesAdapterTest {
|
|||||||
assertThat(viewHolder.isDividerAllowedAbove()).isFalse();
|
assertThat(viewHolder.isDividerAllowedAbove()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void outputSwitcherSlice_shouldAddFirstItemPadding() {
|
||||||
|
addTestLiveData(MEDIA_OUTPUT_SLICE_URI);
|
||||||
|
|
||||||
|
final PanelSlicesAdapter adapter =
|
||||||
|
new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */);
|
||||||
|
final int position = 0;
|
||||||
|
final ViewGroup view = new FrameLayout(mContext);
|
||||||
|
final SliceRowViewHolder viewHolder =
|
||||||
|
adapter.onCreateViewHolder(view, 0 /* view type*/);
|
||||||
|
|
||||||
|
adapter.onBindViewHolder(viewHolder, position);
|
||||||
|
|
||||||
|
assertThat(viewHolder.mSliceSliderLayout.getPaddingTop()).isEqualTo(
|
||||||
|
mPanelFragment.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.output_switcher_slice_padding_top));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void outputSwitcherGroupSlice_shouldAddFirstItemPadding() {
|
||||||
|
addTestLiveData(MEDIA_OUTPUT_GROUP_SLICE_URI);
|
||||||
|
|
||||||
|
final PanelSlicesAdapter adapter =
|
||||||
|
new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */);
|
||||||
|
final int position = 0;
|
||||||
|
final ViewGroup view = new FrameLayout(mContext);
|
||||||
|
final SliceRowViewHolder viewHolder =
|
||||||
|
adapter.onCreateViewHolder(view, 0 /* view type*/);
|
||||||
|
|
||||||
|
adapter.onBindViewHolder(viewHolder, position);
|
||||||
|
|
||||||
|
assertThat(viewHolder.mSliceSliderLayout.getPaddingTop()).isEqualTo(
|
||||||
|
mPanelFragment.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.output_switcher_slice_padding_top));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mediaOutputIndicatorSlice_shouldNotAddFirstItemPadding() {
|
||||||
|
addTestLiveData(MEDIA_OUTPUT_INDICATOR_SLICE_URI);
|
||||||
|
|
||||||
|
final PanelSlicesAdapter adapter =
|
||||||
|
new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */);
|
||||||
|
final int position = 0;
|
||||||
|
final ViewGroup view = new FrameLayout(mContext);
|
||||||
|
final SliceRowViewHolder viewHolder =
|
||||||
|
adapter.onCreateViewHolder(view, 0 /* view type*/);
|
||||||
|
|
||||||
|
adapter.onBindViewHolder(viewHolder, position);
|
||||||
|
|
||||||
|
assertThat(viewHolder.mSliceSliderLayout.getPaddingTop()).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCreateViewHolder_viewTypeSlider_verifyLayout() {
|
public void onCreateViewHolder_viewTypeSlider_verifyLayout() {
|
||||||
final PanelSlicesAdapter adapter =
|
final PanelSlicesAdapter adapter =
|
||||||
|
Reference in New Issue
Block a user