[Android] imeOptions not working on EditText (actionNext, actionDone)

Don’t forget to add

<item name=”android:inputType”>text</item>


<item name=”android:inputType”>textPassword</item>

to your EditText’s style

Directly on XML:



[Android] Raizlabs/DBFlow: Warning:File for type ‘…’ created in the last round will not be subject to annotation processing.

This can be caused by two main reasons:

– Table class with no primary key ( no field is annotated with @Column @PrimaryKey )
– Table class with @Table annotation which does not extend from BaseModel

More log output that could appear:

error: cannot find symbol class <your_class>$Table

in the example it would be

error: cannot find symbol class Ant$Table

[Android] Picasso, resize() vs resizeDimen()

I had trouble changing my resize() calls to resizeDimen(), having icons displaying in different sizes.

As we can see in Picasso’s RequestCreator class , resize() specifies its size in pixels. So:

getResources().getInteger(R.integer.header_logo_w), getResources().getInteger(R.integer.header_logo_h)) 
<?xml version="1.0" encoding="utf-8"?>
 <integer name="header_logo_w">96</integer>
 <integer name="header_logo_h">@integer/header_logo_w</integer>

Is equivalent to the following resizeDimen() call:

.resizeDimen(R.dimen.header_logo_w, R.dimen.header_logo_h)
<?xml version="1.0" encoding="utf-8"?>
<dimen name="header_logo_h">96px</dimen>
<dimen name="header_logo_w">@dimen/header_logo_h</dimen>

[Android SDK] My favorite Android Studio shortcut configuration


CTRL+ “-” / CTRL+ “+”: Collapse / Expand current code region

CTRL+N: generate… (New constructor, getter and setter…)

CTRL+ALT+M: Close All

CTRL+ALT+N: Close All but this (Close others)

CTRL+Shift+T: New terminal Tab (Bottom terminal of Android Studio)


CTRL+F9: Build / Make project

F7: Step into

F8: Step over

F9: Continue


CTRL+Shift+I: auto-indent (also available in Java)

[Android SDK] Fragment getting rotated after camera capture

This has been a painful issue in various devices (specially Samsungs).
After taking a picture, even with the Activity locked to portrait mode, the device was forcing various rotations, destroying the whole Fragment, and all views inside.

The only solution that worked for me was:

 public void onActivityCreated(Bundle savedInstanceState) {
    setRetainInstance(true); // Fixes possible rotations after taking picture with camera


<activity name=".ui.activity.MyCameraActivity" configChanges="screenSize|orientation"/>

Note that MainActivity should be the activity containing the mentioned Fragment on its layout.

Hope it saves time for someone! I wasted several valious hours with this

[Android SDK] Implementing an Image Cache with Picasso

One of the coolest things about Picasso is that you can customize its behavior in a clean and easy way.

One interesting thing that one can find is the image cache.

Before starting, we have to include Picasso. For this example I’m using version 2.5.2. Inside app/build.gradle:

compile 'com.squareup.picasso:picasso:2.5.2'

Now we have to implement our own class implementing Picasso’s Cache interface. It could look like this:

public class CustomCache implements Cache {
  private Context mContext;
  private final File mCacheDir;

public CustomCache(Context mContext) {
  this.mContext = mContext;
  mCacheDir = ((MyApplication)mContext.getApplicationContext()).getPicturesDir();

public Bitmap get(String key) {
  key = String.format("%s.png", transform(key) );
  File f = new File(mCacheDir, key);
  return getBitmapFromFile(f.getAbsolutePath());

public void set(String key, Bitmap bitmap) {
  key = String.format("%s.png", transform(key) );
  File f = new File(mCacheDir, key);
  saveBitmapToFile(bitmap, f.getAbsolutePath());

public int size() {
  String[] children = mCacheDir.list();
  return children != null ? children.length : 0;

public int maxSize() {
  return 100;

public void clear() {
  String[] children = mCacheDir.list();
  for (int i = 0; i < children.length; i++) {
      new File(mCacheDir, children[i]).delete();

public void clearKeyUri(String keyPrefix) {


private String transform(String s) {
   return s.replaceAll("[^A-Za-z0-9]", "");

where getBitmapFromFile() and saveBitmapToFile() could be your regular implementations. At the end of the post i’ll provide two sample implementations for these methods.

The next step is to use Picasso.Builder() to make our global Picasso instance use the previous Cache implementation.

This could go in our Application class, or MainActivity’s onCreate() method:

File cacheDir = ((MyApplication)ctx.getApplicationContext()).getPicturesDir();
Cache cache = new CustomCache(ctx);
Picasso picasso = new Picasso.Builder(ctx)
 .downloader(new OkHttpDownloader(cacheDir))

From now on, when using your Picasso instance like usually:


You’ll have all images cached inside your SD card, in the folder specified by your Cache implementation. So simple, huh?

I hope it’s been helpful for you 🙂

// TODO add getBitmapFromFile(), saveBitmapToFile() :-P

[Android SDK] Non-editable EditText the right way

I’ve wasted plenty of time doing trial-and-error with incorrect solutions for a non-editable EditText. This one works fine on all my devices:


<style name=”NonEditableEditText” parent=”FullW”>
<item name=”android:inputType”>none</item>
<item name=”android:editable”>false</item>

“FullW” just defines layout_width and layout_height properties.

Have a nice coding day! 🙂