Category Archives: Android

Errors running builder ‘Android Pre Compiler’ on project

If you have this error

Errors running builder ‘Android Pre Compiler’ on project ‘XXX’

Than you might be running ADT 21
This is one possible workaround until the fix
  • Open properties of project in Eclipse
  • Then Resources -> Resource filters. Click the “Add…” button -> Check “Exclude all”, “Files and folders”, “All children”.
  • In the text entry box input “.svn” (without quotes).
  • Restart Eclipse.
Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Eclipse fix black toolip in Ubuntu 12.04+

After Install Ubuntu 12.04 I’ve realize that in Eclipse tooltips were with a black background. After a little googling I’ve found the solution.

Edit file /usr/share/themes/Ambiance/gtk-2.0/gtkrc
This file is used by theme Ambiance in ubuntu. If you use another theme you will have a diferent file path. Note themes are instaled here /usr/share/themes
After edit this file locate in the first lines:
tooltip_fg_color
tooltip_bg_color
These are the foreground and background colors of tooltips. Change the color to the values that you like. After a restart you will have the eclipse black tooltip fixed.
Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Alpha numeric input filter

In Android you should know that it’s possible to specify input filters in EditText.
You should also know that it’s possible to create custom input filters. In this post I wil show how to create an Alpha numeric input filter.

First create a class that implements InputFilter

In this class you will have to implement the filter method.

In this method you will have to see if chars in source argument are valid. Every time a char is not valid you will have to return “” and ever time a char is valid you will have to return null.

this is a sample of what should be done:

public class AlphaNumericFilter implements InputFilter {
private Context _context;

public AlphaNumericFilter(Context context) {
this._context = context;
}

@Override
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {

for (int i = start; i < end; i++) {
if (!Character.isLetterOrDigit(source.charAt(i))) {
return “”;
}
}
return null;
}
}

To use it it’s simple.

For a EditText just do this:
this._editText = (EditText) findViewById(R.id.edit_text);
this._editText.setFilters(new InputFilter[]{ new AlphaNumericFilter(MyActivity.this)});

For a EditTextPreference just do this:
this._editText = (EditTextPreference) prefs.findPreference(“edit_text”);
this._editText.getEditText().setFilters(new InputFilter[]{new AlphaNumericFilter(MyPreferenceActivity.this) });;

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

E/OpenGLRenderer(2268): Cannot generate texture from bitmap

After my update to Jelly Bean I’ve stated having this error in my apps:

E/OpenGLRenderer(2268): Cannot generate texture from bitmap
The bad news is that I don’t have any solution
The good news is that I’ve reported this error and it will be addressed in future releases.
UPDATE:
A possible workaround consists in using PNG files instead of GIF files. I’ve tested and it works
In the attachment there is a sample that show the problem.
Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Android Volume Adjust

I’m in a process of restructure one off my apps and one think that I didn’t know until recently is that I can specify in my activity what kind of volume My activity will play. This is useful so that when press key volume up and volume down, I can in fact increase or decrease volume of the media i’m playing.

This is done using the method setVolumeControlStream.
This method accepts one of the following stream types.
AudioManager.STREAM_MUSIC: For media files
AudioManager.STREAM_RING: For ringer volume
AudioManager.STREAM_ALARM: For alarms
AudioManager.STREAM_NOTIFICATION: For notifications
AudioManager.STREAM_SYSTEM: For system volume
AudioManager.STREAM_VOICECALL: for in call volume
In my case my app will reproduce mp3 so I want AudioManager.STREAM_MUSIC.
Additional to setting my stream to music I can also set volume.
This can be done either using setStreamVolume or adjustStreamVolume
Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Google Translator Toolkit

A few weeks ago Google released the Translator Toolkit.

Toolkit

 

This Translator Toolkit is used to translate files from one language to another language, in particular it’s possible to translate Android String.xml file into other languages. In my opinion Google is trying to redeem himself for closing Google Translator API. Why??? My point of view as an Android Developer is simple, developers used the Google API to translate there apps. With that API it was possible to create processed to speed up translations. Since they closed the Google Translator API, developers, like me, start using Bing Translator API.

Now Android developers can stop use Bing and start using the Translator Toolkit. Or many be not…
This is my opinion, Google Translator Toolkit it’s very green and very beta, and misses features that can be optimized using and API.
Missing features:
  • Unable to translate from one language to many languages
    • Google Translator Toolkit, only allow the translation from one language to another.
    • Let’s imagine that I want to translate from English to 40 other languages. It’s a process that might take hours.
  • Unable to recognize string substitution like %s or %1$s
    • As a result sometimes what happens is that the translations becomes % s or % S or  % 1 $ s
  • Takes too much time convert for example to 40 languages
    • It’s much faster create a process that uses Bing Translator API
Beside that It’s better than don’t have nothing.
Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Align RadioButtons in left and right with RadioGroup

Tricky question how to align on RadioButton to the left and another RadioButton to the right using a RadioGroup?

And this is one solution:
    <RadioGroup
    android:layout_width=”fill_parent”
    android:layout_height=”wrap_content”
    android:orientation=”horizontal”>
    <RadioButton
        android:layout_width=”wrap_content”
        android:layout_height=”wrap_content”
        android:layout_weight=”1″
        android:layout_gravity=”center|left”/>
    <RadioButton
        android:layout_width=”wrap_content”
        android:layout_height=”wrap_content”
        android:layout_gravity=”center|right” />
    </RadioGroup>
Basiclly you will need to add to the first RadioButton this:
android:layout_weight=”1″
android:layout_gravity=”center|left”
and add to the second RadioButton this:
android:layout_gravity=”center|right”
Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter