Periodic updates of Windows 8 live Tile - windows-8

Say, I want to update the windows 8 live tile periodically, say after 10 seconds. Is there any way to achieve that? I am using metro xaml c# in windows 8.
Here's the code I am writing on Dispatcher Timer's Tick event:
switch(imageIndex)
{
case 0:
imageUrl = "Assets/Image1.png";
break;
case 1:
imageUrl = "Assets/Image1.png";
break;
case 2:
imageUrl = "Assets/Image1.png";
break;
}
ITileWIdeImageAndText01 tileContent = TileContentFactory.CreateTileWideImageAndText01();
tileContent.TextCaptionWrap.Text = "Hello";
tileContent.Image.Src = imageUrl;
tileContent.Image.Alt = "";
ITileSquareImage squareContent = TileContentFactory.CreateTileSquareImage();
squareContent.Image.Src = imageUrl;
squareContent.Image.Alt = "";
tileContent.SquareContent = squareContent;
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification());
Thanks in advance.

Here's how you should do it:
switch(imageIndex)
{
case 0:
imageUrl = "Assets/Image1.png";
break;
case 1:
imageUrl = "Assets/Image1.png";
break;
case 2:
imageUrl = "Assets/Image1.png";
break;
}
ITileWIdeImageAndText01 tileContent = TileContentFactory.CreateTileWideImageAndText01();
tileContent.TextCaptionWrap.Text = "Hello";
tileContent.Image.Src = imageUrl;
tileContent.Image.Alt = "";
ITileSquareImage squareContent = TileContentFactory.CreateTileSquareImage();
squareContent.Image.Src = imageUrl;
squareContent.Image.Alt = "";
tileContent.SquareContent = squareContent;
var updater = TileUpdateManager.CreateTileUpdaterForApplication();
updater.EnableNotificationQueue(true);
updater.AddToSchedule(
new ScheduledTileNotification(
tileContent.CreateNotification(),
DateTime.Now.AddSeconds(10))
{
ExpirationTime=DateTimeOffset.UtcNow.AddSeconds(20)
});
This will result in a notification coming up 10 seconds after you started the app. And it will be expired 10 more second later.
(Also, maybe you should look into background services, because this particular solution might not be the best for what you want...)

Don't use Dispatcher Timer as it will slow your app. You can use the following in your page Initializer:
TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);

Related

How do i show image on notification bar when push comes from FCM?

I have tried using NotificationServiceExtension,but didn't got proper tutorial in objective-c to achieve that.
Process:- I create a NotificationServiceExtension in that i wrote a code which accepts media urls.then i create app groups.
Payload which is coming from backend:
aps = {
alert = {
body = Test;
title = Test;
};
badge = 1;
"content-available" = 1;
};
badge = 1;
body = Test;
"gcm.message_id" = "0:1511437914514%a62432a6262432";
"gcm.notification.alert" = "";
"gcm.notification.id" = "";
"gcm.notification.location_ids" = "";
"gcm.notification.main_picture" = "somelink/logo-big.png";
"gcm.notification.notification_type" = Generic;
icon = "";
id = "";
"location_ids" = "";
"main_picture" = "somelink/logo-big.png";
"notification_type" = Generic;
title = Test;
If you want to see the app icon when the push notification comes, you need to add the AppIcon under the Images.xcassets folder of your app.

why qml listmodel sync failed when in the worker thread,and how to solve it?

how can i change the text of the button without clicked in the listview delegate?
when i solved the question above,there is a new question.i can't use the worker to sync the model,but when i use sync not in the worker,although it has some error occured from qtcreator,but it works to sync the data role in the model ,and often, sync will fail.
dataloader.js:
WorkerScript.onMessage = function(msg) {
msg.model.sync();
}
PrinterList.qml:
WorkerScript{
id:worker
source:"dataloader.js"
}
function cmpPname(prnName)
{
console.log("cmpPname");
var tmpName = prnName.replace(/_/g," ");
console.log("tmpName=",tmpName);
var pname = new Array;
pname= Jsclient.g_str.split(',');
tmpName = tmpName.split(',');
console.log("pModel.count=",pModel.count);
for(var i = 0;i < pname.length;i++){
if(tmpName == pname[i]){
console.log("pname[%1]=".arg(i),pname[i]);
Jsclient.pstate = "Added";
pModel.setProperty(i,"prstate",qsTr(Jsclient.pstate));
// pModel.get(2).prstate = qsTr(Jsclient.pstate);
sync(); **//this works!!but often failed too.**
}else{
Jsclient.pstate = "Add";
pModel.setProperty(i,"prstate",qsTr(Jsclient.pstate));
}
worker.sendMessage({"model":pModel}); **//this failed,why?**
}
}
finally,i solved the question.
dataloader.js:
WorkerScript.onMessage = function(msg) {
console.log(msg.index,msg.prstate);
msg.model.setProperty(msg.index,"prstate",msg.prstate);
msg.model.sync();
}
list.qml:
worker.sendMessage({"index":i,"prstate":qsTr("Added"),"model":pModel});

ActionScript 3 coding error

I need a little bit of help with some code issue. I am trying to connect to the server from a click of a button. When I execute the code I receive this error in my output: 1120: Access of undefined property nc.close
Which is strange because I already declared the nc property in the btnStart function. I have been tweaking around with the code but I keep getting the same annoying error. If you have any suggestions how to resolve this that be great!
Thanks
Code is below:
btn_One.addEventListener(MouseEvent.CLICK, btnStart);
btn_Two.addEventListener(MouseEvent.CLICK, btnClose);
function btnStart(event:MouseEvent):void{
trace("Connecting...");
var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.connect("rtmfp://localhost/streamingLive");
}
//// ERROR LINE NC.CLOSE();
function btnClose(event:MouseEvent):void{
trace("Closing time");
nc.close();
}
function netStatusHandler(event:NetStatusEvent):void{
switch(event.info.code){
case "NetConnection.Connect.Success":
trace("Awesome connection");
break;
case "NetConnection.Connect.Failed":
trace("Unable to connect");
break;
case "NetConnection.Connect.Rejected":
trace("WHoooops");
break;
case "NetGroup.Connect.Success":
trace("GroupConnection");
break;
case "NetGroup.Connect.Failed":
trace("Group failed");
break;
case "NetGroup.Connect.Rejected":
trace("Ouch!!!");
break;
var ns:NetStream = new NetStream();
ns.publish("live", "streaming");
ns.attachCamera();
ns.attachAudio();
ns.connect(nc);
var ng:NetGroup = new NetGroup(nc, groupspec.groupspecWithAuthorizations());
ng.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
}
}
var cam:Camera = Camera.getCamera();
cam.setMode(420, 320, 15);
cam.setQuality(0, 85);
cam.addEventListener(StatusEvent.STATUS, statusHandler);
var vid:Video = new Video();
vid.width = cam.width;
vid.height = cam.height;
vid.x = 100;
vid.y = 100;
vid.attachCamera(cam);
addChild(vid);
var mic:Microphone = Microphone.getMicrophone();
mic.gain = 50;
mic.framesPerPacket = 1;
mic.setSilenceLevel(0, 2000);
mic.codec = SoundCodec.SPEEX;
//camera access permissions
function statusHandler(event:StatusEvent):void
{
switch (event.code)
{
case "Camera.Muted":
trace("User clicked Deny.");
break;
case "Camera.Unmuted":
trace("User clicked Accept.");
break;
}
}
//audio access permissions
function micStatus(event:StatusEvent):void
{
if (event.code == "Microphone.Unmuted")
{
trace("Microphone access was allowed.");
}
else if (event.code == "Microphone.Muted")
{
trace("Microphone access was denied.");
}
}
//array of camera names
var cameraA:Array = Camera.names;
for ( var i : int = 0; i < cameraA.length; i++){
trace ( "Camera: ", cameraA[i] );
}
var groupspec:GroupSpecifier = new GroupSpecifier("groupone");
groupspec.multicastEnabled = true;
//group postings
groupspec.postingEnabled = true;
//specific peer posting
groupspec.routingEnabled = true;
//automatic peer discovery
groupspec.serverChannelEnabled = true;
nc is declared inside one function, but you're trying to use it inside of another function. Sometimes you can just pass the variable around as an argument, but in this case, that won't really work out too well. So in this case, do the following:
var nc:NetConnection = new NetConnection();
function btnStart(event:MouseEvent):void{
trace("Connecting...");
// var nc:NetConnection = new NetConnection(); // removed
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.connect("rtmfp://localhost/streamingLive");
}
//// ERROR LINE NC.CLOSE();
function btnClose(event:MouseEvent):void{
trace("Closing time");
nc.close();
}

ActionScript 2.0 Random Boolean Function not working

I have the below code which show be randomly true and randomly false. But in my case its always being false. Any help is appreciated. Thanks.
In the below code tail and heads are the tow buttons.
on(release)
{
var guess:Boolean = Boolean(Math.round(Math.random()));
var input:Boolean;
if (event.target.name == "tail"){
input = true;
}
else if (event.target.name == "heads"){
input = false;
}
if (guess == input){
var newresult = Number(income.text) + Number(amount.text);
income.text = Number(newresult);
}
else{
var newresult = Number(income.text) - Number(amount.text);
income.text = Number(newresult);
}
}
This will also work:
on(release)
{
var guess:Boolean = Boolean(Math.floor(Math.random()*2));
if (guess){
result.text = "Your Guess is corrent";
var newresult = Number(income.text) + Number(amount.text);
income.text = Number(newresult);
}
else{
result.text = "Your Guess is wrong";
var newresult = Number(income.text) - Number(amount.text);
income.text = Number(newresult);
}
}
You dont need the event.target.name because the function is within the event handler of each button. So you can just use a random boolean. Event.target.name also doesnt work in AS2.0

DirectX Application Causes Computer Crash

I have written a DirectX11 Application that is running on an Alienware Laptop with a GeForce GT 555m graphics card, so I know the computer supports it.
I have come across this weird thing were my laptop will turn of without any warning if it isn't plugged into power, however the application runs fine if it is plugged into power.
I have tried to replicate this with other DirectX11 Applications, including the Samples that come with DirectX however my application is the only one that does it, but I use very similar code to the Samples. I must be missing something but I don't know what.
This is my code to setup the SwapChain and the RenderTargetView
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
if(vsync) {
swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
}
else {
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
}
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = hwnd;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
if(fullscreen) {
swapChainDesc.Windowed = false;
}
else {
swapChainDesc.Windowed = true;
}
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swapChainDesc.Flags = 0;
D3D_FEATURE_LEVEL featureLevels[4] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, };
if (FAILED(D3D11CreateDeviceAndSwapChain(0, D3D_DRIVER_TYPE_HARDWARE, 0, 0, featureLevels, 4, D3D11_SDK_VERSION, &swapChainDesc, &swapChain, &device, &featureLevel, &deviceContext))) {
if (!device) {
printf("Insanity Error: Failed To Create Direct3D Device\n");
}
if (!swapChain) {
printf("Insanity Error: Failed To Create Swap Chain\n");
}
return false;
}
else {
switch (featureLevel) {
case D3D_FEATURE_LEVEL_11_0:
printf("Insanity Info: Currently Using DirectX 11.0\n");
break;
case D3D_FEATURE_LEVEL_10_1:
printf("Insanity Info: Currently Using DirectX 10.1\n");
break;
case D3D_FEATURE_LEVEL_10_0:
printf("Insanity Info: Currently Using DirectX 10.0\n");
break;
case D3D_FEATURE_LEVEL_9_3:
printf("Insanity Info: Currently Using DirectX 9.3\n");
break;
default:
printf("Insanity Info: Graphics System Unknown\n");
break;
}
}
if (FAILED(swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr))) {
printf("Insanity Error: Faield To Find Back Buffer\n");
return false;
}
if (FAILED(device->CreateRenderTargetView(backBufferPtr, 0, &renderTargetView))) {
printf("Insanity Error: Failed To Create Render View Target\n");
return false;
}
backBufferPtr->Release();
backBufferPtr = 0;
And then this is my code to set up the DepthStencilState and the RasterState
ZeroMemory(&depthStencilDesc, sizeof(D3D11_DEPTH_STENCIL_DESC));
depthStencilDesc.DepthEnable = false;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
depthStencilDesc.StencilEnable = true;
depthStencilDesc.StencilReadMask = 0xFF;
depthStencilDesc.StencilWriteMask = 0xFF;
depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
if (FAILED(device->CreateDepthStencilState(&depthStencilDesc, &depthDisableStencilState))) {
printf("Insanity Error: Failed To Create Depth State\n");
return false;
}
deviceContext->OMSetDepthStencilState(depthEnableStencilState, 1);
this->enableDepthTesting = true;
ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
depthStencilViewDesc.Format = depthBufferDesc.Format;
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthStencilViewDesc.Texture2D.MipSlice = 0;
if (FAILED(device->CreateDepthStencilView(depthStencilBuffer, &depthStencilViewDesc, &depthStencilView))) {
printf("Insanity Error: Failed To Create Depth View\n");
return false;
}
rasterDesc.AntialiasedLineEnable = false;
rasterDesc.CullMode = D3D11_CULL_NONE;
rasterDesc.DepthBias = 0;
rasterDesc.DepthBiasClamp = 0.0f;
rasterDesc.DepthClipEnable = true;
rasterDesc.FillMode = D3D11_FILL_SOLID;
rasterDesc.FrontCounterClockwise = false;
rasterDesc.MultisampleEnable = false;
rasterDesc.ScissorEnable = true;
rasterDesc.SlopeScaledDepthBias = 0.0f;
if (FAILED(device->CreateRasterizerState(&rasterDesc, &rasterState))) {
printf("Insanity Error: Failed To Create Rasterizer State\n");
return false;
}
deviceContext->RSSetState(rasterState);
If any one has any ideas as to what could be going on please help!
Try using the reference device instead of your hardware device and see if the problem recurs. This should help isolate the driver from the code. When you create your device, instead use D3D_DRIVER_TYPE_REFERENCE.