Monday, 29 July 2013

Styling and formatting in xml android file like quotes

Most information about styling and formating text can be found in android doc page:
Formatting and Styling

Escaping apostrophes and quotes
<string name="good_example">"This'll work"</string>
<string name="good_example_2">This\'ll also work</string>
<string name="bad_example">This doesn't work</string>
<string name="bad_example_2">XML encodings don&apos;t work</string>

Formatting strings

In code:

String string = String.format(getString(R.string.welcome_messages), "Mike", 2);

In resources:
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>

Friday, 26 July 2013

Noobroom acc invitation close in 11 days

Noobroom is going close free access to theirs site. In 11 days site will be available only for registered users.

I'm open to send invitation to NoobRoom
PM me for it.

My android app for NoobRoom (shows latest additions) can be found here: Google Play

Thursday, 25 July 2013

Get rid off Failure [INSTALL_FAILED_OLDER_SDK] by gradle

It means your phone/emulator uses older sdk than project.
To fix go to file build.gradle and change min sdk to lower.

 buildscript {  
   repositories {  
   dependencies {  
     classpath ''  
 apply plugin: 'android'  
 dependencies {  
   compile files('libs/android-support-v4.jar')  
 android {  
   compileSdkVersion 17  
   buildToolsVersion "17.0.0"  
   defaultConfig {  
     minSdkVersion 15  
     targetSdkVersion 17  

SimpleDateFormat - How get specific date format from calendar

//Thursday, 25 July
public List<HashMap<String, String>> getCalendarsFormats() {
    Calendar calendar = Calendar.getInstance();
    List<HashMap<String, String>> dates = new ArrayList<HashMap<String, String>>();

    for (int i = 0; i < 4; i++) {
        Calendar tempCalendar = (Calendar) calendar.clone();
        tempCalendar.add(Calendar.DAY_OF_WEEK_IN_MONTH, i);

        HashMap<String, String> tempHash = new HashMap<String, String>();

        SimpleDateFormat formatter1 = new SimpleDateFormat("dd-MM-yyyy");
        String format1 = formatter1.format(tempCalendar.getTime());
        tempHash.put("format1", format1);
        SimpleDateFormat formatter2 = new SimpleDateFormat("EEEE, dd MMMM");
        String format2 = formatter2.format(tempCalendar.getTime());
        tempHash.put("format2", format2);


    return dates;

How listen incoming sms in service

Wednesday, 24 July 2013

How capitalize first letter in string

char[] stringArray = myString.toCharArray();
stringArray[0] = Character.toUpperCase(stringArray[0]);
myString = new String(stringArray);

Obtaining resources by numer of index instead resource id by TypedArray

While using resources as items in you listview or adapter, try store and load it from <_array> tag. You will avoid exceptions in case where apk in specific language has new items and in other not.

Now you can take resource by index, not by specific id.
arr = mCtx.getResources().obtainTypedArray( R.array.art_sounds_url);
mAudioRes = arr.getResourceId( resArrPosition, -1 );