android widget桌面时钟

import java.util.Date; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.util.Log; import android.widget.RemoteViews; public class TimeWidgetProvider extends AppWidgetProvider { private final String TAG="TimeWidgetProvider"; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { RemoteViews updateViews = new RemoteViews(context.getPackageName(),R.layout.main); Date dates=new Date(); int hour=dates.getHours()+8; int min=dates.getMinutes(); int sec=dates.getSeconds(); Log.v(TAG, "sec="+sec); updateViews.setImageViewBitmap(R.id.im2, getBitmap(context , hour, R.drawable.appwidget_clock_hour)); updateViews.setImageViewBitmap(R.id.im3, getBitmap(context , min, R.drawable.appwidget_clock_minute)); updateViews.setImageViewBitmap(R.id.im4, getBitmap(context , sec, R.drawable.appwidget_clock_minute)); //updateViews.setImageViewResource(R.id.im1, R.drawable.appwidget_clock_dial); appWidgetManager.updateAppWidget(appWidgetIds, updateViews); super.onUpdate(context, appWidgetManager, appWidgetIds); } private Bitmap getBitmap(Context context , int angle, int id){ // 加载需要操作的图片,这里是eoeAndroid的logo图片 Bitmap bitmapOrg = BitmapFactory.decodeResource(context.getResources(), id); //获取这个图片的宽和高 int width = bitmapOrg.getWidth(); int height = bitmapOrg.getHeight(); Log.v(TAG, "width="+width); Log.v(TAG, "height="+height); Log.v(TAG, "angle="+angle); // bitmapOrg.ge // 创建操作图片用的matrix对象 Matrix matrix = new Matrix(); //旋转图片 动作 matrix.postRotate(360/12*angle); // 创建新的图片 Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); return resizedBitmap; } private Bitmap getBitmaps(Context context,int angle,int id){ Bitmap bitmapOrg=BitmapFactory.decodeResource(context.getResources(),id); int width=bitmapOrg.getWidth(); int height=bitmapOrg.getHeight(); Matrix matrix=new Matrix(); matrix.postRotate(360/60*angle); Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); return resizedBitmap; } private Bitmap getBitmapss(Context context,int angle,int id){ Bitmap bitmapOrg=BitmapFactory.decodeResource(context.getResources(), id); int width=bitmapOrg.getWidth(); int height=bitmapOrg.getHeight(); Matrix matrix=new Matrix(); matrix.postRotate(360/60*angle); Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); return resizedBitmap; } @Override public void onEnabled(Context context) { // TODO Auto-generated method stub super.onEnabled(context); Log.v("TAG", "onEnabled"); } }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值