展会信息港展会大全

Android Widget桌面时钟
来源:互联网   发布日期:2016-01-14 12:21:54   浏览:1375次  

导读:importjava.util.Date;importandroid.appwidget.AppWidgetManager;importandroid.appwidget.AppWidgetProvider;importandroid.content.Context;importandroid.graphics.Bitmap;importandroid.graphics.BitmapFac......

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

}

}

赞助本站

人工智能实验室

相关热词: Widget 桌面 时钟

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港