VKontakte for Android is here!

How to create calendar event with specific repetition rule

Just a quick note how to set specific repetition rule when creating new calendar event. I haven’t found any documentation about this and had to inspect platform code.

Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", date);
intent.putExtra("allDay", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", date);
intent.putExtra("title", summary);

date (long) is time in ms
allDay means “all day event”
rrule is the repetition rule in specific format (RFC 2445). In my example “FREQ=YEARLY” means yearly repetition.

//DL

Android mini collectibles

Damn! Tried to order it yesterday… but with no success(( It seems we should wait for another couple month…

http://android-shop.deadzebra.com/

Androids I miss you! )

How weight in LinearLayout works

This post is just a quick review of LinearLayout weight attribute.
Here’re a few things:

  1. If you want to divide the space equally between Views with the same weight – set 0dp as Views’ width
  2. If you set View width to wrap_content – size of the Views will depend on weight and content inside each View

hope it will help you to better understand LinearLayout weight idea.

//DL

HowTo: ListView, Adapter, getView and different list items’ layouts in one ListView

I was surprised that getViewTypeCount() is so rarely overrided (codesearch). If you are an expert in this – this post is not for you:-)

ListView and Adapter Basics

How it works:

  1. ListView asks adapter “give me a view” (getView) for each item of the list
  2. A new View is returned and displayed

Next question – what if we have one billion items? Create new view for each item? The answer is NO:-) Android caches views for you.

There’s a component in Android called “Recycler”. I drawed a picture based on Romain Guy presentation at Google IO ‘09.

  1. If you have 1 billion items – there are only visible items in the memory + view in recycler.
  2. ListView asks for a view type1 first time (getView) x visible items. convertView is null in getView – you create new view of type1 and return it.
  3. ListView asks for a view type1 when one item1 is outside of the window and new item the same type is comming from the bottom. convertView is not null = item1. You should just set new data and return convertView back. No need to create view again.

Let’s write a simple code and put System.out to the getView:

Read the rest of this entry »

New WordPress for Android

image

Just checking new official wordpress Android application)

http://android.wordpress.org/

WebView strange behavior in 1.5

If you are developing the app compatible with 1.5 that has WebView within – please pay attention!

Function loadData and loadDataWithBaseURL behave differently.

If you have special characters in your String – loadData will fail in 1.5. You will get something like “the page cannot be displayed… blablabla… data:text/html;utf-8,%3Chtml%3E%3Cbody…” (http://code.google.com/p/android/issues/detail?id=4401)

so instead of using:

webView.loadData(mData, "text/html", "utf-8");

just use:

webView.loadDataWithBaseURL(null, mData, "text/html", "utf-8", null);

loadData sends LOAD_URL message to the WebViewCore, as opposed to loadDataWithBaseURL that uses LOAD_DATA.

In version 1.6 LOAD_URL behavior was changed – now it handles special characters correctly.

Android 1.6: strange things happen with UI

For some reason I had the complex layout:

<LinearLayout
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
..
<FrameLayout
	android:layout_height="fill_parent"
	android:layout_width="fill_parent"
...
<ListView
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"

ListView scroll worked perfectly on 1.5 and 1.6. At some point of time layout was changed to:

<LinearLayout
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
..
<FrameLayout
	android:layout_height="wrap_content"
	android:layout_weight="1"
	android:layout_width="fill_parent"
...
<ListView
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"

and performance decreased dramatically on 1.6 (looks like x10 worse)… same layout works fine on 1.5. It took me a day to find this problem out.

be careful with layouts!

ldpi/hdpi layout folders and Android 1.5

There’s a problem if you develop platform-independent solution. If you have two folders like layout-land and layout-land-ldpi – Android 1.5 takes files from layout-land-ldpi folder. To avoid this just add v4 to the folder name like layout-land-ldpi-v4.

Please make sure that you have correct versions in you AndroidManifest.xml:

<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4" />

Android perfect UI: fighting with dithering

Everyone who tries to use gradients in the images on mobile device comes to the problem: how to make gradients look nicely? The answer is simple – dithering.

I will try to give some tips here about dithering images for Android devices. This is updated version of my previous post about dithering.

First of all you can make dithering in 2 ways:

  1. Dither images from the code or XML on the fly
  2. Pre-dither images in image editor software

Dither images from code

Let’s consider an example: you are trying to make a perfect button for your perfect UI.
You made a superb sketch in (let’s say photoshop) and want to transfer it to your G1 device. In the image editor software the button looks nice:

original button in photoshop

Then try to insert it to the Android Activity layout as ImageView with android:src.

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/b1" />

android - no dither

It looks… horrible isn’t it? Let’s try to apply dithering from XML.

Read the rest of this entry »

←Older