Hello,
Every One in this google Can any one guide me what i suppose to do wrong in
update the image view of android widget in every one second what can i do
for that ,
Here is code that i use but get error can one solve this ...
public class HelloWidget extends AppWidgetProvider{
Context mContext;
public static final int UPDATE_RATE = 1000;
//public Integer[] mThumbIds = {R.drawable.arrow_s};
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
this.mContext=context;
Timer timer=new Timer();
timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 1000);
// for (int appWidgetId : appWidgetIds) {
// setAlarm(context, appWidgetId, UPDATE_RATE);
// }
}
Bitmap mBitmap2;
ImageView mImageView;
private class MyTime extends TimerTask{
RemoteViews mRemoteViews;
AppWidgetManager mAppWidgetManager;
ComponentName mComponentName;
DateFormat format=SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM,
Locale.getDefault());
public MyTime(Context context,AppWidgetManager appWidgetManager){
this.mAppWidgetManager=appWidgetManager;
mRemoteViews=new RemoteViews(context.getPackageName(), R.layout.main);
mComponentName=new ComponentName(context, HelloWidget.class);
}
@Override
public void run() {
// mBitmap=Bitmap.createBitmap(mBitmap2);
// mImageView=new ImageView(mContext);
//mImageView.setImageResource(mThumbIds[0]);
// mImageView.setImageBitmap(mBitmap2);
mBitmap2=Bitmap.createBitmap(10, 146, Bitmap.Config.ARGB_8888);
mBitmap2=BitmapFactory.decodeResource(mContext.getResources(),R.id.secondhand);
Matrix mat=new Matrix();
mat.postRotate(6, 0.5f, 0.5f);
Bitmap rotate=Bitmap.createBitmap(mBitmap2, 0, 0, mBitmap2.getWidth(),
mBitmap2.getHeight(), mat, true);
I try this but this also not work
// Date dt = new Date();
// int seconds = dt.getSeconds();
// Log.v("log_tag", "seconds" + seconds);
// RotateAnimation rotateAnimation = new RotateAnimation(
// (seconds - 1) * 6, seconds * 6,
// Animation.RELATIVE_TO_SELF, 0.5f,
// Animation.RELATIVE_TO_SELF, 0.5f);
//
// rotateAnimation.setInterpolator(new LinearInterpolator());
// rotateAnimation.setDuration(1000);
// rotateAnimation.setFillAfter(true);
// mImageView.setAnimation(rotateAnimation);
// mBitmap=mImageView.getDrawingCache();
//mRemoteViews.describeContents();
//mRemoteViews.setImageViewResource(R.id.secondhand, R.id.secondextra);
//mRemoteViews.setBitmap(R.id.secondhand, "setImageBitmap",mBitmap2 );
mRemoteViews.setImageViewBitmap(R.id.secondhand, rotate);
// mRemoteViews.setImageViewResource(R.id.secondhand,
R.drawable.widgetdial);
mRemoteViews.setTextViewText(R.id.widget_text, "Time:-"+format.format(new
Date()));
mAppWidgetManager.updateAppWidget(mComponentName,mRemoteViews);
}
}
}
Thanks in Advance for any reply.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en