Current Flow

Endeavours into the world of programming and electronics


How To Setup And Use NativeControls In PhoneGap

NativeControls

As many might know the most used plugins in PhoneGap for iOS are NativeControls and ChildBrowser, but installing plugins is a bit tricky and you can’t easily find this kind of help around the internet, for example in my case I’ve learned by reading about plugins installation in PhoneGap and doing tests, so on this post I’ll cover the entire setup and usage of NativeControls (but you can use this for any other plugin in the iOS repo) in a very simple and informative way that even a PhoneGap beginner can understand. I’ll assume that you’ve already had installed and configured the Xcode environment on your Mac and is familiarized with the latest version of it. The first thing you must do is download the phonegap-plugins repo archive and extract it anywhere you like. Now go to the extracted folder and go to iPhone/NativeControls and copy the NativeControls.h and NativeControls.m to the /Plugins folder on Xcode, then move the NativeControls.js to your desired place in the www folder. After all this copying and pasting you must open your PhoneGap.plist under /Supporting Files and add a new item to the Plugins array with the Key and Value NativeControls and the Type String, at the end your project should look something like this:

Xcode

Now you’re ready to start diving into the code. The first thing you should do is include the required Javascript files into your index HTML source in this order:

<script src="phonegap-1.0.0.js" type="text/javascript" charset="utf-8"></script>
<script src="NativeControls.js" type="text/javascript" charset="utf-8"></script>

The next thing to do is go to your main Javascript file, which contains the onDeviceReady event set and put the NativeControls initialization code there. On this example we are going to use the TabBar component to output something like this:

TabBar

As you might have noticed I’m using the Glyphish Pro icon pack there, which you can get for $25, but it’s worth every cent, since it’s such a complete icon pack for your TabBars and more. First of all you should initialize a NativeControls variable and create a assign a TabBar to it using this code:

nativeControls = window.plugins.nativeControls;
nativeControls.createTabBar();

Then you can start creating a icon/button for a tab using this JSON object:

nativeControls.createTabBarItem(
  "books",
  "Books",
  "/www/tabs/book.png",
  {"onSelect": function() {
    // Do something
  }}
);

The first item is the name variable, the second is the icon label, the third is the icon path and the last one is a function that should be called every time icon is clicked. Be aware that you should insert the icon path relative to the project folder! About retina icons I really encourage you to check out this explanation on how to organize them. After you added all the icons you want to the TabBar you should show it in the screen. Then start to place the icons (the order you declare on this function they will get placed) and finally assign a TabBar to be active as the app is fired, just like this:

nativeControls.showTabBar();
nativeControls.showTabBarItems("books", "finished", "about");
nativeControls.selectTabBarItem("books");

If you want you can choose from the pre-defined TabBar icons that Apple include by default on their SDK by using these keywords as the icon item:

  • tabButton:More
  • tabButton:Favorites
  • tabButton:Featured
  • tabButton:TopRated
  • tabButton:Recents
  • tabButton:Contacts
  • tabButton:History
  • tabButton:Bookmarks
  • tabButton:Search
  • tabButton:Downloads
  • tabButton:MostRecent
  • tabButton:MostViewed

Remember that the label will be unusable since these will overwrite it, but you should put something on the label item or it won’t work. I’ve uploaded the full source code to my Gist and you can check it out at Example of NativeControls in PhoneGap. After all this hard work you’re ready to compile your application and test it. If you followed the instructions correctly everything should work. If anything goes wrong please drop us a comment and will be my pleasure to help you. Also leave a comment with your thoughts on this article or suggestions.


Do We Really Need Choices?

My daily use gadgets + my iPhone that was used to take this photo

Disclaimer: If you’re a Android fan boy close this window right now.

I’ve been a truly Android fan boy for 2 years and a Apple hater for 5 years, but this year I did the impossible: Bought an iPad, a Macbook Pro and an iPhone. This acquisitions really changed the way that I saw Android and all the other platforms that I loved. On this article I’ll be talking a bit about the most used argument by Android users to say that their platform is better: Choice. They say that you there are a variety of devices on the market that runs their OS so you can choose the one you like most, also that you can customize Android, flash new ROMs and tweak everything you want of it. While Apple… Yeah, you know how closed they are.

I want to start this sentence by making you deeply think “Do we really need choices?”, I’m sure that if you think really deep on this you will end up in the same point I had. We don’t really need to have choices, all we need is a smartphone that has apps, games, email, phone, etc. (the same principles as the first generation smartphones like my old Nokia E61).

After thinking about this I realized that this got dramatically stronger with tablets. People are buying tablets and don’t even know what they will do with them. When someone asks me which is the best tablet from them I ask “What are you going to use it for?” and everyone is like “Really… I don’t know”. This happens on phones too, people just buy a new phone for no reason. And all this non-sense arrives at choices. No one really want a “different phone”, people just buy the phone that looks cool, don’t matter if it has a 5″ or a 3.5″ screen, if it runs Android, Symbian, Blackberry OS or iOS, they will buy it anyway. Do you really think that “normal persons” (which means people that aren’t tech savvy) will customize their Android phones? Of course not, they won’t install a new launcher, they will only change the wallpaper and add some widgets to the home screen and that’s all!

Apple is doing it right by restricting the users to the same screen size/ratio and keeping the design of their hardware and software almost the same since the first generations of their devices (this includes iPods, iPhones and Macs) is the best way to go. A great example of this on Android is the Nexus lineup, the “pure Google experience”. Those devices get the updates first and have the interface that Google originally made (which means no skins on top of it, just pure vanilla), just because they “locked” the user options into one line of (geeky) products that they can easily manage, which leads to the biggest problem that Android has today: Fragmentation.

All these “choices” are leading to awful experience on the software side and on the developer side. An example of the user experience side is that Dead Space works on the Verizon Galaxy Nexus, but it won’t on the GSM version, don’t forget that we are talking about a Nexus phone, which should be the less-fragmented experience possible. On the developer side it’s very very awful because you must design your app to work on all the different screen sizes/ratios, hardware and also skins that companies love to put on their devices.

If you’re a gadget freak, like me, that buys a lot of devices, you might have already felt the same as I’ve described on this article. We don’t need more choices, we need more standards.

This is an old article from my old blog that I moved to here


Apps I Can't Live a Day Without (Android Edition)

This is the first article of a series I’ll be doing. Here I’m going to list the apps I can’t live a day without, in the various platforms I use on a daily basis.

I decided to start with iOS, which is the one I like most in the phone category, that’s why I always carry my iPhone with me: Apps. But then I choose to start with Android because in my opnion it’s a more productivity OS, also I’m  writing this article on my Eee Pad Slider using Google Docs.

Let me begin by listing the Android devices I own and use every day:

  • ASUS Eee Pad Slider
  • Samsung Galaxy Tab (the original 7" version)
  • Samsung Galaxy S

I also have a Motorola Milestone (aka OG Droid) which I only use to test the apps I develop for Android. So I think it doesn’t count as one of my daily drivers. Now let’s begin with the app list:

Google Music
The best way to listen to my library whenever I go. It syncs my iTunes library with all my devices using the awesome Google cloud and albums that I like most and want to enjoy don’t matter if I have a internet connection, with a single tap and they get downloaded to my device so can be played offline. With a stuning UI and great features it’s by far the best music player for Android in my opinion. If you don’t want the cloud features you can check out DoubleTwist which a great alternative for people that just want their music on the device.

Gaug.es
In my opinion the best analytics service available. It’s simpler than Google Analytics and everything happens in real-time. The app shows all the information you can have on the desktop version and also lets you have the awesome AirTraffic Live feature that shows you in real-time, on a map, the detailed traffic on your site. Since I love to check out every second how my sites are performing I can’t live without it for a day.

Wunderlist
This is just the best task manager app ever invented. With a set of apps for every platform you can imagine from desktops to mobile devices. I use it to manage all the tasks I have to finish regarding my projects and keep them all synced across my devices. Definetly a must-have app for people that must be productive.

Google Docs
The most important app on my Eee Pad Slider. Everyone knows this app, if doesn’t know at least the service you should know. I use it on a daily basis to write my articles and long texts for work or school. I stoped using any office suite, this includes iWork and Microsoft Office, after switching to Docs last year. Don’t matter where I go I can view and edit any document I want.

Read it Later
I choose it instead of Instapaper because of the official support for Android and iOS. I love this app because I can keep all the articles I want to read offline and synced. Really a must-have for people that like to read a lot of articles on a day.


That’s it, if you have any other app you think is awesome please share on the comments.