async void MainPage_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { DataRequest request = args.Request; DataRequestDeferral deferral = request.GetDeferral(); try { var saveFile = await StaticTaqModelView.saveUi2Png("screenshot.png", mainPage); var storageItems = new List <IStorageItem>(); storageItems.Add(saveFile); // 3. Share it //request.Data.SetText("TAQ"); request.Data.Properties.Title = Windows.ApplicationModel.Package.Current.DisplayName; // Facebook app supports SetStorageItems, not SetBitmap. request.Data.SetStorageItems(storageItems); } catch (Exception ex) { Debug.WriteLine(ex.Message); // Ignore. } finally { deferral.Complete(); } }
public int aqVals2Coll(List <double> aqVals, int updateHour, string updateDate) { for (var h = 0; h < 24; h++) { var rotHour = (24 + updateHour - h) % 24; var aqVal = aqVals[rotHour]; // This ugly coding style comes from a problem that the chart doesn't update its Hour axis anymore after the first assignment to Hour. if (rotHour == 0) { aq24HrValColl.Add(new Aq24HrVal { // Replace Hour 0 with date. Hour = updateDate.Replace("-", "/"), Val = aqVal }); } else { aq24HrValColl.Add(new Aq24HrVal { Hour = rotHour + "", Val = aqVal }); } var aqLevel = StaticTaqModel.getAqLevel(AqHistShared.aqName, aqVal); //aq24HrValColl.Where(hv => hv.Hour == "0").First().Hour = updateDate.Replace("-", "/"); aqColors.Add(new SolidColorBrush(StaticTaqModelView.html2RgbColor(StaticTaqModel.aqColors[AqHistShared.aqName][aqLevel]))); } ccm.CustomBrushes = aqColors; return(0); }
// Has to be run by UI context! public void loadDict2Sites(string aqName) { var isSiteUninit = sites.Count() == 0; // if sites is uninitialized. if (isSiteUninit) { foreach (var s in m.sitesStrDict) { var siteDict = s.Value; sites.Add(new SiteViewModel { siteName = s.Key, county = s.Value["County"], twd97Lat = double.Parse(siteDict["TWD97Lat"]), twd97Lon = double.Parse(siteDict["TWD97Lon"]), }); } } foreach (var site in sites) { var circleText = m.sitesStrDict[site.siteName][aqName]; if (aqName == "PublishTime") { circleText = circleText.Substring(11, 5); } var aqLevel = m.getAqLevel(site.siteName, aqName); site.aqi = m.getValidAqVal(m.sitesStrDict[site.siteName]["AQI"]); site.CircleColor = StaticTaqModel.aqColors[aqName][aqLevel]; site.CircleText = site.siteName + "\n" + circleText; site.ListText = m.sitesStrDict[site.siteName][aqName]; site.TextColor = StaticTaqModelView.getTextColor(aqLevel); } }
// id == 0 stands for main site aqgv. public void updateAqgv(int id) { var siteName = m.subscrSiteList[id]; var aqvms = aqvmsList[id]; var i = 0; foreach (var k in StaticTaqModel.fieldNames.Keys) { var aqLevel = m.getAqLevel(siteName, k); var textColor = StaticTaqModelView.getTextColor(aqLevel); aqvms[i].CircleColor = StaticTaqModel.aqColors[k][aqLevel]; aqvms[i].CircleText = StaticTaqModel.fieldNames[k] + "\n" + m.sitesStrDict[siteName][k]; aqvms[i].TextColor = textColor; i++; } }
public object Convert(object value, Type targetType, object parameter, string culture) { var aqLevel = StaticTaqModel.getAqLevel(AqHistShared.aqName, double.Parse((string)value)); return(StaticTaqModelView.getTextColor(aqLevel)); }
// Convert site info to AqViewModel for data bindings. public ObservableCollection <UIElement> loadSite2Aqvm(string siteName) { var aqvms = new ObservableCollection <AqViewModel>(); var aqgvis = new ObservableCollection <UIElement>(); foreach (var k in StaticTaqModel.fieldNames.Keys) { var aqLevel = m.getAqLevel(siteName, k); var textColor = StaticTaqModelView.getTextColor(aqLevel); var aqvm = new AqViewModel { CircleColor = StaticTaqModel.aqColors[k][aqLevel], // default border background color CircleText = StaticTaqModel.fieldNames[k] + "\n" + m.sitesStrDict[siteName][k], TextColor = textColor }; aqvms.Add(aqvm); // Create UIElement for GridViewItem by k value. switch (k) { case "PM2.5": case "PM2.5_AVG": aqgvis.Add(new GridPm2_5(aqvm)); break; case "PM10": case "PM10_AVG": aqgvis.Add(new GridPm10(aqvm)); break; case "O3": case "O3_8hr": aqgvis.Add(new Grid1(aqvm, "O", "3", "ppb")); break; case "CO": case "CO_8hr": aqgvis.Add(new Grid1(aqvm, "CO", "", "ppm")); break; case "SO2": aqgvis.Add(new Grid1(aqvm, "SO", "2", "ppb")); break; case "NO2": aqgvis.Add(new Grid1(aqvm, "NO", "2", "ppb")); break; case "NOx": aqgvis.Add(new Grid1(aqvm, "NO", "x", "ppb")); break; case "NO": aqgvis.Add(new Grid1(aqvm, "NO", "", "ppb")); break; case "WindSpeed": aqgvis.Add(new Grid1(aqvm, "", "", "m/s")); break; case "WindDirec": aqgvis.Add(new Grid1(aqvm, "", "", "°")); break; default: aqgvis.Add(new Grid1(aqvm, "", "", "")); break; } } aqvmsList.Add(aqvms); return(aqgvis); }
public async Task <int> genTileImages(string siteName) { // Get colors by AQI. var aqName = aqHistNames[(int)localSettings.Values["TileBackColorAqId"]]; var aqLevel = getAqLevel(siteName, aqName); // Remove '#'. var rectColorStr = StaticTaqModel.aqColors[aqName][aqLevel].Substring(1); var r = (byte)Convert.ToUInt32(rectColorStr.Substring(0, 2), 16); var g = (byte)Convert.ToUInt32(rectColorStr.Substring(2, 2), 16); var b = (byte)Convert.ToUInt32(rectColorStr.Substring(4, 2), 16); var bgColor = new SolidColorBrush(Color.FromArgb(0xFF, r, g, b)); var textColor = StaticTaqModelView.getTextColor(aqLevel); // Extract time. var dateStr = sitesStrDict[siteName]["PublishTime"].Substring(5, 5).Replace("-", "/"); var timeStr = sitesStrDict[siteName]["PublishTime"].Substring(11, 5); var aqiStr = sitesStrDict[siteName]["AQI"]; var pm2_5_Str = sitesStrDict[siteName]["PM2.5"]; var pm10_Str = sitesStrDict[siteName]["PM10"]; // Small tile var smallTile = new SmallTile(textColor); smallTile.topTxt.Text = siteName; smallTile.downTxt.Text = timeStr; smallTile.border.Background = bgColor; // Med tile var medTile = new MedTile(textColor); medTile.topTxt.Text = siteName; medTile.topVal.Text = timeStr; medTile.medVal.Text = aqiStr; medTile.downVal.Text = pm2_5_Str; medTile.border.Background = bgColor; // Wide tile var wideTile = new WideTile(textColor); wideTile.topTxt.Text = siteName + "-" + dateStr + "-" + timeStr; wideTile.medVal1.Text = aqiStr; wideTile.medVal2.Text = pm2_5_Str; wideTile.medVal3.Text = pm10_Str; wideTile.border.Background = bgColor; // Large tile var largeTile = new LargeTile(textColor); largeTile.val1.Text = siteName; largeTile.val2.Text = sitesStrDict[siteName]["ShortStatus"]; largeTile.val3_1.Text = dateStr; largeTile.val3_2.Text = timeStr; largeTile.val4.Text = aqiStr; largeTile.val5.Text = pm2_5_Str; largeTile.val6.Text = pm10_Str; largeTile.val7.Text = sitesStrDict[siteName]["O3"]; largeTile.val8.Text = sitesStrDict[siteName]["CO"]; largeTile.val9.Text = sitesStrDict[siteName]["SO2"]; largeTile.border.Background = bgColor; await StaticTaqModelView.saveUi2Png(siteName + "SmallTile.png", smallTile); await StaticTaqModelView.saveUi2Png(siteName + "MedTile.png", medTile); await StaticTaqModelView.saveUi2Png(siteName + "WideTile.png", wideTile); await StaticTaqModelView.saveUi2Png(siteName + "LargeTile.png", largeTile); return(0); }
public AqColorMaps() { app = App.Current as App; this.InitializeComponent(); aqLimitsColl = new ObservableCollection <AqLimits>(); var aqLevelCnt = StaticTaqModel.aqiLimits.Count; foreach (var aqName in apNames) { var aqLimit = new AqLimits { Name = aqName, Limits = new ObservableCollection <double>(), Diffs = new ObservableCollection <double>() }; // Skip aqLimits[aqName][0], because it is unused -1. aqLimit.Limits.Add(StaticTaqModel.aqLimits[aqName][1]); aqLimit.Diffs.Add(StaticTaqModel.aqLimits[aqName][1]); for (var i = 2; i < aqLevelCnt; i++) { aqLimit.Limits.Add(StaticTaqModel.aqLimits[aqName][i]); aqLimit.Diffs.Add(StaticTaqModel.aqLimits[aqName][i] - StaticTaqModel.aqLimits[aqName][i - 1]); } aqLimitsColl.Add(aqLimit); } for (var i = 1; i < aqLevelCnt; i++) { var sbs = new StackingColumn100Series(); sbs.Interior = new SolidColorBrush(StaticTaqModelView.html2RgbColor(StaticTaqModel.aqiBgColors[i])); sbs.XBindingPath = "Name"; sbs.YBindingPath = "Diffs[" + i + "]"; var b = new Binding(); b.Source = this; b.Path = new PropertyPath("aqLimitsColl"); b.Mode = BindingMode.OneWay; sbs.SetBinding(StackingBarSeries.ItemsSourceProperty, b); var cai = new ChartAdornmentInfo(); cai.SegmentLabelContent = LabelContent.LabelContentPath; // DataContext =\"aqLimitsColl[" + i + "].\" var textColor = "Black"; if (i > StaticTaqModel.aqTextColorLimit) { textColor = "White"; } var dt = XamlReader.Load($"<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" + "<TextBlock Foreground=\"" + textColor + "\" Text=\"{Binding Converter={StaticResource con}}\"></TextBlock></DataTemplate>") as DataTemplate; cai.LabelTemplate = dt; cai.LabelPosition = AdornmentsLabelPosition.Inner; cai.ShowLabel = true; sbs.AdornmentsInfo = cai; sbs.SegmentSpacing = 0; sfChart.Series.Add(sbs); } this.DataContext = this; }