How does one implement pull-to-refresh with a LongListSelector in Windows Phone 8? - windows-phone-8

I am writing a new WP8 app using the off-the-shelf LongListSelector that is shipped in the Microsoft.Phone.Controls assembly. Can anyone provide a code example that implements pull-to-refresh, originally made popular by Tweetie for iPhone and now common on iOS and Android? The existing examples use non-standard controls and I'd like to maintain my use of LongListSelector in WP8.
EDIT
I have found a good answer on StackOverflow describing the Twitter sample and how to do this in more detail:
Continuous Pagination with LongListSelector

You do not.
Pull-to-refresh is not a standard Windows Phone interaction, and you therefore should not implement it.
No native/first-party Windows Phone application use this functionality, and almost no third-party application does either. There is a reason for that.
To refresh the content of a page (or in your case, a LongListSelector), you should use a refresh ApplicationBacIconButton, just like in the Mail app. That's the standard and preferred way to manage refreshes.
Windows Phone is not Android, nor is it iOS. Keep that in mind when designing an application for it.
It is not a zoo, there are rules.

Actually, I just discovered a project uploaded to the Windows Phone Dev Center on November 30, 2012 that implements "infinite scrolling" using Twitter Search and Windows Phone 8 LongListSelector.
Download this project at: http://code.msdn.microsoft.com/wpapps/TwitterSearch-Windows-b7fc4e5e

If you really must do this (see answer by Miguel Rochefort) then details can be found at http://blogs.msdn.com/b/jasongin/archive/2011/04/13/pull-down-to-refresh-a-wp7-listbox-or-scrollviewer.aspx
Basically, the ScrollViewer has hidden/undocumented states that allow for detecting "compression" at the top or bottom of the list and you can use this to trigger the loading.

This is not completely trivial, but one way of doing it is to use GestureService
this.gestureListener = GestureService.GetGestureListener(containerPage);
this.gestureListener.DragStarted += gestureListener_DragStarted;
this.gestureListener.DragCompleted += gestureListener_DragCompleted;
this.gestureListener.DragDelta += gestureListener_DragDelta;
However, it has some bugs. For example, DragCompleted is not always raised, so you need to double-check for that using ManipulationCompleted event, which seems to be more reliable.
containerPage.ManipulationStarted += delegate { this.manipulationInProgress = true; };
containerPage.ManipulationCompleted += delegate
{
this.manipulationInProgress = false;
PerformDragComplete();
};
Another issue is that DragDelta occasionally reports bad coordinates. So you would need a fix like this:
Point refPosition = e.GetPosition(null);
if (refPosition.X == 0 && refPosition.Y == 0)
{
Tracer.WriteLine("Skipping buggy event");
return;
}
Finally, you can find if list is all the way at the top:
public double VerticalOffset
{
get
{
ViewportControl viewportControl = this.FindChildByName("ViewportControl") as ViewportControl;
if (viewportControl != null)
{
Tracer.WriteLine("ViewPort.Bounds.Top=" + viewportControl.Bounds.Top + " ViewPort.Top=" + viewportControl.Viewport.Top.ToString() + " State=" + this.ManipulationState);
return viewportControl.Bounds.Top - viewportControl.Viewport.Top;
}
return double.NaN;
}
}

You can check out the samples in
https://github.com/Kinnara/WPToolkit
it has an excellent implementation something called a ListView extension of the longllistselector control, that will really help you out.
and remember with longlistselector always try to load 20 items atleast. =)

As the WP8 LLS doesn't use a scrollviewer, I guess you will have to inspect the UI tree to get a hold on the viewport control and see what you can do with ViewportControl.Viewport property ...
Oh ... the twitter application is now using the pull to refresh interaction. I like the UI guidelines of the WP platform but rules, once mastered, are made to be broken ;)
This post here can give you hints on how to get the viewport control and retreive the scrolling offset. this scrolling offset must be of a particular value when the list is bouncing

Related

Override default behavior of navigator.bluetooth.requestDevice()

When I call navigator.bluetooth.requestDevice({acceptAllDevices: true}), a chrome window pops up with the devices around me. I can only pick 1 device here. Is there a way to pick multiple devices or not have this window pop-up; Can I implement my own web based window that show BLE devices around me?
navigator.bluetooth.requestDevice({acceptAllDevices: true})
.then(device => {
console.log(device);
});
The Web Bluetooth GATT Communication API does not allow you to bypass this prompt. See https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web#request_bluetooth_devices
The upcoming Web Bluetooth Scanning API however will let you scan for nearby advertisements and connect to devices: https://webbluetoothcg.github.io/web-bluetooth/scanning.html
It is not fully implemented yet in Chrome.
Follow https://github.com/WebBluetoothCG/web-bluetooth/blob/master/implementation-status.md to keep track of changes.
The new navigator.bluetooth.getDevices API (in Chrome 85 and later) actually allows you to avoid this prompt IF you've previously used requestDevice to pair a device.
The chromestatus page on it is here: https://www.chromestatus.com/feature/4797798639730688
And it contains a link to a developer guide.
The simplest hackiest use would be:
navigator.bluetooth.getDevices().then(function(devices) {
if (devices.length==0) put_up_button_for_requestDevice();
else return devices[0].gatt.connect();
}).then(finish_connecting_as_normal)

Windows Phone 8 Live tiles Text & image update

I created an app for windows Phone 8 and want to implement Live tiles in my app. I don't even know anything about live tiles. I tried many examples from the forums and all.
But all are in the form of buttons(Like Flip, Cycle) If i click Cycle Button it will direct to the start screen to show the Cycle Tile.
But, How could i implement in my app. i want to shows the lives tiles only when user pins into the start screen.
anyone, help me to solve this????
Thanks in Advance.
The first thing you need to know is that LiveTiles on Windows Phone 8 can be implemented only from C#/.NET code, not C++. The native libraries don't have access to LiveTiles, so you need to use the .NET API.
Next... if your app is written in C++ with DirectX, you need to use XAML with Direct3D interop. This means you will have at least 2 VS projects, one using XAML/C#, the other using C++. LiveTiles will be updated through callbacks and delegates, sending events from the C++ component to the C# XAML component.
(If your app is using only C#/.NET, you don;t need any callbacks)
One more thing: the only type of LiveTile which always works on Windows Phone is FlipTile type. If you use iconic tiles, WP8 usually ignores colors, and shows only white&transparency.
Here is a snippet from my C++ component:
std:string dummyStd = "test string to display";
std::wstring dummyWs.assign(dummyStd.begin(), dummyStd.end());
Platform::String^ dummy = ref new Platform::String(separatorWs.c_str());
m_d3DInterop->OnLiveTilesUpdates(dummy);
and a snippet from the C# component:
public void OnLiveTilesUpdates(String s)
{
String szTitle = "title";
String szText = s;
ShellTile oTile = ShellTile.ActiveTiles.First();
{
FlipTileData oFliptile = new FlipTileData();
oFliptile.Title = "";
oFliptile.Count = 0;
oFliptile.BackTitle = szText;
oFliptile.BackContent = szTitle;
oFliptile.WideBackContent = szTitle;
oFliptile.SmallBackgroundImage = new Uri("/Assets/Tiles/FlipTileFrontSmall.png", UriKind.Relative);
oFliptile.BackgroundImage = new Uri("/Assets/Tiles/FlipTileFrontMedium.png", UriKind.Relative);
oFliptile.WideBackgroundImage = new Uri("/Assets/Tiles/FlipTileFrontHigh.png", UriKind.Relative);
oFliptile.BackBackgroundImage = new Uri("/Assets/Tiles/FlipTileFrontMedium.png", UriKind.Relative);
oFliptile.WideBackBackgroundImage = new Uri("/Assets/Tiles/FlipTileFrontHigh.png", UriKind.Relative);
oTile.Update(oFliptile);
}
Remember you need to bind the two snippets of code using events and delegates/callbacks (only if you use XAML with Direct3D interop).
Also, if you arrive here, you should know that the best component to use for rendering is DrawingSurface, because DrawingSurfaceBackgroundGrid has some z-order issues in WP8, and SwapChainBackgroundPanel is not supported in WP8.
PS: you should also do some research regarding secondary tiles.

Create a Notification window in Adobe AIR Application

I want to create an AIR application in which i need to show the notification that when AIR application is minimize then at some interval of time message shows from the system tray similar like giving information.
I have visited this LINK, its a nice component but tutorial is not that much good as component. I need to create a component like that or source is available from this site so modification in this component will also be acceptable. so please help me.
EG: When you minimize the Yahoo Messenger and some one is sign-out or sign-in then it gives notification i want component similar like that...
Thanks in Advance
First Step, We have created a Custom Popup control for Notifications display.
In the second step, we have controlled the display of that popup using the following code
if(!this.stage.nativeWindow.visible || this.stage.nativeWindow.displayState == NativeWindowDisplayState.MINIMIZED)
{
stage.nativeWindow.alwaysInFront = true;
fadeTimer = new Timer(5000,1);
fadeTimer.start();
fadeTimer.addEventListener(TimerEvent.TIMER_COMPLETE, fadePopUp);
popUpWindow = new PopUpWindow();
popUpWindow.isAlerts = true;
popUpWindow.Message = "<b>You have "+event.numNewMessages+" new notification messages<b>";
popUpWindow.type = NativeWindowType.LIGHTWEIGHT;
popUpWindow.open(true);
popUpWindow.fadeInEffect.play();
popUpWindow.nativeWindow.x = Capabilities.screenResolutionX - popUpWindow.width - 10;
popUpWindow.nativeWindow.y = Capabilities.screenResolutionY - popUpWindow.height - 35;
}
The condition used above is what we have used to find out, whether our application window is minimized to System Tray or not. Even though it is not a perfect fix, It didn't fail me yet. It's quiet stable for my app.

How to submit HTML and receive a bitmap?

I have an app that allows a user to use JQuery and Javascript to add images and position them in a div dynamically.
I would like to be able to submit the div with all the HTML to a WebService and receive back an image so we have a bitmap of the result of the end user's work.
I would prefer a solution in .Net as this is what I am most familiar with but am open to pretty much anything?
I would like to be able to submit the div with all the HTML to a WebService and receive back an image
Try http://browsershots.org!
Browsershots makes screenshots of your web design in different operating systems and browsers. It is a free open-source online web application providing developers a convenient way to test their website's browser compatibility in one place.
How about this. You load the html into a webbrowser control and then use the DrawToBitmap method. It doesn't show up on intellisense and this is probably not the best solution, but it works. Observe the DocumentCompleted event and add the following code:
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var bmp = new Bitmap(100, 100);
var rect = new Rectangle(webBrowser.Location.X, webBrowser.Location.Y, webBrowser.Width, webBrowser.Height);
webBrowser.DrawToBitmap(bmp, rect);
bmp.Save("test.jpg", ImageFormat.Jpeg);
}
You'll probably want to change the width and height of that bitmap object (do it in some smart way or something). Hope this helps.
EDIT: I see now that you are using a webservice for this, hence this solution probably won't work. I'll leave it here just for information's sake.
I was not able to figure out how to do this by submitting the html and receiving an image but I was able to create and ASHX handler that returns a png file based on this blog post
which was good enough for my scenario.
He uses CutyCapt to take a screen shot of an existing web page, write the image to a folder on the webserver and return it.

How to control mobile softkeys from Flash application embedded in HTML

I have a flash application running Flash 9 (CS3). Application is able to control the Softkeys when this flash application is loaded in the supported mobile device. But, the application doesn't have control when the same is embedded in HTML page and browsed via supported mobile device. Any ideas how to make this work?
Thanks
Keerthi
There is no special way to receive soft key events when embedded in HTML - if the browser/OS gives the events to Flash, then you can catch them like any other key event:
var myListener = new Object();
myListener.onKeyDown = function() {
var code = Key.getCode();
if (code==ExtendedKey.SOFT1) {
trace("I got a soft key event");
}
}
Key.addListener(myListener);
However, you'll find that most phones/browsers will not give you soft key events when your SWF is embedded in HTML. This isn't part of the Flash Lite spec - strictly speaking I believe they could give you those events if they wanted to, but most phones simply use those keys for browser functions, and consume them before they get to Flash.
Note that you can check at runtime whether or not softkeys are available:
trace(System.capabilities.hasMappableSoftKeys);
trace(System.capabilities.softKeyCount);
If you use a switch statement, you can have more than one keycode associated with an action, you make a desktop version for testing too. I have done it myself.