1 /* 2 * Copyright (C) 2023 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 package com.android.internal.widget.remotecompose.core; 17 18 import java.time.LocalDateTime; 19 20 /** 21 * This generates the standard system variables for time. 22 */ 23 public class TimeVariables { 24 /** 25 * This class populates all time variables in the system 26 * @param context 27 */ updateTime(RemoteContext context)28 public void updateTime(RemoteContext context) { 29 LocalDateTime dateTime = LocalDateTime.now(); 30 // This define the time in the format 31 // seconds run from Midnight=0 quantized to seconds hour 0..3599 32 // minutes run from Midnight=0 quantized to minutes 0..1439 33 // hours run from Midnight=0 quantized to Hours 0-23 34 // CONTINUOUS_SEC is seconds from midnight looping every hour 0-3600 35 // CONTINUOUS_SEC is accurate to milliseconds due to float precession 36 int month = dateTime.getDayOfMonth(); 37 int hour = dateTime.getHour(); 38 int minute = dateTime.getMinute(); 39 int seconds = dateTime.getSecond(); 40 int currentMinute = hour * 60 + minute; 41 int currentSeconds = minute * 60 + seconds; 42 float sec = currentSeconds + dateTime.getNano() * 1E-9f; 43 44 context.loadFloat(RemoteContext.ID_CONTINUOUS_SEC, sec); 45 context.loadFloat(RemoteContext.ID_TIME_IN_SEC, currentSeconds); 46 context.loadFloat(RemoteContext.ID_TIME_IN_MIN, currentMinute); 47 context.loadFloat(RemoteContext.ID_TIME_IN_HR, hour); 48 context.loadFloat(RemoteContext.ID_CALENDAR_MONTH, month); 49 50 } 51 } 52