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

更多相关文章

  1. Android(安卓)图片处理工具类汇总
  2. android 自由缩放图片
  3. android 命令行创建工程
  4. Appcelerator Cloud Push Notification in Android
  5. android的数据库API操作
  6. android中实现图片的上下移动
  7. Android根据URL下载文件保存到SD卡
  8. Appcelerator Cloud Push Notification in Android
  9. android > 获取屏幕分辨率

随机推荐

  1. 基于Xilinx FPGA的高频交易? Aldec公司展
  2. 基于Zynq SoC的D类音频放大器
  3. 合肥市南门小学五(三)班课程表
  4. spring-cloud-alibaba Nacos配置启动
  5. 腾讯计划斥资超百亿收购搜狗,图什么?
  6. 艾伦人工智能研究所发布 AllenNLP 1.0 ,设
  7. “一挖就走”,中芯国际为什么留不住人?
  8. 图神经网络GNN的可解释性问题与解释方法
  9. html制作一张课程表和用户注册表单
  10. 索赔100亿,诉讼费5000万,小i机器人诉苹果侵