Creating Analog clock Widget in Android


Creating Analog clock Widget in Android

Manifest:
<uses-sdk android:minSdkVersion="7" />


<application
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
    <activity
        android:name=".JeethClockActivity"
        android:label="@string/app_name" >
        
    </activity>


    <receiver
        android:name=".WidgetClockClass"
        android:label="CR CLOCK" 
        android:icon="@drawable/icon">>
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/jeethappwidget" />
    </receiver>
</application>

No need of programing in WidgetClockClass.class,
import android.appwidget.AppWidgetProvider;


public class WidgetClockClass extends AppWidgetProvider {


}

Create a folder 'xml' in res folder, then inside that create an xml for appwidget provider,
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 
android:updatePeriodMillis="1000" 
android:minWidth="100dp" 
android:minHeight="100dp" 
android:initialLayout="@layout/clock">
</appwidget-provider>


Then create a layout called clock.xml in layout folder,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical" >


    


    <AnalogClock
        android:id="@+id/analogClock2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


</LinearLayout>

Popular posts from this blog

Shake effect in Android

Example For ListView Using BaseAdapter

Async Task in Android