日历时钟动态更新
BIN
res/drawable-hdpi/com_android_appstore.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
res/drawable-hdpi/com_android_browser.png
Normal file
|
After Width: | Height: | Size: 9.8 KiB |
BIN
res/drawable-hdpi/com_android_calculator2.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
res/drawable-hdpi/com_android_calendar.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
res/drawable-hdpi/com_android_camera.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
res/drawable-hdpi/com_android_clean.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
res/drawable-hdpi/com_android_contacts.png
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
BIN
res/drawable-hdpi/com_android_deskclock.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
res/drawable-hdpi/com_android_dialer.png
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
res/drawable-hdpi/com_android_email.png
Normal file
|
After Width: | Height: | Size: 7.3 KiB |
BIN
res/drawable-hdpi/com_android_fmradio.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
res/drawable-hdpi/com_android_gallery3d_app.png
Normal file
|
After Width: | Height: | Size: 9.0 KiB |
BIN
res/drawable-hdpi/com_android_mms_ui.png
Normal file
|
After Width: | Height: | Size: 8.2 KiB |
BIN
res/drawable-hdpi/com_android_music.png
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
res/drawable-hdpi/com_android_providers_downloads_ui.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
res/drawable-hdpi/com_android_quicksearchbox.png
Normal file
|
After Width: | Height: | Size: 9.2 KiB |
BIN
res/drawable-hdpi/com_android_settings.png
Normal file
|
After Width: | Height: | Size: 8.8 KiB |
BIN
res/drawable-hdpi/com_android_soundrecorder.png
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
BIN
res/drawable-hdpi/com_android_stk_stkmain.png
Normal file
|
After Width: | Height: | Size: 5.1 KiB |
BIN
res/drawable-hdpi/com_android_vdieo.png
Normal file
|
After Width: | Height: | Size: 8.0 KiB |
BIN
res/drawable-hdpi/com_mediatek_filemanager.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
res/drawable-hdpi/com_mediatek_fmradio.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
res/drawable-hdpi/mask.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
res/drawable-hdpi/wallpapers.jpg
Normal file
|
After Width: | Height: | Size: 4.5 MiB |
@@ -40,19 +40,23 @@ import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityOptions;
|
||||
import android.app.WallpaperManager;
|
||||
import android.appwidget.AppWidgetHostView;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentCallbacks2;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.IntentSender;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
@@ -147,6 +151,7 @@ import com.android.uiuios.widget.WidgetsFullSheet;
|
||||
import com.android.uiuios.widget.custom.CustomWidgetParser;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -366,6 +371,17 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
||||
setWorkspaceLoading(true);
|
||||
}
|
||||
|
||||
if (!isDefaultHome()) {
|
||||
setDefaultL();
|
||||
}
|
||||
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
|
||||
int i = sharedPref.getInt("SetWallPaper", 0);
|
||||
if (i == 0) {
|
||||
SetWallPaper();
|
||||
}
|
||||
|
||||
registerTimeReceiver();
|
||||
|
||||
// For handling default keys
|
||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
|
||||
@@ -405,6 +421,94 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
||||
});
|
||||
}
|
||||
|
||||
private void SetWallPaper() {
|
||||
//利用WallpaparManager,添加权限set_wallpaper
|
||||
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
|
||||
try {
|
||||
wallpaperManager.setBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.wallpapers));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("TT", e.getMessage());
|
||||
}
|
||||
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putInt("SetWallPaper", 1);
|
||||
editor.apply();
|
||||
//getSystemService(WALLPAPER_SERVICE)获取wallpaperManager会出问题
|
||||
/* @SuppressLint("ServiceCast")
|
||||
WallpaperManager manager =(WallpaperManager)getSystemService(WALLPAPER_SERVICE);
|
||||
try {
|
||||
manager.setBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.pic1));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
|
||||
public final boolean isDefaultHome() {
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);//Intent.ACTION_VIEW
|
||||
intent.addCategory("android.intent.category.HOME");
|
||||
intent.addCategory("android.intent.category.DEFAULT");
|
||||
PackageManager pm = getPackageManager();
|
||||
ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||
boolean isDefault = getPackageName().equals(info.activityInfo.packageName);
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
private String getHomeLauncher() {
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_HOME);
|
||||
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, 0);
|
||||
String currentHomePackage = resolveInfo.activityInfo.packageName;
|
||||
return currentHomePackage;
|
||||
}
|
||||
|
||||
private void setDefaultL() {
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.addCategory("android.intent.category.HOME");
|
||||
try {
|
||||
intent.setComponent(new ComponentName("android", "com.android.internal.app.ResolverActivity"));
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
intent.setComponent(new ComponentName("com.huawei.android.internal.app", "com.huawei.android.internal.app.HwResolverActivity"));//这个类有些华为手机找不到
|
||||
startActivity(intent);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TimeChangedReceiver mTimeChangedReceiver;
|
||||
|
||||
//监听时间和日期变化
|
||||
public void registerTimeReceiver() {
|
||||
mTimeChangedReceiver = new TimeChangedReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(Intent.ACTION_DATE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIME_TICK);
|
||||
registerReceiver(mTimeChangedReceiver, filter);
|
||||
}
|
||||
|
||||
private class TimeChangedReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_DATE_CHANGED)) {
|
||||
Log.e("fht", "TimeChangedReceiver:" + "data changed");
|
||||
} else if (intent.getAction().equals(Intent.ACTION_TIME_CHANGED)) {
|
||||
Log.e("fht", "TimeChangedReceiver:" + "time changed");
|
||||
} else if (intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) {
|
||||
Log.e("fht", "TimeChangedReceiver:" + "timezone changed");
|
||||
} else if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) {
|
||||
Log.e("fht", "TimeChangedReceiver:" + "time tick");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnterAnimationComplete() {
|
||||
super.onEnterAnimationComplete();
|
||||
|
||||
@@ -92,6 +92,12 @@ public class LauncherAppState {
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
|
||||
|
||||
//时钟日历更新
|
||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
filter.addAction(Intent.ACTION_DATE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIME_TICK);
|
||||
|
||||
if (FeatureFlags.IS_DOGFOOD_BUILD) {
|
||||
filter.addAction(ACTION_FORCE_ROLOAD);
|
||||
|
||||
@@ -273,6 +273,7 @@ public class LauncherModel extends BroadcastReceiver
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (DEBUG_RECEIVER) Log.d(TAG, "onReceive intent=" + intent);
|
||||
Log.e("fht","onReceive intent=" + intent);
|
||||
|
||||
final String action = intent.getAction();
|
||||
if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
|
||||
@@ -303,9 +304,31 @@ public class LauncherModel extends BroadcastReceiver
|
||||
} else if (IS_DOGFOOD_BUILD && ACTION_FORCE_ROLOAD.equals(action)) {
|
||||
Launcher l = (Launcher) getCallback();
|
||||
l.reload();
|
||||
}else if (Intent.ACTION_DATE_CHANGED.equals(action) //日历更新
|
||||
|| Intent.ACTION_TIMEZONE_CHANGED.equals(action)
|
||||
|| Intent.ACTION_TIME_CHANGED.equals(action)) {
|
||||
UserHandle myUser = Process.myUserHandle();
|
||||
changedData(myUser);
|
||||
changedTime(myUser);
|
||||
} else if (Intent.ACTION_TIME_TICK.equals(action)//时钟更新
|
||||
) {
|
||||
UserHandle myUser = Process.myUserHandle();
|
||||
changedTime(myUser);
|
||||
}
|
||||
}
|
||||
|
||||
void changedData(UserHandle user) {
|
||||
final String calendar = "com.android.calendar";
|
||||
enqueueModelUpdateTask(
|
||||
new PackageUpdatedTask(PackageUpdatedTask.OP_UPDATE, user, calendar));
|
||||
}
|
||||
|
||||
void changedTime(UserHandle user) {
|
||||
final String deskclock = "com.android.deskclock";
|
||||
enqueueModelUpdateTask(
|
||||
new PackageUpdatedTask(PackageUpdatedTask.OP_UPDATE, user, deskclock));
|
||||
}
|
||||
|
||||
public void forceReload() {
|
||||
forceReload(-1);
|
||||
}
|
||||
|
||||
221
src/com/android/uiuios/TTUtils/BitmapUtils.java
Normal file
@@ -0,0 +1,221 @@
|
||||
package com.android.uiuios.TTUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.AdaptiveIconDrawable;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.uiuios.R;
|
||||
import com.android.uiuios.Utilities;
|
||||
import com.android.uiuios.icons.LauncherIcons;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class BitmapUtils {
|
||||
public static Drawable getRoundedBitmap(Drawable drawable, Context context) {
|
||||
Bitmap mBitmap= drawable2bitmap(drawable);
|
||||
|
||||
Bitmap bgBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
|
||||
Bitmap mask = BitmapFactory.decodeResource(context.getResources(), R.drawable.mask);
|
||||
int width = mask.getWidth();
|
||||
int height = mask.getHeight();
|
||||
Bitmap bitmapScale = Bitmap.createScaledBitmap(mBitmap, width, height, true);
|
||||
|
||||
// Palette p = Palette.from(mBitmap).generate();
|
||||
// Palette.Swatch vibrant = p.getVibrantSwatch();//有活力的
|
||||
// int color = vibrant.getRgb(); //样本中的像素数量
|
||||
|
||||
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas();
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
canvas.setBitmap(result);
|
||||
// canvas.drawColor(color);
|
||||
canvas.drawBitmap(mask, 0, 0, paint);
|
||||
// paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
canvas.drawBitmap(bitmapScale, 0, 0, paint);
|
||||
// return result;
|
||||
|
||||
Bitmap result2 = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas2 = new Canvas();
|
||||
Paint paint2 = new Paint();
|
||||
paint2.setAntiAlias(true);
|
||||
canvas2.setBitmap(result2);
|
||||
canvas2.drawBitmap(mask, 0, 0, paint2);
|
||||
paint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
canvas2.drawBitmap(result, 0, 0, paint2);
|
||||
return new BitmapDrawable(result2);
|
||||
|
||||
// Canvas mCanvas = new Canvas();
|
||||
// mCanvas.setBitmap(bgBitmap);
|
||||
// Paint mPaint = new Paint();
|
||||
// RectF mRectM = new RectF(scaleM, scaleM, mBitmap.getWidth() - scaleM, mBitmap.getHeight() - scaleM); //设置剪裁圆角的区域
|
||||
// Rect mRect = new Rect(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
|
||||
// RectF mRectF = mRectM;
|
||||
//
|
||||
// float roundPx = 15; //圆角半径
|
||||
// mPaint.setAntiAlias(true);
|
||||
// //Log.d("wy"+TAG,"mBitmap.getWidth()="+mBitmap.getWidth()+", mBitmap.getHeight()="+mBitmap.getHeight());
|
||||
// mCanvas.drawRoundRect(mRectF, roundPx, roundPx, mPaint);
|
||||
// mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
// mCanvas.drawBitmap(mBitmap, mRect, mRect, mPaint);
|
||||
// return bgBitmap;
|
||||
}
|
||||
|
||||
public static Drawable createCalendarIconBitmap(Drawable icon, Context context) {
|
||||
LauncherIcons li = LauncherIcons.obtain(context);
|
||||
|
||||
Bitmap calendarIcon = li.createIconBitmap(icon, 1f);
|
||||
String dayString = String.valueOf(Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
|
||||
String weekString = DateUtils.getWeekDay(System.currentTimeMillis());
|
||||
Canvas sCanvas = new Canvas();
|
||||
synchronized (sCanvas) {
|
||||
sCanvas.setBitmap(calendarIcon);
|
||||
final float mDensity = context.getResources().getDisplayMetrics().density;
|
||||
|
||||
Paint mWeekPaint = new Paint();
|
||||
mWeekPaint.setTypeface(Typeface.SANS_SERIF);
|
||||
mWeekPaint.setTextSize((int) 8F * mDensity);
|
||||
mWeekPaint.setColor(Color.BLACK);
|
||||
mWeekPaint.setAntiAlias(true);
|
||||
|
||||
Rect mWeekRect = new Rect();
|
||||
mWeekPaint.getTextBounds(weekString, 0, weekString.length(), mWeekRect);
|
||||
//通过文字获取矩形的面积
|
||||
int mWeekhoffset = (int) (-34 * mDensity);
|
||||
int mWeekWidth1 = mWeekRect.right - mWeekRect.left;
|
||||
int mWeekHeight1 = mWeekRect.bottom - mWeekRect.top;
|
||||
int mWeekWidth2 = calendarIcon.getWidth();
|
||||
int mWeekHeight2 = calendarIcon.getHeight() + mWeekhoffset;
|
||||
|
||||
sCanvas.drawText(weekString, (mWeekWidth2 - mWeekWidth1) / 2 - mWeekRect.left, (mWeekHeight2 - mWeekHeight1) / 2 - mWeekRect.top, mWeekPaint);
|
||||
|
||||
Paint mDatePaint = new Paint();
|
||||
mDatePaint.setTypeface(Typeface.SANS_SERIF);
|
||||
mDatePaint.setTextSize((int) 25F * mDensity);//文字大小
|
||||
mDatePaint.setColor(0xfffd5872);
|
||||
mDatePaint.setAntiAlias(true);
|
||||
|
||||
Rect rect = new Rect();
|
||||
mDatePaint.getTextBounds(dayString, 0, dayString.length(), rect);
|
||||
//通过文字获取矩形的面积
|
||||
int hoffset = (int) (12 * mDensity);
|
||||
int width1 = rect.right - rect.left;
|
||||
int height1 = rect.bottom - rect.top;
|
||||
int width2 = calendarIcon.getWidth();
|
||||
int height2 = calendarIcon.getHeight() + hoffset;
|
||||
sCanvas.drawText(dayString, (width2 - width1) / 2 - rect.left, (height2 - height1) / 2 - rect.top, mDatePaint);
|
||||
sCanvas.setBitmap(null);
|
||||
return new BitmapDrawable(calendarIcon);
|
||||
}
|
||||
}
|
||||
|
||||
private static Bitmap getBitmap(Context context, int res) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inPreferredConfig = Bitmap.Config.ARGB_4444;
|
||||
return BitmapFactory.decodeResource(context.getResources(), res, options);
|
||||
}
|
||||
|
||||
private static final int DEFAULT_LONG_DEGREE_LENGTH = 10;
|
||||
private static final int DEFAULT_SHORT_DEGREE_LENGTH = 10;
|
||||
|
||||
public static Drawable getDeskClockIcon(Context context) {
|
||||
final float mDensity = context.getResources().getDisplayMetrics().density;
|
||||
|
||||
|
||||
// 添加一个带表盘的背景图
|
||||
Bitmap empty = getBitmap(context, R.drawable.mask);
|
||||
int x = empty.getWidth();
|
||||
int y = empty.getHeight();
|
||||
Bitmap deskClock = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_4444);
|
||||
Canvas canvas = new Canvas(deskClock);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
canvas.drawBitmap(empty, 0, 0, paint);
|
||||
|
||||
//画刻度线
|
||||
float degreeLength = 0f;
|
||||
Paint paintDegree = new Paint();
|
||||
paintDegree.setColor(Color.GRAY);
|
||||
paintDegree.setAntiAlias(true);
|
||||
int width = canvas.getWidth();
|
||||
int hight = canvas.getHeight();
|
||||
int margin = 8;//圆盘的边缘
|
||||
|
||||
for (int i = 0; i < 60; i++) {
|
||||
if (i % 5 == 0) {
|
||||
paintDegree.setStrokeWidth(2 * mDensity);
|
||||
degreeLength = DEFAULT_LONG_DEGREE_LENGTH * mDensity;
|
||||
} else {
|
||||
paintDegree.setStrokeWidth(1 * mDensity);
|
||||
degreeLength = DEFAULT_SHORT_DEGREE_LENGTH * mDensity;
|
||||
}
|
||||
canvas.drawLine(width / 2, Math.abs(width / 2 - hight / 2 - margin * mDensity), width / 2, Math.abs(width / 2 - hight / 2 - margin * mDensity) + degreeLength, paintDegree);
|
||||
canvas.rotate(360 / 60, width / 2, hight / 2);
|
||||
}
|
||||
// 圆心的x y 坐标
|
||||
int cx = x / 2;
|
||||
int cy = y / 2;
|
||||
int radius;
|
||||
int hour = Integer.parseInt(DateUtils.getCurrentHour());
|
||||
int min = Integer.parseInt(DateUtils.getCurrentMin());
|
||||
//设置圆角
|
||||
paint.setStrokeCap(Paint.Cap.ROUND);
|
||||
|
||||
|
||||
//分针的长度
|
||||
radius = (int) (32 * mDensity);
|
||||
paint.setStrokeWidth(3* mDensity);
|
||||
paint.setColor(Color.BLUE);
|
||||
//分针的角度
|
||||
int drgeeMin = min * 6 - 90;
|
||||
if (drgeeMin < 0) {
|
||||
drgeeMin += 360;
|
||||
}
|
||||
//分针 针尖的x y坐标
|
||||
int x1 = (int) (cx + radius * Math.cos(drgeeMin * Math.PI / 180));
|
||||
int y1 = (int) (cy + radius * Math.sin(drgeeMin * Math.PI / 180));
|
||||
canvas.drawLine(x1, y1, cx, cy, paint);
|
||||
|
||||
// paint.setStrokeWidth(6);
|
||||
paint.setColor(Color.RED);
|
||||
// 时针的长度
|
||||
radius = (int) (24 * mDensity);
|
||||
//时针的角度,这里是整点的角度。因为0°是从3点开始,所以这里减90°,从9点开始计算角度
|
||||
int drgeeHour = hour * 30 - 90;
|
||||
if (drgeeHour < 0) {
|
||||
drgeeHour += 360;
|
||||
}
|
||||
// 加上时针在两个整点之间的角度,一分钟在分针上是6°,在时针上是min * 6 / 12
|
||||
drgeeHour += min * 6 / 12;
|
||||
//时针 针尖的x y坐标,相当于已知圆心坐标和半径,求圆上任意一点的坐标
|
||||
int xHour = (int) (cx + radius * Math.cos(drgeeHour * 3.14 / 180));
|
||||
int yHour = (int) (cy + radius * Math.sin(drgeeHour * 3.14 / 180));
|
||||
canvas.drawLine(xHour, yHour, cx, cy, paint);
|
||||
return new BitmapDrawable(deskClock);
|
||||
}
|
||||
|
||||
public static Bitmap drawable2bitmap(Drawable drawable){
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
return ((BitmapDrawable) drawable).getBitmap();
|
||||
} else if (drawable instanceof AdaptiveIconDrawable) {
|
||||
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
drawable.draw(canvas);
|
||||
return bitmap;
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
74
src/com/android/uiuios/TTUtils/DateUtils.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package com.android.uiuios.TTUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class DateUtils {
|
||||
public static String getCurrentDay() {
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd");
|
||||
Long t = new Long(System.currentTimeMillis());
|
||||
String d = format.format(t);
|
||||
return d;
|
||||
}
|
||||
public static String getCurrentSecond() {
|
||||
SimpleDateFormat format = new SimpleDateFormat("ss");
|
||||
Long t = new Long(System.currentTimeMillis());
|
||||
String d = format.format(t);
|
||||
return d;
|
||||
}
|
||||
public static String getCurrentMin() {
|
||||
SimpleDateFormat format = new SimpleDateFormat("mm");
|
||||
Long t = new Long(System.currentTimeMillis());
|
||||
String d = format.format(t);
|
||||
return d;
|
||||
}
|
||||
public static String getCurrentHour() {
|
||||
SimpleDateFormat format = new SimpleDateFormat("HH");
|
||||
Long t = new Long(System.currentTimeMillis());
|
||||
String d = format.format(t);
|
||||
return d;
|
||||
}
|
||||
/**
|
||||
* 根据当前日期获得是星期几
|
||||
* time=yyyy-MM-dd
|
||||
* @return
|
||||
*/
|
||||
public static String getWeekDay(long seconds) {
|
||||
|
||||
Date date = new Date(seconds);
|
||||
String Week = "";
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(date);
|
||||
|
||||
int wek = c.get(Calendar.DAY_OF_WEEK);
|
||||
|
||||
if (wek == 1) {
|
||||
Week += "星期日";
|
||||
}
|
||||
if (wek == 2) {
|
||||
Week += "星期一";
|
||||
}
|
||||
if (wek == 3) {
|
||||
Week += "星期二";
|
||||
}
|
||||
if (wek == 4) {
|
||||
Week += "星期三";
|
||||
}
|
||||
if (wek == 5) {
|
||||
Week += "星期四";
|
||||
}
|
||||
if (wek == 6) {
|
||||
Week += "星期五";
|
||||
}
|
||||
if (wek == 7) {
|
||||
Week += "星期六";
|
||||
}
|
||||
return Week;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -36,6 +36,8 @@ import com.android.uiuios.ItemInfoWithIcon;
|
||||
import com.android.uiuios.LauncherFiles;
|
||||
import com.android.uiuios.LauncherModel;
|
||||
import com.android.uiuios.MainThreadExecutor;
|
||||
import com.android.uiuios.R;
|
||||
import com.android.uiuios.TTUtils.BitmapUtils;
|
||||
import com.android.uiuios.WorkspaceItemInfo;
|
||||
import com.android.uiuios.Utilities;
|
||||
import com.android.uiuios.compat.LauncherAppsCompat;
|
||||
@@ -48,6 +50,8 @@ import com.android.uiuios.model.PackageItemInfo;
|
||||
import com.android.uiuios.util.InstantAppResolver;
|
||||
import com.android.uiuios.util.Preconditions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -226,13 +230,88 @@ public class IconCache extends BaseIconCache {
|
||||
info.contentDescription = entry.contentDescription;
|
||||
info.applyFrom((entry.icon == null) ? getDefaultIcon(info.user) : entry);
|
||||
}
|
||||
private List<String> appClassNameList = new ArrayList<String>() {
|
||||
{
|
||||
this.add("com.android.appstore");//应用市场
|
||||
this.add("com.android.browser.BrowserActivity");//浏览器
|
||||
this.add("com.android.calculator2.Calculator");//计算器
|
||||
this.add("com.android.calendar.AllInOneActivity");//日历
|
||||
this.add("com.android.camera.CameraLauncher");//相机
|
||||
this.add("com.android.contacts.activities.PeopleActivity");//通讯录
|
||||
this.add("com.android.deskclock.DeskClock");//时钟
|
||||
this.add("com.android.dialer.DialtactsActivity");//电话
|
||||
this.add("com.android.gallery3d.app.GalleryActivity");//图库
|
||||
this.add("com.android.mms.ui.BootActivity");//信息
|
||||
this.add("com.android.music.MusicBrowserActivity");//音乐
|
||||
this.add("com.android.providers.downloads.ui.DownloadList");//下载
|
||||
this.add("com.android.documentsui.LauncherActivity");//下载
|
||||
this.add("com.android.quicksearchbox.SearchActivity");//搜索
|
||||
this.add("com.android.settings.Settings");//设置
|
||||
this.add("com.android.soundrecorder.SoundRecorder");//录音机
|
||||
this.add("com.android.stk.StkMain");//sim卡
|
||||
this.add("com.android.vdieo");//视频
|
||||
this.add("com.mediatek.filemanager.FileManagerOperationActivity");//文件管理
|
||||
this.add("com.mediatek.fmradio.FmRadioActivity");//收音机
|
||||
this.add("com.android.fmradio.FmMainActivity");//收音机
|
||||
this.add("com.android.email.activity.Welcome");//电子邮件
|
||||
}
|
||||
};
|
||||
private List<String> appIconList = new ArrayList<String>() {{
|
||||
this.add("com_android_appstore");
|
||||
this.add("com_android_browser");
|
||||
this.add("com_android_calculator2");
|
||||
this.add("com_android_calendar");
|
||||
this.add("com_android_camera");
|
||||
this.add("com_android_contacts");
|
||||
this.add("com_android_deskclock");
|
||||
this.add("com_android_dialer");
|
||||
this.add("com_android_gallery3d_app");
|
||||
this.add("com_android_mms_ui");
|
||||
this.add("com_android_music");
|
||||
this.add("com_android_providers_downloads_ui");
|
||||
this.add("com_android_providers_downloads_ui");
|
||||
this.add("com_android_quicksearchbox");
|
||||
this.add("com_android_settings");
|
||||
this.add("com_android_soundrecorder");
|
||||
this.add("com_android_stk_stkmain");
|
||||
this.add("com_android_vdieo");
|
||||
this.add("com_mediatek_filemanager");
|
||||
this.add("com_android_fmradio");
|
||||
this.add("com_android_fmradio");//收音机
|
||||
this.add("com_android_email");
|
||||
}};
|
||||
|
||||
public Drawable getFullResIcon(LauncherActivityInfo info) {
|
||||
return getFullResIcon(info, true);
|
||||
}
|
||||
|
||||
public Drawable getFullResIcon(LauncherActivityInfo info, boolean flattenDrawable) {
|
||||
return mIconProvider.getIcon(info, mIconDpi, flattenDrawable);
|
||||
//此处修改根据应用包名获取图标
|
||||
Drawable icon = null;
|
||||
if (null != info) {
|
||||
if (appClassNameList.indexOf(info.getComponentName().getClassName()) == -1) {
|
||||
icon = BitmapUtils.getRoundedBitmap(mIconProvider.getIcon(info, mIconDpi, flattenDrawable), mContext);
|
||||
} else {
|
||||
String name = info.getComponentName().getClassName();
|
||||
Log.e("fht", "getDeskClockIcon:"+name);
|
||||
if (name.equals("com.android.calendar.AllInOneActivity")) {
|
||||
icon = BitmapUtils.createCalendarIconBitmap(mContext.getResources().getDrawable(R.drawable.mask), mContext);
|
||||
} else if (name.equals("com.android.deskclock.DeskClock")) {
|
||||
icon = BitmapUtils.getDeskClockIcon(mContext);
|
||||
} else {
|
||||
int i = appClassNameList.indexOf(name);
|
||||
String val = appIconList.get(i);
|
||||
int resID = mContext.getResources().getIdentifier(val, "drawable", "com.android.uiuios");
|
||||
if (resID == 0) {
|
||||
icon = mIconProvider.getIcon(info, mIconDpi, flattenDrawable);
|
||||
} else {
|
||||
icon = mContext.getResources().getDrawable(resID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// return mIconProvider.getIcon(info, mIconDpi, flattenDrawable);
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||