Foxykeep on Androidhttp://android.foxykeep.com Sat, 21 Sep 2013 07:15:35 +0000en-UShourly1http://wordpress.org/?v=3.6How to make professional looking screenshots for your apps — 09/2013 Editionhttp://android.foxykeep.com/news/how-to-make-professional-looking-screenshots-for-your-apps-092013-edition http://android.foxykeep.com/news/how-to-make-professional-looking-screenshots-for-your-apps-092013-edition#commentsSat, 21 Sep 2013 06:47:58 +0000Foxykeephttp://android.foxykeep.com/?p=1070Read more »]]>Cyril Mottier published more than a year ago 2 articles (Creating Professional Looking Screenshots and Doing the Photoshopping) about how to make professional looking screenshots so that your apps are even better when you published them on the Play Store.

These articles are really well written and I recommend that you read them.

They have however one issue — The PSD files given in the articles are a bit outdated now:

They are using a Galaxy Nexus as a base which is not the same ratio as a Nexus 4

(1280 * 720 for the GN versus 1280 * 768 for the N4)

The clock is set to 4:10 (for Jelly Bean 4.1) which was really good a year ago. Now it should be 4:30 (for Jelly Bean MR2 4.3).

So as I was making some nice screenshots tonight for an upcoming app, I’ve updated the PSD so that you can make some up-to-date professional screenshots !

Normally I’d release them under the Beerware licence like all my other projects. But it’s based on Cyril’s work which is available under the Creative Commons BY 3.0 license. So for once it will be available under the Creative Commons BY 3.0 (which is still fairly liberal).

]]>http://android.foxykeep.com/news/how-to-make-professional-looking-screenshots-for-your-apps-092013-edition/feed0Some Gradle Tips for your Android developmenthttp://android.foxykeep.com/dev/some-gradle-tips-for-your-android-development http://android.foxykeep.com/dev/some-gradle-tips-for-your-android-development#commentsFri, 31 May 2013 01:58:42 +0000Foxykeephttp://android.foxykeep.com/?p=1063Read more »]]> As most of you know, Android released the beta of their new IDE called Android Studio (Check the Google I/O session to see why it is so much better that what you are currently using). With it comes the new Android SDK Build System (Same deal, here is the corresponding Google I/O session). It was released a few weeks ago at Google I/O and it’s just awesome. A little more work that the current build system but so much more possibilities offered to us developers :)

The new build system is based on gradle. You can use it partly from Android Studio but as it’s often the case you may have to use it from the command line to do more complex tasks. Here are some tips if you use it from the command line.

For example to compile your project, you have to use gradle assemble. But you can also just write gradle a. As long as there is no other task sharing the part you write after gradle, it will autocomplete it for you.

gradle check can therefore be reduced to gradle ch. You can’t reduce it to gradle c however as there is also gradle clean which also starts with a c

Ok. That’s a good start. But let’s make it even better.

Open a terminal and try the following command$ g(Just a ‘g’, nothing else) You should get the following output:-bash: g: command not foundIf you already have a command called g, you can use gr or gra instead

If that’s the case, go to your .bashrc file and add the following line:alias g='gradle'

Open a new terminal so that the .bashrc is read again with the new line. Now you just have to write g a

In 5 minutes we jumped from gradle assemble to g a

You still want more tips ?! The gradle completion is camelCase based. Which means gradle deviceCheck can be reduced to g dC !

]]>http://android.foxykeep.com/dev/some-gradle-tips-for-your-android-development/feed1ParcelableCodeGeneratorhttp://android.foxykeep.com/projects/parcelablecodegenerator/parcelablecodegenerator http://android.foxykeep.com/projects/parcelablecodegenerator/parcelablecodegenerator#commentsSat, 02 Feb 2013 19:02:13 +0000Foxykeephttp://android.foxykeep.com/?p=1057Read more »]]>If you are used to coding Android applications, there is a good chance that you had to write some Parcelable classes.

A quick reminder about Parcelable : It’s an interface you can implement on your classes. If you do so, you can then store the whole class in a Bundle or as an Intent extra. My webservice library, DataDroid, use Parcelable objects to retrieve the result from the webservices if you don’t use a Database to store your data.

There is one downside with Parcelable … You need to write a LOT of boilerplate to implement the Parcelable interface in your class. And as every good software engineer, I’m lazy :D Which brings us to ParcelableCodeGenerator !!

You can find all the information on its GitHub page, but here is a short explanation :

You clone the repository and import the Java project in Eclipse (or your favorite IDE)

You write a JSON file defining your Parcelable class in the input folder (you can use subfolders to sort your files). Examples are provided to learn the syntax

You run the project as a Java Project

The corresponding classes are “magically” generated in the output folder ready for you to copy them in your project

It’s really easy to use and it’s going to save you a lot of time.

Last important thing : the project license. As all my other projects, it is released under the Beerware license :

You can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.

]]>http://android.foxykeep.com/projects/parcelablecodegenerator/parcelablecodegenerator/feed2DataDroid v2 is available !!!http://android.foxykeep.com/news/datadroid-v2-is-available http://android.foxykeep.com/news/datadroid-v2-is-available#commentsWed, 26 Dec 2012 00:26:37 +0000Foxykeephttp://android.foxykeep.com/?p=1050Read more »]]> The version 2 of DataDroid is finally available !

What’s new ?

A better architecture of the library which reduce a lot the boilerplate the developer has to write (you can check this article to see the difference)

A more robust and easier to use API for your network connections based on HTTPUrlConnection.

New features in the network connection API : HTTP authentication and possibility to disable SSL validation.

Automatic generation of a valid Android User-Agent for your requests

Better management of calling multiple requests at the same time in your Activitiess (It was possible in v1.0 but not easily enough).

The library works with API 8+ now (aka Froyo and future versions) which covers currently 97% of the user base, so it shouldn’t be a problem.

If you want to know how it works and how to use it in your application, go to the DataDroid website and you’ll find all the information you need

]]>http://android.foxykeep.com/news/datadroid-v2-is-available/feed1ContentProviderCodeGenerator or how to create your ContentProviders easilyhttp://android.foxykeep.com/dev/contentprovidercodegenerator-or-how-to-create-your-contentproviders-easily http://android.foxykeep.com/dev/contentprovidercodegenerator-or-how-to-create-your-contentproviders-easily#commentsWed, 26 Sep 2012 05:20:50 +0000Foxykeephttp://android.foxykeep.com/?p=1041Read more »]]>There are multiple ways to store data persistently in Android, like for example the SharedPreferences. One of them is to use a ContentProvider.

A ContentProvider is one of primary building blocks of Android applications, providing content to applications. You can for example use it to open some of your data to other applications. You can also use it to just store your data and not export it to other applications (by setting the flag android:exported="false" in your Android Manifest).

Write your first ContentProvider can be a challenging task as there are a good number of methods to implement and it’s not always clear how to do it. That was one of the reason why I released with DataDroid (my local and remote data management library) some skeletons explaining how to do it by just following a bunch of TODOs to follow.

However you still have a lot of code to write, most of it just being copy/paste all over the classes. And when you start having multiple versions of your ContentProvider with new columns or tables, it begins to be really annoying to have to maintain that…

Which brings us to ContentProviderCodeGenerator !!

Like every lazy software engineer, it was bothering me and so I took/found some time and wrote a code generator ! :)

You can find all the information on its GitHub page, but here is a short explanation :

You clone the repository and import the Java project in Eclipse (or your favorite IDE)

You write a JSON file defining your tables and their columns in the input folder. Examples are provided to learn the syntax

You run the project as a Java Project

All the needed files are “magically” generated in the output folder ready for you to copy them in your project

It’s really easy to use (and if needed I can help you) It makes adding a column or a table so easy it’s not even funny. It just works. (yes I know I just used an Apple slogan on an Android blog) (and if it doesn’t work, I’ll fix it)

Last important thing : the project license. As all my other projects, it is released under the Beerware license :

You can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.

]]>http://android.foxykeep.com/dev/contentprovidercodegenerator-or-how-to-create-your-contentproviders-easily/feed9TimePickerDialog and AM/PM vs 24 Hour formathttp://android.foxykeep.com/dev/timepickerdialog-and-ampm-vs-24-hour-format http://android.foxykeep.com/dev/timepickerdialog-and-ampm-vs-24-hour-format#commentsWed, 29 Aug 2012 23:53:58 +0000Foxykeephttp://android.foxykeep.com/?p=1032Read more »]]>Just a short article to maybe help other people not spend 1 hour searching the web for the answer like I did.

The constructors for DatePickerDialog are pretty much straight-forward. However the one for TimePickerDialog has a small problem :

As you can see in the screenshot above, you need to specify through the is24HourView parameter whether you want to display a time with hours from 0 to 23 (used in France and Germany for example) or you want to display a time with hours from 1 to 12 and also AM/PM selector (used in the USA for example).

The main problem is that I don’t want to choose that in my code. I want it to be linked to the user locale settings like everythink else. I don’t want why it was coded like that but here is how to link this parameter to the user locale :

The method is24HourFormat from DateFormat allows us to retrieve the user setting.

]]>http://android.foxykeep.com/dev/timepickerdialog-and-ampm-vs-24-hour-format/feed1Android + LEGO = Win ?http://android.foxykeep.com/news/android-lego-win http://android.foxykeep.com/news/android-lego-win#commentsMon, 06 Aug 2012 08:10:28 +0000Foxykeephttp://android.foxykeep.com/?p=1020Read more »]]>Update 08/07/2012 : After 24 hours, the project has already reached 2600+. 1/4 of the task is already done ! Now we just need to continue to talk about it so we reached rapidly the 10 000 mark ! :D

For the past years, I have been a developer as well as a huge fan of Android. I also have always played with LEGO (when I was young and even still now)

What if we could combine these 2 worlds ?!

That’s what Marc Young must have been thinking when he started his project !

This project looks awesome with even rotating arms, heads and antennas. And frankly I want one for myself ! :D

There is only one problem… This project is part of the CUUSOO system which is a way for people to present project to LEGO for future creation. And before an idea can be valid, it needs to receive 10 000 votes.

]]>http://android.foxykeep.com/news/android-lego-win/feed1Small issue with ADT 20 and SDK 16 and how to fix ithttp://android.foxykeep.com/dev/small-issue-with-adt-20-and-sdk-16-and-how-to-fix-it http://android.foxykeep.com/dev/small-issue-with-adt-20-and-sdk-16-and-how-to-fix-it#commentsFri, 06 Jul 2012 06:05:07 +0000Foxykeephttp://android.foxykeep.com/?p=1003Read more »]]>The latest version of the Android Developer Tools (ADT) brought a lot of improvements for us developers. Sadly there is a little quirk coming with it too.

If you have a project targeting API 16/Jelly Bean and you are using ADT 20, you might have some problems with the Graphical Layout tool. Instead of displaying the UI, you may end up with the following screen :

The error message is java.util.LinkedHashMap.eldest()Ljava/util/Map$Entry; which is totally clear… or not. By looking inside Eclipse, we can find the corresponding complete Stacktrace :

java.lang.NoSuchMethodError: java.util.LinkedHashMap.eldest()Ljava/util/Map$Entry;
at android.util.LruCache.trimToSize(LruCache.java:206)
at android.util.LruCache.evictAll(LruCache.java:306)
at android.widget.SpellChecker.resetSession(SpellChecker.java:141)
at android.widget.SpellChecker.setLocale(SpellChecker.java:147)
at android.widget.SpellChecker.<init>(SpellChecker.java:112)
at android.widget.Editor.updateSpellCheckSpans(Editor.java:461)
at android.widget.Editor.onAttachedToWindow(Editor.java:212)
at android.widget.TextView.onAttachedToWindow(TextView.java:4455)
at android.view.View.dispatchAttachedToWindow(View.java:11755)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2424)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2424)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2424)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2424)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2424)
at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:37)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:329)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:331)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:372)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1640)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1391)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:1165)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:679)
at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:359)
at org.eclipse.ui.part.MultiPageEditorPart.setActivePage(MultiPageEditorPart.java:1067)

After some research, I found a temporary solution on StackOverflow until this bug is fixed in the next patch of ADT.

The problem seems to be linked to the use of EditText with suggestions in Jelly Bean. On a phone there is no problem but in the Graphical Layout tool it breaks. We have 2 solutions :

Disable the suggestions in the EditText with the inputType textNoSuggestions

It fixes the bug but it prevents the users from using the completion in your app. So let’s forget about it and look at the other solution

Switch the Graphical Layout to a different API (for example ICS/15 which is nearly the same as JB in terms of UI)

To do that, you just need to use the little droid on the top right and switch to 15 as shown in the screenshot below.

And voila ! :)

Update : Xavier Ducrohet (who is working on the ADT tool) replied to my post on Google + and told me that the issue doesn’t come from ADT 20 but from the rendering library of Jelly Bean. So if I understand right, we need to wait for an update of JB to have a fix.

Update 2 : The fix is available in ADT 20.0.1 ! So update the following elements and it will be good :

ADT Plugin in version 20.0.1

Android SDK Tools 20.0.1

Android SDL 16 rev 2

If you don’t see them, clear the cache of the SDK manager in the options

]]>http://android.foxykeep.com/dev/small-issue-with-adt-20-and-sdk-16-and-how-to-fix-it/feed14How to add autocompletion to an EditTexthttp://android.foxykeep.com/dev/how-to-add-autocompletion-to-an-edittext http://android.foxykeep.com/dev/how-to-add-autocompletion-to-an-edittext#commentsThu, 07 Jun 2012 08:01:10 +0000Foxykeephttp://android.foxykeep.com/?p=931Read more »]]>Finally after months and months of saying that I would add development articles to my blog, here is the first one :)

EditText is a component that everybody knows and it is the primary way to get user input in an Android application. What is really less known is its cousin : AutoCompleteTextView. It’s a subclass of EditText that allows you to display possible autocompletions to the user depending on what he/she already entered in the EditText.

This article will focus on how to use this component and how to bind different data sources to provide the completions.

1 – Presentation of AutoCompleteTextView and simple autocompletion

AutoCompleteTextView is used exactly the same way as an EditText in your layouts (as it’s a subclass of EditText). You just need to replace your EditText by an AutoCompleteTextView and this part is done !

Now that our layout is ready, let’s look at the code.

For this first example we are going to use a really simple example (based on the documentation of AutoCompleteTextView class in the Android SDK). The possible autocompletions are going to be a fixed list of countries.

We just have an array of Strings as the data source and we just bind via an ArrayAdapter the list of countries> The component will manage them by itself.

Now let’s look at a little more complex example.

2 – Email autocompletion

Let’s say we have a login screen in our application where the login is an email. An email is quite long and really annoying to type in, especially with a virtual keyboard.

We don’t know all the email addresses the user could potentially have. What we know however from his phone is all the email addresses he/she used as an account (Google, Facebook, Twitter, …). We can use them as a data source to provide completion.

This time instead of using a fixed array of Strings, we load the user accounts through the AccountManager. As some accounts may not have an email address linked to them, we filter them and keep only the ones who matches an email regex. We also use a Set to remove the duplicates. Then we use the same way as before to bind them to the AutoCompleteTextView through an ArrayAdapter.

One thing to know if you want to use this snippet of code as is in your project : it requires the permission android.permission.GET_ACCOUNTS to be able to read the user accounts.

You can use this example with any other data source as long as you manage to get an array of Strings to display.

And here is how it looks :

3 – Webservice autocompletion

For the first 2 examples, we only used static data. Now let’s use dynamic data for the auto-completion. The data is going to be returned from a web service which is going to be called every time the user input changes in the field. For this example, we are going to write the code to add autocompletion to an address field :

As the data is dynamic depending on the current value, we can’t just provide beforehand the list of elements. Instead we create an ArrayAdapter with a special Filter. Everytime the input changes, the performFiltering method is called and we retrieve in it the corresponding values from the webservice. These values are then transfered through the FilterResults object to the publishResults method where we replace the current elements with the new ones.

In our specific case, our webservice is the SDK Geocoder which calls the Maps server to get possible addresses based on input provided by the user. As the result type, Address, is a complex object and we only want to display its formatted address while still keeping the object in the Adapter for further use, we also have to override both getView and convertResultToString methods :

The first one, getView, to choose how to display our special object in the list of possible autocompletions.

convertResultToString is used internally by the AutoCompleteTextView to choose what to display in the EditText field when the user selects one of the completions (in our case, the formatted address).

If the data returned by your webservice is only a String, you don’t need to do that (except if you want a special format, like upper case or something).

One thing to remember, the code in the performFiltering method is executed in a worker thread so we can directly access the webservice (in our case the Geocoder) to get the corresponding results even if it’s a long process.

4 – Conclusion

Normally now you know how to add autocompletion to your applications :)

If you have some questions about it, feel free to comment this article or to contact me via email !

And I have made a small application containing all these examples. Here is the APK and the project source code.

]]>http://android.foxykeep.com/dev/how-to-add-autocompletion-to-an-edittext/feed27How to fix the “NoClassDefFoundError” with ADT 17http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17 http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17#commentsThu, 22 Mar 2012 03:56:40 +0000Foxykeephttp://android.foxykeep.com/?p=899Read more »]]>So I updated my SDK and ADT to version 17 and once again I got a big problem :)

Every project I have which use JAR libraries could still be built without problems but as soon as they start on the phone, they crashed with the following error :

I asked Xavier Ducrohet and Tor Norbye (both working on the ADT plugin) on Google+ about the error and they linked to this page which explains how to solve the problem but is not ultra clear (at least for me).

So here is the same solution but explained with screenshots so we can see more easily what changed :

From left to right, we have :

My project with ADT 16 (the small graphic changes are due to the fact the left image is from Eclipse Windows while the 2 on the right are from Eclipse Mac)

My project with ADT 17 before the fix

My project with ADT 17 after the fix

We can see :

In blue, the changes due to the patch (more info on this at the end of this post)

By doing that, all the libraries in the folder “libs” are found by the Android plugin and are added to the “Android Dependencies” item of the project

Clean the project (not exactly needed)

You are good to go !

This problem is due to the fact that libraries are not managed the same way with the new ADT build. Instead of having 2 different managements of libraries (one for Android Library Projects, one for the standard jars), now both are merged into the Android Dependencies item.

Other info, the annotations.jar file is for the new lint Java annotations (more info here : http://tools.android.com/recent/ignoringlintwarnings) Besides this small problem, the ADT version 17 looks really good and I love the new things added to the lint checks !!

[Update]

The DroidUX Team found another solution to fix the problem. I didn’t test it personally but it don’t see why it shouldn’t work :

Hi,

Just to add to the solution:

If you have references to jars that are not in the ‘libs’ folder, for example if you use ‘classpath variable’, you can resolve the NoClassDefFoundError issue with the new ADT 17 by exporting the references.

To export the references: simply go to “Properties > Java Build Path > Order and Export”, and check all the references you want exported.