android 4.2 动态日历图标功能
来源:互联网 发布:ubuntu配置jdk1.8 编辑:程序博客网 时间:2024/05/13 00:14
添加动态日历图标功能
diff --git a/device/sprd/scx35_sp7731gea/overlay/packages/apps/Calendar/res/mipmap-hdpi/ic_launcher_calendar.png b/device/sprd/scx35_sp7731gea/overlay/packages/apps/Calendar/res/mipmap-hdpi/ic_launcher_calendar.png
index db79b09..9e278b2 100755
Binary files a/device/sprd/scx35_sp7731gea/overlay/packages/apps/Calendar/res/mipmap-hdpi/ic_launcher_calendar.png and b/device/sprd/scx35_sp7731gea/overlay/packages/apps/Calendar/res/mipmap-hdpi/ic_launcher_calendar.png differ
diff --git a/packages/apps/Launcher3/src/com/android/launcher3/IconCache.java b/packages/apps/Launcher3/src/com/android/launcher3/IconCache.java
index 8a07fa9..3bf4e6f 100755
--- a/packages/apps/Launcher3/src/com/android/launcher3/IconCache.java
+++ b/packages/apps/Launcher3/src/com/android/launcher3/IconCache.java
@@ -538,8 +538,13 @@ final int BackGroundDrawId[]={
entry.title = info.activityInfo.name;
}
//更新图标
+ if(info.activityInfo.packageName.equals("com.android.calendar")){
+ entry.icon = Utilities.createCalendarIconBitmap(getFullResIcon(info), mContext);
+ }else{
entry.icon = Utilities.createIconBitmap(
getFullResIcon(info), mContext);
+ }
}
return entry;
}
diff --git a/packages/apps/Launcher3/src/com/android/launcher3/LauncherAppState.java b/packages/apps/Launcher3/src/com/android/launcher3/LauncherAppState.java
old mode 100644
new mode 100755
index d7645f0..b0f189d
--- a/packages/apps/Launcher3/src/com/android/launcher3/LauncherAppState.java
+++ b/packages/apps/Launcher3/src/com/android/launcher3/LauncherAppState.java
@@ -101,6 +101,10 @@ public class LauncherAppState {
filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
+ filter.addAction(Intent.ACTION_TIME_CHANGED);
+ filter.addAction(Intent.ACTION_DATE_CHANGED);
+ filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
sContext.registerReceiver(mModel, filter);
/* SPRD: BugFix bug347797 register shutdown broadcast receiver. @{ */
filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
diff --git a/packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java b/packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java
index 09af49f..59ae00a 100755
--- a/packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java
+++ b/packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java
@@ -1147,7 +1147,13 @@ public class LauncherModel extends BroadcastReceiver {
/* SPRD: BugFix bug347797 If apps can be on external storage, then we don't remove the apps form the DB, when shutdown. @{ */
} else if (Intent.ACTION_SHUTDOWN.equals(action)) {
isBeingShutDown = true;
+ Intent.ACTION_TIME_CHANGED.equals(action) ||
+ Intent.ACTION_TIMEZONE_CHANGED.equals(action)){
+ final String packageName = "com.android.calendar";
+ enqueuePackageUpdated(new PackageUpdatedTask(
+ PackageUpdatedTask.OP_UPDATE, new String[]{packageName}));
+ }
/* SPRD: BugFix bug347797 If apps can be on external storage, then we don't remove the apps form the DB, when shutdown. @} */
}
diff --git a/packages/apps/Launcher3/src/com/android/launcher3/Utilities.java b/packages/apps/Launcher3/src/com/android/launcher3/Utilities.java
old mode 100644
new mode 100755
index 2eeeead..33eb9a5
--- a/packages/apps/Launcher3/src/com/android/launcher3/Utilities.java
+++ b/packages/apps/Launcher3/src/com/android/launcher3/Utilities.java
@@ -39,7 +39,8 @@ import android.view.View;
import android.widget.Toast;
import java.util.ArrayList;
-
+import java.util.Calendar;
+import android.graphics.Typeface;
/**
* Various utilities shared amongst the Launcher's classes.
*/
@@ -177,6 +178,38 @@ final class Utilities {
}
}
+ static Bitmap createCalendarIconBitmap(Drawable icon, Context context){
+ Bitmap calendarIcon = createIconBitmap(icon,context);
+ String dayString = String.valueOf(Calendar.getInstance().get(Calendar.DAY_OF_MONTH)); //获取日期
+
+ synchronized (sCanvas) {
+ final Canvas canvas = sCanvas;
+ canvas.setBitmap(calendarIcon);
+
+ final float mDensity = context.getResources().getDisplayMetrics().density;
+
+ Paint mDatePaint = new Paint();
+ mDatePaint.setTypeface(Typeface.DEFAULT_BOLD);
+ mDatePaint.setTextSize((int)30F * mDensity);
+ mDatePaint.setColor(0xff000000);
+ mDatePaint.setAntiAlias(true);
+
+ Rect rect = new Rect();
+ mDatePaint.getTextBounds(dayString,0,dayString.length(),rect);
+ int hoffset = 20;
+ int width3 = rect.right - rect.left;
+ int height1 = rect.bottom - rect.top;
+ int width4 = calendarIcon.getWidth();
+ int height2 = calendarIcon.getHeight() + hoffset;
+
+ canvas.drawText(dayString,(width4 - width3)/2 - rect.left,(height2 - height1)/2 - rect.top,mDatePaint);
+
+ canvas.setBitmap(null);
+ return calendarIcon;
+ }
+ }
+
/**
* Returns a Bitmap representing the thumbnail of the specified Bitmap.
*
diff --git a/device/sprd/scx35_sp7731gea/overlay/packages/apps/Calendar/res/mipmap-hdpi/ic_launcher_calendar.png b/device/sprd/scx35_sp7731gea/overlay/packages/apps/Calendar/res/mipmap-hdpi/ic_launcher_calendar.png
index db79b09..9e278b2 100755
Binary files a/device/sprd/scx35_sp7731gea/overlay/packages/apps/Calendar/res/mipmap-hdpi/ic_launcher_calendar.png and b/device/sprd/scx35_sp7731gea/overlay/packages/apps/Calendar/res/mipmap-hdpi/ic_launcher_calendar.png differ
diff --git a/packages/apps/Launcher3/src/com/android/launcher3/IconCache.java b/packages/apps/Launcher3/src/com/android/launcher3/IconCache.java
index 8a07fa9..3bf4e6f 100755
--- a/packages/apps/Launcher3/src/com/android/launcher3/IconCache.java
+++ b/packages/apps/Launcher3/src/com/android/launcher3/IconCache.java
@@ -538,8 +538,13 @@ final int BackGroundDrawId[]={
entry.title = info.activityInfo.name;
}
//更新图标
+ if(info.activityInfo.packageName.equals("com.android.calendar")){
+ entry.icon = Utilities.createCalendarIconBitmap(getFullResIcon(info), mContext);
+ }else{
entry.icon = Utilities.createIconBitmap(
getFullResIcon(info), mContext);
+ }
}
return entry;
}
diff --git a/packages/apps/Launcher3/src/com/android/launcher3/LauncherAppState.java b/packages/apps/Launcher3/src/com/android/launcher3/LauncherAppState.java
old mode 100644
new mode 100755
index d7645f0..b0f189d
--- a/packages/apps/Launcher3/src/com/android/launcher3/LauncherAppState.java
+++ b/packages/apps/Launcher3/src/com/android/launcher3/LauncherAppState.java
@@ -101,6 +101,10 @@ public class LauncherAppState {
filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
+ filter.addAction(Intent.ACTION_TIME_CHANGED);
+ filter.addAction(Intent.ACTION_DATE_CHANGED);
+ filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
sContext.registerReceiver(mModel, filter);
/* SPRD: BugFix bug347797 register shutdown broadcast receiver. @{ */
filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
diff --git a/packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java b/packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java
index 09af49f..59ae00a 100755
--- a/packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java
+++ b/packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java
@@ -1147,7 +1147,13 @@ public class LauncherModel extends BroadcastReceiver {
/* SPRD: BugFix bug347797 If apps can be on external storage, then we don't remove the apps form the DB, when shutdown. @{ */
} else if (Intent.ACTION_SHUTDOWN.equals(action)) {
isBeingShutDown = true;
- }
//判断日期是否更新
+ }else if(Intent.ACTION_DATE_CHANGED.equals(action) ||+ Intent.ACTION_TIME_CHANGED.equals(action) ||
+ Intent.ACTION_TIMEZONE_CHANGED.equals(action)){
+ final String packageName = "com.android.calendar";
+ enqueuePackageUpdated(new PackageUpdatedTask(
+ PackageUpdatedTask.OP_UPDATE, new String[]{packageName}));
+ }
/* SPRD: BugFix bug347797 If apps can be on external storage, then we don't remove the apps form the DB, when shutdown. @} */
}
diff --git a/packages/apps/Launcher3/src/com/android/launcher3/Utilities.java b/packages/apps/Launcher3/src/com/android/launcher3/Utilities.java
old mode 100644
new mode 100755
index 2eeeead..33eb9a5
--- a/packages/apps/Launcher3/src/com/android/launcher3/Utilities.java
+++ b/packages/apps/Launcher3/src/com/android/launcher3/Utilities.java
@@ -39,7 +39,8 @@ import android.view.View;
import android.widget.Toast;
import java.util.ArrayList;
-
+import java.util.Calendar;
+import android.graphics.Typeface;
/**
* Various utilities shared amongst the Launcher's classes.
*/
@@ -177,6 +178,38 @@ final class Utilities {
}
}
+ static Bitmap createCalendarIconBitmap(Drawable icon, Context context){
+ Bitmap calendarIcon = createIconBitmap(icon,context);
+ String dayString = String.valueOf(Calendar.getInstance().get(Calendar.DAY_OF_MONTH)); //获取日期
+
+ synchronized (sCanvas) {
+ final Canvas canvas = sCanvas;
+ canvas.setBitmap(calendarIcon);
+
+ final float mDensity = context.getResources().getDisplayMetrics().density;
+
+ Paint mDatePaint = new Paint();
+ mDatePaint.setTypeface(Typeface.DEFAULT_BOLD);
+ mDatePaint.setTextSize((int)30F * mDensity);
+ mDatePaint.setColor(0xff000000);
+ mDatePaint.setAntiAlias(true);
+
+ Rect rect = new Rect();
+ mDatePaint.getTextBounds(dayString,0,dayString.length(),rect);
+ int hoffset = 20;
+ int width3 = rect.right - rect.left;
+ int height1 = rect.bottom - rect.top;
+ int width4 = calendarIcon.getWidth();
+ int height2 = calendarIcon.getHeight() + hoffset;
+
+ canvas.drawText(dayString,(width4 - width3)/2 - rect.left,(height2 - height1)/2 - rect.top,mDatePaint);
+
+ canvas.setBitmap(null);
+ return calendarIcon;
+ }
+ }
+
/**
* Returns a Bitmap representing the thumbnail of the specified Bitmap.
*
0 0
- android 4.2 动态日历图标功能
- android 日历图标显示星期
- Android日历功能
- Android 原生Launcher2中动态刷新日历图标 显示日期与星期
- Android 原生Launcher2中动态刷新日历图标 显示日期与星期
- android 自己实现日历功能
- android launcher 日历图标显示日期
- Android 动态更换图标
- 调用Android自带日历功能
- android方便自定义ui,功能的日历
- Android 自定义日历-实现签到订约功能
- android Notification 图标动态替换
- android 动态改变图标颜色
- Android 动态改变app图标
- Android Launcher 动态icon【时钟】【日历】
- 调用Android自带日历功能(日历列表单、添加一个日历事件)
- 动态日历
- 动态日历
- Web开发中的Filter使用
- 免费的编辑-markdown
- Scrollview
- AutoLayout 中使用 UIScrollView (多个ContentView)
- 头文件 string.h cstring string 区别
- android 4.2 动态日历图标功能
- 容易忽略的meta标签
- iOS中9.0与8.0两个版本通讯录操作(兼容版)
- 个人笔记--img、文件流
- C#的Timer
- leetcode - Create Maximum Number
- Android WebView应用详解
- iOS dispatch队列
- 一个有意思的例子