示例#1
0
        // Resets the value label to the localized description from HMCharacteristic+Readability.
        public void ResetValueLabel()
        {
            var label = ValueLabel;

            if (Value != null && label != null)
            {
                label.Text = characteristic.DescriptionForValue(Value);
            }
        }
        // Sets the cell's text to represent a characteristic and target value.
        // For example, "Brightness → 60%"
        // Sets the subtitle to the service and accessory that this characteristic represents.
        public void SetCharacteristic(HMCharacteristic characteristic, NSNumber targetValue)
        {
            var targetDescription = string.Format ("{0} → {1}", characteristic.LocalizedDescription, characteristic.DescriptionForValue (targetValue));
            TextLabel.Text = targetDescription;

            HMService service = characteristic.Service;
            if (service != null && service.Accessory != null)
                TrySetDetailText (string.Format ("{0} in {1}", service.Name, service.Accessory.Name));
            else
                TrySetDetailText ("Unknown Characteristic");
        }
        // Returns the description for a provided value, taking the characteristic's metadata and possible values into account.
        public static string DescriptionForValue(this HMCharacteristic self, NSObject value)
        {
            if (self.IsWriteOnly())
            {
                return("Write-Only Characteristic");
            }

            var number = value as NSNumber;

            return(number != null?self.DescriptionForValue(number.Int32Value) : value.ToString());
        }
示例#4
0
        // Sets the cell's text to represent a characteristic and target value.
        // For example, "Brightness → 60%"
        // Sets the subtitle to the service and accessory that this characteristic represents.
        public void SetCharacteristic(HMCharacteristic characteristic, NSNumber targetValue)
        {
            var targetDescription = string.Format("{0} → {1}", characteristic.LocalizedDescription, characteristic.DescriptionForValue(targetValue));

            TextLabel.Text = targetDescription;

            HMService service = characteristic.Service;

            if (service != null && service.Accessory != null)
            {
                TrySetDetailText(string.Format("{0} in {1}", service.Name, service.Accessory.Name));
            }
            else
            {
                TrySetDetailText("Unknown Characteristic");
            }
        }