Custom live tile for windows phone 8 - windows-phone-8

I created an app that has my own custom live tile in it.
There are three size of live tile user controls created but added here is only one size(see codes) and I need to add the same for other two sizes(Medium and Small tile).
Here's the source - Custom Live Tile
Below is the code for the Wide Tile...
Dispatcher.BeginInvoke(() =>
{
// Render the new tile image
RenderImageLibrary.WideTileControl wtc =
new RenderImageLibrary.WideTileControl(tempMain, descr, loc);
wtc.SaveJpegComplete += async (s, args) =>
{
try
{
if (args.Success)
{
// Set the tile image URI - "isostore:/" is important! Note that the control already
// puts the image into /Shared/ShellContent which is where tile images in the local folder must be
Uri tileImageUri = new Uri("isostore:/" + args.ImageFileName, UriKind.RelativeOrAbsolute);
Debug.WriteLine(tileImageUri.ToString());
// Set the tile image
FlipTileData ftd = new FlipTileData();
ftd.WideBackgroundImage = tileImageUri;
ShellTile.ActiveTiles.First().Update(ftd);
}
else
{
Debug.WriteLine(args.Exception.ToString());
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
};
wtc.BeginSaveJpeg();
});

You can use
ftd.BackgroundImage = tileImageUri;
ftd.SmallBackgroundImage = tileImageUri;
For more information on FlipTileData you can refer to http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.shell.fliptiledata

Related

Why is my WinRT app closing when trying to debug my background task?

I am trying to experiment with downloading files on a regular basis with background tasks for windows store applications, and am having trouble.
I followed the sample at https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh977055.aspx, and even downloaded/ran it and everything worked perfectly (including being able to step into the timer background task).
So with that I created my own background task in a brand new Windows namespace
Win8BackgroundTest
{
public class TestBackgroundTask
{
public async void Run(IBackgroundTaskInstance taskInstance)
{
var deferral = taskInstance.GetDeferral();
var uri = new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_h264.mov");
var folder = ApplicationData.Current.LocalFolder;
var downloadFile = await folder.CreateFileAsync(uri.Segments.Last(), CreationCollisionOption.GenerateUniqueName);
var dataFile = await folder.CreateFileAsync("downloadData", CreationCollisionOption.GenerateUniqueName);
var downloader = new BackgroundDownloader();
var operation = downloader.CreateDownload(uri, downloadFile);
await FileIO.WriteTextAsync(dataFile, "Success at " + DateTime.Now);
deferral.Complete();
}
public static async void RegisterTask()
{
const string taskName = "TestBackgroundTask";
try
{
var status = await BackgroundExecutionManager.RequestAccessAsync();
if (status == BackgroundAccessStatus.Denied)
{
return;
}
}
catch
{
// already accepted
}
var tasks = BackgroundTaskRegistration.AllTasks
.Where(x => x.Value.Name == taskName)
.ToArray();
if (tasks.Any())
{
return;
}
var builder = new BackgroundTaskBuilder
{
Name = taskName,
TaskEntryPoint = "Win8BackgroundTest.TestBackgroundTask",
};
builder.SetTrigger(new TimeTrigger(60, false));
var registeredTask = builder.Register();
}
}
}
I set up the application's manifest with a Background Tasks declaration, checking the Timer properties checkbox, and set the EntryPoint to Win8BackgroundTest.TestBackgroundTask.
I then added the following at the end of my App.xaml.cs's OnLaunched() method:
TestBackgroundTask.RegisterTask();
Stepping through seems to have task registration work successfully with no exceptions. I then go back to visual studio, added a breakpoint to the first line in my task's Run() method, I then go to the debug locations toolbar, click the down arrow and select TestBackgroundTask. A few seconds later visual studio exits (as does my app).
Does anyone see what I am doing wrong that is causing background tasks to fail?
So after much frustration and a lot of trial and error the issue was a combination of both of the comments.
So first of all, it appears like you cannot have a background task in the same project as the rest of your windows store application. It must be in it's own windows runtime component project.
Finally, there are times where it just doesn't work and for whatever reason deleting the bin and obj folders fix it.

Crop an Image in nokia Imaging SDK 1.2?

Can you give me a sample code for crop an Image using Nokia Imaging SDK 1.2 ? As you know the "Editing Session" class, that I use for cropping Image has gone in SDK 1.2.
Thanks for your attention.
This is an excerpt from the nokia api reference documentation which can be found here:
http://developer.nokia.com/resources/library/Imaging_API_Ref/nokiagraphicsimaging-namespace/cropfilter-class.html
This sample takes CameraCaptureTask result photo and applies a [crop] filter to it.
async void CaptureTask_Completed(object sender, PhotoResult e)
{
// Create a source to read the image from PhotoResult stream
using (var source = new StreamImageSource(e.ChosenPhoto))
{
// Create effect collection with the source stream
using (var filters = new FilterEffect(source))
{
// Initialize the filter
var sampleFilter = new CropFilter(new Windows.Foundation.Rect(0, 0, 500, 500));
// Add the filter to the FilterEffect collection
filters.Filters = new IFilter[] { sampleFilter };
// Create a target where the filtered image will be rendered to
var target = new WriteableBitmap((int)ImageControl.ActualWidth, (int)ImageControl.ActualHeight);
// Create a new renderer which outputs WriteableBitmaps
using (var renderer = new WriteableBitmapRenderer(filters, target))
{
// Render the image with the filter(s)
await renderer.RenderAsync();
// Set the output image to Image control as a source
ImageControl.Source = target;
}
}
}
}

Refresh an ObservableCollection when Item's property changed

I have a observableCollection which is loaded with elements and displayed on the UI .At the same time the app is downloading one Icon for each element of the observable collection.I would like to display each Icon when its download finishes...
My code is working but i guess it's not the best pratice because I bind my collection to the Ui control 2 times...I am pretty convinced that it shouldn't be necessary ...I try to implement the InotifypropertyChanged on the element's Icon property but I still have to add those lines of code to display the Icons:
listDocsLibs = new ObservableCollection<BdeskDocLib>(listBoxGetDocsLibs);
llslistDocslibs.ItemsSource = listDocsLibs;
Below the function which dowload the Icons
List<BdeskDocLib> listBoxGetDocsLibs = new List<BdeskDocLib>();
ObservableCollection<BdeskDocLib> listDocsLibs = new ObservableCollection<BdeskDocLib>();
private async void LoadIconDocLibs()
{
foreach (var doclib in listBoxGetDocsLibs)
{
byte[] Icon = await ServerFunctions.GetDocLibsIcon(doclib);
if (Icon != null)
{
{
var ms = new MemoryStream(Icon);
BitmapImage photo = new BitmapImage();
photo.DecodePixelHeight = 64;
photo.DecodePixelWidth = 92;
photo.SetSource(ms);
doclib.Icon = photo;
}
}
else if (Icon == null)
{
doclib.Icon = new BitmapImage();
doclib.Icon.UriSource = new Uri("/Images/BDocs/ico_ext_inconnu.png", UriKind.Relative);
}
}
}
//IM PRETTY SURE The following code IS NOT NECESSARY BUT WHY MY UI IS NOT REFRESHING WITHOUT ?
listDocsLibs = new ObservableCollection<BdeskDocLib>(listBoxGetDocsLibs);
llslistDocslibs.ItemsSource = listDocsLibs;
}

PDFTron Convert from HTML to PDF on WinRT

I'm writing a Windows 8 Store App using WinJS. My app needs to generate PDFs with text and graphs. I was under the impression that PDFtron could convert HTML to PDF, but that does not seem to be the case for an App Store application. Is this true?
The front end uses WinJS/HTML and Telerik Radcharts to render graphs in SVG. I then pipe the DOM down to disk as an HTML file. It shows the graph and numbers nicely. I want to convert the HTML to a PDF to preserve the styling as well as the content.
The WinRT version does not come with the HTML2PDF assembly or the .Convert() method. Is it somewhere else? I've searched the docs, samples, and the web.
PDFTron's PDFNet SDK on WinRT does not support HTML to PDF conversion (as at version 6.2).
Here is the response I received from PDFTron support on this question:
While the PDFNet SDK on WinRT cannot itself convert from HTML
to PDF, the PDFNet SDK on Windows desktop can do so. You can find
sample code for for HTML to PDF conversion at
http://www.pdftron.com/pdfnet/samplecode.html#HTML2PDF.
Some of our clients send HTML to a server of theirs, where
PDFNet can convert the HTML to PDF. Note that on Windows
desktop there are many conversion options, including converting Office
to PDF and converting any printable document format to PDF.
EVO has implemented the following solution to convert HTML to PDF in WinRT and Windows Store Applications. You can find a compelte code sample in that page.
The copy of the code sample is:
private async void buttonConvertUrlToPdf_Click(object sender, RoutedEventArgs e)
{
// If another conversion is in progress then ignore current request
bool ignoreRequest = false;
lock(pendingConversionSync)
{
if (pendingConversion)
ignoreRequest = true;
else
{
msgUrlToPdfInProgress.Visibility = Windows.UI.Xaml.Visibility.Visible;
pendingConversion = true;
}
}
if (ignoreRequest)
return;
try
{
String serverIP = textBoxServerIP.Text;
uint port = uint.Parse(textBoxServerPort.Text);
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(serverIP, port);
// set service password if necessary
if (textBoxServicePassword.Text.Length > 0)
htmlToPdfConverter.ServicePassword = textBoxServicePassword.Text;
// set HTML viewer width
htmlToPdfConverter.HtmlViewerWidth = int.Parse(textBoxHtmlViewerWidth.Text);
// set HTML viewer height if necessary
if (textBoxHtmlViewerHeight.Text.Length > 0)
htmlToPdfConverter.HtmlViewerHeight = int.Parse(textBoxHtmlViewerHeight.Text);
// set navigation timeout
htmlToPdfConverter.NavigationTimeout = int.Parse(textBoxHtmlViewerWidth.Text);
// set conversion delay if necessary
if (textBoxConversionDelay.Text.Length > 0)
htmlToPdfConverter.ConversionDelay = int.Parse(textBoxConversionDelay.Text);
// set PDF page size
htmlToPdfConverter.PdfDocumentOptions.PdfPageSize = SelectedPdfPageSize();
// set PDF page orientation
htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation = SelectedPdfPageOrientation();
// set margins
htmlToPdfConverter.PdfDocumentOptions.LeftMargin = int.Parse(textBoxLeftMargin.Text);
htmlToPdfConverter.PdfDocumentOptions.RightMargin = int.Parse(textBoxRightMargin.Text);
htmlToPdfConverter.PdfDocumentOptions.TopMargin = int.Parse(textBoxTopMargin.Text);
htmlToPdfConverter.PdfDocumentOptions.BottomMargin = int.Parse(textBoxBottomMargin.Text);
// add header
if (checkBoxAddHeader.IsChecked != null && (bool)checkBoxAddHeader.IsChecked)
{
htmlToPdfConverter.PdfDocumentOptions.ShowHeader = true;
DrawHeader(htmlToPdfConverter, true);
}
// add footer
if (checkBoxAddFooter.IsChecked != null && (bool)checkBoxAddFooter.IsChecked)
{
htmlToPdfConverter.PdfDocumentOptions.ShowFooter = true;
DrawFooter(htmlToPdfConverter, true, true);
}
string urlToConvert = textBoxUrl.Text;
string errorMessage = null;
// Convert the HTML page from give URL to PDF in a buffer
byte[] pdfBytes = await Task.Run<byte[]>(() =>
{
byte[] resultBytes = null;
try
{
resultBytes = htmlToPdfConverter.ConvertUrl(urlToConvert);
}
catch (Exception ex)
{
errorMessage = String.Format("Conversion failed. {0}", ex.Message);
return null;
}
return resultBytes;
});
if (pdfBytes == null)
{
MessageDialog errorMessageDialog = new MessageDialog(errorMessage, "Conversion failed");
await errorMessageDialog.ShowAsync();
return;
}
// Save the PDF in a file
Windows.Storage.StorageFolder installedLocation = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile outStorageFile = installedLocation.CreateFileAsync("EvoHtmlToPdf.pdf", CreationCollisionOption.ReplaceExisting).AsTask().Result;
FileIO.WriteBytesAsync(outStorageFile, pdfBytes).AsTask().Wait();
// Open the file in a PDF viewer
await Windows.System.Launcher.LaunchFileAsync(outStorageFile);
}
finally
{
lock (pendingConversionSync)
{
msgUrlToPdfInProgress.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
pendingConversion = false;
}
}
}

How to add tooltip in map windows phone 8?

My windows 8 phone app programatically add an image (as a pin) to a specific coordinataion in map using mapoverlay. And now i would like to add a tooltip to the image (pin) after tapping on it. Does anyone know how to fix this?
pinIMG = new Image();
pinIMG.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Assets/pin.png", UriKind.Relative));
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = pinIMG;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = new GeoCoordinate(57.724611, 12.938945);
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(myLocationOverlay);
MyMap.Layers.Add(myLocationLayer);
Instead of adding an Image to the MapOverlay, consider adding an ExpanderView control that expands to add additional data. You'll need to download the Windows Phone Toolkit to get the ExpanderView control. While you're at it you might want to switch over to using Map Extensions Pushpins to get databinding support.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
MapLayer myLayer = new MapLayer();
MapOverlay myOverlay = new MapOverlay()
{
GeoCoordinate = new GeoCoordinate(-17, 133)
};
ExpanderView expander = new ExpanderView();
expander.Header = new Image()
{
Source = new BitmapImage(new Uri("Assets/ApplicationIcon.png", UriKind.Relative)),
Width = 200
};
expander.ItemsSource = new[]
{
new TextBlock{ Text = "HELLO"}
};
;
myOverlay.Content = expander;
myLayer.Add(myOverlay);
myMap.Layers.Add(myLayer);
}
When we run this sample we can see the following icon over australia:
And once we click ti we can see our "Hello" text show up:
A few ceavets: the code sample above is terrible. ExpanderView is meant to use both ItemSource and IteTemplate for multiple items databinding. Using it for a single item isn't great. The above code sample is also terrible since it creates UI elements in C# code whereas using Map Extensions could have placed this code in XAML.