I want to develop an widget application in which i want to do some rotate animation of the image view i am confused with with widget provider class i am trying but i am unable to do it if any body don please solve my problem. I am posting my code completely
public class Widget extends AppWidgetProvider{
String act;
private Handler start_handler ;
private AnimationDrawable analogClockBee_anim = null;
private ImageView clock4_bee_Image = null;
private Animation animation_bee = null;
RemoteViews myViews;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onReceive(context, intent);
act=intent.getAction();
animation_bee = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation_bee.setRepeatCount(-1);
animation_bee.setDuration(35000);
animation_bee.setInterpolator(context, android.R.anim.linear_interpolator);
// clock4_bee_Image = (ImageView) findViewById(R.id.clock_bee_rotate_anim);
clock4_bee_Image.setBackgroundResource(R.drawable.bee_animation);
analogClockBee_anim = (AnimationDrawable)clock4_bee_Image.getBackground();
if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(act)) {
myViews=new RemoteViews(context.getPackageName(), R.layout.widget);
AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_ID), myViews);
}
myViews.setImageViewResource(R.id.clock_bee_rotate_anim, R.layout.widget);
start_handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
// TODO Auto-generated method stub
super.handleMessage(msg);
if(msg.what == 0)
{
analogClockBee_anim.start();
clock4_bee_Image.startAnimation(animation_bee);
}
}
};
new Thread(new Runnable()
{
@Override
public void run()
{
// TODO Auto-generated method stub
try {
Thread.sleep(500);
Log.i("inside handler", "5");
start_handler.sendEmptyMessage(0);
Log.i("inside handler", "6");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
}
my manifest code
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name=".Widget" android:label="My Custom Clock Widget">
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget" />
</receiver>
</application>
</manifest>
rotate animation in anim folder
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:interpolator="@android:anim/linear_interpolator"
>
<translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="350"/>
</set>
animation drawable folder xml file
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bee_anim"
android:oneshot="false">
<item android:drawable="@drawable/bee_0" android:duration="50" />
<item android:drawable="@drawable/bee_1" android:duration="50" />
<item android:drawable="@drawable/bee_2" android:duration="50" />
<item android:drawable="@drawable/bee_3" android:duration="50" />
<item android:drawable="@drawable/bee_4" android:duration="50" />
<item android:drawable="@drawable/bee_5" android:duration="50" />
<item android:drawable="@drawable/bee_6" android:duration="50" />
<item android:drawable="@drawable/bee_7" android:duration="50" />
<item android:drawable="@drawable/bee_8" android:duration="50" />
<item android:drawable="@drawable/bee_9" android:duration="50" />
</animation-list>
manifest referred xml file app widget provider
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dp"
android:minHeight="146dp"
android:updatePeriodMillis="0"
android:initialLayout="@layout/widget"/>
layout widget xml file which contain analog clock widget and image view to be animated
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/Widget"
android:gravity="center" >
<AnalogClock
android:id="@+id/analogClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hand_hour="@drawable/clock_4_hour"
android:hand_minute="@drawable/clock_4_min"
android:dial="@drawable/clock_4_bg"/>
<ImageView
android:id="@+id/clock_bee_rotate_anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/analogClock1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="52dp"
android:background="@drawable/bee_0" />
</RelativeLayout>
please some one solve my problem i have strucked in this problem.thanks in advance