Thursday, July 24, 2014

Support for building apps on API Level 4 in App Inventor - Better Tablet Support

We've been working to take App Inventor out of screen compatibility mode, and that work has now been merged. This hasn't made it to a release yet, but it will soon. We will announce the changes in the forums when this happens.

What does it all mean though?
For starters, App Inventor will not support Android 1.5 (API level 3 - Cupcake) anymore, but we are compiling against Android 1.6 (API level 4 - Donut). We know there aren't a lot of devices out there still working at this level, but the change from level 3 to 4 was a rather large step to take, mainly because of the already mentioned screen compatibility mode.

Up to now, all App Inventor apps would be automatically scaled by the system to make them look the same in all devices, no matter their resolution or screen size. This sounds good, but the effect of this was that most elements would look rather awfully oversized on bigger screens such as tablets.  From now on, the resolution of the device will be used, and apps will look much better in larger screens with higher resolutions. As a drawback, the App Inventor designer will be a bit less in sync with what's actually being rendered on the device, but we've done our best to keep things as smooth as possible. If you find any issues with rendering in the designer please do get in touch with us through the forum.

What other changes have been made?
We have added a check to change from Tablet to Phone preview mode. It basically resizes the viewer so that you can see how the app looks at two different sizes. We are using Nexus sizes as generic here, Nexus4 for phone, and Nexus7 for tablet. As you can see in the screenshot below, we have also added the buttons bar found in most newer devices. The two changes are highlighted in red.


Another big change is that now all sizes for elements are density-independent pixels (DP) instead of hardcoded pixels. You will see a change in the Width and Height boxes in the designer.



The concept of DP is a little hard to grasp. Some people compare it to using percentages for sizes in HTML, but that's not quite correct. This is the definition used in the main Android docs:

Density-independent pixel (dp)

A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple:
px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.

This DesignBytes video by Roman Nurik is a good source of information about the topic:




There is an additional property that has also been added to Images: scaleToFit; checking this box you can make an image fit completely the size of its enclosing area, for instance if you fill the parent in width or height, the image will fit the area (the image will not keep its aspect ratio, so be mindful when using this property).


So, with all these changes, what are the things to watch out for?
Some apps might be affected, especially those using hardcoded sizes in pixels. We have made many tests and the majority show very little differences, but there might still be some differences.
The other thing to watch out for is if you were using any tricks to grab the height and width of the screen to size your elements. Watch out for problems in there and please report whatever you find.

And what's next then? Well, this change opens a number of possibilities for App Inventor apps. We can start thinking about using a targetSDK level now, even providing a property in Screen1 to allow the user to choose which level that is. We could also start thinking about moving to API Level 8 (Froyo) as there are not many devices using a level lower than that. But probably the most important change here is that we can now start using support libraries and think about adding some of the most used design patterns in Android, such as Action Bar, navigation patterns, or even themes.

This is all a bit far ahead, but there's no technical reason stopping us now from working on changes like those. If you want to help with any of these projects, do get in touch through the open source forum. Great times ahead!

Friday, June 20, 2014

Software Engineer / Research position - MIT App Inventor

The MIT App Inventor team is looking for a software engineer with interest in research in education, and, of course, open source.
You can find more information in this thread. If you want to know a little more about what we do, you can keep on reading this blog, or ping me on twitter and I'll be happy to talk to you.

What are you waiting for to apply? do it... now!

Monday, June 2, 2014

Random Hacks of Kindness Boston 2014

The fine folks of the Boston brigade of Code for America have done it again... a fantastic weekend full of hacking, delicious food, and awesome projects!


This was also part of the kickoff of the National Day of Civic Hacking competition, but back to Boston, you can find tons of information in the event's hackpad.

Here though, I'm going to write a little about the project I was involved in, Union Capital Boston. The main idea is to create a system of rewards, similar to the typical restaurant or coffee shop loyalty cards, but in which people accumulate points through good deeds in their communities. This is targeted to individuals and families within lower income brackets, so that they can exchange points for things that can help them make ends meet, such as groceries or travel passes.


On the tech side, the main app is being built on meteor. To be honest, I didn't have a lot of time to form an opinion about how meteor works, but the one thing that took me by surprise is that being a node framework, it has its own package manager, and things are a bit confusing (sometimes you load packages from meteor, sometimes from atmosphere, and there's some support for npm??? dunno, I'm confused!).

I spent most of the Saturday trying to push the meteor app into a Cordova app. After many hours fighting with a few different solutions I found on the net, it turned out that the wifi we were using wouldn't allow two devices to talk to each other; so most of my time was spent trying to fix the unfixable. On Saturday night I arrived home, compiled the app without changing a thing, and it all worked. On Sunday back at GreenTown Labs, it wouldn't work again. In any case, you can check out the app in my github repo at UCapp. The readme file also documents all the research I went through on Saturday, and some failed attempts. You can find the main UC Boston app at Duncan's repo, and a lot more information in our project's hackpad.

It was great to meet new people and see some old friends that I hadn't seen in a while. Looking forward to the next meetup (and hackathon) already!

Wednesday, May 28, 2014

App Inventor 2 - Translation Component

In a previous post I talked about the new Yandex.Translate component that we added to App Inventor 2 about a week ago. In this video you can see how to use it.



Make sure you don't tamper with the Yandex note in the About this App Screen as it is a design requirement stated in the terms of use of the Yandex.Translate service.


Monday, May 26, 2014

Breaking changes for DatePicker in App Inventor 2

We've decided to to push a breaking change to our production server, which is something we very rarely do. The reason was that some Java style thinking leaked into one of the components, the DatePicker.

When I wrote that component I was obviously thinking about something else, and I broke one of the most distinctive abstractions that we use in App Inventor: all our sequences are 1-based and not 0-based. Newcomers to programming find this a lot easier to grasp. Because Java returns month numbers on a 0-based array, I went with that and our Month attribute returned 0 for January and 11 for December.
Because the component has not been out for long, we have decided that it's better to change it now and take the heat than leaving this leaked abstraction hurting our users.

More info in this announcement in the forums, and I've added an annotation to the video and post. This break will only affect you if you are still working on an app that uses this component, or if you want to upgrade an app that you programmed in the last week, and you were using some type of correction to counteract the fact that the sequence was 0-based. Otherwise, it should not affect you (we are hoping this affects to only a few developers).

Apologies for this breaking change; it is something that should never happen (again!).

Saturday, May 24, 2014

Note for developers about the new translation component in App Inventor 2

We have recently added a translation component based on the Yandex.Translate service.

This service needs an API key to work, and as you can imagine, we have not pushed that into the repo. In fact, we cannot circulate that key, so if you are creating your own distribution of App Inventor or simply running your own server from the MIT repository, you will have to add that key to the source code before you compile the system.

This is an easy thing to do; once you have created a Yandex account, you can request a key. After that, paste that key in the component.

  public YandexTranslate(ComponentContainer container) {
    super(container.$form());

    // Set up the Yandex.Translate Tagline in the 'About' screen
    form.setYandexTranslateTagline();

    // TODO (user) To provide users with this component you will need to obtain
    // a key with the Yandex.Translate service at http://api.yandex.com/translate/
    yandexKey = "";
    activity = container.$context();
  }

The place to paste it is in the yandexKey string available in the constructor, as shown in the code above. The instructions in the TODO are rather explicit.

And that would be all if you think that all your users will not generate enough traffic to go over the limits of a particular key. If that is not the case, I would recommend to modify the component to allow your users to add their own keys when creating apps. This is what we do in some other components such as Twitter or FusionTables.

Also note that this component, when being used, adds some information to the About screen in the app:


This is a design requirement that is mandatory to use the service. If you decide to tamper with that, or you have disabled the About screen, I would recommend to find another solution to keep this requirement or you will be breaching the terms of use for the service.

Monday, May 19, 2014

App Inventor 2 Spinner component

A Spinner in Android provides a quick way to choose from a set of options. We have added a Spinner to App Inventor 2, and it's super easy to use. Have a look at the following video to find out how.