diff --git a/animationlib/.gitignore b/animationlib/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6213826ab5439d99a236ed9afd4dfd29dbb199a9 --- /dev/null +++ b/animationlib/.gitignore @@ -0,0 +1,13 @@ +*.iml +.project +.classpath +.project.properties +gen/ +bin/ +.idea/ +.gradle/ +local.properties +gradle/ +build/ +gradlew* +.DS_Store diff --git a/animationlib/build.gradle b/animationlib/build.gradle deleted file mode 100644 index bd5c575e2c542c9d4454edc819c985faa7ac97b9..0000000000000000000000000000000000000000 --- a/animationlib/build.gradle +++ /dev/null @@ -1,43 +0,0 @@ -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' - -android { - namespace = "com.android.app.animation" - testNamespace = "com.android.app.animation.tests" - defaultConfig { - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - sourceSets { - main { - java.srcDirs = ['src'] - res.srcDirs = ['res'] - manifest.srcFile 'AndroidManifest.xml' - } - androidTest { - java.srcDirs = ["tests/src", "tests/robolectric/src"] - manifest.srcFile 'tests/AndroidManifest.xml' - } - } - - lintOptions { - abortOnError false - } - tasks.lint.enabled = false - tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" - } - kotlinOptions { - jvmTarget = '1.8' - freeCompilerArgs = ["-Xjvm-default=all"] - } -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0" - implementation "androidx.core:core-animation:1.0.0-alpha02" - implementation "androidx.core:core-ktx:1.9.0" - androidTestImplementation libs.robolectric - androidTestImplementation "androidx.test.ext:junit:1.1.3" - androidTestImplementation "androidx.test:rules:1.4.0" -} diff --git a/animationlib/build.gradle.kts b/animationlib/build.gradle.kts new file mode 100644 index 0000000000000000000000000000000000000000..4025b81ff6c78bd50a984ee526af800bd9c16dfa --- /dev/null +++ b/animationlib/build.gradle.kts @@ -0,0 +1,37 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin) +} + +android { + namespace = "com.android.app.animation" + compileSdk = 35 + + defaultConfig { + minSdk = 35 + vectorDrawables.useSupportLibrary = true + } + + lint { + abortOnError = true + checkReleaseBuilds = false + } + + sourceSets { + named("main") { + java.srcDirs("src") + res.srcDirs("res") + manifest.srcFile("AndroidManifest.xml") + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } +} + +dependencies { + implementation(libs.androidx.core.animation) + implementation(libs.androidx.core) +} diff --git a/contextualeducationlib/.gitignore b/contextualeducationlib/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6213826ab5439d99a236ed9afd4dfd29dbb199a9 --- /dev/null +++ b/contextualeducationlib/.gitignore @@ -0,0 +1,13 @@ +*.iml +.project +.classpath +.project.properties +gen/ +bin/ +.idea/ +.gradle/ +local.properties +gradle/ +build/ +gradlew* +.DS_Store diff --git a/contextualeducationlib/build.gradle b/contextualeducationlib/build.gradle deleted file mode 100644 index 909304dd566eef62c4c8e23a05a10da3f61e205d..0000000000000000000000000000000000000000 --- a/contextualeducationlib/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -plugins { - id 'com.android.library' - id 'org.jetbrains.kotlin.android' -} -android { - namespace = "com.android.systemui.contextualeducation" - - sourceSets { - main { - java.srcDirs = ['src'] - manifest.srcFile 'AndroidManifest.xml' - } - } -} \ No newline at end of file diff --git a/contextualeducationlib/build.gradle.kts b/contextualeducationlib/build.gradle.kts new file mode 100644 index 0000000000000000000000000000000000000000..ec5ca21da1a5666dac90b9104061d457993d56d1 --- /dev/null +++ b/contextualeducationlib/build.gradle.kts @@ -0,0 +1,35 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin) +} + +android { + namespace = "com.android.systemui.contextualeducation" + compileSdk = 35 + + defaultConfig { + minSdk = 35 + vectorDrawables.useSupportLibrary = true + } + + lint { + abortOnError = true + checkReleaseBuilds = false + } + + sourceSets { + named("main") { + java.srcDirs("src") + manifest.srcFile("AndroidManifest.xml") + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } +} + +dependencies { + implementation(libs.androidx.core) +} diff --git a/iconloaderlib/build.gradle.kts b/iconloaderlib/build.gradle.kts index 26784331315ccf0aedf88ea2760c17447de22094..853bebae912fc014d02fba01031dd4301edfec11 100644 --- a/iconloaderlib/build.gradle.kts +++ b/iconloaderlib/build.gradle.kts @@ -1,20 +1,37 @@ plugins { - id(libs.plugins.android.library.get().pluginId) - id(libs.plugins.kotlin.android.get().pluginId) + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin) } android { namespace = "com.android.launcher3.icons" + compileSdk = 35 + + defaultConfig { + minSdk = 35 + vectorDrawables.useSupportLibrary = true + } + + lint { + abortOnError = true + checkReleaseBuilds = false + } + sourceSets { named("main") { - java.setSrcDirs(listOf("src", "src_full_lib")) + java.srcDirs("src") manifest.srcFile("AndroidManifest.xml") - res.setSrcDirs(listOf("res")) + res.srcDirs("res") } } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } } dependencies { - implementation("androidx.core:core") - api(project(":NexusLauncher.Flags")) + implementation(libs.androidx.core) + implementation(files("${rootDir}/libs/com_android_launcher3_flags_lib.jar")) } diff --git a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java index a42232e3f6d4edd6919865cad070997e28bdc3f1..c100220c9fb163f437ecf59110c6898f58988faa 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java +++ b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java @@ -27,9 +27,12 @@ import android.graphics.Path; import android.graphics.PathMeasure; import android.graphics.Rect; import android.graphics.RectF; +import android.graphics.Typeface; import android.util.Log; import android.view.ViewDebug; +import androidx.core.graphics.ColorUtils; + /** * Used to draw a notification dot on top of an icon. */ @@ -38,27 +41,43 @@ public class DotRenderer { private static final String TAG = "DotRenderer"; // The dot size is defined as a percentage of the app icon size. - private static final float SIZE_PERCENTAGE = 0.228f; + private static final float SIZE_PERCENTAGE = 0.21f; + private static final float SIZE_PERCENTAGE_WITH_COUNT = 0.28f; + private static final float SIZE_PERCENTAGE_WITH_COUNT_TABLET = 0.24f; + + // The max number to draw on dots + private static final int MAX_COUNT = 999; - private final float mCircleRadius; + private float mCircleRadius; private final Paint mCirclePaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); + private final Paint mCircleShadowPaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); + + private final Paint mTextPaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); - private final Bitmap mBackgroundWithShadow; - private final float mBitmapOffset; + private Bitmap mBackgroundWithShadow; + private float mBitmapOffset; // Stores the center x and y position as a percentage (0 to 1) of the icon size private final float[] mRightDotPosition; private final float[] mLeftDotPosition; private static final int MIN_DOT_SIZE = 1; + private final Rect mTextRect = new Rect(); + private boolean mDisplayCount; + public DotRenderer(int iconSizePx, Path iconShapePath, int pathSize) { - int size = Math.round(SIZE_PERCENTAGE * iconSizePx); + this(iconSizePx, iconShapePath, pathSize, false, null, false); + } + + public DotRenderer(int iconSizePx, Path iconShapePath, int pathSize, Boolean displayCount, Typeface typeface, boolean isTablet) { + mDisplayCount = displayCount; + int size = Math.round((displayCount ? (isTablet ? SIZE_PERCENTAGE_WITH_COUNT_TABLET : SIZE_PERCENTAGE_WITH_COUNT) : SIZE_PERCENTAGE) * iconSizePx); if (size <= 0) { size = MIN_DOT_SIZE; } ShadowGenerator.Builder builder = new ShadowGenerator.Builder(Color.TRANSPARENT); builder.ambientShadowAlpha = 88; - mBackgroundWithShadow = builder.setupBlurForSize(size).createPill(size, size); + mBackgroundWithShadow = builder.setupBlurForSize(size).createPill(size, displayCount ? (size - 25) : size); mCircleRadius = builder.radius; mBitmapOffset = -mBackgroundWithShadow.getHeight() * 0.5f; // Same as width. @@ -66,6 +85,10 @@ public class DotRenderer { // Find the points on the path that are closest to the top left and right corners. mLeftDotPosition = getPathPoint(iconShapePath, pathSize, -1); mRightDotPosition = getPathPoint(iconShapePath, pathSize, 1); + + mTextPaint.setTextSize(size * 0.65f); + mTextPaint.setTextAlign(Paint.Align.LEFT); + mTextPaint.setTypeface(typeface); } private static float[] getPathPoint(Path path, float size, float direction) { @@ -101,6 +124,18 @@ public class DotRenderer { * Draw a circle on top of the canvas according to the given params. */ public void draw(Canvas canvas, DrawParams params) { + draw(canvas, params, 0); + } + + /** + * Draw a circle on top of the canvas according to the given params. + */ + public void draw(Canvas canvas, DrawParams params, int numNotifications) { + draw(canvas, params, numNotifications, false, false); + } + + public void draw(Canvas canvas, DrawParams params, int numNotifications, + boolean isTablet, boolean isTaskbar) { if (params == null) { Log.e(TAG, "Invalid null argument(s) passed in call to draw."); return; @@ -114,22 +149,116 @@ public class DotRenderer { // Ensure dot fits entirely in canvas clip bounds. Rect canvasBounds = canvas.getClipBounds(); - float offsetX = params.leftAlign - ? Math.max(0, canvasBounds.left - (dotCenterX + mBitmapOffset)) - : Math.min(0, canvasBounds.right - (dotCenterX - mBitmapOffset)); - float offsetY = Math.max(0, canvasBounds.top - (dotCenterY + mBitmapOffset)); - // We draw the dot relative to its center. - canvas.translate(dotCenterX + offsetX, dotCenterY + offsetY); - canvas.scale(params.scale, params.scale); + if (isTablet) { + // We draw the dot relative to its center. + float availableWidth = (float) (canvasBounds.width() - iconBounds.width()) / 2; + + // We check if the dot is too close to the edge of the screen and nudge it if necessary. + boolean mustNudge = availableWidth < mCircleRadius; + float dx = mustNudge ? mCircleRadius : dotCenterX; + + // Taskbar icons are too small and do not show the dot text. + // We will displace the dot to the correct position. + if (isTaskbar) { + canvas.translate(dotCenterX - mCircleRadius, dotCenterY - mCircleRadius); + } else { + canvas.translate(dx, dotCenterY - 10f); + } + } else { + float offsetX = params.leftAlign + ? Math.max(0, canvasBounds.left - (dotCenterX + mBitmapOffset)) + : Math.min(0, canvasBounds.right - (dotCenterX - mBitmapOffset)); + float offsetY = Math.max(0, canvasBounds.top - (dotCenterY + mBitmapOffset)); + + // We draw the dot relative to its center. + float dx = dotCenterX + offsetX; + float dy = dotCenterY + offsetY - 15f; + + canvas.translate(dx, dy); + } + + float scale = params.scale * (isTablet && !isTaskbar ? 0.75f : 1f); + canvas.scale(scale, scale); - mCirclePaint.setColor(Color.BLACK); - canvas.drawBitmap(mBackgroundWithShadow, mBitmapOffset, mBitmapOffset, mCirclePaint); mCirclePaint.setColor(params.dotColor); - canvas.drawCircle(0, 0, mCircleRadius, mCirclePaint); + mCircleShadowPaint.setColor(params.shadowDotColor); + + if (!isTaskbar) { + drawBadge(canvas, numNotifications, isTablet); + } + + if (mDisplayCount && numNotifications > 0 && !isTaskbar) { + // Draw the numNotifications text + mTextPaint.setColor(getCounterTextColor(Color.WHITE)); + mTextPaint.setTypeface(Typeface.DEFAULT_BOLD); + mTextPaint.setTextSize(32f); + String text = numToNotation(numNotifications); + mTextPaint.getTextBounds(text, 0, text.length(), mTextRect); + float y = mTextRect.height() / 2f - mTextRect.bottom; + canvas.drawText(text, -10f, 21f, mTextPaint); + } + canvas.restore(); } + private void drawBadge(Canvas canvas, int numNotifications, boolean isTablet) { + if (numNotifications < 10) { + float centerY = 9f; + canvas.drawCircle(0, centerY, mCircleRadius, mCircleShadowPaint); + canvas.drawCircle(0, centerY, mCircleRadius, mCirclePaint); + } else { + RectF rect; + if (numNotifications < 100) { + rect = new RectF(-mCircleRadius + 2, -mCircleRadius + 10, mCircleRadius + 17, mCircleRadius + 8); + } else if (numNotifications < 1000) { + float b = (isTablet) ? mCircleRadius + 10: mCircleRadius + 8; + rect = new RectF(-mCircleRadius -2, -mCircleRadius + 10, mCircleRadius + 40, b); + } else if (numNotifications < 9999) { + int tt = (numNotifications/100)*100; + if (tt % 1000 == 0) { // num like 2000,3000,4000 + rect = new RectF(-mCircleRadius + 2, -mCircleRadius + 10, mCircleRadius + 17, mCircleRadius + 8); + } else if (isTablet) { // 999 < num < 10000 + rect = new RectF(-mCircleRadius - 2, -mCircleRadius+ 10, mCircleRadius + 40, mCircleRadius + 10); + } else { + rect = new RectF(-mCircleRadius + 2, -mCircleRadius + 10, mCircleRadius + 45, mCircleRadius + 10); + } + } else { // num >= 10000 + float t = (isTablet) ? -mCircleRadius + 11: -mCircleRadius + 10; + float b = (isTablet) ? mCircleRadius + 11: mCircleRadius + 10; + rect = new RectF(-mCircleRadius + 2, t, mCircleRadius + 45, b); + } + canvas.drawRoundRect(rect, 50, 50, mCircleShadowPaint); + canvas.drawRoundRect(rect, 50, 50, mCirclePaint); + } + } + + private String numToNotation(int num) { + if (num < 1000) { + return String.valueOf(num); + } else if (num < 10000) { + int t = (num/100) * 100; + double v = t / 1000.0; + if (t % 1000 == 0) { + return String.format("%dk", (int)v); + } else { + return String.format("%.1fk", v); + } + } else { + return "10k+"; + } + } + + /** + * Returns the color to use for the counter text based on the dot's background color. + * + * @param dotBackgroundColor The color of the dot background. + * @return The color to use on the counter text. + */ + private int getCounterTextColor(int dotBackgroundColor) { + return ColorUtils.setAlphaComponent(dotBackgroundColor, 0xFF); + } + public static class DrawParams { /** The color (possibly based on the icon) to use for the dot. */ @ViewDebug.ExportedProperty(category = "notification dot", formatToHexString = true) @@ -146,5 +275,7 @@ public class DotRenderer { /** Whether the dot should align to the top left of the icon rather than the top right. */ @ViewDebug.ExportedProperty(category = "notification dot") public boolean leftAlign; + @ViewDebug.ExportedProperty(category = "notification dot", formatToHexString = true) + public int shadowDotColor; } } diff --git a/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java b/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java index 594db358185d6fa9bff0da562319ced668e951fb..80a314aaee7e5b00832e27e006651361218c8264 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java +++ b/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java @@ -71,6 +71,8 @@ public class IconProvider { public static final boolean ATLEAST_T = BuildCompat.isAtLeastT(); private static final String ICON_METADATA_KEY_PREFIX = ".dynamic_icons"; + private static final String MONTH_BG_ICON_METADATA_KEY_PREFIX = ".month_dynamic_icons"; + private static final String DAY_FG_ICON_METADATA_KEY_PREFIX = ".day_dynamic_icons"; private static final String SYSTEM_STATE_SEPARATOR = " "; @@ -207,7 +209,9 @@ public class IconProvider { .metaData; final Resources resources = pm.getResourcesForApplication(mCalendar.getPackageName()); final int id = getDynamicIconId(metadata, resources); - if (id != ID_NULL) { + final int[] monthDayIds = getDynamicBackgroundIconId(metadata, resources); + if (id != ID_NULL && (monthDayIds == null || + monthDayIds[0] == ID_NULL || monthDayIds[1] == ID_NULL )) { if (DEBUG) Log.d(TAG, "Got icon #" + id); Drawable drawable = resources.getDrawableForDensity(id, iconDpi, null /* theme */); if (ATLEAST_T && drawable instanceof AdaptiveIconDrawable && td != null) { @@ -225,6 +229,10 @@ public class IconProvider { } } return drawable; + } else if (monthDayIds != null) { + Drawable background = resources.getDrawableForDensity(monthDayIds[0], iconDpi, null /* theme */); + Drawable foreground = resources.getDrawableForDensity(monthDayIds[1], iconDpi, null /* theme */); + return new AdaptiveIconDrawable(background, foreground); } } catch (PackageManager.NameNotFoundException e) { if (DEBUG) { @@ -268,6 +276,28 @@ public class IconProvider { } } + private int[] getDynamicBackgroundIconId(Bundle metadata, Resources resources) { + if (metadata == null) { + return null; + } + String bgKey = mCalendar.getPackageName() + MONTH_BG_ICON_METADATA_KEY_PREFIX; + String fgKey = mCalendar.getPackageName() + DAY_FG_ICON_METADATA_KEY_PREFIX; + final int bgArrayId = metadata.getInt(bgKey, ID_NULL); + final int fgArrayId = metadata.getInt(fgKey, ID_NULL); + if (bgArrayId == ID_NULL || fgArrayId == ID_NULL) { + return null; + } + try { + return new int[] {resources.obtainTypedArray(bgArrayId).getResourceId(getMonth(), ID_NULL), + resources.obtainTypedArray(fgArrayId).getResourceId(getDay(), ID_NULL)}; + } catch (Resources.NotFoundException e) { + if (DEBUG) { + Log.d(TAG, "package defines '" + bgKey + " and " + fgKey + "' but corresponding array not found"); + } + return null; + } + } + /** * Refreshes the system state definition used to check the validity of an app icon. It * incorporates all the properties that can affect the app icon like the list of enabled locale @@ -285,6 +315,10 @@ public class IconProvider { return Calendar.getInstance().get(Calendar.DAY_OF_MONTH) - 1; } + private static int getMonth() { + return Calendar.getInstance().get(Calendar.MONTH); + } + private static ComponentName parseComponentOrNull(Context context, int resId) { String cn = context.getString(resId); return TextUtils.isEmpty(cn) ? null : ComponentName.unflattenFromString(cn); diff --git a/msdllib/.gitignore b/msdllib/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6213826ab5439d99a236ed9afd4dfd29dbb199a9 --- /dev/null +++ b/msdllib/.gitignore @@ -0,0 +1,13 @@ +*.iml +.project +.classpath +.project.properties +gen/ +bin/ +.idea/ +.gradle/ +local.properties +gradle/ +build/ +gradlew* +.DS_Store diff --git a/msdllib/build.gradle.kts b/msdllib/build.gradle.kts new file mode 100644 index 0000000000000000000000000000000000000000..ec488e8b132d99adff8d173ff2cb47ce25fb9a85 --- /dev/null +++ b/msdllib/build.gradle.kts @@ -0,0 +1,35 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin) +} + +android { + namespace = "com.google.android.msdl" + compileSdk = 35 + + defaultConfig { + minSdk = 35 + vectorDrawables.useSupportLibrary = true + } + + lint { + abortOnError = true + checkReleaseBuilds = false + } + + sourceSets { + named("main") { + java.srcDirs("src") + manifest.srcFile("AndroidManifest.xml") + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } +} + +dependencies { + implementation(libs.androidx.core) +}