Inheritance: IUIElement, IDimensionAwareElement
示例#1
0
文件: HomePage.cs 项目: leewoody/hobd
        protected virtual UIElement CreateItem(Dictionary <string, string> attrs, PanoramaSection section)
        {
            string id = "";

            try{
                if (!attrs.TryGetValue("id", out id))
                {
                    return(null);
                }

                var sensor = HOBD.Registry.Sensor(id);
                if (sensor != null)
                {
                    var sensorItem = new SensorTextElement(sensor, attrs);
                    sensorItem.HandleTapAction = () => { sensorItem.Text = HOBD.t("sdesc." + sensor.Name); Redraw(); };

                    List <SensorTextElement> ui_list = null;
                    sensorUIMap.TryGetValue(sensor, out ui_list);
                    if (ui_list == null)
                    {
                        ui_list = new List <SensorTextElement>();
                        sensorUIMap.Add(sensor, ui_list);
                    }
                    ui_list.Add(sensorItem);

                    List <SensorListener> sensor_list = null;
                    sectionSensorMap.TryGetValue(section, out sensor_list);
                    if (sensor_list == null)
                    {
                        sensor_list = new List <SensorListener>();
                        sectionSensorMap.Add(section, sensor_list);
                    }

                    SensorListener sl = new SensorListener();
                    sl.sensor = sensor;
                    sl.period = 0;
                    string period = null;
                    if (attrs.TryGetValue("period", out period))
                    {
                        sl.period = int.Parse(period);
                    }

                    sensor_list.Add(sl);

                    return(sensorItem);
                }
            }catch (Exception e)
            {
                Logger.error("CreateItem", "Failed creating Sensor Element: " + id, e);
            }
            return(new DynamicElement("n/a: " + id)
            {
                Style = HOBD.theme.PhoneTextSmallStyle
            });
        }
示例#2
0
文件: HomePage.cs 项目: cail/hobd
        protected virtual UIElement CreateItem(Dictionary<string, string> attrs, PanoramaSection section)
        {
            string id = "";
            try{
                if (!attrs.TryGetValue("id", out id))
                    return null;

                var sensor = HOBD.Registry.Sensor(id);
                if (sensor != null)
                {
                    var sensorItem = new SensorTextElement(sensor, attrs);
                    sensorItem.HandleTapAction = () => { sensorItem.Text = HOBD.t("sdesc."+sensor.Name); Redraw(); };

                    List<SensorTextElement> ui_list = null;
                    sensorUIMap.TryGetValue(sensor, out ui_list);
                    if (ui_list == null){
                        ui_list = new List<SensorTextElement>();
                        sensorUIMap.Add(sensor, ui_list);
                    }
                    ui_list.Add(sensorItem);

                    List<SensorListener> sensor_list = null;
                    sectionSensorMap.TryGetValue(section, out sensor_list);
                    if (sensor_list == null){
                        sensor_list = new List<SensorListener>();
                        sectionSensorMap.Add(section, sensor_list);
                    }

                    SensorListener sl = new SensorListener();
                    sl.sensor = sensor;
                    sl.period = 0;
                    string period = null;
                    if (attrs.TryGetValue("period", out period))
                        sl.period = int.Parse(period);

                    sensor_list.Add(sl);

                    return sensorItem;
                }
            }catch(Exception e)
            {
                Logger.error("CreateItem", "Failed creating Sensor Element: "+id, e);
            }
            return new DynamicElement("n/a: "+id){ Style = HOBD.theme.PhoneTextSmallStyle };
        }