Example #1
0
        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();
            }
        }
Example #2
0
        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);
        }