Plugin 05: Accelerometer

In our series on plugins, today we’re going to cover plugin which can help us to work with Accelerometer sensor. This sensor is responsible to detect X, Y, Z co-ordinates of the devices. Using data received from this sensor, you can build games like TempleRun, where users can collect the coins by tilting the device.

There are different APIs for different platform and their usage is different too. First, lets see how we can use this sensor in different platform and then we’ll use plugin in Xamarin.Forms application.

Being Windows Runtime API, the API and its usage is same in Windows and Windows Phone. Here, you create object of the sensor and register for ‘ReadingChanged’ event. Whenever device position is changed, it is reported through that event and UI can be updated using Dispatcher.

In case of Android, it is again similar to Windows platform. Create object of SensorManager and register for SensorChanged event.

iOS is not any different. You create object of CMMotionManager and then listen to sensor for changes.

As you can see, for three different platforms the APIs are totally different. But with Plugins for Xamarin.Forms it becomes easy. You can use DeviceMotion plugin which can work across all these platforms. And the code for same looks like:

In this series on plugin we’ve seen how particular concept can be implemented in all the three platforms and how we can use plugin to make life easier. This will be be last post in this series, but there are many plugins available which you can explore and use in your projects. Do let me know if you want to cover any specific plugin. We’ll start with a new series in couple of weeks. Till then… happy coding :)

Namaste
Mayur Tendulkar

Advertisements

//PUBLISH – Global Event Updates

Microsoft is hosting a global event //PUBLISH. This event is in series with //build, //learn and will be called //publish. You can find more information about this event at: https://publishwindows.com/ 

The idea behind this event is to help you get your apps in the store. If you’re working on any existing app (Windows Store or Windows Phone) or have an app idea, we’ll help you to complete it and submit it on the store. We at Pune User Group are happy to say that, PUG will be hosting this event in Pune. As this is a global event, we’ll be hosting it on the same dates i.e. 16th and 17th May. This post will give you idea about the event.

In Pune, you can find agenda and registration details here: Pune Link. Once you register, we’ll send confirmation mail to registered users and they’ll be invited for the event.

As it is going to be session+coding+support event, please make sure that your machine is properly configured. Please get the latest version of Visual Studio and Windows Phone SDK installed on your machine to avoid confusion at the venue. If you need any help with it, please contact us. My email ID is mayur.tendulkar {at} puneusergroup.org

And have I mentioned, there will be prizes too (for eligible candidates Smile)

Till then.. register and happy coding.

Mayur Tendulkar

It’s All About Controls (Part 2)

Thanks for reading Part 1 of this multi-part blog post. If you’ve missed, in Part 1, we talked about what has been added (or converged with Windows) in Windows Phone 8.1 SDK. This part will mainly cover the changes that are included in this SDK. These are important changes and you must make a note of it to build stunning apps. Perhaps, later, there will be part 3, in which I’ll cover some 3rd party components, which can be used in Universal apps. Do let me know if you want to cover anything specific.

Panorama Is Now Hub

wp_ss_20140421_0003 wp_ss_20140421_00014

With Windows and Windows Phone convergence, Panorama control from Windows Phone is changed to Hub control. It is similar to Hub control available on Windows and gives effects like Panorama. It also, share the same XAML in both the platforms

image  

image


StatusBar (SystemTray) Changes

StatusBar or SystemTray is top-most component on page, which shows various details:

image

In Windows Phone 8 apps, you could show/hide system tray from XAML. For example:

image

Now, in 8.1 (WinRT) apps you’ll need to use code behind to do it. For example:

image


Flyouts, Flyouts Everywhere

Flyout is a new control in WP8.1 SDK. As MSDN says, use it to display lightweight UI. Also, unlike a dialog, a flyout can be lightly dismissed by clicking or tapping outside it. You can create a flyout by using following code. And actually add a flyout to any control which is a FrameworkElement.

1  

image


Command From Your Bar

With WP8.1, you do get your old AppBar.. but also get CommandBar. This command bar shares code with Windows. It also have Primary Commands and Secondary Commands. Which represents main buttons and menu on bottom app-bar in WP app. Whereas, on Windows, they have positions on app-bar as left and right.

image

image


Zoom – SemanticZoom

With WP8.1, LongListSelector is gone. However, it is replaced with SemanticZoom – in convergence with Windows. This control actually has two views which are shown in different way according to Zoom In/Out mode. It will be another topic for blog. But to put it into simple words: you’ll see a large list of photos in Grid. But when you *squeeze* it, you’ll see a list. OR vice a versa as you design your view.

image

With these controls, there are some more changes in controls are added. Like RichTextBLOCK (not Box), WebView (not Browser). But I would love to keep this post short.  

In next series (rather, I’m planning to change the name Smile), I’m going to talk about API changes in Windows Phone 8.1 SDK. Meanwhile, do let me know your feedback and if you want anything more covered here.

Happy Coding

Mayur Tendulkar

What’s Next For Phone Developer?

If you’re a Windows Phone Developer, by now you might have heard about OR rather, upgraded your phone to Windows Phone 8.1. Microsoft, recently released Windows Phone 8.1 (Codenamed Blue) for Developers. To get these bits on your device, you need to a registered Windows Phone developer and need to install Preview For Developers app on your phone. You can find more information here Once you upgrade the phone, you’ll find lots of resources online to get to know what’s new in Windows Phone 8.1.

Now, as a developer, you’ve the phone to test and build apps for. However, to build applications for this latest version of Windows Phone, you need Visual Studio 2013 Update 2 (currently in RC). You can get these bits from here

As a developer, first, you need to unlock your phone. If you remember, there used to be Phone Registration Tool, which gets installed when you install Windows Phone SDK. Now, this tool is integrated into Visual Studio and you can launch it from Tools menu

Untitled

When you connect your phone, you can easily developer unlock it to test your applications on it.

image

Similarly, you can use, App Deployment tool to deploy XAP (or now Appx) to Phone.

image

New addition to these tools is ‘Windows Phone Power Tools’. And these tools does lot of work for you, right from verifying the app, checking the performance and what not.

image

Even thought, this release is titled as Windows Phone 8.1, there are so many features that *I* will personally call it Windows Phone 9 Smile

To give you idea about what’s new in this platform and how you can develop apps for it, Microsoft is hosting online events. These are all free online events. So, register now and get the benefits from it.

Building Apps for Windows Phone 8.1 Jump Start (April 29- May 1)
//Learn – Global Community Webcast (April 24)

Happy Coding,

Mayur Tendulkar

One Code To Rule Them All, but Why?

Windows: runs on more than 90% desktops, laptops, netbooks and nowadays it runs on kiosks, smart devices, phones and these days gaming console. However, developers always faced challenge to target all these devices and deliver ONE app, which can run on all these devices. There were differences in APIs, kernel, core services and what not.

When .NET was released, Microsoft tried to solve this problem by introducing .NET Framework on desktop and .NET Compact Framework – a subset of full .NET Framework *modified* for smart devices. Then, there was yet another .NET Framework for yet another class of devices called .NET Micro-Framework. So, developers had three different .NET Frameworks to target different class of devices, yet someone can’t just copy/paste code from one device app to another. Libraries compiled for one device may not work on another (e.g. app compiled for Windows Mobile *may* fail if ran on desktop – as both used to be PEs). But, for someone like me, it was a good start. I could write apps for mobile phones or desktop using the same language that I know i.e. C# or VB.NET.

Later, Microsoft introduced a very nice concept of Portable Class Libraries, which allowed developers to share code between various platforms.

image 

The limitation was, PCLs are binaries which give you ‘least common denominator’ of APIs available across platforms you selected. So, if you select .NET Framework and Windows 8, APIs which common to these two platform will be selected. And, if you wanted to do maximum code-reuse, your best bet is to follow MVVM like patterns, put models/view models in PCL and create app for views. So, the project structure will look like:

image

PCLs solve some of the issues in best possible way. But when it comes to Windows & Windows Phone, there are lot of similarities like UI, API set, programming model. Here we need some solution which can give maximum code reuse and go beyond PCLs.

Welcome to Universal Apps

image

Universal Apps allows you to build app with maximum code sharing which can work on Windows and Windows Phone (and Xbox in future). When you create Universal App, template creates 3 projects for you as shown below:

image

Now, you may say that it looks pretty similar to above mentioned solution which use PCLs.  Yes, it looks same, but there are internal differences:

When you create Universal App, you can share UI, Media, Code, XAML, etc.. using Shared Project. Now, Shared project allow you to share *code* between projects, whereas PCL allow you to share *binary* between projects. That also means, you can’t use #if.. #then compiler switches in PCLs and can’t write (or rather get benefit from) platform specific code. So, it also means that, when you build the project, you don’t get *.Shared.dll or something and it is not *referenced*, rather during build the code will be automatically included from shared project into individual projects. You can spot the difference in icon here.

image

With Universal App, you can share UI as well. In next screenshot you can see that there is almost no difference in Windows page and Windows Phone page.

image

image

Just tell me which one is which and I’ll give you a gift when we’ll meet next time Smile. Now rather I typing here, following slide will speak a lot:

image

After all this, if you *package* these projects, you get APPX which you can submit to the store.

This is certainly a nice move from Microsoft considering developer audience. For consumers, they can now buy app on desktop and can use it on phone. And for me this is true ‘ONE MICROSOFT’ Smile

There are many new announcements happened at //build/ to follow them and If you want to know more about Windows Phone 8.1 Features, Universal App FAQs, do visit blogs from my friends:

Namaste,

Mayur Tendulkar