Esempio n. 1
0
 private void AddDataAttr(List<Tuple<string, string>> data, CustomAttribute attr, string attrName)
 {
     string propertyName = "Data" + char.ToUpperInvariant(attrName[0]) + attrName.Substring(1);
     string value = attr.GetValue<string>(-1, propertyName);
     if (value == null)
         return;
     data.Add(Tuple.Create(attrName, value));
 }
Esempio n. 2
0
        /// <summary>
        /// Create app widget provider xml file.
        /// </summary>
        private void CreateAppWidgetProviderFile(string tempFolder, int index, CustomAttribute attr)
        {
            var resourceName = AppWidgetProviderResource.GetResourceName(index);
            var path = Path.Combine(Path.Combine(tempFolder, @"res\xml"), resourceName + ".xml");

            var doc = new XDocument();
            var root = new XElement("appwidget-provider");
            doc.Add(root);

            root.AddAttrIfNotEmpty("minWidth", Namespace, attr.GetValue<string>("MinWidth"));
            root.AddAttrIfNotEmpty("minHeight", Namespace, attr.GetValue<string>("MinHeight"));
            root.AddAttrIfNotDefault("updatePeriodMillis", Namespace, attr.GetValue<long>("UpdatePeriod"), 0L);
            root.AddAttrIfNotEmpty("previewImage", Namespace, attr.GetValue<string>("PreviewImage"), FormatDrawable);
            root.AddAttrIfNotEmpty("initialLayout", Namespace, attr.GetValue<string>("InitialLayout"), FormatLayout);
            var configureActivityType = attr.GetValue<TypeReference>("ConfigureActivity");
            if (configureActivityType != null)
            {
                var configureActivityTypeDef = configureActivityType.Resolve();
                if (configureActivityTypeDef == null)
                    throw new ArgumentException("Cannot resolve " + configureActivityType.FullName);
                root.AddAttr("configure", Namespace, FormatClassName(XBuilder.AsTypeDefinition(module, configureActivityTypeDef)));
            }
            root.AddAttrIfNotDefault("resizeMode", Namespace, attr.GetValue<int>("ResizeMode"), 0, widgetResizeModesOptions.Format);
            root.AddAttrIfNotDefault("widgetCategory", Namespace, attr.GetValue<int>("Category"), 0, widgetCategoriesOptions.Format);
            root.AddAttrIfNotEmpty("initialKeyguardLayout", Namespace, attr.GetValue<string>("InitialKeyguardLayout"), FormatLayout);

            Directory.CreateDirectory(Path.GetDirectoryName(path));
            doc.Save(path);
        }