Wednesday 24 April 2013

Detect the screen resolution for Windows Phone OS 7.1 applications

    As you probably know Windows Phone 7.1 applications run perfectly on Windows Phone 8 devices. This means that your application/s could run on multiple display resolutions (which are the resolutions supported by Windows Phone 8 devices). If you want to take advantage of the new resolutions (for example downloading higher quality images for higher resolutions devices, fix some minor UI anomalies on higher resolutions) you will need to know the ScaleFactor of the device. The property is only available in the Windows Phone 8.0 SDK, but the good news is that you can access it using reflection.

Solution:
We retrieve the Get method of the ScaleFactor property and invoke it only if the application is running on an Windows Phone 8 device.

Here is the source code:
  public static Size DisplayResolution  
{
get
{
if (Environment.OSVersion.Version.Major<8)
return new Size(480,800);
int scaleFactor=(int) GetProperty(Application.Current.Host.Content, "ScaleFactor");
switch (scaleFactor)
{
case 100:
return new Size(480, 800);
case 150:
return new Size(720, 1280);
case 160:
return new Size(768, 1280);
}
return new Size(480, 800);
}
}
private static object GetProperty(object instance, string name)
{
var getMethod= instance.GetType().GetProperty(name).GetGetMethod();
return getMethod.Invoke(instance, null);
}

I am also attaching a small sample Windows Phone OS 7.1 test project.


SOURCE CODE

P.S. I think Telerik could use this method to fix this RadToolTip visual anomaly (the 1 pixel width lines that I have filled with blue for contrast) :


NAMASTE

Wednesday 17 April 2013

BlackBerry Z10 innovation, features were worth the wait



I've never been as excited about a FedEx delivery as I was for the package with the BlackBerry Z10. It arrived from Verizon Wireless in an understated velvet-black box. Now it's showtime.

All the hype about the new BlackBerry was running through my mind — the delays and months of waiting while other smartphones made their debut. The promise of a new operating system based on QNX technology that is also known very well in the automobile technology circles and the nuclear reactors industry. So I'm thinking this device had better be special and worth the wait.

At the first glance, I noticed that the Z10, clad in solid back with a grippy, textured back that almost sticks to your hand, has grown in size to a respectable 4.2-inch display, which makes my iPhone 5 seem small. BlackBerry needed this size increase, as the older models seemed to stuck in the past, much like the earlier iPhone devices were for several years, while the competitors rocketed past them in width and height.

The Z10 has flexed its muscles by being a couple of millimeters taller than the iPhone 5 at 5.12 inches, but falls short of the Samsung Galaxy's S III and the HTC One, which are both at around four inches when standing tall. The Z10 weighs 4.78 ounces, which heavier than the iPhone, but lighter than the HTC One. I imagine the textured back adds a little weight, but it's a good thing, as the Z10 is not slippery in your hands.

A dual-core 1.5 gigahertz processor runs the Z10, backed up with two gigabytes of RAM and a 1800 mAH battery rated at 10 hours of talk time. A micro HDMI port will provide a connection to a HDTV or projector.

While the new hardware has good tale-of-the-tape specs among the competition, this device is all about the new Blackberry 10 software.

The Z10 is not a device that you'll purchase in the morning, spend all day with it and decide you don't like it. That's not enough time to uncover all the goodies and features the new OS has to offer. It's going to take several days and the like-ability will grow each day, as you spend time learning all the "gestures" that controls the new OS.

The touchscreen keypad on the Z10 is now one of the best around. I could type my entire email address with bringing up secondary characters for numbers, the @ symbol and a period. As you compose a message, the suggested words are quite helpful; you just flick them up into your sentence as you type. Somehow, the Z10 knows what you might want to say next, which according BlackBerry, will get smarter and smarter as the Z10 learns your writing style.

The all-familiar red blinking light in the upper right corner alerts you when a new message arrives. Then the "BlackBerry Flow" feature swings into action and you can follow along me as I flow into BlackBerry Hub interface.

I hit the power button to wake the Z10 and see immediately where the message is coming from by way of a red star on the email icon one one of my social media apps. A quick upward gesture unlocks the display and a couple of gestures to the right gets me to the Hub. Ah, the red star is on the email icon, so a tap opens my inbox and another tap open the message. Another neat feature is how calendar entries appear above the list in your email inbox. Just swipe downward to view what's next on the agenda.

The Z10's multitasking feature keeps several apps open and ready for you to choose at any time. A quick upward gesture will get you to the running apps panel. I predict this feature will show up on other smartphones soon.

Another favorite feature of mine on the Z10 is the "BlackBerry Remember" interface, where you can organize to-dos by color-coded folders. This is pretty common, but the new BlackBerry 10 OS takes it a few steps further by adding the capability to send emails and information from the Web to Remember folders. So, the BlackBerry becomes sort of like a Evernote or a general repository for various tidbits of information that can be acted upon later. Tags and voice notes can also be added to the notes to make the easier to find later.

Just being able to turn emails into a to-do or action item can be a powerful productivity tool for enterprise users. I know of other productivity applications that are designed around this feature alone, as well as clipping notes from the Web browsing.

I am off the corporate email grid right now and was unable to try out the full email capabilities, but the Z10 did a good job of managing my Hotmail account. I just to had to remember to make sure I'm logged in to receive the latest emails. But some early adopters are reporting problems with setting up their business email accounts.

As the Near Field Communication, or NFC, technology continues to emerge, BlackBerry has embraced it with useful capabilities built into Z10. Although just a tap will transfer information to another NFC-enabled device, I found the use of custom tags to be the most interesting. The Z10 has a Smart Tags app, which can save information from NFC tags that you encounter as well as create custom email or text messages to be sent with a tap, such as "I'm in a meeting, will call you later." I see this as being another useful tool for business users.



The Z10 is chock full of innovative features, such as the "video with screen share" and the unique "camera with time shift" to capture the best moment from the eight megapixel camera. You'll need to spend some time learning about this device and just exploring to really appreciate all it has to offer. Just knowing which direction to swipe your finger to accomplish something is a good start to mastering the Z10.

I spent a few days waking the Z10 by hitting the power button until I learned to swipe upward from the BlackBerry logo at the bottom of the display. A two-finger swipe from the bottom shows the keyboard; a long press on the space bar or two-finger swipe downward hides it. For the Hub, swipe upward from the logo, then once or twice to the right. There are numerous other navigation tips; too many to mention here. For new Z10 owners, you have some learning to do.

The Z10 is intuitive and innovative, but also challenging. But I would ante up around $200 for this device if I was smartphone shopping. It's the best of all the BlackBerry devices I've had experience with and finally, thank you, thank you, it has an excellent Web browser based on the HTM5 interface. I don't even miss the infamous roller ball or scroll wheel from earlier devices.

As for apps, the Z10 launched with around 70,000 apps available and the latest count is around 100,000. As a BlackBerry apps developer, I need to get busy and submit something to the BlackBerry App World. But I'm sure a quick search will turn up some of your old favorites, such as BlackBerry's rock-solid Password Keeper.

The Z10 is currently available on Verizon, the source of my review device, AT&T and T-Mobile . If you're a die-hard BlackBerry fan and must have a QWERTY physical keypad, I hear the next model of the BlackBerry 10 devices, the Q10, is due in a few months.

In the meantime, the Z10 is my thumbs-up device. I can say it was worth the wait.

Visit us on Facebook | Follow on Twitter

Tuesday 16 April 2013

3 ways to force the WebBrowser control to logout from Facebook

     Decided to write this post because it took me some time to find the answer. Maybe you already know that if you use OAuth Facebook connect inside your Windows Phone application there is one step where you use the WebBrowser control to let the user authenticate on the Facebook server and authorize your app. The "problem" presents itself when you want to link another user because the WebBrowser control has already memorized the old credentials and will automatically use them. What needs to be done is to logout the old user from the WebBrowser without actually telling the user to go on the web page and click logout. I have found 3 easy ways to do that: the first two will work on both Windows Phone 7.x and Windows Phone 8 and are Facebook specific and the third one will only work on Windows Phone 8 (generic method for OAuth providers). The 3 methods can use the WebBrowser control headless (you don't actually have to show the WebBrowser control to the user and don't even have to have the webbrowser attached to a Page):  

Method 1: described by Rene Schulte in this blog post  
The method constructs the logout Uri using your AppId and a SessionKey that is obtained from the AccessToken you got when the user authenticated.

Get the SessionKey:
  private static string ExtractSessionKeyFromAccessToken(string accessToken)  
{
if (!String.IsNullOrEmpty(accessToken))
{
var parts = accessToken.Split('|');
if (parts.Length > 2)
{
return parts[1];
}
}
return String.Empty;
}

Obtain the logout Uri:
  public Uri GetLogoutUri(FacebookCredentials credentials)  
{
var sessionkey = ExtractSessionKeyFromAccessToken(credentials.AccessToken);
var url = String.Format("http://facebook.com/logout.php?app_key={0}&session_key={1}&next={2}", EndpointData.FacebookAppId, sessionkey, EndpointData.FacebookLogoutCallbackUrl);
return new Uri(url);
}

Make the WebBrowser navigate to the logout Uri:
 Browser.Navigate(FacebookService.GetLogoutUri(EndpointData.Settings.Facebook));  

Method 2:
If for some reason you don't have the Facebook AppId available (my case) you can use the WebBrowser to navigate to the Logout page https://www.facebook.com/logout.php and after the page gets loaded you just execute the script document.forms['logout_form']:
 wb.LoadCompleted += wb_LoadCompleted;  
wb.Navigate(new Uri("https://www.facebook.com/logout.php"));
Once the page gets loaded:
 void wb_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)  
{
wb.LoadCompleted -= wb_LoadCompleted;
if (wb.SaveToString().Contains("logout_form"))
wb.InvokeScript("eval", "document.forms['logout_form'].submit();");
}

Method 3:
This is the easiest one, but will only work on Windows Phone 8: call the new WebBrowser async method ClearCookiesAsync(). This method works for every OAuth provider (Dropbox, Box, Skydrive, Picasa, Flickr, Google Drive... infinite list).

NAMASTE

Monday 8 April 2013

Verizon's 4G LTE Router offers the ultimate mobile Wi-Fi experience

If you're looking for the ultimate in on-the-go Internet access with the reliability of a good old-fashioned home or business wired service, then a router with wireless capabilities will fill your needs.

The 4G LTE Router from Verizon Wireless takes the concept of a wired router and adds a twist with two antennas to make adaptable for mobile duty. You'll feel right a home with several ports on the back that even include a WAN port for connecting to the Internet via cable or DSL, four ethernet ports for desktop or laptops wired connections, a power button and a power adapter input.

Then it really gets good. For wireless connections when out and about, a Verizon SIM card needs to be in place and the two antennas attached. Plug it in and look for the router in the list of available wireless networks. You should be in business now and the only thing left to do is to add a password to protect your device from WI-Fi prowlers.

This device differs from a regular mobile hotspot in that you have access to ethernet ports for wired connections, even though you're using a wireless Internet signal. That feature alone makes the Verizon router worth a look to consider the $99.99 cost after a $50 mail-in rebate with a new two-year customer agreement.

If you find yourself on vacation, a business trip or suddenly out in the boondocks, but you need to go online, this device will get you there at download speeds of 5 to 12 Mbps and average upload speeds of 2 to 5 Mbps.

A 4G wireless router is the way to go for mobile online needs or an office away from the office.

Thursday 4 April 2013

HTC First - Facebook dedicated smartphone

Few weeks of rumors and speculations and here we have - new HTC device, called HTC First and created together with (and for!) Facebook. It's surely not a flagship model, but also not a low-end device.

Actually it has quite nice specifications:

  • Platform: Android 4.1
  • Processor: Qualcomm® MSM8930AA 1.4Ghz, dual-core
  • Memory: 16 GB, 1 GB RAM
  • GSM 850/900/1800/1900/2100, HSDPA 21/5.76, LTE 4/17
  • Display: 4.3-inch, HD 720p
  • Battery: 2000mAh (non-removable)
  • Main camera: 5 MP camera with auto focus, LED flash, BSI sensor, f/2.0 aperture, 28mm lens, 1080p video recording
  • Front camera: 1.6 MP camera
  • Dimensions: 4.96 x 2.56 x 0.35 (in) (LxWxT)
  • Weight: 4.37 oz

What is special about this device, is very deep Facebook integration. It has its own Facebook launcher instead of HTC Sense launcher. What else?

  • Cover feed: A constant, fresh stream of photos and updates from your newsfeed, cover feed is always present when you wake up your phone.  It lets you stay up-to-date on your friends’ latest activities in real-time, all the time.  You can swipe through to see more photos and updates, double tap to “like” a post and comment right from cover feed.  To learn more about cover feed, check out this video.
  • Notifications: Notifications from apps and friends appear right on your home screen.  It’s easier to see when you have a missed call, calendar reminder or new message. Open a notification with a double tap or clear them away to see your Cover Feed.  To learn more about notifications, check out this video.
  • Chat Heads: The mobile messenger lets you jump in and out of conversations while you do other things, like watch a video and browse the web.  Reply right from chat heads, or move them around if you're not ready to respond. Plus you can send and receive texts and Facebook messages from the same spot.  To learn more about chat heads, check out this video.
  • App Launcher:  See your favorite apps and post right to Facebook from the same spot. You choose what’s on your app launcher—press and hold an app then drag it anywhere.
  • Instagram:  HTC First is the only phone that comes with Instagram pre-loaded.

Personally, I'm very curious how this device will work with its custom launcher and what will be customers judgement. I think it has a huge potential. The idea of new custom launcher is more then interesting. Let's take a quick pick how it looks like:





To me, it seems to be very simplified version of Android launcher. It might be a great choice for users who are not expecting their phone to be multimedia all-in-one device, but they want to easily stay in touch with their friends using the most popular social channel. There is also Instagram pre-installed, so sharing your great moments captured with 5 MP back camera will be easy as well. Additionally, it is very likely that the overall system performance in HTC First will be very good. Qualcomm 1.4 GHz dual-core CPU in pair with 1GB of RAM memory will probably bring you smooth user interface experience, considering the fact that device doesn't have pretty heavy HTC Sense on board. So, do you think it is a device for you?

Have any questions or comments? Feel free to share! Also, if you like this article, please use media sharing buttons (Twitter, G+, Facebook) down this post!



Facebook unveils a new home screen for Android devices



It was a big day for Facebook, as Chairman and CEO Mark Zuckerberg, unveiled "Facebook Home," a slick interface for the Android operation system that brings messages, photos and recent stories to the home screen of your Android smartphone.

Smartphone manufacturer HTC also announced the HTC First, the first device to have the Facebook Home interface incorporated into the Android OS. It'll also come pre-loaded with Instagram, which is another popular photo-sharing service owned by Facebook that utilizes a twist of photo filters for cool effects.

The Facebook gurus views the home screen as "the soul of your phone" and offers an alternative with Facebook Home, which does not need to open an app to see all your social media connections.

The ingenuity with Home begins with a virtual button at the bottom of your display that shows your face. A simple swipe up and it shows all your regular apps or you can swipe it away to hide them all.



Then the beauty of the Home interface shines with a feature called "Chat Heads," which allows messages you receive to pop up over any application currently running. A conversation can be held with your Facebook friends on top of – let's say – while using the Internet browser. The chats can be dragged around the screen and when you're done, just tap and they're gone.



Another unique feature of the Home overlay is that some of this social media interaction can go on while the phone is still locked by using called Cover Feed. This feature will allow a steady stream of photos, likes, comments and status updates from your newsfeed.

The new features will be available on April 12 on the HTC First, a 4G LTE device that will come in red, baby blue, white and black. It'll be available exclusively from AT&T for $99.99 and is now available for pre-order.

Several other Android smartphone with the latest version of the Facebook and Messenger apps will also be Home friendly. They include the HTC One, One X, One X Plus, Samsung Galaxy S3, Note 2 and the S4 when it is launched. Android tablets will come on board later, but there is not indication of when Home will play with iOS devices.

Facebook sees their new Home interface as a way to flip the smartphone home-screen experience from being designed around apps to being designed around people.

We'll have to wait and see if their latest creation gets any "Likes" from its one billion users.

Visit us on Facebook | Follow on Twitter | Send an email

Tuesday 2 April 2013

Smooth scrolling content on Windows Phone

     Gotta say that I am not 100% satisfied about the title of this blog post, but since I haven't found a better one I will use this one (don't get it wrong windows phone has smooth scrolling implemented). This post is focusing on how to smooth scroll the content of a ScrollViewer. If you are using the ScrollViewer you know that it already has the method ScrollToVerticalOffset that can be used to manually scroll the content but this method doesn't have any animation implemented so you will see only a fast redraw of the new content without getting the "feeling" that the content scrolled to the new position. The easiest way to achieve this task would be using a StoryBoard with an Animation on the property VerticalOffset of the ScrollViewer, but VerticalOffset is a read-only property so it cannot be set and therefore cannot be used for animation.
     The solution I found was to build a custom control and add a custom property that can be used as a target for a DoubleAnimation. The attached sample (see the link at the end of the post) is using a ListBox as the content of my Custom Control but you can use anything else inside the control (a better approach for the ListBox would be to create a custom control derived directly from ListBox and use the built-in ScrollViewer). 
      Let's start from the XAML part of the User Control:

  <ScrollViewer x:Name="scroller">  
<ContentPresenter Content="{Binding ContentArea, ElementName=userControl}"/>
</ScrollViewer>

    So we have a ScrollViewer which inside has a ContentPreseter that has its content binded to the control's property ContentArea. Now let us have a look at the .cs code.

 public static readonly DependencyProperty VerticalOffsetProperty = DependencyProperty.Register("VerticalOffset",  
typeof(double), typeof(SmoothScroller), new PropertyMetadata(VerticalOffsetPropertyChanged));
public double VerticalOffset
{
get { return (double)this.GetValue(VerticalOffsetProperty); }
set { this.SetValue(VerticalOffsetProperty, value); }
}
private static void VerticalOffsetPropertyChanged(object sender, DependencyPropertyChangedEventArgs args)
{
SmoothScroller cThis = sender as SmoothScroller;
cThis.scroller.ScrollToVerticalOffset((double)args.NewValue);
}
public static readonly DependencyProperty ContentAreaProperty = DependencyProperty.Register("ContentArea", typeof(object), typeof(SmoothScroller), null);
public object ContentArea
{
get { return (object)GetValue(ContentAreaProperty); }
set { SetValue(ContentAreaProperty, value); }
}

     The property that we will use for animation is the VerticalOffset that uses the method VerticalOffsetPropertyChanged to scroll to a vertical offset inside the control's scroller. The property VerticalOffset can be animated and we will use it to smooth scroll the ListBox content.
     Here is the content of the MainPage.xaml

  <uc:SmoothScroller x:Name="smoothScroller">  
<uc:SmoothScroller.ContentArea>
<ListBox x:Name="lstItems" ItemsSource="{Binding Items}" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemTemplate="{StaticResource DataTemplate}" >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</uc:SmoothScroller.ContentArea>
</uc:SmoothScroller>

     So we have the SmoothScroller control which inside its ContentArea has a ListBox (the ListBox has it's scrollviewer disabled). What the sample does is it is changing the selected item every second (incrementing the selectedindex) and scrolls the content so that the newly SelectedItem is centered in the ScrollViewer. Here is the code used for scrolling:

  void dt_Tick(object sender, EventArgs e)  
{
((ListBox)smoothScroller.ContentArea).SelectedIndex = idx;
var container = ((ListBox)smoothScroller.ContentArea).ItemContainerGenerator.ContainerFromIndex(idx) as FrameworkElement;
var transform = container.TransformToVisual(smoothScroller.scroller);
var elementLocation = transform.Transform(new Point(0, 0));
double newVerticalOffset = elementLocation.Y + smoothScroller.scroller.VerticalOffset - smoothScroller.scroller.ActualHeight / 2 ;
//Animate transition
DoubleAnimation verticalAnimation = new DoubleAnimation();
verticalAnimation.From = smoothScroller.scroller.VerticalOffset;
verticalAnimation.To = newVerticalOffset;
verticalAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500));
var sb = new Storyboard();
sb.Children.Add(verticalAnimation);
Storyboard.SetTarget(verticalAnimation, smoothScroller);
Storyboard.SetTargetProperty(verticalAnimation, new PropertyPath(SmoothScroller.VerticalOffsetProperty));
sb.Begin();
idx++;
if (idx >= 56)
dt.Stop();
}

     Pretty basic: select the new index in the ListBox, calculate the new VerticalOffset so that the newly selected item is centered in our scrollviewer and create and start a 500ms animation for the SmoothScroller.VerticalOffsetProperty. Anyway I am sure that you will better understand how it works when you will try the sample code.
     The sample is far from perfect (before starting a new animation I should check if the old one finished, should not automatically scroll when the user is manipulating the list,...).
     Here is a screenshot from the sample:

As usual let me know if you need help. The code works on both Windows Phone 7.1 and Windows Phone 8 SDK.

SOURCE CODE


HTC One variants [update]

Image taken from smart.com.ph


In my article here I was writing about HTC One GSM/LTE (UL) and GSM (U) versions. The question if ROM based on UL firmware can be flashed on U device is still valid, but now we have some more details about these variants.
It turns out, that UL version of HTC One (having both GSM & LTE radio) will be available mostly in the Europe and North America. Model ID (MID) of this version is PN0710000.

U version (GSM radio only) is going mostly to Asian markets. Model ID (MID) of this version is PN0711000. There is also WL variant, which will be the Sprint version of HTC One. I don't know MID number of this version yet.

In the past we had similar situation with slightly different MIDs numbers of the same device. HTC Sensation had PG5813000 and Sensation XE had PG5813001. Both devices can use the same custom ROMs. HTC Desire HD has PD9810000, while Telus variant had PD9814000 and HTC Inspire 4G (U.S. version of HTC Desire HD) had PD9812000. Again, one custom ROM can be flashed on all 3 devices.
There are also some more details that leads to the conclusion, that most probably users with HTC One variant will be able to use their device with no issues after flashing custom ROM based on UL RUU. This is surely a very good news for both users and custom ROM developers. However, this will probably not enable LTE modem on U devices. So if you want to use LTE and your carrier supports this technology, make sure you will buy HTC One UL.

Have any questions or comments? Feel free to share! Also, if you like this article, please use media sharing buttons (Twitter, G+, Facebook) down this post!