Credits: http://betterandroid.wordpress.com. The following code is borrowed from LiveFolders sample code from betterandroid site listed previously
satya - Tuesday, April 21, 2009 2:41:36 PM
manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.betterandroid.livefolder"
android:versionCode="3"
android:versionName="1.2">
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher_contacts_phones">
<activity android:name=".Contacts"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- LIVE FOLDERS -->
<activity
android:name=".ContactsLiveFolders$AllContacts"
android:label="@string/liveFolderAll"
android:icon="@drawable/ic_launcher_contacts">
<intent-filter>
<action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ContactsLiveFolders$FavoriteContacts"
android:label="@string/liveFolderFavorites"
android:icon="@drawable/ic_launcher_contacts_starred">
<intent-filter>
<action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<provider android:authorities="com.betterandroid.openhome.livefolder.contacts"
android:multiprocess="true"
android:name="ContactsProvider" />
</application>
</manifest>
satya - Tuesday, April 21, 2009 2:42:25 PM
contacts.java
package com.betterandroid.livefolder;
import android.app.Activity;
import android.os.Bundle;
public class Contacts extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
satya - Tuesday, April 21, 2009 2:43:35 PM
ContactsLiveFolders
package com.betterandroid.livefolder;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.LiveFolders;
public class ContactsLiveFolders {
public static class FavoriteContacts extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
final String action = intent.getAction();
if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
setResult(RESULT_OK, createLiveFolder(this, ContactsProvider.FAVORITES_URI,
getString(R.string.liveFolder_favorites_label),
R.drawable.ic_launcher_contacts_starred));
} else {
setResult(RESULT_CANCELED);
}
finish();
}
}
public static class AllContacts extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
final String action = intent.getAction();
if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
setResult(RESULT_OK, createLiveFolder(this, ContactsProvider.CONTACTS_URI,
getString(R.string.liveFolder_all_label),
R.drawable.ic_launcher_contacts));
} else {
setResult(RESULT_CANCELED);
}
finish();
}
}
private static Intent createLiveFolder(Context context, Uri uri, String name,
int icon) {
final Intent intent = new Intent();
intent.setData(uri);
intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, name);
intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,
Intent.ShortcutIconResource.fromContext(context, icon));
intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);
return intent;
}
}
satya - Tuesday, April 21, 2009 2:44:39 PM
ContactsProvider
package com.betterandroid.livefolder;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.provider.BaseColumns;
import android.provider.LiveFolders;
import android.provider.Contacts.People;
public class ContactsProvider extends ContentProvider {
public static final String AUTHORITY = "com.betterandroid.openhome.livefolder.contacts";
/**
* The content:// style URL for this table
*/
public static final Uri CONTACTS_URI = Uri.parse("content://" +
AUTHORITY + "/contacts" );
public static final Uri FAVORITES_URI = Uri.parse("content://" +
AUTHORITY + "/contacts/favorites" );
private static final int TYPE_ALL = 0;
private static final int TYPE_FAVORITE = 1;
private static final UriMatcher URI_MATCHER;
static{
URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
URI_MATCHER.addURI(AUTHORITY, "contacts", TYPE_ALL);
URI_MATCHER.addURI(AUTHORITY, "contacts/favorites", TYPE_FAVORITE);
}
@Override
public boolean onCreate() {
return true;
}
@Override
public int bulkInsert(Uri arg0, ContentValues[] values) {
return 0; //nothing to insert
}
private static final String[] CURSOR_COLUMNS = new String[]{
BaseColumns._ID, LiveFolders.NAME, LiveFolders.DESCRIPTION, LiveFolders.INTENT, LiveFolders.ICON_PACKAGE, LiveFolders.ICON_RESOURCE
};
private static final String[] CURSOR_ERROR_COLUMNS = new String[]{
BaseColumns._ID, LiveFolders.NAME, LiveFolders.DESCRIPTION};
private static final Object[] ERROR_MESSAGE =
new Object[]{-1, "No contacts found", "Check your contacts database"};
private static MatrixCursor ERROR = new MatrixCursor(CURSOR_ERROR_COLUMNS);
static {
ERROR.addRow(ERROR_MESSAGE);
}
private static final String[] CONTACTS_COLUMN = new String[]{
People._ID, People.DISPLAY_NAME, People.TIMES_CONTACTED, People.STARRED
};
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
int type = URI_MATCHER.match(uri);
if(type == UriMatcher.NO_MATCH){
return ERROR;
}
MatrixCursor mc = new MatrixCursor(CURSOR_COLUMNS);
Cursor allContacts = null;
try {
String filter = type == TYPE_FAVORITE ? People.STARRED +" = 1" : null;
allContacts = getContext().getContentResolver().query(People.CONTENT_URI, CONTACTS_COLUMN, filter, null, People.DISPLAY_NAME);
while(allContacts.moveToNext()){
String contactedDate = "Time contacted: "+allContacts.getInt(2);
boolean isStarred = allContacts.getInt(3) > 0;
mc.addRow(new Object[]{allContacts.getLong(0), allContacts.getString(1), contactedDate,
Uri.parse("content://contacts/people/"+allContacts.getLong(0)),
isStarred ? getContext().getPackageName() : null,
isStarred ? R.drawable.star_on : null
});
}
return mc;
} catch (Exception e) {
return ERROR;
}finally{
allContacts.close();
}
}
@Override
public String getType(Uri uri) {
return getContext().getPackageName(); //not very meaningful
}
public Uri insert(Uri uri, ContentValues initialValues) {
throw new UnsupportedOperationException("no insert");
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
return 0;
}
}
satya - Tuesday, April 21, 2009 2:51:23 PM
Here is the layout file just in case
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:autoLink="all"
android:textSize="20dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="for text see below"
/>
</LinearLayout>
satya - Tuesday, April 21, 2009 2:52:27 PM
here is the text
This is a demostration of the Live Folder feature that is only available in Cupcake. You can download Open Home to try it out. To use go to Open Home, long press the screen and choose Live Folder. For a video demo go to http://betterandroid.wordpress.com