1 /* 2 * Copyright 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 androidx.wear.protolayout.expression 17 18 import androidx.wear.protolayout.expression.DynamicBuilders.DynamicType 19 import java.util.Objects 20 21 /** 22 * Represent a key that references a dynamic value source, such as state pushed by app/tile or 23 * real-time data from the platform. 24 * 25 * @param T The data type of the dynamic values that this key is bound to. 26 */ 27 public abstract class DynamicDataKey<T : DynamicType> 28 /** 29 * Create a [DynamicDataKey] with the specified key in the given namespace. 30 * 31 * @property namespace The namespace of the key for the dynamic data source. 32 * @property key The key that references the dynamic data source. 33 */ 34 internal constructor(public val namespace: String, public val key: String) { 35 equalsnull36 override fun equals(other: Any?): Boolean { 37 if (other === this) { 38 return true 39 } 40 41 if (other !is DynamicDataKey<*>) { 42 return false 43 } 44 45 return key == other.key && namespace == other.namespace 46 } 47 hashCodenull48 override fun hashCode(): Int = Objects.hash(key, namespace) 49 50 override fun toString(): String = "DynamicDataKey{namespace=$namespace, key=$key}" 51 } 52