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"); } }

android widget桌面时钟_第1张图片

更多相关文章

  1. Android根据不同语言切换图片
  2. Android 图片处理工具类汇总
  3. android里图片下载工具类AsyncImageLoader分析
  4. android 自由缩放图片
  5. android的数据库API操作
  6. android中实现图片的上下移动
  7. android图片压缩并转为base64字符串
  8. android > 图片旋转
  9. android 滚动的缓冲图片

随机推荐

  1. Android中使用imageviewswitcher 实现图
  2. unity发布android流程
  3. Android(安卓)手机关机流程及异常分析
  4. 如何学画素描?简单动物素描画法
  5. q版人物如何绘制?画q版人物步骤教程
  6. 如何快速学习画漫画人物?板绘漫画人物画法
  7. Anaconda下安装Jupyter notebook
  8. UEditorPlus v2.2.0发布 VUE示例支持,图片
  9. 【点量云】浅谈云流送技术原理应用领域
  10. ubuntu20.04禁止自动休眠的几种方式