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 android.text.format.DateFormat.getBestDateTimePattern; 20 21 import static com.android.systemui.complication.dagger.DreamClockTimeComplicationComponent.DreamClockTimeComplicationModule.DREAM_CLOCK_TIME_COMPLICATION_VIEW; 22 import static com.android.systemui.complication.dagger.RegisteredComplicationsModule.DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS; 23 24 import android.view.View; 25 import android.widget.TextClock; 26 27 import com.android.internal.logging.UiEventLogger; 28 import com.android.systemui.CoreStartable; 29 import com.android.systemui.complication.dagger.DreamClockTimeComplicationComponent; 30 import com.android.systemui.dagger.qualifiers.SystemUser; 31 import com.android.systemui.dreams.DreamOverlayStateController; 32 import com.android.systemui.shared.condition.Monitor; 33 import com.android.systemui.util.ViewController; 34 import com.android.systemui.util.condition.ConditionalCoreStartable; 35 36 import javax.inject.Inject; 37 import javax.inject.Named; 38 39 /** 40 * Clock Time Complication that produce Clock Time view holder. 41 */ 42 public class DreamClockTimeComplication implements Complication { 43 private final DreamClockTimeComplicationComponent.Factory mComponentFactory; 44 45 /** 46 * Default constructor for {@link DreamClockTimeComplication}. 47 */ 48 @Inject DreamClockTimeComplication( DreamClockTimeComplicationComponent.Factory componentFactory)49 public DreamClockTimeComplication( 50 DreamClockTimeComplicationComponent.Factory componentFactory) { 51 mComponentFactory = componentFactory; 52 } 53 54 @Override getRequiredTypeAvailability()55 public int getRequiredTypeAvailability() { 56 return COMPLICATION_TYPE_TIME; 57 } 58 59 /** 60 * Create {@link DreamClockTimeViewHolder}. 61 */ 62 @Override createView(ComplicationViewModel model)63 public ViewHolder createView(ComplicationViewModel model) { 64 return mComponentFactory.create().getViewHolder(); 65 } 66 67 /** 68 * {@link CoreStartable} responsible for registering {@link DreamClockTimeComplication} with 69 * SystemUI. 70 */ 71 public static class Registrant extends ConditionalCoreStartable { 72 private final DreamOverlayStateController mDreamOverlayStateController; 73 private final DreamClockTimeComplication mComplication; 74 75 /** 76 * Default constructor to register {@link DreamClockTimeComplication}. 77 */ 78 @Inject Registrant( DreamOverlayStateController dreamOverlayStateController, DreamClockTimeComplication dreamClockTimeComplication, @SystemUser Monitor monitor)79 public Registrant( 80 DreamOverlayStateController dreamOverlayStateController, 81 DreamClockTimeComplication dreamClockTimeComplication, 82 @SystemUser Monitor monitor) { 83 super(monitor); 84 mDreamOverlayStateController = dreamOverlayStateController; 85 mComplication = dreamClockTimeComplication; 86 } 87 88 @Override onStart()89 public void onStart() { 90 mDreamOverlayStateController.addComplication(mComplication); 91 } 92 } 93 94 /** 95 * {@link ViewHolder} to contain value/logic associated with {@link DreamClockTimeComplication}. 96 */ 97 public static class DreamClockTimeViewHolder implements ViewHolder { 98 private final TextClock mView; 99 private final ComplicationLayoutParams mLayoutParams; 100 101 @Inject DreamClockTimeViewHolder( @amedDREAM_CLOCK_TIME_COMPLICATION_VIEW) TextClock view, @Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS) ComplicationLayoutParams layoutParams, DreamClockTimeViewController viewController)102 DreamClockTimeViewHolder( 103 @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) TextClock view, 104 @Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS) 105 ComplicationLayoutParams layoutParams, 106 DreamClockTimeViewController viewController) { 107 mView = view; 108 mLayoutParams = layoutParams; 109 viewController.init(); 110 111 // Support localized AM/PM marker for 12h mode in content description. 112 String formatSkeleton = view.is24HourModeEnabled() ? "Hm" : "hm"; 113 String pattern = getBestDateTimePattern(view.getTextLocale(), formatSkeleton); 114 view.setContentDescriptionFormat12Hour(pattern); 115 view.setContentDescriptionFormat24Hour(pattern); 116 } 117 118 @Override getView()119 public View getView() { 120 return mView; 121 } 122 123 @Override getLayoutParams()124 public ComplicationLayoutParams getLayoutParams() { 125 return mLayoutParams; 126 } 127 } 128 129 static class DreamClockTimeViewController extends ViewController<View> { 130 private final UiEventLogger mUiEventLogger; 131 132 @Inject DreamClockTimeViewController( @amedDREAM_CLOCK_TIME_COMPLICATION_VIEW) TextClock view, UiEventLogger uiEventLogger)133 DreamClockTimeViewController( 134 @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) TextClock view, 135 UiEventLogger uiEventLogger) { 136 super(view); 137 138 mUiEventLogger = uiEventLogger; 139 } 140 141 @Override onViewAttached()142 protected void onViewAttached() {} 143 144 @Override onViewDetached()145 protected void onViewDetached() {} 146 } 147 } 148