I am a new comer. I wants to create a custom clock widget. Firstly I try to rotate one needle. There is no error found. But IMAGEVIEW stands still. I want some help.
thanks in advance.
Here is my widget.java.
thanks in advance.
Here is my widget.java.
Code:
public class widget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 1000);
}
private class MyTime extends TimerTask {
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;
Bitmap bitmap;
private Time mCalendar;
private float mSecond;
private ImageView mMainImg;
public MyTime(Context context, AppWidgetManager appWidgetManager) {
this.appWidgetManager = appWidgetManager;
remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
thisWidget = new ComponentName(context, widget.class);
bitmap = BitmapFactory.decodeResource(context.getResources(),
R.id.imgMinute);
}
@Override
public void run() {
mCalendar =new Time();
onTimeChanged();
rotate(bitmap);
appWidgetManager.updateAppWidget(thisWidget, remoteViews);
}
public void rotate(Bitmap bitmap){
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.preRotate(mSecond * 360.0f);
Bitmap rotaBitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix,
true);
BitmapDrawable bdr = new BitmapDrawable(rotaBitmap);
mMainImg.setImageDrawable(bdr);
}
private void onTimeChanged() {
mCalendar.setToNow();
int second = mCalendar.second;
mSecond= second / 60.0f;
}
}
}