From 45f17c5bef44a01dcf2295fdf4cbdb95151490d6 Mon Sep 17 00:00:00 2001 From: Dan Sandler Date: Wed, 2 May 2018 20:01:38 -0400 Subject: P is for PAINT. Bug: 109925861 Test: adb shell am start \ -a android.intent.action.MAIN \ -c com.android.internal.category.PLATLOGO Merged-In: Ic3020007c716be264e9523d6dbae9e13a95fa571 Change-Id: Ic3020007c716be264e9523d6dbae9e13a95fa571 --- .../com/android/internal/app/PlatLogoActivity.java | 80 +++- packages/EasterEgg/Android.bp | 33 ++ packages/EasterEgg/Android.mk | 29 -- packages/EasterEgg/AndroidManifest.xml | 93 +---- .../res/color-night/toolbar_icon_color.xml | 20 + .../EasterEgg/res/color/toolbar_icon_color.xml | 20 + packages/EasterEgg/res/drawable/back.xml | 22 -- packages/EasterEgg/res/drawable/belly.xml | 22 -- packages/EasterEgg/res/drawable/body.xml | 22 -- packages/EasterEgg/res/drawable/bowtie.xml | 22 -- packages/EasterEgg/res/drawable/cap.xml | 22 -- packages/EasterEgg/res/drawable/collar.xml | 22 -- packages/EasterEgg/res/drawable/face_spot.xml | 22 -- packages/EasterEgg/res/drawable/food_bits.xml | 33 -- packages/EasterEgg/res/drawable/food_chicken.xml | 39 -- packages/EasterEgg/res/drawable/food_cookie.xml | 35 -- packages/EasterEgg/res/drawable/food_dish.xml | 24 -- packages/EasterEgg/res/drawable/food_donut.xml | 24 -- packages/EasterEgg/res/drawable/food_sysuituna.xml | 24 -- packages/EasterEgg/res/drawable/foot1.xml | 22 -- packages/EasterEgg/res/drawable/foot2.xml | 22 -- packages/EasterEgg/res/drawable/foot3.xml | 22 -- packages/EasterEgg/res/drawable/foot4.xml | 22 -- packages/EasterEgg/res/drawable/head.xml | 22 -- packages/EasterEgg/res/drawable/ic_clear.xml | 27 ++ packages/EasterEgg/res/drawable/ic_close.xml | 24 -- packages/EasterEgg/res/drawable/ic_dropper.xml | 39 ++ packages/EasterEgg/res/drawable/ic_hourglass.xml | 27 ++ packages/EasterEgg/res/drawable/ic_share.xml | 24 -- packages/EasterEgg/res/drawable/icon.xml | 33 +- packages/EasterEgg/res/drawable/icon_bg.xml | 18 + packages/EasterEgg/res/drawable/left_ear.xml | 22 -- .../EasterEgg/res/drawable/left_ear_inside.xml | 22 -- packages/EasterEgg/res/drawable/left_eye.xml | 22 -- packages/EasterEgg/res/drawable/leg1.xml | 22 -- packages/EasterEgg/res/drawable/leg2.xml | 22 -- packages/EasterEgg/res/drawable/leg2_shadow.xml | 22 -- packages/EasterEgg/res/drawable/leg3.xml | 22 -- packages/EasterEgg/res/drawable/leg4.xml | 22 -- packages/EasterEgg/res/drawable/mouth.xml | 27 -- packages/EasterEgg/res/drawable/nose.xml | 22 -- packages/EasterEgg/res/drawable/octo_bg.xml | 8 - packages/EasterEgg/res/drawable/p.xml | 33 ++ packages/EasterEgg/res/drawable/right_ear.xml | 22 -- .../EasterEgg/res/drawable/right_ear_inside.xml | 23 -- packages/EasterEgg/res/drawable/right_eye.xml | 22 -- packages/EasterEgg/res/drawable/stat_icon.xml | 30 -- packages/EasterEgg/res/drawable/tail.xml | 26 -- packages/EasterEgg/res/drawable/tail_cap.xml | 22 -- packages/EasterEgg/res/drawable/tail_shadow.xml | 22 -- packages/EasterEgg/res/drawable/toolbar_bg.xml | 19 + .../EasterEgg/res/drawable/toolbar_button_bg.xml | 25 ++ packages/EasterEgg/res/layout/activity_paint.xml | 48 +++ packages/EasterEgg/res/layout/brushes.xml | 25 ++ packages/EasterEgg/res/layout/cat_view.xml | 82 ---- packages/EasterEgg/res/layout/colors.xml | 26 ++ packages/EasterEgg/res/layout/edit_text.xml | 30 -- packages/EasterEgg/res/layout/food_layout.xml | 31 -- packages/EasterEgg/res/layout/neko_activity.xml | 25 -- packages/EasterEgg/res/layout/toolbar.xml | 111 ++++++ packages/EasterEgg/res/values-night/colors.xml | 21 + packages/EasterEgg/res/values-night/styles.xml | 21 + .../EasterEgg/res/values/attrs_toolbar_view.xml | 19 + packages/EasterEgg/res/values/colors.xml | 21 + packages/EasterEgg/res/values/dimens.xml | 19 - packages/EasterEgg/res/values/strings.xml | 39 +- packages/EasterEgg/res/values/styles.xml | 23 ++ packages/EasterEgg/res/xml/filepaths.xml | 19 - .../EasterEgg/src/com/android/egg/neko/Cat.java | 434 -------------------- .../EasterEgg/src/com/android/egg/neko/Food.java | 60 --- .../android/egg/neko/NekoActivationActivity.java | 57 --- .../src/com/android/egg/neko/NekoDialog.java | 107 ----- .../src/com/android/egg/neko/NekoLand.java | 338 ---------------- .../com/android/egg/neko/NekoLockedActivity.java | 45 --- .../src/com/android/egg/neko/NekoService.java | 165 -------- .../src/com/android/egg/neko/NekoTile.java | 114 ------ .../src/com/android/egg/neko/PrefState.java | 92 ----- .../src/com/android/egg/octo/Ocquarium.java | 89 ----- .../src/com/android/egg/octo/OctopusDrawable.java | 436 --------------------- .../com/android/egg/octo/TaperedPathStroke.java | 55 --- .../com/android/egg/paint/BrushPropertyDrawable.kt | 93 +++++ .../com/android/egg/paint/CutoutAvoidingToolbar.kt | 88 +++++ .../src/com/android/egg/paint/PaintActivity.java | 351 +++++++++++++++++ .../src/com/android/egg/paint/Painting.kt | 358 +++++++++++++++++ .../EasterEgg/src/com/android/egg/paint/Palette.kt | 83 ++++ .../src/com/android/egg/paint/SpotFilter.kt | 124 ++++++ .../src/com/android/egg/paint/ToolbarView.kt | 77 ++++ 87 files changed, 1854 insertions(+), 3259 deletions(-) create mode 100644 packages/EasterEgg/Android.bp delete mode 100644 packages/EasterEgg/Android.mk create mode 100644 packages/EasterEgg/res/color-night/toolbar_icon_color.xml create mode 100644 packages/EasterEgg/res/color/toolbar_icon_color.xml delete mode 100644 packages/EasterEgg/res/drawable/back.xml delete mode 100644 packages/EasterEgg/res/drawable/belly.xml delete mode 100644 packages/EasterEgg/res/drawable/body.xml delete mode 100644 packages/EasterEgg/res/drawable/bowtie.xml delete mode 100644 packages/EasterEgg/res/drawable/cap.xml delete mode 100644 packages/EasterEgg/res/drawable/collar.xml delete mode 100644 packages/EasterEgg/res/drawable/face_spot.xml delete mode 100644 packages/EasterEgg/res/drawable/food_bits.xml delete mode 100644 packages/EasterEgg/res/drawable/food_chicken.xml delete mode 100644 packages/EasterEgg/res/drawable/food_cookie.xml delete mode 100644 packages/EasterEgg/res/drawable/food_dish.xml delete mode 100644 packages/EasterEgg/res/drawable/food_donut.xml delete mode 100644 packages/EasterEgg/res/drawable/food_sysuituna.xml delete mode 100644 packages/EasterEgg/res/drawable/foot1.xml delete mode 100644 packages/EasterEgg/res/drawable/foot2.xml delete mode 100644 packages/EasterEgg/res/drawable/foot3.xml delete mode 100644 packages/EasterEgg/res/drawable/foot4.xml delete mode 100644 packages/EasterEgg/res/drawable/head.xml create mode 100644 packages/EasterEgg/res/drawable/ic_clear.xml delete mode 100644 packages/EasterEgg/res/drawable/ic_close.xml create mode 100644 packages/EasterEgg/res/drawable/ic_dropper.xml create mode 100644 packages/EasterEgg/res/drawable/ic_hourglass.xml delete mode 100644 packages/EasterEgg/res/drawable/ic_share.xml create mode 100644 packages/EasterEgg/res/drawable/icon_bg.xml delete mode 100644 packages/EasterEgg/res/drawable/left_ear.xml delete mode 100644 packages/EasterEgg/res/drawable/left_ear_inside.xml delete mode 100644 packages/EasterEgg/res/drawable/left_eye.xml delete mode 100644 packages/EasterEgg/res/drawable/leg1.xml delete mode 100644 packages/EasterEgg/res/drawable/leg2.xml delete mode 100644 packages/EasterEgg/res/drawable/leg2_shadow.xml delete mode 100644 packages/EasterEgg/res/drawable/leg3.xml delete mode 100644 packages/EasterEgg/res/drawable/leg4.xml delete mode 100644 packages/EasterEgg/res/drawable/mouth.xml delete mode 100644 packages/EasterEgg/res/drawable/nose.xml delete mode 100644 packages/EasterEgg/res/drawable/octo_bg.xml create mode 100644 packages/EasterEgg/res/drawable/p.xml delete mode 100644 packages/EasterEgg/res/drawable/right_ear.xml delete mode 100644 packages/EasterEgg/res/drawable/right_ear_inside.xml delete mode 100644 packages/EasterEgg/res/drawable/right_eye.xml delete mode 100644 packages/EasterEgg/res/drawable/stat_icon.xml delete mode 100644 packages/EasterEgg/res/drawable/tail.xml delete mode 100644 packages/EasterEgg/res/drawable/tail_cap.xml delete mode 100644 packages/EasterEgg/res/drawable/tail_shadow.xml create mode 100644 packages/EasterEgg/res/drawable/toolbar_bg.xml create mode 100644 packages/EasterEgg/res/drawable/toolbar_button_bg.xml create mode 100644 packages/EasterEgg/res/layout/activity_paint.xml create mode 100644 packages/EasterEgg/res/layout/brushes.xml delete mode 100644 packages/EasterEgg/res/layout/cat_view.xml create mode 100644 packages/EasterEgg/res/layout/colors.xml delete mode 100644 packages/EasterEgg/res/layout/edit_text.xml delete mode 100644 packages/EasterEgg/res/layout/food_layout.xml delete mode 100644 packages/EasterEgg/res/layout/neko_activity.xml create mode 100644 packages/EasterEgg/res/layout/toolbar.xml create mode 100644 packages/EasterEgg/res/values-night/colors.xml create mode 100644 packages/EasterEgg/res/values-night/styles.xml create mode 100644 packages/EasterEgg/res/values/attrs_toolbar_view.xml create mode 100644 packages/EasterEgg/res/values/colors.xml delete mode 100644 packages/EasterEgg/res/values/dimens.xml create mode 100644 packages/EasterEgg/res/values/styles.xml delete mode 100644 packages/EasterEgg/res/xml/filepaths.xml delete mode 100644 packages/EasterEgg/src/com/android/egg/neko/Cat.java delete mode 100644 packages/EasterEgg/src/com/android/egg/neko/Food.java delete mode 100644 packages/EasterEgg/src/com/android/egg/neko/NekoActivationActivity.java delete mode 100644 packages/EasterEgg/src/com/android/egg/neko/NekoDialog.java delete mode 100644 packages/EasterEgg/src/com/android/egg/neko/NekoLand.java delete mode 100644 packages/EasterEgg/src/com/android/egg/neko/NekoLockedActivity.java delete mode 100644 packages/EasterEgg/src/com/android/egg/neko/NekoService.java delete mode 100644 packages/EasterEgg/src/com/android/egg/neko/NekoTile.java delete mode 100644 packages/EasterEgg/src/com/android/egg/neko/PrefState.java delete mode 100644 packages/EasterEgg/src/com/android/egg/octo/Ocquarium.java delete mode 100644 packages/EasterEgg/src/com/android/egg/octo/OctopusDrawable.java delete mode 100644 packages/EasterEgg/src/com/android/egg/octo/TaperedPathStroke.java create mode 100644 packages/EasterEgg/src/com/android/egg/paint/BrushPropertyDrawable.kt create mode 100644 packages/EasterEgg/src/com/android/egg/paint/CutoutAvoidingToolbar.kt create mode 100644 packages/EasterEgg/src/com/android/egg/paint/PaintActivity.java create mode 100644 packages/EasterEgg/src/com/android/egg/paint/Painting.kt create mode 100644 packages/EasterEgg/src/com/android/egg/paint/Palette.kt create mode 100644 packages/EasterEgg/src/com/android/egg/paint/SpotFilter.kt create mode 100644 packages/EasterEgg/src/com/android/egg/paint/ToolbarView.kt diff --git a/core/java/com/android/internal/app/PlatLogoActivity.java b/core/java/com/android/internal/app/PlatLogoActivity.java index f6a69d9aeb93..57785443919e 100644 --- a/core/java/com/android/internal/app/PlatLogoActivity.java +++ b/core/java/com/android/internal/app/PlatLogoActivity.java @@ -18,6 +18,9 @@ package com.android.internal.app; import android.animation.TimeAnimator; import android.app.Activity; +import android.content.ActivityNotFoundException; +import android.content.ContentResolver; +import android.content.Intent; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; @@ -25,12 +28,15 @@ import android.graphics.Paint; import android.graphics.Path; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.provider.Settings; import android.util.Log; import android.view.MotionEvent; import android.view.MotionEvent.PointerCoords; import android.view.View; import android.widget.FrameLayout; +import org.json.JSONObject; + public class PlatLogoActivity extends Activity { FrameLayout layout; TimeAnimator anim; @@ -87,7 +93,7 @@ public class PlatLogoActivity extends Activity { darkest = 0; for (int i=0; i 1) { + if (pressure < pressure_min) pressure_min = pressure; + if (pressure > pressure_max) pressure_max = pressure; + final int pc = event.getPointerCount(); + if (pc > maxPointers) maxPointers = pc; + if (pc > 1) { event.getPointerCoords(0, pc0); event.getPointerCoords(1, pc1); bg.setRadius((float) Math.hypot(pc0.x - pc1.x, pc0.y - pc1.y) / 2f); } break; + case MotionEvent.ACTION_CANCEL: + case MotionEvent.ACTION_UP: + try { + final String touchDataJson = Settings.System.getString(cr, TOUCH_STATS); + final JSONObject touchData = new JSONObject( + touchDataJson != null ? touchDataJson : "{}"); + if (touchData.has("min")) { + pressure_min = Math.min(pressure_min, touchData.getDouble("min")); + } + if (touchData.has("max")) { + pressure_max = Math.max(pressure_max, touchData.getDouble("max")); + } + touchData.put("min", pressure_min); + touchData.put("max", pressure_max); + Settings.System.putString(cr, TOUCH_STATS, touchData.toString()); + } catch (Exception e) { + Log.e("PlatLogoActivity", "Can't write touch settings", e); + } + + if (maxPointers == 1) { + tapCount ++; + if (tapCount < 7) { + bg.randomizePalette(); + } else { + launchNextStage(); + } + } else { + tapCount = 0; + } + maxPointers = 0; + break; } return true; } }); } + private void launchNextStage() { + final ContentResolver cr = getContentResolver(); + + if (Settings.System.getLong(cr, Settings.System.EGG_MODE, 0) == 0) { + // For posterity: the moment this user unlocked the easter egg + try { + Settings.System.putLong(cr, + Settings.System.EGG_MODE, + System.currentTimeMillis()); + } catch (RuntimeException e) { + Log.e("PlatLogoActivity", "Can't write settings", e); + } + } + try { + startActivity(new Intent(Intent.ACTION_MAIN) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_CLEAR_TASK) + .addCategory("com.android.internal.category.PLATLOGO")); + } catch (ActivityNotFoundException ex) { + Log.e("PlatLogoActivity", "No more eggs."); + } + finish(); + } + @Override public void onStart() { super.onStart(); diff --git a/packages/EasterEgg/Android.bp b/packages/EasterEgg/Android.bp new file mode 100644 index 000000000000..43ed810b5674 --- /dev/null +++ b/packages/EasterEgg/Android.bp @@ -0,0 +1,33 @@ +// +// Copyright (C) 2018 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. +// + +android_app { + // the build system in pi-dev can't quite handle R.java in kt + // so we will have a mix of java and kotlin files + srcs: ["src/**/*.java", "src/**/*.kt"], + + resource_dirs: ["res"], + + name: "EasterEgg", + + certificate: "platform", + + sdk_version: "current", + + optimize: { + enabled: false, + } +} diff --git a/packages/EasterEgg/Android.mk b/packages/EasterEgg/Android.mk deleted file mode 100644 index 605a75d16977..000000000000 --- a/packages/EasterEgg/Android.mk +++ /dev/null @@ -1,29 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := optional - -LOCAL_STATIC_JAVA_LIBRARIES := \ - jsr305 - -LOCAL_STATIC_ANDROID_LIBRARIES := \ - android-support-v4 \ - android-support-v13 \ - android-support-dynamic-animation \ - android-support-v7-recyclerview \ - android-support-v7-preference \ - android-support-v7-appcompat \ - android-support-v14-preference - -LOCAL_USE_AAPT2 := true - -LOCAL_SRC_FILES := $(call all-java-files-under, src) -LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res - -LOCAL_PACKAGE_NAME := EasterEgg -LOCAL_PRIVATE_PLATFORM_APIS := true -LOCAL_CERTIFICATE := platform - -include $(BUILD_PACKAGE) - -include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/packages/EasterEgg/AndroidManifest.xml b/packages/EasterEgg/AndroidManifest.xml index 172490dc9178..6651d9a930f3 100644 --- a/packages/EasterEgg/AndroidManifest.xml +++ b/packages/EasterEgg/AndroidManifest.xml @@ -1,8 +1,8 @@ + package="com.android.egg" + android:versionCode="1" + android:versionName="1.0"> - + - - + - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - + + \ No newline at end of file diff --git a/packages/EasterEgg/res/color-night/toolbar_icon_color.xml b/packages/EasterEgg/res/color-night/toolbar_icon_color.xml new file mode 100644 index 000000000000..c0a81520f849 --- /dev/null +++ b/packages/EasterEgg/res/color-night/toolbar_icon_color.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/packages/EasterEgg/res/color/toolbar_icon_color.xml b/packages/EasterEgg/res/color/toolbar_icon_color.xml new file mode 100644 index 000000000000..d3247e406a91 --- /dev/null +++ b/packages/EasterEgg/res/color/toolbar_icon_color.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/packages/EasterEgg/res/drawable/back.xml b/packages/EasterEgg/res/drawable/back.xml deleted file mode 100644 index b55d65cdf76d..000000000000 --- a/packages/EasterEgg/res/drawable/back.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/belly.xml b/packages/EasterEgg/res/drawable/belly.xml deleted file mode 100644 index 8b0e9afac463..000000000000 --- a/packages/EasterEgg/res/drawable/belly.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/body.xml b/packages/EasterEgg/res/drawable/body.xml deleted file mode 100644 index 86087209eff5..000000000000 --- a/packages/EasterEgg/res/drawable/body.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/bowtie.xml b/packages/EasterEgg/res/drawable/bowtie.xml deleted file mode 100644 index 33fa9216712f..000000000000 --- a/packages/EasterEgg/res/drawable/bowtie.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/cap.xml b/packages/EasterEgg/res/drawable/cap.xml deleted file mode 100644 index d8b4cc58a261..000000000000 --- a/packages/EasterEgg/res/drawable/cap.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/collar.xml b/packages/EasterEgg/res/drawable/collar.xml deleted file mode 100644 index 5e4d0fd4f886..000000000000 --- a/packages/EasterEgg/res/drawable/collar.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/face_spot.xml b/packages/EasterEgg/res/drawable/face_spot.xml deleted file mode 100644 index a89fb4fdaadd..000000000000 --- a/packages/EasterEgg/res/drawable/face_spot.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/food_bits.xml b/packages/EasterEgg/res/drawable/food_bits.xml deleted file mode 100644 index 1b2bb6f36947..000000000000 --- a/packages/EasterEgg/res/drawable/food_bits.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - diff --git a/packages/EasterEgg/res/drawable/food_chicken.xml b/packages/EasterEgg/res/drawable/food_chicken.xml deleted file mode 100644 index 95b2fb55b796..000000000000 --- a/packages/EasterEgg/res/drawable/food_chicken.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - diff --git a/packages/EasterEgg/res/drawable/food_cookie.xml b/packages/EasterEgg/res/drawable/food_cookie.xml deleted file mode 100644 index 74dd134355e2..000000000000 --- a/packages/EasterEgg/res/drawable/food_cookie.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/packages/EasterEgg/res/drawable/food_dish.xml b/packages/EasterEgg/res/drawable/food_dish.xml deleted file mode 100644 index 3fff6a90fad2..000000000000 --- a/packages/EasterEgg/res/drawable/food_dish.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/food_donut.xml b/packages/EasterEgg/res/drawable/food_donut.xml deleted file mode 100644 index eaf831ea560c..000000000000 --- a/packages/EasterEgg/res/drawable/food_donut.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/food_sysuituna.xml b/packages/EasterEgg/res/drawable/food_sysuituna.xml deleted file mode 100644 index 28cf4a2c7683..000000000000 --- a/packages/EasterEgg/res/drawable/food_sysuituna.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/foot1.xml b/packages/EasterEgg/res/drawable/foot1.xml deleted file mode 100644 index 0d9085998a18..000000000000 --- a/packages/EasterEgg/res/drawable/foot1.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/foot2.xml b/packages/EasterEgg/res/drawable/foot2.xml deleted file mode 100644 index 364ba0cd861c..000000000000 --- a/packages/EasterEgg/res/drawable/foot2.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/foot3.xml b/packages/EasterEgg/res/drawable/foot3.xml deleted file mode 100644 index e3a512a2568d..000000000000 --- a/packages/EasterEgg/res/drawable/foot3.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/foot4.xml b/packages/EasterEgg/res/drawable/foot4.xml deleted file mode 100644 index 66b78fa26649..000000000000 --- a/packages/EasterEgg/res/drawable/foot4.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/head.xml b/packages/EasterEgg/res/drawable/head.xml deleted file mode 100644 index df600a8613cd..000000000000 --- a/packages/EasterEgg/res/drawable/head.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/ic_clear.xml b/packages/EasterEgg/res/drawable/ic_clear.xml new file mode 100644 index 000000000000..489dcd20759d --- /dev/null +++ b/packages/EasterEgg/res/drawable/ic_clear.xml @@ -0,0 +1,27 @@ + + + + diff --git a/packages/EasterEgg/res/drawable/ic_close.xml b/packages/EasterEgg/res/drawable/ic_close.xml deleted file mode 100644 index 60ea36b11fcc..000000000000 --- a/packages/EasterEgg/res/drawable/ic_close.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/ic_dropper.xml b/packages/EasterEgg/res/drawable/ic_dropper.xml new file mode 100644 index 000000000000..230730921b9a --- /dev/null +++ b/packages/EasterEgg/res/drawable/ic_dropper.xml @@ -0,0 +1,39 @@ + + + + + + diff --git a/packages/EasterEgg/res/drawable/ic_hourglass.xml b/packages/EasterEgg/res/drawable/ic_hourglass.xml new file mode 100644 index 000000000000..fe4b9c47e547 --- /dev/null +++ b/packages/EasterEgg/res/drawable/ic_hourglass.xml @@ -0,0 +1,27 @@ + + + + diff --git a/packages/EasterEgg/res/drawable/ic_share.xml b/packages/EasterEgg/res/drawable/ic_share.xml deleted file mode 100644 index 8cebc7ed46de..000000000000 --- a/packages/EasterEgg/res/drawable/ic_share.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/icon.xml b/packages/EasterEgg/res/drawable/icon.xml index 5ce9e5133847..2306b7b554c5 100644 --- a/packages/EasterEgg/res/drawable/icon.xml +++ b/packages/EasterEgg/res/drawable/icon.xml @@ -1,7 +1,7 @@ - - - - - - - - + + + + diff --git a/packages/EasterEgg/res/drawable/icon_bg.xml b/packages/EasterEgg/res/drawable/icon_bg.xml new file mode 100644 index 000000000000..c1553ce50946 --- /dev/null +++ b/packages/EasterEgg/res/drawable/icon_bg.xml @@ -0,0 +1,18 @@ + + + \ No newline at end of file diff --git a/packages/EasterEgg/res/drawable/left_ear.xml b/packages/EasterEgg/res/drawable/left_ear.xml deleted file mode 100644 index 2b98736df039..000000000000 --- a/packages/EasterEgg/res/drawable/left_ear.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/left_ear_inside.xml b/packages/EasterEgg/res/drawable/left_ear_inside.xml deleted file mode 100644 index 1d947edc31e2..000000000000 --- a/packages/EasterEgg/res/drawable/left_ear_inside.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/left_eye.xml b/packages/EasterEgg/res/drawable/left_eye.xml deleted file mode 100644 index 4dde1b661393..000000000000 --- a/packages/EasterEgg/res/drawable/left_eye.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/leg1.xml b/packages/EasterEgg/res/drawable/leg1.xml deleted file mode 100644 index d72c746b6232..000000000000 --- a/packages/EasterEgg/res/drawable/leg1.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/leg2.xml b/packages/EasterEgg/res/drawable/leg2.xml deleted file mode 100644 index a772a870af7d..000000000000 --- a/packages/EasterEgg/res/drawable/leg2.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/leg2_shadow.xml b/packages/EasterEgg/res/drawable/leg2_shadow.xml deleted file mode 100644 index b01bd6995c0b..000000000000 --- a/packages/EasterEgg/res/drawable/leg2_shadow.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/leg3.xml b/packages/EasterEgg/res/drawable/leg3.xml deleted file mode 100644 index d471236687b5..000000000000 --- a/packages/EasterEgg/res/drawable/leg3.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/leg4.xml b/packages/EasterEgg/res/drawable/leg4.xml deleted file mode 100644 index e5868eb80c59..000000000000 --- a/packages/EasterEgg/res/drawable/leg4.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/mouth.xml b/packages/EasterEgg/res/drawable/mouth.xml deleted file mode 100644 index ddcf2e82f976..000000000000 --- a/packages/EasterEgg/res/drawable/mouth.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/nose.xml b/packages/EasterEgg/res/drawable/nose.xml deleted file mode 100644 index d403cd1baadf..000000000000 --- a/packages/EasterEgg/res/drawable/nose.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/octo_bg.xml b/packages/EasterEgg/res/drawable/octo_bg.xml deleted file mode 100644 index 1e46cf434a8b..000000000000 --- a/packages/EasterEgg/res/drawable/octo_bg.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/EasterEgg/res/drawable/p.xml b/packages/EasterEgg/res/drawable/p.xml new file mode 100644 index 000000000000..596b7824cdb7 --- /dev/null +++ b/packages/EasterEgg/res/drawable/p.xml @@ -0,0 +1,33 @@ + + + + + diff --git a/packages/EasterEgg/res/drawable/right_ear.xml b/packages/EasterEgg/res/drawable/right_ear.xml deleted file mode 100644 index b9fb4d1c7470..000000000000 --- a/packages/EasterEgg/res/drawable/right_ear.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/right_ear_inside.xml b/packages/EasterEgg/res/drawable/right_ear_inside.xml deleted file mode 100644 index 86b6e3428d1f..000000000000 --- a/packages/EasterEgg/res/drawable/right_ear_inside.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - diff --git a/packages/EasterEgg/res/drawable/right_eye.xml b/packages/EasterEgg/res/drawable/right_eye.xml deleted file mode 100644 index a1871a62c25b..000000000000 --- a/packages/EasterEgg/res/drawable/right_eye.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/stat_icon.xml b/packages/EasterEgg/res/drawable/stat_icon.xml deleted file mode 100644 index 608cb2017c3f..000000000000 --- a/packages/EasterEgg/res/drawable/stat_icon.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - diff --git a/packages/EasterEgg/res/drawable/tail.xml b/packages/EasterEgg/res/drawable/tail.xml deleted file mode 100644 index 0cca23c3e16c..000000000000 --- a/packages/EasterEgg/res/drawable/tail.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/tail_cap.xml b/packages/EasterEgg/res/drawable/tail_cap.xml deleted file mode 100644 index b82f6f9b478a..000000000000 --- a/packages/EasterEgg/res/drawable/tail_cap.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/tail_shadow.xml b/packages/EasterEgg/res/drawable/tail_shadow.xml deleted file mode 100644 index bb1ff12b3afe..000000000000 --- a/packages/EasterEgg/res/drawable/tail_shadow.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - diff --git a/packages/EasterEgg/res/drawable/toolbar_bg.xml b/packages/EasterEgg/res/drawable/toolbar_bg.xml new file mode 100644 index 000000000000..0f0e702fd7c8 --- /dev/null +++ b/packages/EasterEgg/res/drawable/toolbar_bg.xml @@ -0,0 +1,19 @@ + + + + + \ No newline at end of file diff --git a/packages/EasterEgg/res/drawable/toolbar_button_bg.xml b/packages/EasterEgg/res/drawable/toolbar_button_bg.xml new file mode 100644 index 000000000000..1b6a53ec7cc6 --- /dev/null +++ b/packages/EasterEgg/res/drawable/toolbar_button_bg.xml @@ -0,0 +1,25 @@ + + + + + + + + + + diff --git a/packages/EasterEgg/res/layout/activity_paint.xml b/packages/EasterEgg/res/layout/activity_paint.xml new file mode 100644 index 000000000000..a4c17afd1531 --- /dev/null +++ b/packages/EasterEgg/res/layout/activity_paint.xml @@ -0,0 +1,48 @@ + + + + + + + + + + \ No newline at end of file diff --git a/packages/EasterEgg/res/layout/brushes.xml b/packages/EasterEgg/res/layout/brushes.xml new file mode 100644 index 000000000000..0c4b849b4eb8 --- /dev/null +++ b/packages/EasterEgg/res/layout/brushes.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file diff --git a/packages/EasterEgg/res/layout/cat_view.xml b/packages/EasterEgg/res/layout/cat_view.xml deleted file mode 100644 index 85b494d2e68d..000000000000 --- a/packages/EasterEgg/res/layout/cat_view.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packages/EasterEgg/res/layout/colors.xml b/packages/EasterEgg/res/layout/colors.xml new file mode 100644 index 000000000000..b90f4d71b1e9 --- /dev/null +++ b/packages/EasterEgg/res/layout/colors.xml @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file diff --git a/packages/EasterEgg/res/layout/edit_text.xml b/packages/EasterEgg/res/layout/edit_text.xml deleted file mode 100644 index 9f7ac802bad4..000000000000 --- a/packages/EasterEgg/res/layout/edit_text.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/packages/EasterEgg/res/layout/food_layout.xml b/packages/EasterEgg/res/layout/food_layout.xml deleted file mode 100644 index d0ca0c8899aa..000000000000 --- a/packages/EasterEgg/res/layout/food_layout.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - diff --git a/packages/EasterEgg/res/layout/neko_activity.xml b/packages/EasterEgg/res/layout/neko_activity.xml deleted file mode 100644 index 21a4600bae40..000000000000 --- a/packages/EasterEgg/res/layout/neko_activity.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages/EasterEgg/res/layout/toolbar.xml b/packages/EasterEgg/res/layout/toolbar.xml new file mode 100644 index 000000000000..9a5a9c541a4d --- /dev/null +++ b/packages/EasterEgg/res/layout/toolbar.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/EasterEgg/res/values-night/colors.xml b/packages/EasterEgg/res/values-night/colors.xml new file mode 100644 index 000000000000..7c188f77f444 --- /dev/null +++ b/packages/EasterEgg/res/values-night/colors.xml @@ -0,0 +1,21 @@ + + + + #FF333333 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/packages/EasterEgg/res/values-night/styles.xml b/packages/EasterEgg/res/values-night/styles.xml new file mode 100644 index 000000000000..4edf6926da41 --- /dev/null +++ b/packages/EasterEgg/res/values-night/styles.xml @@ -0,0 +1,21 @@ + + + + diff --git a/packages/EasterEgg/res/values/attrs_toolbar_view.xml b/packages/EasterEgg/res/values/attrs_toolbar_view.xml new file mode 100644 index 000000000000..ed1360f7d468 --- /dev/null +++ b/packages/EasterEgg/res/values/attrs_toolbar_view.xml @@ -0,0 +1,19 @@ + + + + + diff --git a/packages/EasterEgg/res/values/colors.xml b/packages/EasterEgg/res/values/colors.xml new file mode 100644 index 000000000000..1a5388b738dd --- /dev/null +++ b/packages/EasterEgg/res/values/colors.xml @@ -0,0 +1,21 @@ + + + + #FFDDDDDD + #FFFFFFFF + #FF000000 + \ No newline at end of file diff --git a/packages/EasterEgg/res/values/dimens.xml b/packages/EasterEgg/res/values/dimens.xml deleted file mode 100644 index e9dcebd27f7b..000000000000 --- a/packages/EasterEgg/res/values/dimens.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - 64dp - diff --git a/packages/EasterEgg/res/values/strings.xml b/packages/EasterEgg/res/values/strings.xml index 61e38342872e..32dbc97a00fb 100644 --- a/packages/EasterEgg/res/values/strings.xml +++ b/packages/EasterEgg/res/values/strings.xml @@ -1,6 +1,6 @@ - Android Easter Egg - Android Neko - New cats - \???? - A cat is here. - Cat #%s - Cats - Forget %s? - - Empty dish - Bits - Fish - Chicken - Treat - - - @drawable/food_dish - @drawable/food_bits - @drawable/food_sysuituna - @drawable/food_chicken - @drawable/food_cookie - - - 0 - 15 - 30 - 60 - 120 - - - 0 - 5 - 35 - 65 - 90 - + PAINT.APK diff --git a/packages/EasterEgg/res/values/styles.xml b/packages/EasterEgg/res/values/styles.xml new file mode 100644 index 000000000000..44e2ce52aab8 --- /dev/null +++ b/packages/EasterEgg/res/values/styles.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/packages/EasterEgg/res/xml/filepaths.xml b/packages/EasterEgg/res/xml/filepaths.xml deleted file mode 100644 index 2130025e9265..000000000000 --- a/packages/EasterEgg/res/xml/filepaths.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - \ No newline at end of file diff --git a/packages/EasterEgg/src/com/android/egg/neko/Cat.java b/packages/EasterEgg/src/com/android/egg/neko/Cat.java deleted file mode 100644 index dd1bd07f3298..000000000000 --- a/packages/EasterEgg/src/com/android/egg/neko/Cat.java +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -package com.android.egg.neko; - -import android.app.Notification; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.content.res.Resources; -import android.graphics.*; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.Icon; -import android.os.Bundle; - -import java.io.ByteArrayOutputStream; -import java.util.Random; -import java.util.concurrent.ThreadLocalRandom; - -import com.android.egg.R; -import com.android.internal.logging.MetricsLogger; - -import static com.android.egg.neko.NekoLand.CHAN_ID; - -public class Cat extends Drawable { - public static final long[] PURR = {0, 40, 20, 40, 20, 40, 20, 40, 20, 40, 20, 40}; - - private Random mNotSoRandom; - private Bitmap mBitmap; - private long mSeed; - private String mName; - private int mBodyColor; - private int mFootType; - private boolean mBowTie; - - private synchronized Random notSoRandom(long seed) { - if (mNotSoRandom == null) { - mNotSoRandom = new Random(); - mNotSoRandom.setSeed(seed); - } - return mNotSoRandom; - } - - public static final float frandrange(Random r, float a, float b) { - return (b-a)*r.nextFloat() + a; - } - - public static final Object choose(Random r, Object...l) { - return l[r.nextInt(l.length)]; - } - - public static final int chooseP(Random r, int[] a) { - int pct = r.nextInt(1000); - final int stop = a.length-2; - int i=0; - while (i> 16; - final int g = (color & 0x00FF00) >> 8; - final int b = color & 0x0000FF; - return (r + g + b) < 0x80; - } - - public Cat(Context context, long seed) { - D = new CatParts(context); - mSeed = seed; - - setName(context.getString(R.string.default_cat_name, - String.valueOf(mSeed % 1000))); - - final Random nsr = notSoRandom(seed); - - // body color - mBodyColor = chooseP(nsr, P_BODY_COLORS); - if (mBodyColor == 0) mBodyColor = Color.HSVToColor(new float[] { - nsr.nextFloat()*360f, frandrange(nsr,0.5f,1f), frandrange(nsr,0.5f, 1f)}); - - tint(mBodyColor, D.body, D.head, D.leg1, D.leg2, D.leg3, D.leg4, D.tail, - D.leftEar, D.rightEar, D.foot1, D.foot2, D.foot3, D.foot4, D.tailCap); - tint(0x20000000, D.leg2Shadow, D.tailShadow); - if (isDark(mBodyColor)) { - tint(0xFFFFFFFF, D.leftEye, D.rightEye, D.mouth, D.nose); - } - tint(isDark(mBodyColor) ? 0xFFEF9A9A : 0x20D50000, D.leftEarInside, D.rightEarInside); - - tint(chooseP(nsr, P_BELLY_COLORS), D.belly); - tint(chooseP(nsr, P_BELLY_COLORS), D.back); - final int faceColor = chooseP(nsr, P_BELLY_COLORS); - tint(faceColor, D.faceSpot); - if (!isDark(faceColor)) { - tint(0xFF000000, D.mouth, D.nose); - } - - mFootType = 0; - if (nsr.nextFloat() < 0.25f) { - mFootType = 4; - tint(0xFFFFFFFF, D.foot1, D.foot2, D.foot3, D.foot4); - } else { - if (nsr.nextFloat() < 0.25f) { - mFootType = 2; - tint(0xFFFFFFFF, D.foot1, D.foot3); - } else if (nsr.nextFloat() < 0.25f) { - mFootType = 3; // maybe -2 would be better? meh. - tint(0xFFFFFFFF, D.foot2, D.foot4); - } else if (nsr.nextFloat() < 0.1f) { - mFootType = 1; - tint(0xFFFFFFFF, (Drawable) choose(nsr, D.foot1, D.foot2, D.foot3, D.foot4)); - } - } - - tint(nsr.nextFloat() < 0.333f ? 0xFFFFFFFF : mBodyColor, D.tailCap); - - final int capColor = chooseP(nsr, isDark(mBodyColor) ? P_LIGHT_SPOT_COLORS : P_DARK_SPOT_COLORS); - tint(capColor, D.cap); - //tint(chooseP(nsr, isDark(bodyColor) ? P_LIGHT_SPOT_COLORS : P_DARK_SPOT_COLORS), D.nose); - - final int collarColor = chooseP(nsr, P_COLLAR_COLORS); - tint(collarColor, D.collar); - mBowTie = nsr.nextFloat() < 0.1f; - tint(mBowTie ? collarColor : 0, D.bowtie); - } - - public static Cat create(Context context) { - return new Cat(context, Math.abs(ThreadLocalRandom.current().nextInt())); - } - - public Notification.Builder buildNotification(Context context) { - final Bundle extras = new Bundle(); - extras.putString("android.substName", context.getString(R.string.notification_name)); - final Intent intent = new Intent(Intent.ACTION_MAIN) - .setClass(context, NekoLand.class) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - return new Notification.Builder(context) - .setSmallIcon(Icon.createWithResource(context, R.drawable.stat_icon)) - .setLargeIcon(createNotificationLargeIcon(context)) - .setColor(getBodyColor()) - .setPriority(Notification.PRIORITY_LOW) - .setContentTitle(context.getString(R.string.notification_title)) - .setShowWhen(true) - .setCategory(Notification.CATEGORY_STATUS) - .setContentText(getName()) - .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) - .setAutoCancel(true) - .setChannel(CHAN_ID) - .setVibrate(PURR) - .addExtras(extras); - } - - public long getSeed() { - return mSeed; - } - - @Override - public void draw(Canvas canvas) { - final int w = Math.min(canvas.getWidth(), canvas.getHeight()); - final int h = w; - - if (mBitmap == null || mBitmap.getWidth() != w || mBitmap.getHeight() != h) { - mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); - final Canvas bitCanvas = new Canvas(mBitmap); - slowDraw(bitCanvas, 0, 0, w, h); - } - canvas.drawBitmap(mBitmap, 0, 0, null); - } - - private void slowDraw(Canvas canvas, int x, int y, int w, int h) { - for (int i = 0; i < D.drawingOrder.length; i++) { - final Drawable d = D.drawingOrder[i]; - if (d != null) { - d.setBounds(x, y, x+w, y+h); - d.draw(canvas); - } - } - - } - - public Bitmap createBitmap(int w, int h) { - if (mBitmap != null && mBitmap.getWidth() == w && mBitmap.getHeight() == h) { - return mBitmap.copy(mBitmap.getConfig(), true); - } - Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); - slowDraw(new Canvas(result), 0, 0, w, h); - return result; - } - - public static Icon recompressIcon(Icon bitmapIcon) { - if (bitmapIcon.getType() != Icon.TYPE_BITMAP) return bitmapIcon; - final Bitmap bits = bitmapIcon.getBitmap(); - final ByteArrayOutputStream ostream = new ByteArrayOutputStream( - bits.getWidth() * bits.getHeight() * 2); // guess 50% compression - final boolean ok = bits.compress(Bitmap.CompressFormat.PNG, 100, ostream); - if (!ok) return null; - return Icon.createWithData(ostream.toByteArray(), 0, ostream.size()); - } - - public Icon createNotificationLargeIcon(Context context) { - final Resources res = context.getResources(); - final int w = 2*res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); - final int h = 2*res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); - return recompressIcon(createIcon(context, w, h)); - } - - public Icon createIcon(Context context, int w, int h) { - Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); - final Canvas canvas = new Canvas(result); - final Paint pt = new Paint(); - float[] hsv = new float[3]; - Color.colorToHSV(mBodyColor, hsv); - hsv[2] = (hsv[2]>0.5f) - ? (hsv[2] - 0.25f) - : (hsv[2] + 0.25f); - pt.setColor(Color.HSVToColor(hsv)); - float r = w/2; - canvas.drawCircle(r, r, r, pt); - int m = w/10; - - slowDraw(canvas, m, m, w-m-m, h-m-m); - - return Icon.createWithBitmap(result); - } - - @Override - public void setAlpha(int i) { - - } - - @Override - public void setColorFilter(ColorFilter colorFilter) { - - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSLUCENT; - } - - public String getName() { - return mName; - } - - public void setName(String name) { - this.mName = name; - } - - public int getBodyColor() { - return mBodyColor; - } - - public void logAdd(Context context) { - logCatAction(context, "egg_neko_add"); - } - - public void logRename(Context context) { - logCatAction(context, "egg_neko_rename"); - } - - public void logRemove(Context context) { - logCatAction(context, "egg_neko_remove"); - } - - public void logShare(Context context) { - logCatAction(context, "egg_neko_share"); - } - - private void logCatAction(Context context, String prefix) { - MetricsLogger.count(context, prefix, 1); - MetricsLogger.histogram(context, prefix +"_color", - getColorIndex(mBodyColor, P_BODY_COLORS)); - MetricsLogger.histogram(context, prefix + "_bowtie", mBowTie ? 1 : 0); - MetricsLogger.histogram(context, prefix + "_feet", mFootType); - } - - public static class CatParts { - public Drawable leftEar; - public Drawable rightEar; - public Drawable rightEarInside; - public Drawable leftEarInside; - public Drawable head; - public Drawable faceSpot; - public Drawable cap; - public Drawable mouth; - public Drawable body; - public Drawable foot1; - public Drawable leg1; - public Drawable foot2; - public Drawable leg2; - public Drawable foot3; - public Drawable leg3; - public Drawable foot4; - public Drawable leg4; - public Drawable tail; - public Drawable leg2Shadow; - public Drawable tailShadow; - public Drawable tailCap; - public Drawable belly; - public Drawable back; - public Drawable rightEye; - public Drawable leftEye; - public Drawable nose; - public Drawable bowtie; - public Drawable collar; - public Drawable[] drawingOrder; - - public CatParts(Context context) { - body = context.getDrawable(R.drawable.body); - head = context.getDrawable(R.drawable.head); - leg1 = context.getDrawable(R.drawable.leg1); - leg2 = context.getDrawable(R.drawable.leg2); - leg3 = context.getDrawable(R.drawable.leg3); - leg4 = context.getDrawable(R.drawable.leg4); - tail = context.getDrawable(R.drawable.tail); - leftEar = context.getDrawable(R.drawable.left_ear); - rightEar = context.getDrawable(R.drawable.right_ear); - rightEarInside = context.getDrawable(R.drawable.right_ear_inside); - leftEarInside = context.getDrawable(R.drawable.left_ear_inside); - faceSpot = context.getDrawable(R.drawable.face_spot); - cap = context.getDrawable(R.drawable.cap); - mouth = context.getDrawable(R.drawable.mouth); - foot4 = context.getDrawable(R.drawable.foot4); - foot3 = context.getDrawable(R.drawable.foot3); - foot1 = context.getDrawable(R.drawable.foot1); - foot2 = context.getDrawable(R.drawable.foot2); - leg2Shadow = context.getDrawable(R.drawable.leg2_shadow); - tailShadow = context.getDrawable(R.drawable.tail_shadow); - tailCap = context.getDrawable(R.drawable.tail_cap); - belly = context.getDrawable(R.drawable.belly); - back = context.getDrawable(R.drawable.back); - rightEye = context.getDrawable(R.drawable.right_eye); - leftEye = context.getDrawable(R.drawable.left_eye); - nose = context.getDrawable(R.drawable.nose); - collar = context.getDrawable(R.drawable.collar); - bowtie = context.getDrawable(R.drawable.bowtie); - drawingOrder = getDrawingOrder(); - } - private Drawable[] getDrawingOrder() { - return new Drawable[] { - collar, - leftEar, leftEarInside, rightEar, rightEarInside, - head, - faceSpot, - cap, - leftEye, rightEye, - nose, mouth, - tail, tailCap, tailShadow, - foot1, leg1, - foot2, leg2, - foot3, leg3, - foot4, leg4, - leg2Shadow, - body, belly, - bowtie - }; - } - } -} diff --git a/packages/EasterEgg/src/com/android/egg/neko/Food.java b/packages/EasterEgg/src/com/android/egg/neko/Food.java deleted file mode 100644 index 5c0f12e2639f..000000000000 --- a/packages/EasterEgg/src/com/android/egg/neko/Food.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -package com.android.egg.neko; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.Icon; - -import com.android.egg.R; - -public class Food { - private final int mType; - - private static int[] sIcons; - private static String[] sNames; - - public Food(int type) { - mType = type; - } - - public Icon getIcon(Context context) { - if (sIcons == null) { - TypedArray icons = context.getResources().obtainTypedArray(R.array.food_icons); - sIcons = new int[icons.length()]; - for (int i = 0; i < sIcons.length; i++) { - sIcons[i] = icons.getResourceId(i, 0); - } - icons.recycle(); - } - return Icon.createWithResource(context, sIcons[mType]); - } - - public String getName(Context context) { - if (sNames == null) { - sNames = context.getResources().getStringArray(R.array.food_names); - } - return sNames[mType]; - } - - public long getInterval(Context context) { - return context.getResources().getIntArray(R.array.food_intervals)[mType]; - } - - public int getType() { - return mType; - } -} diff --git a/packages/EasterEgg/src/com/android/egg/neko/NekoActivationActivity.java b/packages/EasterEgg/src/com/android/egg/neko/NekoActivationActivity.java deleted file mode 100644 index c0b725c05899..000000000000 --- a/packages/EasterEgg/src/com/android/egg/neko/NekoActivationActivity.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -package com.android.egg.neko; - -import android.app.Activity; -import android.content.ComponentName; -import android.content.pm.PackageManager; -import android.util.Log; -import android.widget.Toast; - -import com.android.internal.logging.MetricsLogger; - -public class NekoActivationActivity extends Activity { - private void toastUp(String s) { - Toast toast = Toast.makeText(this, s, Toast.LENGTH_SHORT); - toast.getView().setBackgroundDrawable(null); - toast.show(); - } - - @Override - public void onStart() { - super.onStart(); - - final PackageManager pm = getPackageManager(); - final ComponentName cn = new ComponentName(this, NekoTile.class); - if (pm.getComponentEnabledSetting(cn) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { - if (NekoLand.DEBUG) { - Log.v("Neko", "Disabling tile."); - } - pm.setComponentEnabledSetting(cn, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, - PackageManager.DONT_KILL_APP); - MetricsLogger.histogram(this, "egg_neko_enable", 0); - toastUp("\uD83D\uDEAB"); - } else { - if (NekoLand.DEBUG) { - Log.v("Neko", "Enabling tile."); - } - pm.setComponentEnabledSetting(cn, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP); - MetricsLogger.histogram(this, "egg_neko_enable", 1); - toastUp("\uD83D\uDC31"); - } - finish(); - } -} diff --git a/packages/EasterEgg/src/com/android/egg/neko/NekoDialog.java b/packages/EasterEgg/src/com/android/egg/neko/NekoDialog.java deleted file mode 100644 index 2d2fbe8207af..000000000000 --- a/packages/EasterEgg/src/com/android/egg/neko/NekoDialog.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -package com.android.egg.neko; - -import android.support.annotation.NonNull; -import android.app.Dialog; -import android.content.Context; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -import com.android.egg.R; -import com.android.internal.logging.MetricsLogger; - -import java.util.ArrayList; - -public class NekoDialog extends Dialog { - - private final Adapter mAdapter; - - public NekoDialog(@NonNull Context context) { - super(context, android.R.style.Theme_Material_Dialog_NoActionBar); - RecyclerView view = new RecyclerView(getContext()); - mAdapter = new Adapter(getContext()); - view.setLayoutManager(new GridLayoutManager(getContext(), 2)); - view.setAdapter(mAdapter); - final float dp = context.getResources().getDisplayMetrics().density; - final int pad = (int)(16*dp); - view.setPadding(pad, pad, pad, pad); - setContentView(view); - } - - private void onFoodSelected(Food food) { - PrefState prefs = new PrefState(getContext()); - int currentState = prefs.getFoodState(); - if (currentState == 0 && food.getType() != 0) { - NekoService.registerJob(getContext(), food.getInterval(getContext())); - } - MetricsLogger.histogram(getContext(), "egg_neko_offered_food", food.getType()); - prefs.setFoodState(food.getType()); - dismiss(); - } - - private class Adapter extends RecyclerView.Adapter { - - private final Context mContext; - private final ArrayList mFoods = new ArrayList<>(); - - public Adapter(Context context) { - mContext = context; - int[] foods = context.getResources().getIntArray(R.array.food_names); - // skip food 0, you can't choose it - for (int i=1; i list = mPrefs.getCats(); - Collections.sort(list, new Comparator() { - @Override - public int compare(Cat cat, Cat cat2) { - Color.colorToHSV(cat.getBodyColor(), hsv); - float bodyH1 = hsv[0]; - Color.colorToHSV(cat2.getBodyColor(), hsv); - float bodyH2 = hsv[0]; - return Float.compare(bodyH1, bodyH2); - } - }); - cats = list.toArray(new Cat[0]); - } - mAdapter.setCats(cats); - return cats.length; - } - - private void onCatClick(Cat cat) { - if (CAT_GEN) { - mPrefs.addCat(cat); - new AlertDialog.Builder(NekoLand.this) - .setTitle("Cat added") - .setPositiveButton(android.R.string.ok, null) - .show(); - } else { - showNameDialog(cat); - } -// noman.notify(1, cat.buildNotification(NekoLand.this).build()); - } - - private void onCatRemove(Cat cat) { - cat.logRemove(this); - mPrefs.removeCat(cat); - } - - private void showNameDialog(final Cat cat) { - final Context context = new ContextThemeWrapper(this, - android.R.style.Theme_Material_Light_Dialog_NoActionBar); - // TODO: Move to XML, add correct margins. - View view = LayoutInflater.from(context).inflate(R.layout.edit_text, null); - final EditText text = (EditText) view.findViewById(android.R.id.edit); - text.setText(cat.getName()); - text.setSelection(cat.getName().length()); - final int size = context.getResources() - .getDimensionPixelSize(android.R.dimen.app_icon_size); - Drawable catIcon = cat.createIcon(this, size, size).loadDrawable(this); - new AlertDialog.Builder(context) - .setTitle(" ") - .setIcon(catIcon) - .setView(view) - .setPositiveButton(android.R.string.ok, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - cat.logRename(context); - cat.setName(text.getText().toString().trim()); - mPrefs.addCat(cat); - } - }).show(); - } - - @Override - public void onPrefsChanged() { - updateCats(); - } - - private class CatAdapter extends RecyclerView.Adapter { - - private Cat[] mCats; - - public void setCats(Cat[] cats) { - mCats = cats; - notifyDataSetChanged(); - } - - @Override - public CatHolder onCreateViewHolder(ViewGroup parent, int viewType) { - return new CatHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.cat_view, parent, false)); - } - - private void setContextGroupVisible(final CatHolder holder, boolean vis) { - final View group = holder.contextGroup; - if (vis && group.getVisibility() != View.VISIBLE) { - group.setAlpha(0); - group.setVisibility(View.VISIBLE); - group.animate().alpha(1.0f).setDuration(333); - Runnable hideAction = new Runnable() { - @Override - public void run() { - setContextGroupVisible(holder, false); - } - }; - group.setTag(hideAction); - group.postDelayed(hideAction, 5000); - } else if (!vis && group.getVisibility() == View.VISIBLE) { - group.removeCallbacks((Runnable) group.getTag()); - group.animate().alpha(0f).setDuration(250).withEndAction(new Runnable() { - @Override - public void run() { - group.setVisibility(View.INVISIBLE); - } - }); - } - } - - @Override - public void onBindViewHolder(final CatHolder holder, int position) { - Context context = holder.itemView.getContext(); - final int size = context.getResources().getDimensionPixelSize(R.dimen.neko_display_size); - holder.imageView.setImageIcon(mCats[position].createIcon(context, size, size)); - holder.textView.setText(mCats[position].getName()); - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onCatClick(mCats[holder.getAdapterPosition()]); - } - }); - holder.itemView.setOnLongClickListener(new OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - setContextGroupVisible(holder, true); - return true; - } - }); - holder.delete.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - setContextGroupVisible(holder, false); - new AlertDialog.Builder(NekoLand.this) - .setTitle(getString(R.string.confirm_delete, mCats[position].getName())) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - onCatRemove(mCats[holder.getAdapterPosition()]); - } - }) - .show(); - } - }); - holder.share.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - setContextGroupVisible(holder, false); - Cat cat = mCats[holder.getAdapterPosition()]; - if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) - != PackageManager.PERMISSION_GRANTED) { - mPendingShareCat = cat; - requestPermissions( - new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, - STORAGE_PERM_REQUEST); - return; - } - shareCat(cat); - } - }); - } - - @Override - public int getItemCount() { - return mCats.length; - } - } - - private void shareCat(Cat cat) { - final File dir = new File( - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), - getString(R.string.directory_name)); - if (!dir.exists() && !dir.mkdirs()) { - Log.e("NekoLand", "save: error: can't create Pictures directory"); - return; - } - final File png = new File(dir, cat.getName().replaceAll("[/ #:]+", "_") + ".png"); - Bitmap bitmap = cat.createBitmap(EXPORT_BITMAP_SIZE, EXPORT_BITMAP_SIZE); - if (bitmap != null) { - try { - OutputStream os = new FileOutputStream(png); - bitmap.compress(Bitmap.CompressFormat.PNG, 0, os); - os.close(); - MediaScannerConnection.scanFile( - this, - new String[] {png.toString()}, - new String[] {"image/png"}, - null); - Log.v("Neko", "cat file: " + png); - Uri uri = FileProvider.getUriForFile(this, "com.android.egg.fileprovider", png); - Log.v("Neko", "cat uri: " + uri); - Intent intent = new Intent(Intent.ACTION_SEND); - intent.putExtra(Intent.EXTRA_STREAM, uri); - intent.putExtra(Intent.EXTRA_SUBJECT, cat.getName()); - intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - intent.setType("image/png"); - startActivity(Intent.createChooser(intent, null)); - cat.logShare(this); - } catch (IOException e) { - Log.e("NekoLand", "save: error: " + e); - } - } - } - - @Override - public void onRequestPermissionsResult(int requestCode, - String permissions[], int[] grantResults) { - if (requestCode == STORAGE_PERM_REQUEST) { - if (mPendingShareCat != null) { - shareCat(mPendingShareCat); - mPendingShareCat = null; - } - } - } - - private static class CatHolder extends RecyclerView.ViewHolder { - private final ImageView imageView; - private final TextView textView; - private final View contextGroup; - private final View delete; - private final View share; - - public CatHolder(View itemView) { - super(itemView); - imageView = (ImageView) itemView.findViewById(android.R.id.icon); - textView = (TextView) itemView.findViewById(android.R.id.title); - contextGroup = itemView.findViewById(R.id.contextGroup); - delete = itemView.findViewById(android.R.id.closeButton); - share = itemView.findViewById(android.R.id.shareText); - } - } -} diff --git a/packages/EasterEgg/src/com/android/egg/neko/NekoLockedActivity.java b/packages/EasterEgg/src/com/android/egg/neko/NekoLockedActivity.java deleted file mode 100644 index 5f01da879ebb..000000000000 --- a/packages/EasterEgg/src/com/android/egg/neko/NekoLockedActivity.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -package com.android.egg.neko; - -import android.support.annotation.Nullable; -import android.app.Activity; -import android.content.DialogInterface; -import android.content.DialogInterface.OnDismissListener; -import android.os.Bundle; -import android.view.WindowManager; - -public class NekoLockedActivity extends Activity implements OnDismissListener { - - private NekoDialog mDialog; - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); - - mDialog = new NekoDialog(this); - mDialog.setOnDismissListener(this); - mDialog.show(); - } - - @Override - public void onDismiss(DialogInterface dialog) { - finish(); - } -} diff --git a/packages/EasterEgg/src/com/android/egg/neko/NekoService.java b/packages/EasterEgg/src/com/android/egg/neko/NekoService.java deleted file mode 100644 index 42506e61d2ec..000000000000 --- a/packages/EasterEgg/src/com/android/egg/neko/NekoService.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -package com.android.egg.neko; - -import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.job.JobInfo; -import android.app.job.JobParameters; -import android.app.job.JobScheduler; -import android.app.job.JobService; -import android.content.ComponentName; -import android.content.Context; -import android.net.Uri; -import android.os.Bundle; - -import java.util.List; -import android.util.Log; - -import com.android.egg.R; - -import java.util.Random; - -import static com.android.egg.neko.Cat.PURR; -import static com.android.egg.neko.NekoLand.CHAN_ID; - -public class NekoService extends JobService { - - private static final String TAG = "NekoService"; - - public static int JOB_ID = 42; - - public static int CAT_NOTIFICATION = 1; - public static int DEBUG_NOTIFICATION = 1234; - - public static float CAT_CAPTURE_PROB = 1.0f; // generous - - public static long SECONDS = 1000; - public static long MINUTES = 60 * SECONDS; - - public static long INTERVAL_FLEX = 5 * MINUTES; - - public static float INTERVAL_JITTER_FRAC = 0.25f; - - private static void setupNotificationChannels(Context context) { - NotificationManager noman = context.getSystemService(NotificationManager.class); - NotificationChannel eggChan = new NotificationChannel(CHAN_ID, - context.getString(R.string.notification_channel_name), - NotificationManager.IMPORTANCE_DEFAULT); - eggChan.setSound(Uri.EMPTY, Notification.AUDIO_ATTRIBUTES_DEFAULT); // cats are quiet - eggChan.setVibrationPattern(PURR); // not totally quiet though - eggChan.setBlockableSystem(true); // unlike a real cat, you can push this one off your lap - eggChan.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); // cats sit in the window - noman.createNotificationChannel(eggChan); - } - - @Override - public boolean onStartJob(JobParameters params) { - Log.v(TAG, "Starting job: " + String.valueOf(params)); - - NotificationManager noman = getSystemService(NotificationManager.class); - if (NekoLand.DEBUG_NOTIFICATIONS) { - final Bundle extras = new Bundle(); - extras.putString("android.substName", getString(R.string.notification_name)); - final int size = getResources() - .getDimensionPixelSize(android.R.dimen.notification_large_icon_width); - final Cat cat = Cat.create(this); - final Notification.Builder builder - = cat.buildNotification(this) - .setContentTitle("DEBUG") - .setChannel(NekoLand.CHAN_ID) - .setContentText("Ran job: " + params); - noman.notify(DEBUG_NOTIFICATION, builder.build()); - } - - final PrefState prefs = new PrefState(this); - int food = prefs.getFoodState(); - if (food != 0) { - prefs.setFoodState(0); // nom - final Random rng = new Random(); - if (rng.nextFloat() <= CAT_CAPTURE_PROB) { - Cat cat; - List cats = prefs.getCats(); - final int[] probs = getResources().getIntArray(R.array.food_new_cat_prob); - final float new_cat_prob = (float)((food < probs.length) ? probs[food] : 50) / 100f; - - if (cats.size() == 0 || rng.nextFloat() <= new_cat_prob) { - cat = Cat.create(this); - prefs.addCat(cat); - cat.logAdd(this); - Log.v(TAG, "A new cat is here: " + cat.getName()); - } else { - cat = cats.get(rng.nextInt(cats.size())); - Log.v(TAG, "A cat has returned: " + cat.getName()); - } - - final Notification.Builder builder = cat.buildNotification(this); - noman.notify(CAT_NOTIFICATION, builder.build()); - } - } - cancelJob(this); - return false; - } - - @Override - public boolean onStopJob(JobParameters jobParameters) { - return false; - } - - public static void registerJobIfNeeded(Context context, long intervalMinutes) { - JobScheduler jss = context.getSystemService(JobScheduler.class); - JobInfo info = jss.getPendingJob(JOB_ID); - if (info == null) { - registerJob(context, intervalMinutes); - } - } - - public static void registerJob(Context context, long intervalMinutes) { - setupNotificationChannels(context); - - JobScheduler jss = context.getSystemService(JobScheduler.class); - jss.cancel(JOB_ID); - long interval = intervalMinutes * MINUTES; - long jitter = (long)(INTERVAL_JITTER_FRAC * interval); - interval += (long)(Math.random() * (2 * jitter)) - jitter; - final JobInfo jobInfo = new JobInfo.Builder(JOB_ID, - new ComponentName(context, NekoService.class)) - .setPeriodic(interval, INTERVAL_FLEX) - .build(); - - Log.v(TAG, "A cat will visit in " + interval + "ms: " + String.valueOf(jobInfo)); - jss.schedule(jobInfo); - - if (NekoLand.DEBUG_NOTIFICATIONS) { - NotificationManager noman = context.getSystemService(NotificationManager.class); - noman.notify(DEBUG_NOTIFICATION, new Notification.Builder(context) - .setSmallIcon(R.drawable.stat_icon) - .setContentTitle(String.format("Job scheduled in %d min", (interval / MINUTES))) - .setContentText(String.valueOf(jobInfo)) - .setPriority(Notification.PRIORITY_MIN) - .setCategory(Notification.CATEGORY_SERVICE) - .setChannel(NekoLand.CHAN_ID) - .setShowWhen(true) - .build()); - } - } - - public static void cancelJob(Context context) { - JobScheduler jss = context.getSystemService(JobScheduler.class); - Log.v(TAG, "Canceling job"); - jss.cancel(JOB_ID); - } -} diff --git a/packages/EasterEgg/src/com/android/egg/neko/NekoTile.java b/packages/EasterEgg/src/com/android/egg/neko/NekoTile.java deleted file mode 100644 index 159b40a3e5af..000000000000 --- a/packages/EasterEgg/src/com/android/egg/neko/NekoTile.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -package com.android.egg.neko; - -import android.content.Intent; -import android.service.quicksettings.Tile; -import android.service.quicksettings.TileService; -import android.util.Log; - -import com.android.egg.neko.PrefState.PrefsListener; -import com.android.internal.logging.MetricsLogger; - -public class NekoTile extends TileService implements PrefsListener { - - private static final String TAG = "NekoTile"; - - private PrefState mPrefs; - - @Override - public void onCreate() { - super.onCreate(); - mPrefs = new PrefState(this); - } - - @Override - public void onStartListening() { - super.onStartListening(); - mPrefs.setListener(this); - updateState(); - } - - @Override - public void onStopListening() { - super.onStopListening(); - mPrefs.setListener(null); - } - - @Override - public void onTileAdded() { - super.onTileAdded(); - MetricsLogger.count(this, "egg_neko_tile_added", 1); - } - - @Override - public void onTileRemoved() { - super.onTileRemoved(); - MetricsLogger.count(this, "egg_neko_tile_removed", 1); - } - - @Override - public void onPrefsChanged() { - updateState(); - } - - private void updateState() { - Tile tile = getQsTile(); - int foodState = mPrefs.getFoodState(); - Food food = new Food(foodState); - if (foodState != 0) { - NekoService.registerJobIfNeeded(this, food.getInterval(this)); - } - tile.setIcon(food.getIcon(this)); - tile.setLabel(food.getName(this)); - tile.setState(foodState != 0 ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); - tile.updateTile(); - } - - @Override - public void onClick() { - if (mPrefs.getFoodState() != 0) { - // there's already food loaded, let's empty it - MetricsLogger.count(this, "egg_neko_empty_food", 1); - mPrefs.setFoodState(0); - NekoService.cancelJob(this); - } else { - // time to feed the cats - if (isLocked()) { - if (isSecure()) { - Log.d(TAG, "startActivityAndCollapse"); - Intent intent = new Intent(this, NekoLockedActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivityAndCollapse(intent); - } else { - unlockAndRun(new Runnable() { - @Override - public void run() { - showNekoDialog(); - } - }); - } - } else { - showNekoDialog(); - } - } - } - - private void showNekoDialog() { - Log.d(TAG, "showNekoDialog"); - MetricsLogger.count(this, "egg_neko_select_food", 1); - showDialog(new NekoDialog(this)); - } -} diff --git a/packages/EasterEgg/src/com/android/egg/neko/PrefState.java b/packages/EasterEgg/src/com/android/egg/neko/PrefState.java deleted file mode 100644 index bf71b197d3cb..000000000000 --- a/packages/EasterEgg/src/com/android/egg/neko/PrefState.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -package com.android.egg.neko; - -import android.content.Context; -import android.content.SharedPreferences; -import android.content.SharedPreferences.OnSharedPreferenceChangeListener; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class PrefState implements OnSharedPreferenceChangeListener { - - private static final String FILE_NAME = "mPrefs"; - - private static final String FOOD_STATE = "food"; - - private static final String CAT_KEY_PREFIX = "cat:"; - - private final Context mContext; - private final SharedPreferences mPrefs; - private PrefsListener mListener; - - public PrefState(Context context) { - mContext = context; - mPrefs = mContext.getSharedPreferences(FILE_NAME, 0); - } - - // Can also be used for renaming. - public void addCat(Cat cat) { - mPrefs.edit() - .putString(CAT_KEY_PREFIX + String.valueOf(cat.getSeed()), cat.getName()) - .apply(); - } - - public void removeCat(Cat cat) { - mPrefs.edit().remove(CAT_KEY_PREFIX + String.valueOf(cat.getSeed())).apply(); - } - - public List getCats() { - ArrayList cats = new ArrayList<>(); - Map map = mPrefs.getAll(); - for (String key : map.keySet()) { - if (key.startsWith(CAT_KEY_PREFIX)) { - long seed = Long.parseLong(key.substring(CAT_KEY_PREFIX.length())); - Cat cat = new Cat(mContext, seed); - cat.setName(String.valueOf(map.get(key))); - cats.add(cat); - } - } - return cats; - } - - public int getFoodState() { - return mPrefs.getInt(FOOD_STATE, 0); - } - - public void setFoodState(int foodState) { - mPrefs.edit().putInt(FOOD_STATE, foodState).apply(); - } - - public void setListener(PrefsListener listener) { - mListener = listener; - if (mListener != null) { - mPrefs.registerOnSharedPreferenceChangeListener(this); - } else { - mPrefs.unregisterOnSharedPreferenceChangeListener(this); - } - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - mListener.onPrefsChanged(); - } - - public interface PrefsListener { - void onPrefsChanged(); - } -} diff --git a/packages/EasterEgg/src/com/android/egg/octo/Ocquarium.java b/packages/EasterEgg/src/com/android/egg/octo/Ocquarium.java deleted file mode 100644 index 8a06cc604f1e..000000000000 --- a/packages/EasterEgg/src/com/android/egg/octo/Ocquarium.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2017 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. - */ - -package com.android.egg.octo; - -import android.app.Activity; -import android.os.Bundle; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.ImageView; - -import com.android.egg.R; - -public class Ocquarium extends Activity { - ImageView mImageView; - private OctopusDrawable mOcto; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - final float dp = getResources().getDisplayMetrics().density; - - getWindow().setBackgroundDrawableResource(R.drawable.octo_bg); - - FrameLayout bg = new FrameLayout(this); - setContentView(bg); - bg.setAlpha(0f); - bg.animate().setStartDelay(500).setDuration(5000).alpha(1f).start(); - - mImageView = new ImageView(this); - bg.addView(mImageView, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - - mOcto = new OctopusDrawable(getApplicationContext()); - mOcto.setSizePx((int) (OctopusDrawable.randfrange(40f,180f) * dp)); - mImageView.setImageDrawable(mOcto); - - mImageView.setOnTouchListener(new View.OnTouchListener() { - boolean touching; - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - switch (motionEvent.getActionMasked()) { - case MotionEvent.ACTION_DOWN: - if (mOcto.hitTest(motionEvent.getX(), motionEvent.getY())) { - touching = true; - mOcto.stopDrift(); - } - break; - case MotionEvent.ACTION_MOVE: - if (touching) { - mOcto.moveTo(motionEvent.getX(), motionEvent.getY()); - } - break; - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: - touching = false; - mOcto.startDrift(); - break; - } - return true; - } - }); - } - - @Override - protected void onPause() { - mOcto.stopDrift(); - super.onPause(); - } - - @Override - protected void onResume() { - super.onResume(); - mOcto.startDrift(); - } -} diff --git a/packages/EasterEgg/src/com/android/egg/octo/OctopusDrawable.java b/packages/EasterEgg/src/com/android/egg/octo/OctopusDrawable.java deleted file mode 100644 index 5dde6e115268..000000000000 --- a/packages/EasterEgg/src/com/android/egg/octo/OctopusDrawable.java +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright (C) 2017 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. - */ - -package com.android.egg.octo; - -import android.animation.TimeAnimator; -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.ColorFilter; -import android.graphics.DashPathEffect; -import android.graphics.Matrix; -import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.PixelFormat; -import android.graphics.PointF; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.support.animation.DynamicAnimation; -import android.support.animation.SpringForce; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.animation.SpringAnimation; -import android.support.animation.FloatValueHolder; - -public class OctopusDrawable extends Drawable { - private static float BASE_SCALE = 100f; - public static boolean PATH_DEBUG = false; - - private static int BODY_COLOR = 0xFF101010; - private static int ARM_COLOR = 0xFF101010; - private static int ARM_COLOR_BACK = 0xFF000000; - private static int EYE_COLOR = 0xFF808080; - - private static int[] BACK_ARMS = {1, 3, 4, 6}; - private static int[] FRONT_ARMS = {0, 2, 5, 7}; - - private Paint mPaint = new Paint(); - private Arm[] mArms = new Arm[8]; - final PointF point = new PointF(); - private int mSizePx = 100; - final Matrix M = new Matrix(); - final Matrix M_inv = new Matrix(); - private TimeAnimator mDriftAnimation; - private boolean mBlinking; - private float[] ptmp = new float[2]; - private float[] scaledBounds = new float[2]; - - public static float randfrange(float a, float b) { - return (float) (Math.random()*(b-a) + a); - } - public static float clamp(float v, float a, float b) { - return vb?b:v; - } - - public OctopusDrawable(Context context) { - float dp = context.getResources().getDisplayMetrics().density; - setSizePx((int) (100*dp)); - mPaint.setAntiAlias(true); - for (int i=0; i nextjump) { - vy = JUMP_VY; - nextjump = t + (long) randfrange(5000, 10000); - } - if (unblink > 0 && t > unblink) { - setBlinking(false); - unblink = 0; - } else if (Math.random() < 0.001f) { - setBlinking(true); - unblink = t + 200; - } - - ax = (float) (MAX_VX * Math.sin(t_sec*.25f)); - - vx = clamp(vx + dt_sec * ax, -MAX_VX, MAX_VX); - vy = clamp(vy + dt_sec * ay, -100*MAX_VY, MAX_VY); - - // oob check - if (point.y - BASE_SCALE/2 > scaledBounds[1]) { - vy = JUMP_VY; - } else if (point.y + BASE_SCALE < 0) { - vy = MAX_VY; - } - - point.x = clamp(point.x + dt_sec * vx, 0, scaledBounds[0]); - point.y = point.y + dt_sec * vy; - - repositionArms(); - } - }); - } - mDriftAnimation.start(); - } - - public void stopDrift() { - mDriftAnimation.cancel(); - } - - @Override - public void onBoundsChange(Rect bounds) { - final float w = bounds.width(); - final float h = bounds.height(); - - lockArms(true); - moveTo(w/2, h/2); - lockArms(false); - - scaledBounds[0] = w; - scaledBounds[1] = h; - M_inv.mapPoints(scaledBounds); - } - - // real pixel coordinates - public void moveTo(float x, float y) { - point.x = x; - point.y = y; - mapPointF(M_inv, point); - repositionArms(); - } - - public boolean hitTest(float x, float y) { - ptmp[0] = x; - ptmp[1] = y; - M_inv.mapPoints(ptmp); - return Math.hypot(ptmp[0] - point.x, ptmp[1] - point.y) < BASE_SCALE/2; - } - - private void lockArms(boolean l) { - for (Arm arm : mArms) { - arm.setLocked(l); - } - } - private void repositionArms() { - for (int i=0; i=len) { - t=len; - last=true; - } - pm.getPosTan(t, pos, tan); - float r = len > 0 ? lerp(t/len, r1, r2) : r1; - c.drawCircle(pos[0], pos[1], r, pt); - t += Math.max(r*0.25f, sMinStepPx); // walk forward 1/4 radius, not too small though - if (last) break; - } - } -} diff --git a/packages/EasterEgg/src/com/android/egg/paint/BrushPropertyDrawable.kt b/packages/EasterEgg/src/com/android/egg/paint/BrushPropertyDrawable.kt new file mode 100644 index 000000000000..4a02ee688cf4 --- /dev/null +++ b/packages/EasterEgg/src/com/android/egg/paint/BrushPropertyDrawable.kt @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.android.egg.paint + +import android.content.Context +import android.graphics.* +import android.graphics.PixelFormat.TRANSLUCENT +import android.graphics.drawable.Drawable +import android.util.DisplayMetrics + +class BrushPropertyDrawable : Drawable { + val framePaint = Paint(Paint.ANTI_ALIAS_FLAG).also { + it.color = Color.BLACK + it.style = Paint.Style.FILL + } + val wellPaint = Paint(Paint.ANTI_ALIAS_FLAG).also { + it.color = Color.RED + it.style = Paint.Style.FILL + } + + constructor(context: Context) { + _size = (24 * context.resources.displayMetrics.density).toInt() + } + + private var _size = 24 + private var _scale = 1f + + fun setFrameColor(color: Int) { + framePaint.color = color + invalidateSelf() + } + + fun setWellColor(color: Int) { + wellPaint.color = color + invalidateSelf() + } + + fun setWellScale(scale: Float) { + _scale = scale + invalidateSelf() + } + + override fun getIntrinsicWidth(): Int { + return _size + } + + override fun getIntrinsicHeight(): Int { + return _size + } + + override fun draw(c: Canvas?) { + c?.let { + val w = bounds.width().toFloat() + val h = bounds.height().toFloat() + val inset = _size / 12 // 2dp in a 24x24 icon + val r = Math.min(w, h) / 2 + + c.drawCircle(w/2, h/2, (r - inset) * _scale + 1 , wellPaint) + + val p = Path() + p.addCircle(w/2, h/2, r, Path.Direction.CCW) + p.addCircle(w/2, h/2, r - inset, Path.Direction.CW) + c.drawPath(p, framePaint) + } + } + + override fun setAlpha(p0: Int) { + // + } + + override fun getOpacity(): Int { + return TRANSLUCENT + } + + override fun setColorFilter(p0: ColorFilter?) { + // + } + +} \ No newline at end of file diff --git a/packages/EasterEgg/src/com/android/egg/paint/CutoutAvoidingToolbar.kt b/packages/EasterEgg/src/com/android/egg/paint/CutoutAvoidingToolbar.kt new file mode 100644 index 000000000000..164fc5a5af3d --- /dev/null +++ b/packages/EasterEgg/src/com/android/egg/paint/CutoutAvoidingToolbar.kt @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.android.egg.paint + +import android.content.Context +import android.util.AttributeSet +import android.view.* +import android.view.ViewGroup.LayoutParams.MATCH_PARENT +import android.widget.LinearLayout + +class CutoutAvoidingToolbar : LinearLayout { + private var _insets: WindowInsets? = null + + constructor(context: Context) : super(context) { + init(null, 0) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(attrs, 0) + } + + constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) { + init(attrs, defStyle) + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + adjustLayout() + } + + override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets { + _insets = insets + adjustLayout() + return super.onApplyWindowInsets(insets) + } + + fun adjustLayout() { + _insets?.displayCutout?.boundingRects?.let { + var cutoutCenter = 0 + var cutoutLeft = 0 + var cutoutRight = 0 + + // collect at most three cutouts + for (r in it) { + if (r.top > 0) continue + + if (r.left == left) { + cutoutLeft = r.width() + } else if (r.right == right) { + cutoutRight = r.width() + } else { + cutoutCenter = r.width() + } + } + + // apply to layout + (findViewWithTag("cutoutLeft") as View?)?.let { + it.layoutParams = LayoutParams(cutoutLeft, MATCH_PARENT) + } + (findViewWithTag("cutoutCenter") as View?)?.let { + it.layoutParams = LayoutParams(cutoutCenter, MATCH_PARENT) + } + (findViewWithTag("cutoutRight") as View?)?.let { + it.layoutParams = LayoutParams(cutoutRight, MATCH_PARENT) + } + + requestLayout() + } + } + + private fun init(attrs: AttributeSet?, defStyle: Int) { + } + +} diff --git a/packages/EasterEgg/src/com/android/egg/paint/PaintActivity.java b/packages/EasterEgg/src/com/android/egg/paint/PaintActivity.java new file mode 100644 index 000000000000..ac47fbda09c6 --- /dev/null +++ b/packages/EasterEgg/src/com/android/egg/paint/PaintActivity.java @@ -0,0 +1,351 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.android.egg.paint; + +import static android.view.MotionEvent.ACTION_CANCEL; +import static android.view.MotionEvent.ACTION_DOWN; +import static android.view.MotionEvent.ACTION_MOVE; +import static android.view.MotionEvent.ACTION_UP; + +import android.app.Activity; +import android.content.res.Configuration; +import android.graphics.Bitmap; +import android.graphics.Color; +import android.os.Bundle; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.view.animation.OvershootInterpolator; +import android.widget.FrameLayout; +import android.widget.ImageButton; +import android.widget.LinearLayout; +import android.widget.Magnifier; + +import com.android.egg.R; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.stream.IntStream; + +public class PaintActivity extends Activity { + private static final float MAX_BRUSH_WIDTH_DP = 100f; + private static final float MIN_BRUSH_WIDTH_DP = 1f; + + private static final int NUM_BRUSHES = 6; + private static final int NUM_COLORS = 6; + + private Painting painting = null; + private CutoutAvoidingToolbar toolbar = null; + private LinearLayout brushes = null; + private LinearLayout colors = null; + private Magnifier magnifier = null; + private boolean sampling = false; + + private View.OnClickListener buttonHandler = new View.OnClickListener() { + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.btnBrush: + view.setSelected(true); + hideToolbar(colors); + toggleToolbar(brushes); + break; + case R.id.btnColor: + view.setSelected(true); + hideToolbar(brushes); + toggleToolbar(colors); + break; + case R.id.btnClear: + painting.clear(); + break; + case R.id.btnSample: + sampling = true; + view.setSelected(true); + break; + case R.id.btnZen: + painting.setZenMode(!painting.getZenMode()); + view.animate() + .setStartDelay(200) + .setInterpolator(new OvershootInterpolator()) + .rotation(painting.getZenMode() ? 0f : 90f); + break; + } + } + }; + + private void showToolbar(View bar) { + if (bar.getVisibility() != View.GONE) return; + bar.setVisibility(View.VISIBLE); + bar.setTranslationY(toolbar.getHeight()/2); + bar.animate() + .translationY(toolbar.getHeight()) + .alpha(1f) + .setDuration(220) + .start(); + } + + private void hideToolbar(View bar) { + if (bar.getVisibility() != View.VISIBLE) return; + bar.animate() + .translationY(toolbar.getHeight()/2) + .alpha(0f) + .setDuration(150) + .withEndAction(new Runnable() { + @Override + public void run() { + bar.setVisibility(View.GONE); + } + }) + .start(); + } + + private void toggleToolbar(View bar) { + if (bar.getVisibility() == View.VISIBLE) { + hideToolbar(bar); + } else { + showToolbar(bar); + } + } + + private BrushPropertyDrawable widthButtonDrawable; + private BrushPropertyDrawable colorButtonDrawable; + private float maxBrushWidth, minBrushWidth; + private int nightMode = Configuration.UI_MODE_NIGHT_UNDEFINED; + + static final float lerp(float f, float a, float b) { + return a + (b-a) * f; + } + + void setupViews(Painting oldPainting) { + setContentView(R.layout.activity_paint); + + painting = oldPainting != null ? oldPainting : new Painting(this); + ((FrameLayout) findViewById(R.id.contentView)).addView(painting, + new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT)); + + painting.setPaperColor(getColor(R.color.paper_color)); + painting.setPaintColor(getColor(R.color.paint_color)); + + toolbar = findViewById(R.id.toolbar); + brushes = findViewById(R.id.brushes); + colors = findViewById(R.id.colors); + + magnifier = new Magnifier(painting); + + painting.setOnTouchListener( + new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent event) { + switch (event.getActionMasked()) { + case ACTION_DOWN: + case ACTION_MOVE: + if (sampling) { + magnifier.show(event.getX(), event.getY()); + colorButtonDrawable.setWellColor( + painting.sampleAt(event.getX(), event.getY())); + return true; + } + break; + case ACTION_CANCEL: + if (sampling) { + findViewById(R.id.btnSample).setSelected(false); + sampling = false; + magnifier.dismiss(); + } + break; + case ACTION_UP: + if (sampling) { + findViewById(R.id.btnSample).setSelected(false); + sampling = false; + magnifier.dismiss(); + painting.setPaintColor( + painting.sampleAt(event.getX(), event.getY())); + refreshBrushAndColor(); + } + break; + } + return false; // allow view to continue handling + } + }); + + findViewById(R.id.btnBrush).setOnClickListener(buttonHandler); + findViewById(R.id.btnColor).setOnClickListener(buttonHandler); + findViewById(R.id.btnClear).setOnClickListener(buttonHandler); + findViewById(R.id.btnSample).setOnClickListener(buttonHandler); + findViewById(R.id.btnZen).setOnClickListener(buttonHandler); + + findViewById(R.id.btnColor).setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View view) { + colors.removeAllViews(); + showToolbar(colors); + refreshBrushAndColor(); + return true; + } + }); + + findViewById(R.id.btnClear).setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View view) { + painting.invertContents(); + return true; + } + }); + + widthButtonDrawable = new BrushPropertyDrawable(this); + widthButtonDrawable.setFrameColor(getColor(R.color.toolbar_icon_color)); + colorButtonDrawable = new BrushPropertyDrawable(this); + colorButtonDrawable.setFrameColor(getColor(R.color.toolbar_icon_color)); + + ((ImageButton) findViewById(R.id.btnBrush)).setImageDrawable(widthButtonDrawable); + ((ImageButton) findViewById(R.id.btnColor)).setImageDrawable(colorButtonDrawable); + + refreshBrushAndColor(); + } + + private void refreshBrushAndColor() { + final LinearLayout.LayoutParams button_lp = new LinearLayout.LayoutParams( + 0, ViewGroup.LayoutParams.WRAP_CONTENT); + button_lp.weight = 1f; + if (brushes.getChildCount() == 0) { + for (int i = 0; i < NUM_BRUSHES; i++) { + final BrushPropertyDrawable icon = new BrushPropertyDrawable(this); + icon.setFrameColor(getColor(R.color.toolbar_icon_color)); + // exponentially increasing brush size + final float width = lerp( + (float) Math.pow((float) i / NUM_BRUSHES, 2f), minBrushWidth, + maxBrushWidth); + icon.setWellScale(width / maxBrushWidth); + icon.setWellColor(getColor(R.color.toolbar_icon_color)); + final ImageButton button = new ImageButton(this); + button.setImageDrawable(icon); + button.setBackground(getDrawable(R.drawable.toolbar_button_bg)); + button.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View view) { + brushes.setSelected(false); + hideToolbar(brushes); + painting.setBrushWidth(width); + refreshBrushAndColor(); + } + }); + brushes.addView(button, button_lp); + } + } + + if (colors.getChildCount() == 0) { + final Palette pal = new Palette(NUM_COLORS); + for (final int c : IntStream.concat( + IntStream.of(Color.BLACK, Color.WHITE), + Arrays.stream(pal.getColors()) + ).toArray()) { + final BrushPropertyDrawable icon = new BrushPropertyDrawable(this); + icon.setFrameColor(getColor(R.color.toolbar_icon_color)); + icon.setWellColor(c); + final ImageButton button = new ImageButton(this); + button.setImageDrawable(icon); + button.setBackground(getDrawable(R.drawable.toolbar_button_bg)); + button.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View view) { + colors.setSelected(false); + hideToolbar(colors); + painting.setPaintColor(c); + refreshBrushAndColor(); + } + }); + colors.addView(button, button_lp); + } + } + + widthButtonDrawable.setWellScale(painting.getBrushWidth() / maxBrushWidth); + widthButtonDrawable.setWellColor(painting.getPaintColor()); + colorButtonDrawable.setWellColor(painting.getPaintColor()); + } + + private void refreshNightMode(Configuration config) { + int newNightMode = + (config.uiMode & Configuration.UI_MODE_NIGHT_MASK); + if (nightMode != newNightMode) { + if (nightMode != Configuration.UI_MODE_NIGHT_UNDEFINED) { + painting.invertContents(); + + ((ViewGroup) painting.getParent()).removeView(painting); + setupViews(painting); + + final View decorView = getWindow().getDecorView(); + int decorSUIV = decorView.getSystemUiVisibility(); + + if (newNightMode == Configuration.UI_MODE_NIGHT_YES) { + decorView.setSystemUiVisibility( + decorSUIV & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } else { + decorView.setSystemUiVisibility( + decorSUIV | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } + nightMode = newNightMode; + } + } + + public PaintActivity() { + + } + + @Override + public void onTrimMemory(int level) { + super.onTrimMemory(level); + + painting.onTrimMemory(); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + + refreshNightMode(newConfig); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + WindowManager.LayoutParams lp = getWindow().getAttributes(); + lp.flags = lp.flags + | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN + | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; + getWindow().setAttributes(lp); + + maxBrushWidth = MAX_BRUSH_WIDTH_DP * getResources().getDisplayMetrics().density; + minBrushWidth = MIN_BRUSH_WIDTH_DP * getResources().getDisplayMetrics().density; + + setupViews(null); + refreshNightMode(getResources().getConfiguration()); + } + + @Override + public void onPostResume() { + super.onPostResume(); + } + +} diff --git a/packages/EasterEgg/src/com/android/egg/paint/Painting.kt b/packages/EasterEgg/src/com/android/egg/paint/Painting.kt new file mode 100644 index 000000000000..a4a3d3d835e0 --- /dev/null +++ b/packages/EasterEgg/src/com/android/egg/paint/Painting.kt @@ -0,0 +1,358 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.android.egg.paint + +import android.content.Context +import android.content.res.Resources +import android.graphics.* +import android.provider.Settings +import android.util.AttributeSet +import android.util.DisplayMetrics +import android.view.MotionEvent +import android.view.View +import android.view.WindowInsets +import java.util.concurrent.TimeUnit +import android.util.Log +import android.provider.Settings.System + +import org.json.JSONObject + +fun hypot(x: Float, y: Float): Float { + return Math.hypot(x.toDouble(), y.toDouble()).toFloat() +} + +fun invlerp(x: Float, a: Float, b: Float): Float { + return if (b > a) { + (x - a) / (b - a) + } else 1.0f +} + +public class Painting : View, SpotFilter.Plotter { + companion object { + val FADE_MINS = TimeUnit.MINUTES.toMillis(3) // about how long a drawing should last + val ZEN_RATE = TimeUnit.SECONDS.toMillis(2) // how often to apply the fade + val ZEN_FADE = Math.max(1f, ZEN_RATE / FADE_MINS * 255f) + + val FADE_TO_WHITE_CF = ColorMatrixColorFilter(ColorMatrix(floatArrayOf( + 1f, 0f, 0f, 0f, ZEN_FADE, + 0f, 1f, 0f, 0f, ZEN_FADE, + 0f, 0f, 1f, 0f, ZEN_FADE, + 0f, 0f, 0f, 1f, 0f + ))) + + val FADE_TO_BLACK_CF = ColorMatrixColorFilter(ColorMatrix(floatArrayOf( + 1f, 0f, 0f, 0f, -ZEN_FADE, + 0f, 1f, 0f, 0f, -ZEN_FADE, + 0f, 0f, 1f, 0f, -ZEN_FADE, + 0f, 0f, 0f, 1f, 0f + ))) + + val INVERT_CF = ColorMatrixColorFilter(ColorMatrix(floatArrayOf( + -1f, 0f, 0f, 0f, 255f, + 0f, -1f, 0f, 0f, 255f, + 0f, 0f, -1f, 0f, 255f, + 0f, 0f, 0f, 1f, 0f + ))) + + val TOUCH_STATS = "touch.stats" // Settings.System key + } + + var devicePressureMin = 0f; // ideal value + var devicePressureMax = 1f; // ideal value + + var zenMode = true + set(value) { + if (field != value) { + field = value + removeCallbacks(fadeRunnable) + if (value && isAttachedToWindow) { + handler.postDelayed(fadeRunnable, ZEN_RATE) + } + } + } + + var bitmap: Bitmap? = null + var paperColor : Int = 0xFFFFFFFF.toInt() + + private var _paintCanvas: Canvas? = null + private val _bitmapLock = Object() + + private var _drawPaint = Paint(Paint.ANTI_ALIAS_FLAG) + private var _lastX = 0f + private var _lastY = 0f + private var _lastR = 0f + private var _insets: WindowInsets? = null + + private var _brushWidth = 100f + + private var _filter = SpotFilter(10, 0.5f, 0.9f, this) + + private val fadeRunnable = object : Runnable { + private val pt = Paint() + override fun run() { + val c = _paintCanvas + if (c != null) { + pt.colorFilter = + if (paperColor.and(0xFF) > 0x80) + FADE_TO_WHITE_CF + else + FADE_TO_BLACK_CF + + synchronized(_bitmapLock) { + c.drawBitmap(bitmap, 0f, 0f, pt) + } + invalidate() + } + postDelayed(this, ZEN_RATE) + } + } + + constructor(context: Context) : super(context) { + init(null, 0) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(attrs, 0) + } + + constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) { + init(attrs, defStyle) + } + + private fun init(attrs: AttributeSet?, defStyle: Int) { + loadDevicePressureData() + } + + override fun onAttachedToWindow() { + super.onAttachedToWindow() + + setupBitmaps() + + if (zenMode) { + handler.postDelayed(fadeRunnable, ZEN_RATE) + } + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + setupBitmaps() + } + + override fun onDetachedFromWindow() { + if (zenMode) { + removeCallbacks(fadeRunnable) + } + super.onDetachedFromWindow() + } + + fun onTrimMemory() { + } + + override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets { + _insets = insets + if (insets != null && _paintCanvas == null) { + setupBitmaps() + } + return super.onApplyWindowInsets(insets) + } + + private fun powf(a: Float, b: Float): Float { + return Math.pow(a.toDouble(), b.toDouble()).toFloat() + } + + override fun plot(s: MotionEvent.PointerCoords) { + val c = _paintCanvas + if (c == null) return + synchronized(_bitmapLock) { + var x = _lastX + var y = _lastY + var r = _lastR + val newR = Math.max(1f, powf(adjustPressure(s.pressure), 2f).toFloat() * _brushWidth) + + if (r >= 0) { + val d = hypot(s.x - x, s.y - y) + if (d > 1f && (r + newR) > 1f) { + val N = (2 * d / Math.min(4f, r + newR)).toInt() + + val stepX = (s.x - x) / N + val stepY = (s.y - y) / N + val stepR = (newR - r) / N + for (i in 0 until N - 1) { // we will draw the last circle below + x += stepX + y += stepY + r += stepR + c.drawCircle(x, y, r, _drawPaint) + } + } + } + + c.drawCircle(s.x, s.y, newR, _drawPaint) + _lastX = s.x + _lastY = s.y + _lastR = newR + } + } + + private fun loadDevicePressureData() { + try { + val touchDataJson = Settings.System.getString(context.contentResolver, TOUCH_STATS) + val touchData = JSONObject( + if (touchDataJson != null) touchDataJson else "{}") + if (touchData.has("min")) devicePressureMin = touchData.getDouble("min").toFloat() + if (touchData.has("max")) devicePressureMax = touchData.getDouble("max").toFloat() + if (devicePressureMin < 0) devicePressureMin = 0f + if (devicePressureMax < devicePressureMin) devicePressureMax = devicePressureMin + 1f + } catch (e: Exception) { + } + } + + private fun adjustPressure(pressure: Float): Float { + if (pressure > devicePressureMax) devicePressureMax = pressure + if (pressure < devicePressureMin) devicePressureMin = pressure + return invlerp(pressure, devicePressureMin, devicePressureMax) + } + + override fun onTouchEvent(event: MotionEvent?): Boolean { + val c = _paintCanvas + if (event == null || c == null) return super.onTouchEvent(event) + + /* + val pt = Paint(Paint.ANTI_ALIAS_FLAG) + pt.style = Paint.Style.STROKE + pt.color = 0x800000FF.toInt() + _paintCanvas?.drawCircle(event.x, event.y, 20f, pt) + */ + + when (event.actionMasked) { + MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { + _filter.add(event) + _filter.finish() + invalidate() + } + + MotionEvent.ACTION_DOWN -> { + _lastR = -1f + _filter.add(event) + invalidate() + } + + MotionEvent.ACTION_MOVE -> { + _filter.add(event) + + invalidate() + } + } + + return true + } + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + + bitmap?.let { + canvas.drawBitmap(bitmap, 0f, 0f, _drawPaint); + } + } + + // public api + fun clear() { + bitmap = null + setupBitmaps() + invalidate() + } + + fun sampleAt(x: Float, y: Float): Int { + val localX = (x - left).toInt() + val localY = (y - top).toInt() + return bitmap?.getPixel(localX, localY) ?: Color.BLACK + } + + fun setPaintColor(color: Int) { + _drawPaint.color = color + } + + fun getPaintColor(): Int { + return _drawPaint.color + } + + fun setBrushWidth(w: Float) { + _brushWidth = w + } + + fun getBrushWidth(): Float { + return _brushWidth + } + + private fun setupBitmaps() { + val dm = DisplayMetrics() + display.getRealMetrics(dm) + val w = dm.widthPixels + val h = dm.heightPixels + val oldBits = bitmap + var bits = oldBits + if (bits == null || bits.width != w || bits.height != h) { + bits = Bitmap.createBitmap( + w, + h, + Bitmap.Config.ARGB_8888 + ) + } + if (bits == null) return + + val c = Canvas(bits) + + if (oldBits != null) { + if (oldBits.width < oldBits.height != bits.width < bits.height) { + // orientation change. let's rotate things so they fit better + val matrix = Matrix() + if (bits.width > bits.height) { + // now landscape + matrix.postRotate(-90f) + matrix.postTranslate(0f, bits.height.toFloat()) + } else { + // now portrait + matrix.postRotate(90f) + matrix.postTranslate(bits.width.toFloat(), 0f) + } + if (bits.width != oldBits.height || bits.height != oldBits.width) { + matrix.postScale( + bits.width.toFloat()/oldBits.height, + bits.height.toFloat()/oldBits.width) + } + c.matrix = matrix + } + // paint the old artwork atop the new + c.drawBitmap(oldBits, 0f, 0f, _drawPaint) + c.matrix = Matrix() + } else { + c.drawColor(paperColor) + } + + bitmap = bits + _paintCanvas = c + } + + fun invertContents() { + val invertPaint = Paint() + invertPaint.colorFilter = INVERT_CF + synchronized(_bitmapLock) { + _paintCanvas?.drawBitmap(bitmap, 0f, 0f, invertPaint) + } + invalidate() + } +} + diff --git a/packages/EasterEgg/src/com/android/egg/paint/Palette.kt b/packages/EasterEgg/src/com/android/egg/paint/Palette.kt new file mode 100644 index 000000000000..7043efe1f4f5 --- /dev/null +++ b/packages/EasterEgg/src/com/android/egg/paint/Palette.kt @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.android.egg.paint + +import android.graphics.Color + +class Palette { + var colors : IntArray + var lightest = 0 + var darkest = 0 + + /** + * rough luminance calculation + * https://www.w3.org/TR/AERT/#color-contrast + */ + private fun lum(rgb: Int): Float { + return (Color.red(rgb) * 299f + Color.green(rgb) * 587f + Color.blue(rgb) * 114f) / 1000f + } + + /** + * create a random evenly-spaced color palette + * guaranteed to contrast! + */ + fun randomize(S: Float, V: Float) { + val hsv = floatArrayOf((Math.random() * 360f).toFloat(), S, V) + val count = colors.size + colors[0] = Color.HSVToColor(hsv) + lightest = 0 + darkest = 0 + + for (i in 0 until count) { + hsv[0] = (hsv[0] + 360f / count).rem(360f) + val color = Color.HSVToColor(hsv) + colors[i] = color + + val lum = lum(colors[i]) + if (lum < lum(colors[darkest])) darkest = i + if (lum > lum(colors[lightest])) lightest = i + } + } + + override fun toString() : String { + val str = StringBuilder("Palette{ ") + for (c in colors) { + str.append(String.format("#%08x ", c)) + } + str.append("}") + return str.toString() + } + + constructor(count: Int) { + colors = IntArray(count) + randomize(1f, 1f) + } + + constructor(count: Int, S: Float, V: Float) { + colors = IntArray(count) + randomize(S, V) + } + + constructor(_colors: IntArray) { + colors = _colors + for (i in 0 until colors.size) { + val lum = lum(colors[i]) + if (lum < lum(colors[darkest])) darkest = i + if (lum > lum(colors[lightest])) lightest = i + } + } +} \ No newline at end of file diff --git a/packages/EasterEgg/src/com/android/egg/paint/SpotFilter.kt b/packages/EasterEgg/src/com/android/egg/paint/SpotFilter.kt new file mode 100644 index 000000000000..2c15c0dc4861 --- /dev/null +++ b/packages/EasterEgg/src/com/android/egg/paint/SpotFilter.kt @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.android.egg.paint + +import java.util.LinkedList + +import android.view.MotionEvent + +class SpotFilter(internal var mBufSize: Int, posDecay: Float, pressureDecay: Float, internal var mPlotter: Plotter) { + val spots = LinkedList() // newest at front + val tmpSpot = MotionEvent.PointerCoords() + var lastTool = MotionEvent.TOOL_TYPE_UNKNOWN + + val posDecay: Float + val pressureDecay: Float + + interface Plotter { + fun plot(s: MotionEvent.PointerCoords) + } + + init { + this.posDecay = if (posDecay in 0f..1f) posDecay else 1f + this.pressureDecay = if (pressureDecay in 0f..1f) pressureDecay else 1f + } + + fun filterInto(out: MotionEvent.PointerCoords, tool: Int): MotionEvent.PointerCoords { + lastTool = tool + + var wi = 1f // weight for ith component (position) + var w = 0f // total weight + var wi_press = 1f // weight for ith component (pressure) + var w_press = 0f // total weight (pressure) + + var x = 0f + var y = 0f + var pressure = 0f + var size = 0f + for (pi in spots) { + x += pi.x * wi + y += pi.y * wi + + pressure += pi.pressure * wi_press + size += pi.size * wi_press + + w += wi + wi *= posDecay // exponential backoff + + w_press += wi_press + wi_press *= pressureDecay + + if (PRECISE_STYLUS_INPUT && tool == MotionEvent.TOOL_TYPE_STYLUS) { + // just take the newest one, no need to average + break + } + } + + out.x = x / w + out.y = y / w + out.pressure = pressure / w_press + out.size = size / w_press + return out + } + + protected fun addInternal(c: MotionEvent.PointerCoords, tool: Int) { + val coord = + if (spots.size == mBufSize) { + spots.removeLast() + } else { + MotionEvent.PointerCoords() + } + coord.copyFrom(c) + + spots.add(0, coord) + + filterInto(tmpSpot, tool) + mPlotter.plot(tmpSpot) + } + + fun add(cv: List, tool: Int) { + for (c in cv) { + addInternal(c, tool) + } + } + + fun add(evt: MotionEvent) { + val tool = evt.getToolType(0) + for (i in 0 until evt.historySize) { + evt.getHistoricalPointerCoords(0, i, tmpSpot) + addInternal(tmpSpot, tool) + } + evt.getPointerCoords(0, tmpSpot) + addInternal(tmpSpot, tool) + } + + fun finish() { + while (spots.size > 0) { + filterInto(tmpSpot, lastTool) + spots.removeLast() + mPlotter.plot(tmpSpot) + } + + spots.clear() + } + + companion object { + var PRECISE_STYLUS_INPUT = true + } +} + + diff --git a/packages/EasterEgg/src/com/android/egg/paint/ToolbarView.kt b/packages/EasterEgg/src/com/android/egg/paint/ToolbarView.kt new file mode 100644 index 000000000000..86b11e7be81e --- /dev/null +++ b/packages/EasterEgg/src/com/android/egg/paint/ToolbarView.kt @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.android.egg.paint + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint +import android.graphics.Rect +import android.graphics.drawable.Drawable +import android.text.TextPaint +import android.transition.ChangeBounds +import android.transition.Transition +import android.transition.TransitionListenerAdapter +import android.transition.TransitionManager +import android.util.AttributeSet +import android.view.* +import android.view.animation.OvershootInterpolator +import android.widget.FrameLayout + +class ToolbarView : FrameLayout { + var inTransition = false + var transitionListener: Transition.TransitionListener = object : TransitionListenerAdapter() { + override fun onTransitionStart(transition: Transition?) { + inTransition = true + } + override fun onTransitionEnd(transition: Transition?) { + inTransition = false + } + } + + constructor(context: Context) : super(context) { + init(null, 0) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(attrs, 0) + } + + constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) { + init(attrs, defStyle) + } + + override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets { + var lp = layoutParams as FrameLayout.LayoutParams? + if (lp != null && insets != null) { + if (insets.hasStableInsets()) { + lp.topMargin = insets.stableInsetTop + lp.bottomMargin = insets.stableInsetBottom + } else { + lp.topMargin = insets.systemWindowInsetTop + lp.bottomMargin = insets.systemWindowInsetBottom + } + layoutParams = lp + } + + return super.onApplyWindowInsets(insets) + } + + private fun init(attrs: AttributeSet?, defStyle: Int) { + } + +} -- cgit v1.2.3-59-g8ed1b