“iPhonish” Tabs

Oct 25, 2009

Let me intro­duce my cus­tom tabs recipe: cus­tom tabs lay­out with Radi­oGroup wid­get and hid­den Tab­Wid­get view. Lay­out file can looks like this:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@android:id/tabhost" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <FrameLayout android:id="@android:id/tabcontent"
      android:layout_width="fill_parent" android:layout_height="0dip"
      android:layout_weight="1" android:padding="20dip" android:background="#fff"/>

    <RadioGroup android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:orientation="horizontal"
      android:checkedButton="@+id/first" android:id="@+id/states">
      <RadioButton android:id="@+id/first" android:background="@drawable/button_radio"
        android:width="80dip" android:height="70dip" />
      <RadioButton android:id="@+id/second" android:background="@drawable/button_radio"
        android:width="80dip" android:height="70dip" />
      <RadioButton android:id="@+id/third" android:background="@drawable/button_radio"
        android:width="80dip" android:height="70dip" />
      <RadioButton android:id="@+id/fourth" android:background="@drawable/button_radio"
        android:width="80dip" android:height="70dip" />
    </RadioGroup>

    <TabWidget android:id="@android:id/tabs"
      android:layout_width="fill_parent" android:layout_height="wrap_content"
      android:layout_weight="0" android:visibility="gone" />
  </LinearLayout>
</TabHost>

There is no way to setup but­ton draw­able of RadioBut­ton wid­get in lay­out XML file, so we should do it at Activ­ity cre­ate event:

    private void setupUI() {
        RadioButton rbFirst = (RadioButton) findViewById(R.id.first);
        RadioButton rbSecond = (RadioButton) findViewById(R.id.second);
        RadioButton rbThird = (RadioButton) findViewById(R.id.third);
        RadioButton rbFourth = (RadioButton) findViewById(R.id.fourth);
        rbFirst.setButtonDrawable(R.drawable.ebay);
        rbSecond.setButtonDrawable(R.drawable.flickr);
        rbThird.setButtonDrawable(R.drawable.skype);
        rbFourth.setButtonDrawable(R.drawable.you_tube);
        RadioGroup rg = (RadioGroup) findViewById(R.id.states);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            public void onCheckedChanged(RadioGroup group, final int checkedId) {
                switch (checkedId) {
                case R.id.first:
                    getTabHost().setCurrentTab(0);
                    break;
                case R.id.second:
                    getTabHost().setCurrentTab(1);
                    break;
                case R.id.third:
                    getTabHost().setCurrentTab(2);
                    break;
                case R.id.fourth:
                    getTabHost().setCurrentTab(3);
                    break;
                }
            }
        });
    }

Final result:
tabs

And as usual there are source code and exe­cutable file.

 

SQLite con­tains full-text search mod­ule called FTS3, using this mod­ule you can eas­ily add fast full text search to an Android appli­ca­tion.
First you need to cre­ate vir­tual table:

CREATE VIRTUAL TABLE TableName
    USING FTS3(ColOne TEXT, ColTwo DATETIME)

Your table must con­tains at least 1 TEXT field.
The FTS3 vir­tual table acts like a reg­u­lar table, but you need to man­u­ally main­tain the indexes to keep ref­er­en­tial integrity — you should UPDATE the FTS3 table from time to time.
The full-text query in SQLite looks like this:

SELECT * FROM TableName WHERE ColOne MATCH 'search phrase'

Make sure you use MATCH instead of equals or LIKE to scan a TEXT col­umn in a vir­tual table.
There is a sam­ple appli­ca­tion to demon­strate full-text search in action:
fts3
Down­load full-text search sam­ple appli­ca­tion.

Day 25: Twitter Client

Jul 13, 2009

The appli­ca­tion is a basic Twit­ter client. (Notice that Twit­ter Client stores pass­word at Shared­Pref­er­ence, in the real life appli­ca­tion you should take care about pro­tect­ing sen­si­tive data). Btw, you can fol­low me @bakhtiyor on Twitter.

twitter-client

Appli­ca­tion Twit­ter Client
SDK 1.5r2
Sources (SVN) http://android-30days-apps.googlecode.com/svn/trunk/25day/
Exe­cutable 25day.apk

Related links:

  1. JTwit­ter — Java library for the Twit­ter API
  2. Pret­ty­Time — time for­mat­ting library
  3. Cute Tweet Iconset

Day 24: Rotary Dialer

Jul 10, 2009

The appli­ca­tion is so pop­u­lar now Rotary Dialer. Spe­cial thanks to my friend Elnur for fan­tas­tic graphic work of Rotary Dialer.

rotary-dialer

Appli­ca­tion Rotary Dialer
SDK 1.5r2
Sources (SVN) http://android-30days-apps.googlecode.com/svn/trunk/24day/
Exe­cutable 24day.apk

Day 23: Scottris

Jul 9, 2009

The clone of famous Tetris game.

scottris1

Use left/right/down arrows to move a piece, up arrow (or sin­gle tap) to rotate and cen­ter but­ton (or long tap) to fall. You also can use touch and accelerom­e­ter gestures.

Appli­ca­tion Scot­tris
SDK 1.5r2
Sources (SVN) http://android-30days-apps.googlecode.com/svn/trunk/23day/
Exe­cutable 23day.apk

Related links:

  1. Tetris meets the Java bean

Page optimized by WP Minify WordPress Plugin