1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.complication; 18 19 import static com.android.systemui.complication.dagger.DreamClockTimeComplicationComponent.DreamClockTimeComplicationModule.DREAM_CLOCK_TIME_COMPLICATION_VIEW; 20 import static com.android.systemui.complication.dagger.RegisteredComplicationsModule.DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS; 21 22 import android.view.View; 23 24 import com.android.internal.logging.UiEventLogger; 25 import com.android.systemui.CoreStartable; 26 import com.android.systemui.complication.dagger.DreamClockTimeComplicationComponent; 27 import com.android.systemui.dagger.qualifiers.SystemUser; 28 import com.android.systemui.dreams.DreamOverlayStateController; 29 import com.android.systemui.shared.condition.Monitor; 30 import com.android.systemui.util.ViewController; 31 import com.android.systemui.util.condition.ConditionalCoreStartable; 32 33 import javax.inject.Inject; 34 import javax.inject.Named; 35 36 /** 37 * Clock Time Complication that produce Clock Time view holder. 38 */ 39 public class DreamClockTimeComplication implements Complication { 40 private final DreamClockTimeComplicationComponent.Factory mComponentFactory; 41 42 /** 43 * Default constructor for {@link DreamClockTimeComplication}. 44 */ 45 @Inject DreamClockTimeComplication( DreamClockTimeComplicationComponent.Factory componentFactory)46 public DreamClockTimeComplication( 47 DreamClockTimeComplicationComponent.Factory componentFactory) { 48 mComponentFactory = componentFactory; 49 } 50 51 @Override getRequiredTypeAvailability()52 public int getRequiredTypeAvailability() { 53 return COMPLICATION_TYPE_TIME; 54 } 55 56 /** 57 * Create {@link DreamClockTimeViewHolder}. 58 */ 59 @Override createView(ComplicationViewModel model)60 public ViewHolder createView(ComplicationViewModel model) { 61 return mComponentFactory.create().getViewHolder(); 62 } 63 64 /** 65 * {@link CoreStartable} responsible for registering {@link DreamClockTimeComplication} with 66 * SystemUI. 67 */ 68 public static class Registrant extends ConditionalCoreStartable { 69 private final DreamOverlayStateController mDreamOverlayStateController; 70 private final DreamClockTimeComplication mComplication; 71 72 /** 73 * Default constructor to register {@link DreamClockTimeComplication}. 74 */ 75 @Inject Registrant( DreamOverlayStateController dreamOverlayStateController, DreamClockTimeComplication dreamClockTimeComplication, @SystemUser Monitor monitor)76 public Registrant( 77 DreamOverlayStateController dreamOverlayStateController, 78 DreamClockTimeComplication dreamClockTimeComplication, 79 @SystemUser Monitor monitor) { 80 super(monitor); 81 mDreamOverlayStateController = dreamOverlayStateController; 82 mComplication = dreamClockTimeComplication; 83 } 84 85 @Override onStart()86 public void onStart() { 87 mDreamOverlayStateController.addComplication(mComplication); 88 } 89 } 90 91 /** 92 * {@link ViewHolder} to contain value/logic associated with {@link DreamClockTimeComplication}. 93 */ 94 public static class DreamClockTimeViewHolder implements ViewHolder { 95 private final View mView; 96 private final ComplicationLayoutParams mLayoutParams; 97 98 @Inject DreamClockTimeViewHolder( @amedDREAM_CLOCK_TIME_COMPLICATION_VIEW) View view, @Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS) ComplicationLayoutParams layoutParams, DreamClockTimeViewController viewController)99 DreamClockTimeViewHolder( 100 @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) View view, 101 @Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS) 102 ComplicationLayoutParams layoutParams, 103 DreamClockTimeViewController viewController) { 104 mView = view; 105 mLayoutParams = layoutParams; 106 viewController.init(); 107 } 108 109 @Override getView()110 public View getView() { 111 return mView; 112 } 113 114 @Override getLayoutParams()115 public ComplicationLayoutParams getLayoutParams() { 116 return mLayoutParams; 117 } 118 } 119 120 static class DreamClockTimeViewController extends ViewController<View> { 121 private final UiEventLogger mUiEventLogger; 122 123 @Inject DreamClockTimeViewController( @amedDREAM_CLOCK_TIME_COMPLICATION_VIEW) View view, UiEventLogger uiEventLogger)124 DreamClockTimeViewController( 125 @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) View view, 126 UiEventLogger uiEventLogger) { 127 super(view); 128 129 mUiEventLogger = uiEventLogger; 130 } 131 132 @Override onViewAttached()133 protected void onViewAttached() {} 134 135 @Override onViewDetached()136 protected void onViewDetached() {} 137 } 138 } 139