Refactor dream complications.
- move SmartspaceComplication under dreams/complication - move all layout params definitions under shared complication module - inject layout params into SmartspaceComplication Bug: 217199227 Fix: 217199227 Test: manual Change-Id: I50ff8774bcb86d41fb14b48329392d99b63cbfb8
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
|
||||
package com.android.systemui.dreams.complication;
|
||||
|
||||
import static com.android.systemui.dreams.complication.dagger.DreamClockTimeComplicationModule.DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS;
|
||||
import static com.android.systemui.dreams.complication.dagger.DreamClockTimeComplicationModule.DREAM_CLOCK_TIME_COMPLICATION_VIEW;
|
||||
import static com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule.DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
@@ -19,8 +19,8 @@ package com.android.systemui.dreams.complication;
|
||||
import static com.android.systemui.controls.dagger.ControlsComponent.Visibility.AVAILABLE;
|
||||
import static com.android.systemui.controls.dagger.ControlsComponent.Visibility.AVAILABLE_AFTER_UNLOCK;
|
||||
import static com.android.systemui.controls.dagger.ControlsComponent.Visibility.UNAVAILABLE;
|
||||
import static com.android.systemui.dreams.complication.dagger.DreamHomeControlsComplicationComponent.DreamHomeControlsModule.DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS;
|
||||
import static com.android.systemui.dreams.complication.dagger.DreamHomeControlsComplicationComponent.DreamHomeControlsModule.DREAM_HOME_CONTROLS_CHIP_VIEW;
|
||||
import static com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule.DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.dreams;
|
||||
package com.android.systemui.dreams.complication;
|
||||
|
||||
import static com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule.DREAM_SMARTSPACE_LAYOUT_PARAMS;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcelable;
|
||||
@@ -23,21 +25,33 @@ import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.android.systemui.CoreStartable;
|
||||
import com.android.systemui.dreams.complication.Complication;
|
||||
import com.android.systemui.dreams.complication.ComplicationLayoutParams;
|
||||
import com.android.systemui.dreams.complication.ComplicationViewModel;
|
||||
import com.android.systemui.dreams.DreamOverlayStateController;
|
||||
import com.android.systemui.dreams.smartspace.DreamSmartspaceController;
|
||||
import com.android.systemui.plugins.BcSmartspaceDataPlugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
|
||||
/**
|
||||
* {@link SmartSpaceComplication} embodies the SmartSpace view found on the lockscreen as a
|
||||
* {@link Complication}
|
||||
*/
|
||||
public class SmartSpaceComplication implements Complication {
|
||||
private final Provider<SmartSpaceComplicationViewHolder> mViewHolderProvider;
|
||||
|
||||
@Inject
|
||||
public SmartSpaceComplication(Provider<SmartSpaceComplicationViewHolder> viewHolderProvider) {
|
||||
mViewHolderProvider = viewHolderProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder createView(ComplicationViewModel model) {
|
||||
return mViewHolderProvider.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link CoreStartable} responsbile for registering {@link SmartSpaceComplication} with
|
||||
* SystemUI.
|
||||
@@ -89,17 +103,20 @@ public class SmartSpaceComplication implements Complication {
|
||||
}
|
||||
}
|
||||
|
||||
private static class SmartSpaceComplicationViewHolder implements ViewHolder {
|
||||
static class SmartSpaceComplicationViewHolder implements ViewHolder {
|
||||
private View mView = null;
|
||||
private static final int SMARTSPACE_COMPLICATION_WEIGHT = 10;
|
||||
private final DreamSmartspaceController mSmartSpaceController;
|
||||
private final Context mContext;
|
||||
private final ComplicationLayoutParams mLayoutParams;
|
||||
|
||||
@Inject
|
||||
protected SmartSpaceComplicationViewHolder(
|
||||
Context context,
|
||||
DreamSmartspaceController smartSpaceController) {
|
||||
DreamSmartspaceController smartSpaceController,
|
||||
@Named(DREAM_SMARTSPACE_LAYOUT_PARAMS) ComplicationLayoutParams layoutParams) {
|
||||
mSmartSpaceController = smartSpaceController;
|
||||
mContext = context;
|
||||
mLayoutParams = layoutParams;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,25 +136,7 @@ public class SmartSpaceComplication implements Complication {
|
||||
|
||||
@Override
|
||||
public ComplicationLayoutParams getLayoutParams() {
|
||||
return new ComplicationLayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ComplicationLayoutParams.POSITION_TOP | ComplicationLayoutParams.POSITION_START,
|
||||
ComplicationLayoutParams.DIRECTION_DOWN,
|
||||
SMARTSPACE_COMPLICATION_WEIGHT, true);
|
||||
return mLayoutParams;
|
||||
}
|
||||
}
|
||||
|
||||
private final DreamSmartspaceController mSmartSpaceController;
|
||||
private final Context mContext;
|
||||
|
||||
@Inject
|
||||
public SmartSpaceComplication(Context context,
|
||||
DreamSmartspaceController smartSpaceController) {
|
||||
mContext = context;
|
||||
mSmartSpaceController = smartSpaceController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder createView(ComplicationViewModel model) {
|
||||
return new SmartSpaceComplicationViewHolder(mContext, mSmartSpaceController);
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,10 @@ package com.android.systemui.dreams.complication.dagger;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextClock;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.dreams.complication.ComplicationLayoutParams;
|
||||
import com.android.systemui.dreams.complication.DreamClockTimeComplication;
|
||||
|
||||
import javax.inject.Named;
|
||||
@@ -38,11 +36,6 @@ import dagger.Provides;
|
||||
@Module
|
||||
public interface DreamClockTimeComplicationModule {
|
||||
String DREAM_CLOCK_TIME_COMPLICATION_VIEW = "clock_time_complication_view";
|
||||
String DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS =
|
||||
"clock_time_complication_layout_params";
|
||||
// Order weight of insert into parent container
|
||||
//TODO(b/217199227): move to a single location.
|
||||
int INSERT_ORDER_WEIGHT = 0;
|
||||
String TAG_WEIGHT = "'wght' ";
|
||||
int WEIGHT = 200;
|
||||
|
||||
@@ -59,18 +52,4 @@ public interface DreamClockTimeComplicationModule {
|
||||
view.setFontVariationSettings(TAG_WEIGHT + WEIGHT);
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the layout parameters for the complication view.
|
||||
*/
|
||||
@Provides
|
||||
@Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS)
|
||||
static ComplicationLayoutParams provideLayoutParams() {
|
||||
return new ComplicationLayoutParams(0,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ComplicationLayoutParams.POSITION_BOTTOM
|
||||
| ComplicationLayoutParams.POSITION_START,
|
||||
ComplicationLayoutParams.DIRECTION_UP,
|
||||
INSERT_ORDER_WEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,10 @@ package com.android.systemui.dreams.complication.dagger;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.dreams.complication.ComplicationLayoutParams;
|
||||
import com.android.systemui.dreams.complication.DreamHomeControlsComplication;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
@@ -70,12 +67,6 @@ public interface DreamHomeControlsComplicationComponent {
|
||||
@Module
|
||||
interface DreamHomeControlsModule {
|
||||
String DREAM_HOME_CONTROLS_CHIP_VIEW = "dream_home_controls_chip_view";
|
||||
String DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS = "home_controls_chip_layout_params";
|
||||
|
||||
// TODO(b/217199227): move to a single location.
|
||||
// Weight of order in the parent container. The home controls complication should have low
|
||||
// weight and be placed at the end.
|
||||
int INSERT_ORDER_WEIGHT = 0;
|
||||
|
||||
/**
|
||||
* Provides the dream home controls chip view.
|
||||
@@ -87,22 +78,5 @@ public interface DreamHomeControlsComplicationComponent {
|
||||
return (ImageView) layoutInflater.inflate(R.layout.dream_overlay_home_controls_chip,
|
||||
null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the layout parameters for the dream home controls complication.
|
||||
*/
|
||||
@Provides
|
||||
@DreamHomeControlsComplicationScope
|
||||
@Named(DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS)
|
||||
static ComplicationLayoutParams provideLayoutParams(@Main Resources res) {
|
||||
return new ComplicationLayoutParams(
|
||||
res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_width),
|
||||
res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height),
|
||||
ComplicationLayoutParams.POSITION_BOTTOM
|
||||
| ComplicationLayoutParams.POSITION_START,
|
||||
ComplicationLayoutParams.DIRECTION_END,
|
||||
INSERT_ORDER_WEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,9 +16,18 @@
|
||||
|
||||
package com.android.systemui.dreams.complication.dagger;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.dagger.SystemUIBinder;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.dreams.complication.ComplicationLayoutParams;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
/**
|
||||
* Module for all components with corresponding dream layer complications registered in
|
||||
@@ -31,4 +40,55 @@ import dagger.Module;
|
||||
DreamHomeControlsComplicationComponent.class,
|
||||
})
|
||||
public interface RegisteredComplicationsModule {
|
||||
String DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS = "time_complication_layout_params";
|
||||
String DREAM_SMARTSPACE_LAYOUT_PARAMS = "smartspace_layout_params";
|
||||
String DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS = "home_controls_chip_layout_params";
|
||||
|
||||
int DREAM_CLOCK_TIME_COMPLICATION_WEIGHT = 0;
|
||||
int DREAM_SMARTSPACE_COMPLICATION_WEIGHT = 0;
|
||||
int DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT = 0;
|
||||
|
||||
/**
|
||||
* Provides layout parameters for the clock time complication.
|
||||
*/
|
||||
@Provides
|
||||
@Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS)
|
||||
static ComplicationLayoutParams provideClockTimeLayoutParams() {
|
||||
return new ComplicationLayoutParams(0,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ComplicationLayoutParams.POSITION_BOTTOM
|
||||
| ComplicationLayoutParams.POSITION_START,
|
||||
ComplicationLayoutParams.DIRECTION_UP,
|
||||
DREAM_CLOCK_TIME_COMPLICATION_WEIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides layout parameters for the home controls complication.
|
||||
*/
|
||||
@Provides
|
||||
@Named(DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS)
|
||||
static ComplicationLayoutParams provideHomeControlsChipLayoutParams(@Main Resources res) {
|
||||
return new ComplicationLayoutParams(
|
||||
res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_width),
|
||||
res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height),
|
||||
ComplicationLayoutParams.POSITION_BOTTOM
|
||||
| ComplicationLayoutParams.POSITION_START,
|
||||
ComplicationLayoutParams.DIRECTION_END,
|
||||
DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides layout parameters for the smartspace complication.
|
||||
*/
|
||||
@Provides
|
||||
@Named(DREAM_SMARTSPACE_LAYOUT_PARAMS)
|
||||
static ComplicationLayoutParams provideSmartspaceLayoutParams() {
|
||||
return new ComplicationLayoutParams(0,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ComplicationLayoutParams.POSITION_TOP
|
||||
| ComplicationLayoutParams.POSITION_START,
|
||||
ComplicationLayoutParams.DIRECTION_DOWN,
|
||||
DREAM_SMARTSPACE_COMPLICATION_WEIGHT,
|
||||
true /*snapToGuide*/);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.systemui.dreams;
|
||||
package com.android.systemui.dreams.complication;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -30,8 +31,7 @@ import android.view.View;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.dreams.complication.Complication;
|
||||
import com.android.systemui.dreams.complication.ComplicationViewModel;
|
||||
import com.android.systemui.dreams.DreamOverlayStateController;
|
||||
import com.android.systemui.dreams.smartspace.DreamSmartspaceController;
|
||||
import com.android.systemui.plugins.BcSmartspaceDataPlugin;
|
||||
|
||||
@@ -183,9 +183,9 @@ public class SmartSpaceComplicationTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetView_reusesSameView() {
|
||||
final SmartSpaceComplication complication = new SmartSpaceComplication(getContext(),
|
||||
mSmartspaceController);
|
||||
final Complication.ViewHolder viewHolder = complication.createView(mComplicationViewModel);
|
||||
final Complication.ViewHolder viewHolder =
|
||||
new SmartSpaceComplication.SmartSpaceComplicationViewHolder(getContext(),
|
||||
mSmartspaceController, mock(ComplicationLayoutParams.class));
|
||||
when(mSmartspaceController.buildAndConnectView(any())).thenReturn(mBcSmartspaceView);
|
||||
assertEquals(viewHolder.getView(), viewHolder.getView());
|
||||
}
|
||||
Reference in New Issue
Block a user