Dream complications styling update.

- update complication weights so home controls, media entry chip, and
  smartspace are always shown below the clock
- instead of applying the bottom padding to home controls at the layout
  engine level in order to center align with smartspace, apply to the
  home controls chip view, which prevents the layout engine from giving
  an exception to adding padding to a root node

Bug: 259264239
Bug: 259719867
Test: https://screenshot.googleplex.com/BZNatvxHFHxqxaS
Test: https://screenshot.googleplex.com/9gxsLUZWTFy7sGX
Change-Id: Icfcc3653ad7eb52e707c8289803188388484666e
This commit is contained in:
Darrell Shi
2022-11-18 20:52:41 +00:00
parent b96b7ad9e9
commit e0fa9f694c
9 changed files with 47 additions and 136 deletions

View File

@@ -14,16 +14,21 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<ImageView
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_controls_chip"
android:layout_height="@dimen/keyguard_affordance_fixed_height"
android:layout_width="@dimen/keyguard_affordance_fixed_width"
android:layout_gravity="bottom|start"
android:scaleType="center"
android:tint="?android:attr/textColorPrimary"
android:src="@drawable/controls_icon"
android:background="@drawable/keyguard_bottom_affordance_bg"
android:layout_marginStart="@dimen/keyguard_affordance_horizontal_offset"
android:layout_marginBottom="@dimen/keyguard_affordance_vertical_offset"
android:contentDescription="@string/quick_controls_title" />
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingVertical="@dimen/dream_overlay_complication_home_controls_padding">
<ImageView
android:id="@+id/home_controls_chip"
android:layout_height="@dimen/keyguard_affordance_fixed_height"
android:layout_width="@dimen/keyguard_affordance_fixed_width"
android:layout_gravity="bottom|start"
android:scaleType="center"
android:tint="?android:attr/textColorPrimary"
android:src="@drawable/controls_icon"
android:background="@drawable/keyguard_bottom_affordance_bg"
android:contentDescription="@string/quick_controls_title" />
</FrameLayout>

View File

@@ -192,9 +192,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll
break;
}
// Add margin if specified by the complication. Otherwise add default margin
// between complications.
if (mLayoutParams.isMarginSpecified() || !isRoot) {
if (!isRoot) {
final int margin = mLayoutParams.getMargin(mDefaultMargin);
switch(direction) {
case ComplicationLayoutParams.DIRECTION_DOWN:

View File

@@ -260,13 +260,6 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams {
return mWeight;
}
/**
* Returns whether margin has been specified by the complication.
*/
public boolean isMarginSpecified() {
return mMargin != MARGIN_UNSPECIFIED;
}
/**
* Returns the margin to apply between complications, or the given default if no margin is
* specified.

View File

@@ -32,6 +32,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.CoreStartable;
import com.android.systemui.R;
import com.android.systemui.animation.ActivityLaunchAnimator;
import com.android.systemui.controls.ControlsServiceInfo;
import com.android.systemui.controls.dagger.ControlsComponent;
@@ -151,7 +152,7 @@ public class DreamHomeControlsComplication implements Complication {
@Inject
DreamHomeControlsChipViewHolder(
DreamHomeControlsChipViewController dreamHomeControlsChipViewController,
@Named(DREAM_HOME_CONTROLS_CHIP_VIEW) ImageView view,
@Named(DREAM_HOME_CONTROLS_CHIP_VIEW) View view,
@Named(DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS) ComplicationLayoutParams layoutParams
) {
mView = view;
@@ -174,7 +175,7 @@ public class DreamHomeControlsComplication implements Complication {
/**
* Controls behavior of the dream complication.
*/
static class DreamHomeControlsChipViewController extends ViewController<ImageView> {
static class DreamHomeControlsChipViewController extends ViewController<View> {
private static final String TAG = "DreamHomeControlsCtrl";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -203,7 +204,7 @@ public class DreamHomeControlsComplication implements Complication {
@Inject
DreamHomeControlsChipViewController(
@Named(DREAM_HOME_CONTROLS_CHIP_VIEW) ImageView view,
@Named(DREAM_HOME_CONTROLS_CHIP_VIEW) View view,
ActivityStarter activityStarter,
Context context,
ControlsComponent controlsComponent,
@@ -218,9 +219,10 @@ public class DreamHomeControlsComplication implements Complication {
@Override
protected void onViewAttached() {
mView.setImageResource(mControlsComponent.getTileImageId());
mView.setContentDescription(mContext.getString(mControlsComponent.getTileTitleId()));
mView.setOnClickListener(this::onClickHomeControls);
final ImageView chip = mView.findViewById(R.id.home_controls_chip);
chip.setImageResource(mControlsComponent.getTileImageId());
chip.setContentDescription(mContext.getString(mControlsComponent.getTileTitleId()));
chip.setOnClickListener(this::onClickHomeControls);
}
@Override

View File

@@ -19,7 +19,7 @@ package com.android.systemui.dreams.complication.dagger;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.view.View;
import com.android.systemui.R;
import com.android.systemui.dreams.complication.DreamHomeControlsComplication;
@@ -74,8 +74,8 @@ public interface DreamHomeControlsComplicationComponent {
@Provides
@DreamHomeControlsComplicationScope
@Named(DREAM_HOME_CONTROLS_CHIP_VIEW)
static ImageView provideHomeControlsChipView(LayoutInflater layoutInflater) {
return (ImageView) layoutInflater.inflate(R.layout.dream_overlay_home_controls_chip,
static View provideHomeControlsChipView(LayoutInflater layoutInflater) {
return layoutInflater.inflate(R.layout.dream_overlay_home_controls_chip,
null, false);
}
}

View File

@@ -47,10 +47,10 @@ public interface RegisteredComplicationsModule {
String DREAM_MEDIA_ENTRY_LAYOUT_PARAMS = "media_entry_layout_params";
int DREAM_CLOCK_TIME_COMPLICATION_WEIGHT = 1;
int DREAM_SMARTSPACE_COMPLICATION_WEIGHT = 0;
int DREAM_SMARTSPACE_COMPLICATION_WEIGHT = 2;
int DREAM_MEDIA_COMPLICATION_WEIGHT = 0;
int DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT = 2;
int DREAM_MEDIA_ENTRY_COMPLICATION_WEIGHT = 1;
int DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT = 4;
int DREAM_MEDIA_ENTRY_COMPLICATION_WEIGHT = 3;
/**
* Provides layout parameters for the clock time complication.
@@ -72,17 +72,14 @@ public interface RegisteredComplicationsModule {
*/
@Provides
@Named(DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS)
static ComplicationLayoutParams provideHomeControlsChipLayoutParams(@Main Resources res) {
static ComplicationLayoutParams provideHomeControlsChipLayoutParams() {
return new ComplicationLayoutParams(
res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_width),
res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height),
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
ComplicationLayoutParams.POSITION_BOTTOM
| ComplicationLayoutParams.POSITION_START,
ComplicationLayoutParams.DIRECTION_UP,
DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT,
// Add margin to the bottom of home controls to horizontally align with smartspace.
res.getDimensionPixelSize(
R.dimen.dream_overlay_complication_home_controls_padding));
ComplicationLayoutParams.DIRECTION_END,
DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT);
}
/**

View File

@@ -361,8 +361,7 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase {
assertThat(lp.getMarginEnd()).isEqualTo(margin);
});
// The third view should be at the top end corner. No margin should be applied if not
// specified.
// The third view should be at the top end corner. No margin should be applied.
verifyChange(thirdViewInfo, true, lp -> {
assertThat(lp.topToTop == ConstraintLayout.LayoutParams.PARENT_ID).isTrue();
assertThat(lp.endToEnd == ConstraintLayout.LayoutParams.PARENT_ID).isTrue();
@@ -441,69 +440,6 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase {
});
}
/**
* Ensures the root complication applies margin if specified.
*/
@Test
public void testRootComplicationSpecifiedMargin() {
final int defaultMargin = 5;
final int complicationMargin = 10;
final ComplicationLayoutEngine engine =
new ComplicationLayoutEngine(mLayout, defaultMargin, mTouchSession, 0, 0);
final ViewInfo firstViewInfo = new ViewInfo(
new ComplicationLayoutParams(
100,
100,
ComplicationLayoutParams.POSITION_TOP
| ComplicationLayoutParams.POSITION_END,
ComplicationLayoutParams.DIRECTION_DOWN,
0),
Complication.CATEGORY_STANDARD,
mLayout);
addComplication(engine, firstViewInfo);
final ViewInfo secondViewInfo = new ViewInfo(
new ComplicationLayoutParams(
100,
100,
ComplicationLayoutParams.POSITION_TOP
| ComplicationLayoutParams.POSITION_END,
ComplicationLayoutParams.DIRECTION_START,
0),
Complication.CATEGORY_SYSTEM,
mLayout);
addComplication(engine, secondViewInfo);
firstViewInfo.clearInvocations();
secondViewInfo.clearInvocations();
final ViewInfo thirdViewInfo = new ViewInfo(
new ComplicationLayoutParams(
100,
100,
ComplicationLayoutParams.POSITION_TOP
| ComplicationLayoutParams.POSITION_END,
ComplicationLayoutParams.DIRECTION_START,
1,
complicationMargin),
Complication.CATEGORY_SYSTEM,
mLayout);
addComplication(engine, thirdViewInfo);
// The third view is the root view and has specified margin, which should be applied based
// on its direction.
verifyChange(thirdViewInfo, true, lp -> {
assertThat(lp.getMarginStart()).isEqualTo(0);
assertThat(lp.getMarginEnd()).isEqualTo(complicationMargin);
assertThat(lp.topMargin).isEqualTo(0);
assertThat(lp.bottomMargin).isEqualTo(0);
});
}
/**
* Ensures layout in a particular position updates.
*/

View File

@@ -96,36 +96,11 @@ public class ComplicationLayoutParamsTest extends SysuiTestCase {
}
}
/**
* Ensures ComplicationLayoutParams correctly returns whether the complication specified margin.
*/
@Test
public void testIsMarginSpecified() {
final ComplicationLayoutParams paramsNoMargin = new ComplicationLayoutParams(
100,
100,
ComplicationLayoutParams.POSITION_TOP
| ComplicationLayoutParams.POSITION_START,
ComplicationLayoutParams.DIRECTION_DOWN,
0);
assertThat(paramsNoMargin.isMarginSpecified()).isFalse();
final ComplicationLayoutParams paramsWithMargin = new ComplicationLayoutParams(
100,
100,
ComplicationLayoutParams.POSITION_TOP
| ComplicationLayoutParams.POSITION_START,
ComplicationLayoutParams.DIRECTION_DOWN,
0,
20 /*margin*/);
assertThat(paramsWithMargin.isMarginSpecified()).isTrue();
}
/**
* Ensures unspecified margin uses default.
*/
@Test
public void testUnspecifiedMarginUsesDefault() {
public void testDefaultMargin() {
final ComplicationLayoutParams params = new ComplicationLayoutParams(
100,
100,

View File

@@ -35,6 +35,7 @@ import android.widget.ImageView;
import androidx.test.filters.SmallTest;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.controls.ControlsServiceInfo;
import com.android.systemui.controls.controller.ControlsController;
@@ -84,7 +85,10 @@ public class DreamHomeControlsComplicationTest extends SysuiTestCase {
private ArgumentCaptor<ControlsListingController.ControlsListingCallback> mCallbackCaptor;
@Mock
private ImageView mView;
private View mView;
@Mock
private ImageView mHomeControlsView;
@Mock
private ActivityStarter mActivityStarter;
@@ -105,6 +109,7 @@ public class DreamHomeControlsComplicationTest extends SysuiTestCase {
when(mControlsComponent.getControlsListingController()).thenReturn(
Optional.of(mControlsListingController));
when(mControlsComponent.getVisibility()).thenReturn(AVAILABLE);
when(mView.findViewById(R.id.home_controls_chip)).thenReturn(mHomeControlsView);
}
@Test
@@ -206,9 +211,9 @@ public class DreamHomeControlsComplicationTest extends SysuiTestCase {
final ArgumentCaptor<View.OnClickListener> clickListenerCaptor =
ArgumentCaptor.forClass(View.OnClickListener.class);
verify(mView).setOnClickListener(clickListenerCaptor.capture());
verify(mHomeControlsView).setOnClickListener(clickListenerCaptor.capture());
clickListenerCaptor.getValue().onClick(mView);
clickListenerCaptor.getValue().onClick(mHomeControlsView);
verify(mUiEventLogger).log(
DreamHomeControlsComplication.DreamHomeControlsChipViewController
.DreamOverlayEvent.DREAM_HOME_CONTROLS_TAPPED);