├── AndroidNougatEasterEgg └── use_this_directory_for_your_Android_Studio_project ├── AndroidNougatEasterEgg.apk ├── photos ├── feature_graphic.png ├── web_hi_res_512.png ├── handset │ ├── Screenshot_1505021763.png │ ├── Screenshot_1505021790.png │ ├── Screenshot_1505021801.png │ ├── Screenshot_1505021807.png │ └── Screenshot_1505021820.png ├── tablet10 │ ├── Screenshot_1505012824.png │ ├── Screenshot_1505012958.png │ ├── Screenshot_1505012962.png │ ├── Screenshot_1505012970.png │ └── Screenshot_1505012975.png └── tablet7 │ ├── Screenshot_1505012470.png │ ├── Screenshot_1505013342.png │ ├── Screenshot_1505013392.png │ ├── Screenshot_1505013395.png │ └── Screenshot_1505013403.png ├── AndroidNougatEasterEggSdk29.apk ├── workspace ├── res │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ ├── values │ │ ├── dimens.xml │ │ └── strings.xml │ ├── drawable │ │ ├── body.xml │ │ ├── leg1.xml │ │ ├── leg2.xml │ │ ├── leg3.xml │ │ ├── leg4.xml │ │ ├── collar.xml │ │ ├── bowtie.xml │ │ ├── leg2_shadow.xml │ │ ├── tail_shadow.xml │ │ ├── head.xml │ │ ├── left_ear.xml │ │ ├── left_ear_inside.xml │ │ ├── nose.xml │ │ ├── foot1.xml │ │ ├── foot2.xml │ │ ├── foot3.xml │ │ ├── foot4.xml │ │ ├── right_ear.xml │ │ ├── face_spot.xml │ │ ├── left_eye.xml │ │ ├── right_ear_inside.xml │ │ ├── right_eye.xml │ │ ├── tail_cap.xml │ │ ├── belly.xml │ │ ├── back.xml │ │ ├── cap.xml │ │ ├── ic_close.xml │ │ ├── tail.xml │ │ ├── mouth.xml │ │ ├── food_dish.xml │ │ ├── ic_share.xml │ │ ├── food_sysuituna.xml │ │ ├── stat_icon.xml │ │ ├── food_bits.xml │ │ ├── food_chicken.xml │ │ └── food_donut.xml │ ├── layout │ │ ├── neko_activity.xml │ │ ├── edit_text.xml │ │ ├── food_layout.xml │ │ └── cat_view.xml │ └── menu │ │ └── neko_activity.xml ├── .bazelrc ├── WORKSPACE ├── release.proguard ├── .bazelproject ├── src │ └── com │ │ └── covertbagel │ │ └── neko │ │ ├── Sort.java │ │ ├── NekoLockedActivity.java │ │ ├── BaseActivity.java │ │ ├── Food.java │ │ ├── NekoTile.java │ │ ├── NekoDialog.java │ │ ├── PrefState.java │ │ ├── NekoService.java │ │ ├── Cat.java │ │ └── NekoLand.java ├── BUILD ├── AndroidManifestSdk29.xml └── AndroidManifestSdk24.xml ├── .gitignore ├── README.md ├── teleport_cats └── teleport_cats.sh └── LICENSE /AndroidNougatEasterEgg/use_this_directory_for_your_Android_Studio_project: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /AndroidNougatEasterEgg.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/AndroidNougatEasterEgg.apk -------------------------------------------------------------------------------- /photos/feature_graphic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/feature_graphic.png -------------------------------------------------------------------------------- /photos/web_hi_res_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/web_hi_res_512.png -------------------------------------------------------------------------------- /AndroidNougatEasterEggSdk29.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/AndroidNougatEasterEggSdk29.apk -------------------------------------------------------------------------------- /photos/handset/Screenshot_1505021763.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/handset/Screenshot_1505021763.png -------------------------------------------------------------------------------- /photos/handset/Screenshot_1505021790.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/handset/Screenshot_1505021790.png -------------------------------------------------------------------------------- /photos/handset/Screenshot_1505021801.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/handset/Screenshot_1505021801.png -------------------------------------------------------------------------------- /photos/handset/Screenshot_1505021807.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/handset/Screenshot_1505021807.png -------------------------------------------------------------------------------- /photos/handset/Screenshot_1505021820.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/handset/Screenshot_1505021820.png -------------------------------------------------------------------------------- /photos/tablet10/Screenshot_1505012824.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/tablet10/Screenshot_1505012824.png -------------------------------------------------------------------------------- /photos/tablet10/Screenshot_1505012958.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/tablet10/Screenshot_1505012958.png -------------------------------------------------------------------------------- /photos/tablet10/Screenshot_1505012962.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/tablet10/Screenshot_1505012962.png -------------------------------------------------------------------------------- /photos/tablet10/Screenshot_1505012970.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/tablet10/Screenshot_1505012970.png -------------------------------------------------------------------------------- /photos/tablet10/Screenshot_1505012975.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/tablet10/Screenshot_1505012975.png -------------------------------------------------------------------------------- /photos/tablet7/Screenshot_1505012470.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/tablet7/Screenshot_1505012470.png -------------------------------------------------------------------------------- /photos/tablet7/Screenshot_1505013342.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/tablet7/Screenshot_1505013342.png -------------------------------------------------------------------------------- /photos/tablet7/Screenshot_1505013392.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/tablet7/Screenshot_1505013392.png -------------------------------------------------------------------------------- /photos/tablet7/Screenshot_1505013395.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/tablet7/Screenshot_1505013395.png -------------------------------------------------------------------------------- /photos/tablet7/Screenshot_1505013403.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/photos/tablet7/Screenshot_1505013403.png -------------------------------------------------------------------------------- /workspace/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/workspace/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /workspace/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/workspace/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /workspace/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/workspace/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /workspace/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/workspace/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /workspace/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-blay/AndroidNougatEasterEgg/HEAD/workspace/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | AndroidNougatEasterEgg/.bazelproject 2 | AndroidNougatEasterEgg/.blaze 3 | AndroidNougatEasterEgg/.idea 4 | teleport_cats/abe.jar 5 | teleport_cats/adb 6 | teleport_cats/*.ab 7 | workspace/bazel-* 8 | workspace/gen 9 | -------------------------------------------------------------------------------- /workspace/.bazelrc: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Christopher Blay 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | common --incompatible_depset_is_not_iterable=false 16 | -------------------------------------------------------------------------------- /workspace/WORKSPACE: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017, 2018, 2019 Christopher Blay 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | android_sdk_repository( 16 | name = "androidsdk", 17 | api_level = 29, 18 | build_tools_version = "29.0.2", 19 | path = "/opt/android-sdk", 20 | ) 21 | -------------------------------------------------------------------------------- /workspace/release.proguard: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017, 2019 Christopher Blay 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/* 16 | -optimizationpasses 5 17 | -allowaccessmodification 18 | -dontwarn android.support.v4.** 19 | -------------------------------------------------------------------------------- /workspace/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 64dp 20 | 21 | -------------------------------------------------------------------------------- /workspace/.bazelproject: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017, 2019 Christopher Blay 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | android_sdk_platform: android-29 16 | java_language_level: 8 17 | 18 | directories: 19 | . 20 | 21 | targets: 22 | //:AndroidNougatEasterEggDev 23 | //:AndroidNougatEasterEggSdk24 24 | //:AndroidNougatEasterEggSdk29 25 | -------------------------------------------------------------------------------- /workspace/res/drawable/body.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/leg1.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/leg2.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/leg3.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/leg4.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/collar.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/bowtie.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/leg2_shadow.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/tail_shadow.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/head.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/left_ear.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/left_ear_inside.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/nose.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/foot1.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/foot2.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/foot3.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/foot4.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/right_ear.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/face_spot.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/left_eye.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/right_ear_inside.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /workspace/res/drawable/right_eye.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/tail_cap.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/belly.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/back.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/cap.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /workspace/res/drawable/ic_close.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 24 | 25 | -------------------------------------------------------------------------------- /workspace/res/drawable/tail.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 26 | 27 | -------------------------------------------------------------------------------- /workspace/res/layout/neko_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 25 | 26 | -------------------------------------------------------------------------------- /workspace/res/layout/edit_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 22 | 23 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /workspace/res/drawable/mouth.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 27 | 28 | -------------------------------------------------------------------------------- /workspace/res/drawable/food_dish.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 24 | 25 | -------------------------------------------------------------------------------- /workspace/src/com/covertbagel/neko/Sort.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Christopher Blay 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 | * KIND, either express or implied. See the License for the specific language governing 12 | * permissions and limitations under the License. 13 | */ 14 | 15 | package com.covertbagel.neko; 16 | 17 | import android.support.annotation.IntDef; 18 | 19 | import java.lang.annotation.Retention; 20 | 21 | import static com.covertbagel.neko.Sort.BODY_HUE; 22 | import static com.covertbagel.neko.Sort.LEGACY; 23 | import static com.covertbagel.neko.Sort.LEVEL; 24 | import static com.covertbagel.neko.Sort.NAME; 25 | import static java.lang.annotation.RetentionPolicy.SOURCE; 26 | 27 | @Retention(SOURCE) 28 | @IntDef({LEGACY, BODY_HUE, NAME, LEVEL}) 29 | @interface Sort { 30 | int LEGACY = 0; 31 | int BODY_HUE = 1; 32 | int NAME = 2; 33 | int LEVEL = 3; 34 | } 35 | -------------------------------------------------------------------------------- /workspace/res/drawable/ic_share.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 24 | 25 | -------------------------------------------------------------------------------- /workspace/res/drawable/food_sysuituna.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 24 | 25 | -------------------------------------------------------------------------------- /workspace/res/layout/food_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 22 | 27 | 30 | 31 | -------------------------------------------------------------------------------- /workspace/res/menu/neko_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 24 | 27 | 30 | 33 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /workspace/res/drawable/stat_icon.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 24 | 27 | 30 | 31 | -------------------------------------------------------------------------------- /workspace/src/com/covertbagel/neko/NekoLockedActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * Copyright (C) 2017, 2018 Christopher Blay 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the 11 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 12 | * KIND, either express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.covertbagel.neko; 17 | 18 | import android.content.DialogInterface; 19 | import android.content.DialogInterface.OnDismissListener; 20 | import android.os.Bundle; 21 | import android.support.annotation.Nullable; 22 | import android.view.WindowManager; 23 | 24 | public final class NekoLockedActivity extends BaseActivity implements OnDismissListener { 25 | 26 | private NekoDialog mDialog; 27 | 28 | @Override 29 | public void onCreate(@Nullable Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED 32 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD 33 | | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 34 | | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 35 | mDialog = new NekoDialog(this); 36 | mDialog.setOnDismissListener(this); 37 | mDialog.show(); 38 | } 39 | 40 | @Override 41 | public void onDismiss(DialogInterface dialog) { 42 | finish(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /workspace/res/drawable/food_bits.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 24 | 27 | 30 | 33 | 34 | -------------------------------------------------------------------------------- /workspace/res/drawable/food_chicken.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 24 | 27 | 30 | 33 | 36 | 39 | 40 | -------------------------------------------------------------------------------- /workspace/src/com/covertbagel/neko/BaseActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018, 2019 Christopher Blay 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 | * KIND, either express or implied. See the License for the specific language governing 12 | * permissions and limitations under the License. 13 | */ 14 | 15 | package com.covertbagel.neko; 16 | 17 | import android.app.Activity; 18 | import android.os.Bundle; 19 | import android.os.PersistableBundle; 20 | import android.support.annotation.NonNull; 21 | import android.util.Log; 22 | 23 | abstract class BaseActivity extends Activity { 24 | 25 | @Override 26 | public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { 27 | try { 28 | super.onRestoreInstanceState(savedInstanceState); 29 | } catch (Throwable throwable) { 30 | log("Suppressed Throwable in onRestoreInstanceState(Bundle)", throwable); 31 | } 32 | } 33 | 34 | @Override 35 | public void onRestoreInstanceState( 36 | Bundle savedInstanceState, PersistableBundle persistentState) { 37 | try { 38 | super.onRestoreInstanceState(savedInstanceState, persistentState); 39 | } catch (Throwable throwable) { 40 | log("Suppressed Throwable in onRestoreInstanceState(Bundle, PersistableBundle)", 41 | throwable); 42 | } 43 | } 44 | 45 | private void log(String message, Throwable throwable) { 46 | Log.w(getClass().getSimpleName(), message, throwable); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /workspace/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017, 2019 Christopher Blay 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | deps = [ 16 | "@androidsdk//com.android.support:recyclerview-v7-25.3.1", 17 | "@androidsdk//com.android.support:support-annotations-25.3.1", 18 | "@androidsdk//com.android.support:support-compat-25.3.1", 19 | "@androidsdk//com.android.support:support-core-ui-25.3.1", 20 | ] 21 | 22 | android_binary( 23 | name = "AndroidNougatEasterEggDev", 24 | srcs = glob(["src/**/*.java"]), 25 | custom_package = "com.covertbagel.neko", 26 | manifest = "AndroidManifestSdk29.xml", 27 | resource_files = glob(["res/**"]), 28 | deps = deps, 29 | ) 30 | 31 | android_binary( 32 | name = "AndroidNougatEasterEggSdk24", 33 | srcs = glob(["src/**/*.java"]), 34 | custom_package = "com.covertbagel.neko", 35 | manifest = "AndroidManifestSdk24.xml", 36 | proguard_generate_mapping = 1, 37 | proguard_specs = ["release.proguard"], 38 | resource_files = glob(["res/**"]), 39 | deps = deps, 40 | ) 41 | 42 | android_binary( 43 | name = "AndroidNougatEasterEggSdk29", 44 | srcs = glob(["src/**/*.java"]), 45 | custom_package = "com.covertbagel.neko", 46 | manifest = "AndroidManifestSdk29.xml", 47 | proguard_generate_mapping = 1, 48 | proguard_specs = ["release.proguard"], 49 | resource_files = glob(["res/**"]), 50 | deps = deps, 51 | ) 52 | -------------------------------------------------------------------------------- /workspace/src/com/covertbagel/neko/Food.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * Copyright (C) 2017, 2018 Christopher Blay 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the 11 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 12 | * KIND, either express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.covertbagel.neko; 17 | 18 | import android.content.Context; 19 | import android.content.res.TypedArray; 20 | import android.graphics.drawable.Icon; 21 | 22 | public final class Food { 23 | 24 | private final int mType; 25 | 26 | private static int[] sIcons; 27 | private static String[] sNames; 28 | 29 | Food(int type) { 30 | mType = type; 31 | } 32 | 33 | Icon getIcon(Context context) { 34 | if (sIcons == null) { 35 | TypedArray icons = context.getResources().obtainTypedArray(R.array.food_icons); 36 | sIcons = new int[icons.length()]; 37 | for (int i = 0; i < sIcons.length; i++) { 38 | sIcons[i] = icons.getResourceId(i, 0); 39 | } 40 | icons.recycle(); 41 | } 42 | return Icon.createWithResource(context, sIcons[mType]); 43 | } 44 | 45 | String getName(Context context) { 46 | if (sNames == null) { 47 | sNames = context.getResources().getStringArray(R.array.food_names); 48 | } 49 | return sNames[mType]; 50 | } 51 | 52 | long getInterval(Context context) { 53 | return context.getResources().getIntArray(R.array.food_intervals)[mType]; 54 | } 55 | 56 | int getType() { 57 | return mType; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Nougat Easter Egg (a.k.a. "Android Neko") 2 | 3 | I wanted to keep playing this game on Android O, so lifted the source from 4 | AOSP, cleaned it up a bit, fixed some things, put it in a Bazel workspace, 5 | and published it on Google Play Store. 6 | 7 | ## How to install 8 | 9 | * Get it from the Google Play Store at 10 | https://play.google.com/store/apps/details?id=com.covertbagel.neko 11 | * For Android Nougat (7), Oreo (8), and Pie (9): Download 12 | `AndroidNougatEasterEgg.apk` and sideload it. It's exactly 13 | the same as the version published on Play Store. 14 | * For Android 10 and up: Download `AndroidNougatEasterEggSdk29.apk` and 15 | sideload it. It's exactly the same as the version published on Play Store. 16 | 17 | ## How to keep your cats 18 | 19 | There is experimental support for teleporting cats from the Android system 20 | easter egg app to this one in `teleport_cats`. It has only been tested on 21 | Debian-based Linux distributions but hopefully works on Mac OS X and Cygwin 22 | too. 23 | 24 | It requires a Java runtime, Android SDK platform tools (really just ADB), 25 | and Android Backup Extractor JAR available at 26 | https://sourceforge.net/projects/adbextractor/. 27 | 28 | ## How to build 29 | 30 | This project uses Bazel to build. You'll need to get Bazel setup first but 31 | then it's really easy to build. 32 | 33 | - Android SDK 29, build tools 29.0.2, and Android Support Library 25.3.1 need 34 | to be in your local Android SDK installation. 35 | - This project is configured to look for your Android SDK installation at 36 | `/opt/android-sdk` but it's easy enough to change that to wherever you like. 37 | Just modify the one reference in `workspace/WORKSPACE`. 38 | - Go to `workspace` and run `bazel build :AndroidNougatEasterEggDev`. 39 | 40 | ## How to hack 41 | 42 | You _could_ just edit with your text editor of choice and use Bazel directly 43 | from the command line... 44 | 45 | ...but also it's pretty straightforward to import this Bazel project into 46 | Android Studio. Just install the Bazel plugin for Android Studio, use the 47 | "Import Bazel Project" option, point to `workspace` for the workspace, 48 | use `workspace/.bazelproject`, and create a project directory here called 49 | `AndroidNougatEasterEgg` (already in .gitignore) to use. 50 | -------------------------------------------------------------------------------- /workspace/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | Android Nougat Easter Egg 20 | \???? 21 | A cat is here. 22 | Cat #%s 23 | Forget %s? 24 | Sort 25 | Android 7.0 26 | Android 7.1 27 | Name 28 | Level 29 | 30 | Empty dish 31 | Bits 32 | Fish 33 | Chicken 34 | Treat 35 | 36 | 37 | @drawable/food_dish 38 | @drawable/food_bits 39 | @drawable/food_sysuituna 40 | @drawable/food_chicken 41 | @drawable/food_donut 42 | 43 | 44 | 0 45 | 15 46 | 30 47 | 60 48 | 120 49 | 50 | 51 | 0 52 | 5 53 | 35 54 | 65 55 | 90 56 | 57 | 58 | -------------------------------------------------------------------------------- /workspace/AndroidManifestSdk29.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 23 | 24 | 25 | 26 | 27 | 28 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 46 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /workspace/AndroidManifestSdk24.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 46 | 47 | 48 | 53 | 54 | 55 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /workspace/src/com/covertbagel/neko/NekoTile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * Copyright (C) 2017, 2018 Christopher Blay 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the 11 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 12 | * KIND, either express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.covertbagel.neko; 17 | 18 | import android.content.Intent; 19 | import android.service.quicksettings.Tile; 20 | import android.service.quicksettings.TileService; 21 | 22 | public final class NekoTile extends TileService implements PrefState.PrefsListener { 23 | 24 | private PrefState mPrefs; 25 | 26 | @Override 27 | public void onCreate() { 28 | super.onCreate(); 29 | mPrefs = new PrefState(this); 30 | } 31 | 32 | @Override 33 | public void onStartListening() { 34 | super.onStartListening(); 35 | mPrefs.setListener(this); 36 | updateState(); 37 | } 38 | 39 | @Override 40 | public void onStopListening() { 41 | super.onStopListening(); 42 | mPrefs.setListener(null); 43 | } 44 | 45 | @Override 46 | public void onPrefsChanged() { 47 | updateState(); 48 | } 49 | 50 | private void updateState() { 51 | final Tile tile = getQsTile(); 52 | if (tile == null) { 53 | return; 54 | } 55 | final int foodState = mPrefs.getFoodState(); 56 | final Food food = new Food(foodState); 57 | if (foodState != 0) { 58 | NekoService.registerJobIfNeeded(this, food.getInterval(this)); 59 | } 60 | tile.setIcon(food.getIcon(this)); 61 | tile.setLabel(food.getName(this)); 62 | tile.setState(foodState != 0 ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); 63 | tile.updateTile(); 64 | } 65 | 66 | @Override 67 | public void onClick() { 68 | if (mPrefs.getFoodState() != 0) { 69 | // there's already food loaded, let's empty it 70 | mPrefs.setFoodState(0); 71 | NekoService.cancelJob(this); 72 | } else { 73 | // time to feed the cats 74 | if (isLocked()) { 75 | if (isSecure()) { 76 | Intent intent = new Intent(this, NekoLockedActivity.class); 77 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 78 | startActivityAndCollapse(intent); 79 | } else { 80 | unlockAndRun(this::showNekoDialog); 81 | } 82 | } else { 83 | showNekoDialog(); 84 | } 85 | } 86 | } 87 | 88 | private void showNekoDialog() { 89 | showDialog(new NekoDialog(this)); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /workspace/res/layout/cat_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 28 | 29 | 32 | 33 | 40 | 41 | 47 | 48 | 56 | 57 | 61 | 62 | 70 | 71 | 72 | 73 | 74 | 75 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /workspace/src/com/covertbagel/neko/NekoDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * Copyright (C) 2017, 2018 Christopher Blay 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the 11 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 12 | * KIND, either express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.covertbagel.neko; 17 | 18 | import android.app.Dialog; 19 | import android.content.Context; 20 | import android.support.annotation.NonNull; 21 | import android.support.v7.widget.GridLayoutManager; 22 | import android.support.v7.widget.RecyclerView; 23 | import android.view.LayoutInflater; 24 | import android.view.View; 25 | import android.view.ViewGroup; 26 | import android.widget.ImageView; 27 | import android.widget.TextView; 28 | 29 | import java.util.ArrayList; 30 | 31 | public final class NekoDialog extends Dialog { 32 | 33 | private final Adapter mAdapter; 34 | 35 | NekoDialog(@NonNull Context context) { 36 | super(context, android.R.style.Theme_Material_Dialog_NoActionBar); 37 | RecyclerView view = new RecyclerView(getContext()); 38 | mAdapter = new Adapter(getContext()); 39 | view.setLayoutManager(new GridLayoutManager(getContext(), 2)); 40 | view.setAdapter(mAdapter); 41 | final float dp = context.getResources().getDisplayMetrics().density; 42 | final int pad = (int)(16*dp); 43 | view.setPadding(pad, pad, pad, pad); 44 | setContentView(view); 45 | } 46 | 47 | private void onFoodSelected(Food food) { 48 | PrefState prefs = new PrefState(getContext()); 49 | int currentState = prefs.getFoodState(); 50 | if (currentState == 0 && food.getType() != 0) { 51 | NekoService.registerJob(getContext(), food.getInterval(getContext())); 52 | } 53 | prefs.setFoodState(food.getType()); 54 | dismiss(); 55 | } 56 | 57 | private final class Adapter extends RecyclerView.Adapter { 58 | 59 | private final Context mContext; 60 | private final ArrayList mFoods = new ArrayList<>(); 61 | 62 | Adapter(Context context) { 63 | mContext = context; 64 | int[] foods = context.getResources().getIntArray(R.array.food_names); 65 | // skip food 0, you can't choose it 66 | for (int i=1; i onFoodSelected(mFoods.get(holder.getAdapterPosition()))); 86 | } 87 | 88 | @Override 89 | public int getItemCount() { 90 | return mFoods.size(); 91 | } 92 | } 93 | 94 | private static final class Holder extends RecyclerView.ViewHolder { 95 | 96 | Holder(View itemView) { 97 | super(itemView); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /workspace/src/com/covertbagel/neko/PrefState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * Copyright (C) 2017, 2018, 2019 Christopher Blay 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the 11 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 12 | * KIND, either express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.covertbagel.neko; 17 | 18 | import android.content.Context; 19 | import android.content.SharedPreferences; 20 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener; 21 | import android.util.Log; 22 | 23 | import java.util.ArrayList; 24 | import java.util.HashSet; 25 | import java.util.List; 26 | import java.util.Map; 27 | import java.util.Set; 28 | 29 | public final class PrefState implements OnSharedPreferenceChangeListener { 30 | 31 | private static final String FILE_NAME = "mPrefs"; 32 | private static final String FOOD_STATE = "food"; 33 | private static final String SORT = "sort"; 34 | private static final String CAT_KEY_PREFIX = "cat:"; 35 | 36 | private final Context mContext; 37 | private final SharedPreferences mPrefs; 38 | private PrefsListener mListener; 39 | 40 | PrefState(Context context) { 41 | mContext = context; 42 | mPrefs = mContext.getSharedPreferences(FILE_NAME, 0); 43 | } 44 | 45 | // Can also be used for renaming. 46 | void addCat(Cat cat) { 47 | mPrefs.edit() 48 | .putString(CAT_KEY_PREFIX + cat.getSeed(), cat.getName()) 49 | .apply(); 50 | } 51 | 52 | void removeCat(Cat cat) { 53 | mPrefs.edit().remove(CAT_KEY_PREFIX + cat.getSeed()).apply(); 54 | } 55 | 56 | List getCats() { 57 | final List cats = new ArrayList<>(); 58 | final Map map = mPrefs.getAll(); 59 | final Set invalidCatKeys = new HashSet<>(); 60 | for (String key : map.keySet()) { 61 | if (key.startsWith(CAT_KEY_PREFIX)) { 62 | final long seed; 63 | try { 64 | seed = Long.parseLong(key.substring(CAT_KEY_PREFIX.length())); 65 | } catch (NumberFormatException exception) { 66 | invalidCatKeys.add(key); 67 | continue; 68 | } 69 | cats.add(new Cat(mContext, seed, String.valueOf(map.get(key)))); 70 | } 71 | } 72 | if (!invalidCatKeys.isEmpty()) { 73 | Log.w("PrefState", "Removing invalid cat keys " + invalidCatKeys); 74 | final SharedPreferences.Editor editor = mPrefs.edit(); 75 | for (String key : invalidCatKeys) { 76 | editor.remove(key); 77 | } 78 | editor.apply(); 79 | } 80 | return cats; 81 | } 82 | 83 | int getFoodState() { 84 | return mPrefs.getInt(FOOD_STATE, 0); 85 | } 86 | 87 | void setFoodState(int foodState) { 88 | mPrefs.edit().putInt(FOOD_STATE, foodState).apply(); 89 | } 90 | 91 | @Sort 92 | int getSort() { 93 | return mPrefs.getInt(SORT, Sort.BODY_HUE); 94 | } 95 | 96 | void setSort(@Sort int sort) { 97 | mPrefs.edit().putInt(SORT, sort).apply(); 98 | } 99 | 100 | void setListener(PrefsListener listener) { 101 | mListener = listener; 102 | if (mListener != null) { 103 | mPrefs.registerOnSharedPreferenceChangeListener(this); 104 | } else { 105 | mPrefs.unregisterOnSharedPreferenceChangeListener(this); 106 | } 107 | } 108 | 109 | @Override 110 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 111 | mListener.onPrefsChanged(); 112 | } 113 | 114 | interface PrefsListener { 115 | void onPrefsChanged(); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /teleport_cats/teleport_cats.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Christopher Blay 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Exit immediately if anything goes wrong. 18 | set -eu 19 | 20 | # Prevent running this script somewhere it might mess stuff up. 21 | for FILE in *; do 22 | if [ "$FILE" != 'teleport_cats.sh' \ 23 | -a "$FILE" != 'abe.jar' \ 24 | -a "$FILE" != 'adb' ]; then 25 | echo 'Please run this script in a mostly empty directory. The' 26 | echo 'directory must contain Android Backup Extractor JAR named' 27 | echo '"abe.jar". It may optionally contain this script only if it is' 28 | echo 'named "teleport_cats.sh". It may optionally contain an "adb"' 29 | echo 'executable which will be used instead of the one on $PATH.' 30 | echo 'Delete or move all other files and directories as they may be' 31 | echo 'overwritten, modified, or deleted.' 32 | exit 33 | fi 34 | done 35 | 36 | # Make sure "abe.jar" is setup properly. 37 | if [ ! -f 'abe.jar' ]; then 38 | echo 'Can not find regular file "abe.jar" in this directory.' 39 | echo 'Please download from https://sourceforge.net/projects/adbextractor/' 40 | exit 41 | fi 42 | if [ ! -x 'abe.jar' ]; then 43 | echo '"abe.jar" is not executable. Please `chmod +x abe.jar` if you' 44 | echo 'trust it and want it to be executed by this script.' 45 | exit 46 | fi 47 | 48 | # Make sure Java is setup properly. 49 | if [ "`which java`" == '' ]; then 50 | echo 'No Java executable on $PATH. Please install Java runtime.' 51 | exit 52 | fi 53 | 54 | # Make sure ADB is setup properly. 55 | if [ -f 'adb' ]; then 56 | if [ -x 'adb' ]; then 57 | echo 'Using "adb" from this directory.' 58 | ADB='./adb' 59 | else 60 | echo '"adb" exists in this directory but is not executable.' 61 | echo 'Please `chmod +x adb` if you trust it and want it to be' 62 | echo 'executed by this script. Otherwise delete or move it.' 63 | exit 64 | fi 65 | else 66 | if [ "`which adb`" == '' ]; then 67 | echo 'No ADB executable on $PATH or in this directory.' 68 | echo 'Please either install Android SDK platform tools and put them' 69 | echo 'on your $PATH or place an executable "adb" in this directory.' 70 | exit 71 | else 72 | echo 'Using "adb" from $PATH.' 73 | ADB='adb' 74 | fi 75 | fi 76 | 77 | # Retrieve, unpack, and untar system easter egg backup. 78 | $ADB backup -f com.android.egg.ab com.android.egg 79 | java -jar abe.jar unpack com.android.egg.ab com.android.egg.tar 80 | tar -xf com.android.egg.tar 81 | rm com.android.egg.tar 82 | 83 | # Turn unpacked system backup into one for this app. 84 | cd apps/com.android.egg 85 | echo "1 86 | com.covertbagel.neko 87 | 1 88 | 25 89 | com.android.vending 90 | 0 91 | 1 92 | 308201ad30820116a00302010202044f1125d0300d06092a864886f70d0101050500301b31193017060355040313104368726973746f7068657220426c6179301e170d3132303131343036353035365a170d3337303130373036353035365a301b31193017060355040313104368726973746f7068657220426c617930819f300d06092a864886f70d010101050003818d00308189028181009900480d88c8a22794c2de266e57e3286bb61f4804ee265cd0e11ca6936186a2ccd91da89fa65a28f428dd9ccaf0fc23e96ff6559e021e0dd6ac17757c176968aea99fef6180b8a14d59e4e1ee4b4840dacd49dda641e56cbf75d99cb37cab965a27a54419c316d78915bf9dbad5e8df7cbb70c57b946144fa607fe4a45d22b10203010001300d06092a864886f70d010105050003818100228f0ec9660a6fe6029305df034f8e43e31cf0f80ec132384049442353ec940f4a38e04dcce1403b13719fdb062ec1a1c158bbb6dcffb98a42318da1cc99ff6291398bb314accf8c43e6f96332e62c808eb0558a75fc5bcffddf312043158e7f40b2c7c2783d0bc1cc169f72e53fca9db220bb9714bad0f30c83d658a479f698" > _manifest 93 | cd .. 94 | mv com.android.egg com.covertbagel.neko 95 | cd .. 96 | 97 | # Tar and pack modified backup into one for this app. 98 | tar -cf com.covertbagel.neko.tar \ 99 | apps/com.covertbagel.neko/_manifest apps/com.covertbagel.neko/sp/mPrefs.xml 100 | rm -rf apps 101 | java -jar abe.jar pack-kk com.covertbagel.neko.tar com.covertbagel.neko.ab 102 | rm com.covertbagel.neko.tar 103 | 104 | # Restore backup into this app. 105 | $ADB restore com.covertbagel.neko.ab 106 | 107 | -------------------------------------------------------------------------------- /workspace/res/drawable/food_donut.xml: -------------------------------------------------------------------------------- 1 | 16 | 21 | 24 | 25 | -------------------------------------------------------------------------------- /workspace/src/com/covertbagel/neko/NekoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * Copyright (C) 2017, 2018, 2019 Christopher Blay 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the 11 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 12 | * KIND, either express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.covertbagel.neko; 17 | 18 | import android.app.NotificationChannel; 19 | import android.app.NotificationManager; 20 | import android.app.job.JobInfo; 21 | import android.app.job.JobParameters; 22 | import android.app.job.JobScheduler; 23 | import android.app.job.JobService; 24 | import android.content.ComponentName; 25 | import android.content.Context; 26 | import android.os.Build; 27 | import android.util.Log; 28 | 29 | import java.util.List; 30 | import java.util.Random; 31 | 32 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; 33 | 34 | public final class NekoService extends JobService { 35 | 36 | private static final int JOB_ID = 42; 37 | private static final int CAT_NOTIFICATION = 1; 38 | private static final long SECONDS = 1000; 39 | private static final long MINUTES = 60 * SECONDS; 40 | private static final long INTERVAL_FLEX = 5 * MINUTES; 41 | private static final float INTERVAL_JITTER_FRAC = 0.25f; 42 | private static final long[] PURR = {0, 40, 20, 40, 20, 40, 20, 40, 20, 40, 20, 40}; 43 | private static final String CHANNEL_ID = "arrivals"; 44 | private static final String CHANNEL_NAME = "Arrivals"; 45 | private static final String TAG = "NekoService"; 46 | static final Random RANDOM = new Random(); 47 | 48 | @SuppressWarnings("ObsoleteSdkInt") 49 | @Override 50 | public boolean onStartJob(JobParameters params) { 51 | final PrefState prefs = new PrefState(this); 52 | final int food = prefs.getFoodState(); 53 | if (food != 0) { 54 | prefs.setFoodState(0); // nom 55 | final Cat cat; 56 | final List cats = prefs.getCats(); 57 | final int[] probs = getResources().getIntArray(R.array.food_new_cat_prob); 58 | final float newCatProb = (float)((food < probs.length) ? probs[food] : 50) / 100f; 59 | if (cats.size() == 0 || RANDOM.nextFloat() <= newCatProb) { 60 | cat = Cat.create(this); 61 | prefs.addCat(cat); 62 | } else { 63 | cat = cats.get(RANDOM.nextInt(cats.size())); 64 | } 65 | final NotificationManager manager = getSystemService(NotificationManager.class); 66 | if (manager != null) { 67 | if (Build.VERSION.SDK_INT >= 29) { 68 | final NotificationChannel channel = 69 | new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, IMPORTANCE_DEFAULT); 70 | channel.setSound(null, null); 71 | channel.setVibrationPattern(PURR); 72 | manager.createNotificationChannel(channel); 73 | } 74 | manager.notify(CAT_NOTIFICATION, cat.buildNotification(this, CHANNEL_ID, PURR)); 75 | } else { 76 | Log.w(TAG, "Null NotificationManager in onStartJob()"); 77 | } 78 | } 79 | cancelJob(this); 80 | return false; 81 | } 82 | 83 | @Override 84 | public boolean onStopJob(JobParameters jobParameters) { 85 | return false; 86 | } 87 | 88 | static void registerJobIfNeeded(Context context, long intervalMinutes) { 89 | final JobScheduler jobScheduler = context.getSystemService(JobScheduler.class); 90 | if (jobScheduler == null) { 91 | Log.w(TAG, "Null JobScheduler in registerJobIfNeeded()"); 92 | return; 93 | } 94 | if (jobScheduler.getPendingJob(JOB_ID) == null) { 95 | registerJob(context, intervalMinutes); 96 | } 97 | } 98 | 99 | public static void registerJob(Context context, long intervalMinutes) { 100 | final JobScheduler jobScheduler = context.getSystemService(JobScheduler.class); 101 | if (jobScheduler == null) { 102 | Log.w(TAG, "Null JobScheduler in registerJob()"); 103 | return; 104 | } 105 | jobScheduler.cancel(JOB_ID); 106 | long interval = intervalMinutes * MINUTES; 107 | final long jitter = (long)(INTERVAL_JITTER_FRAC * interval); 108 | interval += (long)(Math.random() * (2 * jitter)) - jitter; 109 | final JobInfo jobInfo = 110 | new JobInfo.Builder(JOB_ID, new ComponentName(context, NekoService.class)) 111 | .setPeriodic(interval, INTERVAL_FLEX).build(); 112 | jobScheduler.schedule(jobInfo); 113 | } 114 | 115 | public static void cancelJob(Context context) { 116 | final JobScheduler jobScheduler = context.getSystemService(JobScheduler.class); 117 | if (jobScheduler == null) { 118 | Log.w(TAG, "Null JobScheduler in cancelJob()"); 119 | return; 120 | } 121 | jobScheduler.cancel(JOB_ID); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /workspace/src/com/covertbagel/neko/Cat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * Copyright (C) 2017, 2018, 2019 Christopher Blay 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the 11 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 12 | * KIND, either express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.covertbagel.neko; 17 | 18 | import android.app.Notification; 19 | import android.app.PendingIntent; 20 | import android.content.Context; 21 | import android.content.Intent; 22 | import android.content.res.Resources; 23 | import android.graphics.Bitmap; 24 | import android.graphics.Canvas; 25 | import android.graphics.Color; 26 | import android.graphics.ColorFilter; 27 | import android.graphics.Paint; 28 | import android.graphics.PixelFormat; 29 | import android.graphics.drawable.Drawable; 30 | import android.graphics.drawable.Icon; 31 | import android.os.Build; 32 | import android.support.annotation.NonNull; 33 | 34 | import java.io.ByteArrayOutputStream; 35 | import java.util.Random; 36 | 37 | public final class Cat extends Drawable { 38 | 39 | private Random mNotSoRandom; 40 | private Bitmap mBitmap; 41 | private long mSeed; 42 | private String mName; 43 | private int mBodyColor; 44 | 45 | private synchronized Random notSoRandom(long seed) { 46 | if (mNotSoRandom == null) { 47 | mNotSoRandom = new Random(seed); 48 | } 49 | return mNotSoRandom; 50 | } 51 | 52 | private static float frandrange(Random r, float a, float b) { 53 | return (b-a)*r.nextFloat() + a; 54 | } 55 | 56 | private static Object choose(Random r, Object...l) { 57 | return l[r.nextInt(l.length)]; 58 | } 59 | 60 | private static int chooseP(Random r, int[] a) { 61 | int pct = r.nextInt(1000); 62 | final int stop = a.length-2; 63 | int i=0; 64 | while (i> 16; 126 | final int g = (color & 0x00FF00) >> 8; 127 | final int b = color & 0x0000FF; 128 | return (r + g + b) < 0x80; 129 | } 130 | 131 | Cat(Context context, long seed, String name) { 132 | D = new CatParts(context); 133 | mSeed = seed; 134 | setName(name); 135 | 136 | final Random nsr = notSoRandom(seed); 137 | 138 | // body color 139 | mBodyColor = chooseP(nsr, P_BODY_COLORS); 140 | if (mBodyColor == 0) mBodyColor = Color.HSVToColor(new float[] { 141 | nsr.nextFloat()*360f, frandrange(nsr,0.5f,1f), frandrange(nsr,0.5f, 1f)}); 142 | 143 | tint(mBodyColor, D.body, D.head, D.leg1, D.leg2, D.leg3, D.leg4, D.tail, 144 | D.leftEar, D.rightEar, D.foot1, D.foot2, D.foot3, D.foot4, D.tailCap); 145 | tint(0x20000000, D.leg2Shadow, D.tailShadow); 146 | if (isDark(mBodyColor)) { 147 | tint(0xFFFFFFFF, D.leftEye, D.rightEye, D.mouth, D.nose); 148 | } 149 | tint(isDark(mBodyColor) ? 0xFFEF9A9A : 0x20D50000, D.leftEarInside, D.rightEarInside); 150 | 151 | tint(chooseP(nsr, P_BELLY_COLORS), D.belly); 152 | tint(chooseP(nsr, P_BELLY_COLORS), D.back); 153 | final int faceColor = chooseP(nsr, P_BELLY_COLORS); 154 | tint(faceColor, D.faceSpot); 155 | if (!isDark(faceColor)) { 156 | tint(0xFF000000, D.mouth, D.nose); 157 | } 158 | 159 | if (nsr.nextFloat() < 0.25f) { 160 | tint(0xFFFFFFFF, D.foot1, D.foot2, D.foot3, D.foot4); 161 | } else { 162 | if (nsr.nextFloat() < 0.25f) { 163 | tint(0xFFFFFFFF, D.foot1, D.foot3); 164 | } else if (nsr.nextFloat() < 0.25f) { 165 | tint(0xFFFFFFFF, D.foot2, D.foot4); 166 | } else if (nsr.nextFloat() < 0.1f) { 167 | tint(0xFFFFFFFF, (Drawable) choose(nsr, D.foot1, D.foot2, D.foot3, D.foot4)); 168 | } 169 | } 170 | 171 | tint(nsr.nextFloat() < 0.333f ? 0xFFFFFFFF : mBodyColor, D.tailCap); 172 | 173 | final int capColor = chooseP(nsr, isDark(mBodyColor) ? P_LIGHT_SPOT_COLORS : P_DARK_SPOT_COLORS); 174 | tint(capColor, D.cap); 175 | 176 | final int collarColor = chooseP(nsr, P_COLLAR_COLORS); 177 | tint(collarColor, D.collar); 178 | tint((nsr.nextFloat() < 0.1f) ? collarColor : 0, D.bowtie); 179 | } 180 | 181 | static Cat create(Context context) { 182 | final long seed = Math.abs(NekoService.RANDOM.nextLong()); 183 | return new Cat(context, seed, context.getString( 184 | R.string.default_cat_name, String.valueOf(seed % 1000))); 185 | } 186 | 187 | @SuppressWarnings({"deprecation", "ObsoleteSdkInt"}) 188 | Notification buildNotification(Context context, String channelId, long[] vibrationPattern) { 189 | final Intent intent = new Intent(Intent.ACTION_MAIN) 190 | .setClass(context, NekoLand.class) 191 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 192 | final Notification.Builder builder; 193 | if (Build.VERSION.SDK_INT >= 29) { 194 | builder = new Notification.Builder(context, channelId); 195 | } else { 196 | builder = new Notification.Builder(context); 197 | } 198 | return builder 199 | .setSmallIcon(Icon.createWithResource(context, R.drawable.stat_icon)) 200 | .setLargeIcon(createNotificationLargeIcon(context)) 201 | .setColor(getBodyColor()) 202 | .setPriority(Notification.PRIORITY_LOW) 203 | .setContentTitle(context.getString(R.string.notification_title)) 204 | .setShowWhen(true) 205 | .setCategory(Notification.CATEGORY_STATUS) 206 | .setContentText(getName()) 207 | .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) 208 | .setAutoCancel(true) 209 | .setVibrate(vibrationPattern) 210 | .build(); 211 | } 212 | 213 | long getSeed() { 214 | return mSeed; 215 | } 216 | 217 | @Override 218 | public void draw(@NonNull Canvas canvas) { 219 | final int widthAndHeight = Math.min(canvas.getWidth(), canvas.getHeight()); 220 | if (mBitmap == null 221 | || mBitmap.getWidth() != widthAndHeight || mBitmap.getHeight() != widthAndHeight) { 222 | mBitmap = Bitmap.createBitmap(widthAndHeight, widthAndHeight, Bitmap.Config.ARGB_8888); 223 | final Canvas bitCanvas = new Canvas(mBitmap); 224 | slowDraw(bitCanvas, 0, 0, widthAndHeight, widthAndHeight); 225 | } 226 | canvas.drawBitmap(mBitmap, 0, 0, null); 227 | } 228 | 229 | private void slowDraw(Canvas canvas, int x, int y, int w, int h) { 230 | for (int i = 0; i < D.drawingOrder.length; i++) { 231 | final Drawable d = D.drawingOrder[i]; 232 | if (d != null) { 233 | d.setBounds(x, y, x+w, y+h); 234 | d.draw(canvas); 235 | } 236 | } 237 | 238 | } 239 | 240 | Bitmap createBitmap(int w, int h) { 241 | if (mBitmap != null && mBitmap.getWidth() == w && mBitmap.getHeight() == h) { 242 | return mBitmap.copy(mBitmap.getConfig(), true); 243 | } 244 | Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); 245 | slowDraw(new Canvas(result), 0, 0, w, h); 246 | return result; 247 | } 248 | 249 | private static Icon recompressIconBitmapIntoIcon(Bitmap bitmap) { 250 | final ByteArrayOutputStream ostream = new ByteArrayOutputStream( 251 | bitmap.getWidth() * bitmap.getHeight() * 2); // guess 50% compression 252 | final boolean ok = bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); 253 | return ok ? Icon.createWithData(ostream.toByteArray(), 0, ostream.size()) : null; 254 | } 255 | 256 | private Icon createNotificationLargeIcon(Context context) { 257 | final Resources res = context.getResources(); 258 | final int w = 2 * res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); 259 | final int h = 2 * res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); 260 | return recompressIconBitmapIntoIcon(createIconBitmap(w, h)); 261 | } 262 | 263 | private Bitmap createIconBitmap(int w, int h) { 264 | final Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); 265 | final Canvas canvas = new Canvas(result); 266 | final Paint pt = new Paint(); 267 | float[] hsv = new float[3]; 268 | Color.colorToHSV(mBodyColor, hsv); 269 | hsv[2] = (hsv[2] > 0.5f) ? (hsv[2] - 0.25f) : (hsv[2] + 0.25f); 270 | pt.setColor(Color.HSVToColor(hsv)); 271 | final int r = w / 2; 272 | canvas.drawCircle(r, r, r, pt); 273 | final int m = w / 10; 274 | slowDraw(canvas, m, m, w - m - m, h - m - m); 275 | return result; 276 | } 277 | 278 | Icon createIcon(int w, int h) { 279 | return Icon.createWithBitmap(createIconBitmap(w, h)); 280 | } 281 | 282 | @Override 283 | public void setAlpha(int i) {} 284 | 285 | @Override 286 | public void setColorFilter(ColorFilter colorFilter) {} 287 | 288 | @Override 289 | public int getOpacity() { 290 | return PixelFormat.TRANSLUCENT; 291 | } 292 | 293 | String getName() { 294 | return mName; 295 | } 296 | 297 | void setName(String name) { 298 | mName = name; 299 | } 300 | 301 | int getBodyColor() { 302 | return mBodyColor; 303 | } 304 | 305 | private static class CatParts { 306 | Drawable leftEar; 307 | Drawable rightEar; 308 | Drawable rightEarInside; 309 | Drawable leftEarInside; 310 | Drawable head; 311 | Drawable faceSpot; 312 | Drawable cap; 313 | Drawable mouth; 314 | Drawable body; 315 | Drawable foot1; 316 | Drawable leg1; 317 | Drawable foot2; 318 | Drawable leg2; 319 | Drawable foot3; 320 | Drawable leg3; 321 | Drawable foot4; 322 | Drawable leg4; 323 | Drawable tail; 324 | Drawable leg2Shadow; 325 | Drawable tailShadow; 326 | Drawable tailCap; 327 | Drawable belly; 328 | Drawable back; 329 | Drawable rightEye; 330 | Drawable leftEye; 331 | Drawable nose; 332 | Drawable bowtie; 333 | Drawable collar; 334 | Drawable[] drawingOrder; 335 | 336 | CatParts(Context context) { 337 | body = context.getDrawable(R.drawable.body); 338 | head = context.getDrawable(R.drawable.head); 339 | leg1 = context.getDrawable(R.drawable.leg1); 340 | leg2 = context.getDrawable(R.drawable.leg2); 341 | leg3 = context.getDrawable(R.drawable.leg3); 342 | leg4 = context.getDrawable(R.drawable.leg4); 343 | tail = context.getDrawable(R.drawable.tail); 344 | leftEar = context.getDrawable(R.drawable.left_ear); 345 | rightEar = context.getDrawable(R.drawable.right_ear); 346 | rightEarInside = context.getDrawable(R.drawable.right_ear_inside); 347 | leftEarInside = context.getDrawable(R.drawable.left_ear_inside); 348 | faceSpot = context.getDrawable(R.drawable.face_spot); 349 | cap = context.getDrawable(R.drawable.cap); 350 | mouth = context.getDrawable(R.drawable.mouth); 351 | foot4 = context.getDrawable(R.drawable.foot4); 352 | foot3 = context.getDrawable(R.drawable.foot3); 353 | foot1 = context.getDrawable(R.drawable.foot1); 354 | foot2 = context.getDrawable(R.drawable.foot2); 355 | leg2Shadow = context.getDrawable(R.drawable.leg2_shadow); 356 | tailShadow = context.getDrawable(R.drawable.tail_shadow); 357 | tailCap = context.getDrawable(R.drawable.tail_cap); 358 | belly = context.getDrawable(R.drawable.belly); 359 | back = context.getDrawable(R.drawable.back); 360 | rightEye = context.getDrawable(R.drawable.right_eye); 361 | leftEye = context.getDrawable(R.drawable.left_eye); 362 | nose = context.getDrawable(R.drawable.nose); 363 | collar = context.getDrawable(R.drawable.collar); 364 | bowtie = context.getDrawable(R.drawable.bowtie); 365 | drawingOrder = getDrawingOrder(); 366 | } 367 | private Drawable[] getDrawingOrder() { 368 | return new Drawable[] { 369 | collar, 370 | leftEar, leftEarInside, rightEar, rightEarInside, 371 | head, 372 | faceSpot, 373 | cap, 374 | leftEye, rightEye, 375 | nose, mouth, 376 | tail, tailCap, tailShadow, 377 | foot1, leg1, 378 | foot2, leg2, 379 | foot3, leg3, 380 | foot4, leg4, 381 | leg2Shadow, 382 | body, belly, 383 | bowtie 384 | }; 385 | } 386 | } 387 | } 388 | -------------------------------------------------------------------------------- /workspace/src/com/covertbagel/neko/NekoLand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * Copyright (C) 2017, 2018, 2019 Christopher Blay 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the 11 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 12 | * KIND, either express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.covertbagel.neko; 17 | 18 | import android.Manifest; 19 | import android.annotation.TargetApi; 20 | import android.app.ActionBar; 21 | import android.app.AlertDialog; 22 | import android.content.ContentResolver; 23 | import android.content.ContentUris; 24 | import android.content.ContentValues; 25 | import android.content.Context; 26 | import android.content.DialogInterface; 27 | import android.content.Intent; 28 | import android.content.pm.PackageManager; 29 | import android.database.Cursor; 30 | import android.graphics.Bitmap; 31 | import android.graphics.Color; 32 | import android.graphics.drawable.Drawable; 33 | import android.media.MediaScannerConnection; 34 | import android.net.Uri; 35 | import android.os.Build; 36 | import android.os.Bundle; 37 | import android.os.Environment; 38 | import android.provider.MediaStore; 39 | import android.support.annotation.NonNull; 40 | import android.support.annotation.Nullable; 41 | import android.support.v7.widget.GridLayoutManager; 42 | import android.support.v7.widget.RecyclerView; 43 | import android.util.Log; 44 | import android.view.ContextThemeWrapper; 45 | import android.view.LayoutInflater; 46 | import android.view.Menu; 47 | import android.view.MenuInflater; 48 | import android.view.MenuItem; 49 | import android.view.View; 50 | import android.view.ViewGroup; 51 | import android.widget.EditText; 52 | import android.widget.ImageView; 53 | import android.widget.TextView; 54 | 55 | import java.io.File; 56 | import java.io.FileOutputStream; 57 | import java.io.IOException; 58 | import java.io.OutputStream; 59 | import java.util.ArrayList; 60 | import java.util.List; 61 | 62 | public final class NekoLand extends BaseActivity implements PrefState.PrefsListener { 63 | 64 | private static final String TAG = "NekoLand"; 65 | private static final int STORAGE_PERM_REQUEST = 123; 66 | private static final int CAT_GEN = 0; // Set to 0 to disable, N > 0 to generate N cats. 67 | private static final String IMAGE_PNG = "image/png"; 68 | private static final int EXPORT_BITMAP_SIZE = 600; 69 | private static final String DIRECTORY_NAME = "Cats"; 70 | private static final String[] PROJECTION = new String[] { 71 | MediaStore.Images.ImageColumns._ID, 72 | MediaStore.Images.ImageColumns.DISPLAY_NAME, 73 | }; 74 | private static final String RELATIVE_PATH = "Pictures/" + DIRECTORY_NAME + "/"; 75 | private static final String SELECTION = MediaStore.Images.ImageColumns.DISPLAY_NAME 76 | + " = ? and " + MediaStore.Images.ImageColumns.MIME_TYPE + " = ? and " 77 | + MediaStore.Images.ImageColumns.RELATIVE_PATH + " = ?"; 78 | 79 | private PrefState mPrefs; 80 | @Sort private int mSort; 81 | private CatAdapter mAdapter; 82 | private Cat mPendingShareCat; 83 | 84 | @Override 85 | public void onCreate(@Nullable Bundle savedInstanceState) { 86 | super.onCreate(savedInstanceState); 87 | setContentView(R.layout.neko_activity); 88 | final ActionBar actionBar = getActionBar(); 89 | if (actionBar != null) { 90 | actionBar.setDisplayOptions(0); 91 | } 92 | mPrefs = new PrefState(this); 93 | mPrefs.setListener(this); 94 | mSort = mPrefs.getSort(); 95 | mAdapter = new CatAdapter(); 96 | final RecyclerView recyclerView = findViewById(R.id.holder); 97 | recyclerView.setAdapter(mAdapter); 98 | recyclerView.setLayoutManager(new GridLayoutManager(this, 3)); 99 | updateCats(); 100 | } 101 | 102 | @Override 103 | protected void onDestroy() { 104 | super.onDestroy(); 105 | mPrefs.setListener(null); 106 | } 107 | 108 | @Override 109 | public boolean onCreateOptionsMenu(@NonNull Menu menu) { 110 | super.onCreateOptionsMenu(menu); 111 | new MenuInflater(this).inflate(R.menu.neko_activity, menu); 112 | final int checkedId; 113 | switch (mSort) { 114 | case Sort.LEGACY: 115 | checkedId = R.id.sort_legacy; 116 | break; 117 | case Sort.BODY_HUE: 118 | checkedId = R.id.sort_body_hue; 119 | break; 120 | case Sort.NAME: 121 | checkedId = R.id.sort_name; 122 | break; 123 | case Sort.LEVEL: 124 | checkedId = R.id.sort_level; 125 | break; 126 | default: 127 | return true; 128 | } 129 | final MenuItem menuItem = menu.findItem(checkedId); 130 | if (menuItem != null) { 131 | menuItem.setChecked(true); 132 | } 133 | return true; 134 | } 135 | 136 | @Override 137 | public boolean onOptionsItemSelected(@NonNull MenuItem item) { 138 | final int itemId = item.getItemId(); 139 | @Sort final int newSort; 140 | if (itemId == R.id.sort_legacy) { 141 | newSort = Sort.LEGACY; 142 | } else if (itemId == R.id.sort_body_hue) { 143 | newSort = Sort.BODY_HUE; 144 | } else if (itemId == R.id.sort_name) { 145 | newSort = Sort.NAME; 146 | } else if (itemId == R.id.sort_level) { 147 | newSort = Sort.LEVEL; 148 | } else { 149 | return super.onOptionsItemSelected(item); 150 | } 151 | if (mSort != newSort) { 152 | mSort = newSort; 153 | invalidateOptionsMenu(); 154 | mPrefs.setSort(newSort); 155 | } 156 | return true; 157 | } 158 | 159 | private void updateCats() { 160 | final List cats; 161 | if (CAT_GEN > 0) { 162 | cats = new ArrayList<>(CAT_GEN); 163 | for (int i = 0; i < CAT_GEN; i++) { 164 | cats.add(Cat.create(this)); 165 | } 166 | } else { 167 | cats = mPrefs.getCats(); 168 | } 169 | switch (mSort) { 170 | case Sort.LEGACY: 171 | break; // No sorting necessary. 172 | case Sort.BODY_HUE: 173 | final float[] hsv = new float[3]; 174 | cats.sort((Cat cat, Cat cat2) -> { 175 | Color.colorToHSV(cat.getBodyColor(), hsv); 176 | final float bodyH1 = hsv[0]; 177 | Color.colorToHSV(cat2.getBodyColor(), hsv); 178 | final float bodyH2 = hsv[0]; 179 | return Float.compare(bodyH1, bodyH2); 180 | }); 181 | break; 182 | case Sort.NAME: 183 | //cats.sort(Comparator.comparing(Cat::getName)); 184 | cats.sort((Cat cat, Cat cat2) -> cat.getName().compareTo(cat2.getName())); 185 | break; 186 | case Sort.LEVEL: 187 | //cats.sort(Comparator.comparingLong(Cat::getSeed)); 188 | cats.sort((Cat cat, Cat cat2) -> Float.compare(cat.getSeed(), cat2.getSeed())); 189 | break; 190 | } 191 | mAdapter.setCats(cats.toArray(new Cat[cats.size()])); 192 | } 193 | 194 | private void onCatClick(Cat cat) { 195 | if (CAT_GEN > 0) { 196 | mPrefs.addCat(cat); 197 | new AlertDialog.Builder(NekoLand.this) 198 | .setTitle("Cat added") 199 | .setPositiveButton(android.R.string.ok, null) 200 | .show(); 201 | } else { 202 | showNameDialog(cat); 203 | } 204 | } 205 | 206 | private void onCatRemove(Cat cat) { 207 | mPrefs.removeCat(cat); 208 | } 209 | 210 | private void showNameDialog(final Cat cat) { 211 | Context context = new ContextThemeWrapper( 212 | this, android.R.style.Theme_Material_Light_Dialog_NoActionBar); 213 | View view = LayoutInflater.from(context).inflate(R.layout.edit_text, null); 214 | final EditText text = view.findViewById(android.R.id.edit); 215 | text.setText(cat.getName()); 216 | text.setSelection(cat.getName().length()); 217 | final int size = context.getResources() 218 | .getDimensionPixelSize(android.R.dimen.app_icon_size); 219 | final Drawable catIcon = cat.createIcon(size, size).loadDrawable(this); 220 | new AlertDialog.Builder(context) 221 | .setTitle(" ") 222 | .setIcon(catIcon) 223 | .setView(view) 224 | .setPositiveButton(android.R.string.ok, (DialogInterface dialog, int which) -> { 225 | cat.setName(text.getText().toString().trim()); 226 | mPrefs.addCat(cat); 227 | }).show(); 228 | } 229 | 230 | @Override 231 | public void onPrefsChanged() { 232 | updateCats(); 233 | } 234 | 235 | private class CatAdapter extends RecyclerView.Adapter { 236 | 237 | private Cat[] mCats; 238 | 239 | void setCats(Cat[] cats) { 240 | mCats = cats; 241 | notifyDataSetChanged(); 242 | } 243 | 244 | @Override 245 | public CatHolder onCreateViewHolder(ViewGroup parent, int viewType) { 246 | return new CatHolder(LayoutInflater.from(parent.getContext()) 247 | .inflate(R.layout.cat_view, parent, false)); 248 | } 249 | 250 | private void setContextGroupVisible(final CatHolder holder, boolean vis) { 251 | final View group = holder.contextGroup; 252 | if (vis && group.getVisibility() != View.VISIBLE) { 253 | group.setAlpha(0); 254 | group.setVisibility(View.VISIBLE); 255 | group.animate().alpha(1.0f).setDuration(333); 256 | final Runnable hideAction = () -> setContextGroupVisible(holder, false); 257 | group.setTag(hideAction); 258 | group.postDelayed(hideAction, 5000); 259 | } else if (!vis && group.getVisibility() == View.VISIBLE) { 260 | group.removeCallbacks((Runnable) group.getTag()); 261 | group.animate().alpha(0f).setDuration(250).withEndAction( 262 | () -> group.setVisibility(View.INVISIBLE)); 263 | } 264 | } 265 | 266 | @Override 267 | public void onBindViewHolder(final CatHolder holder, final int position) { 268 | Context context = holder.itemView.getContext(); 269 | final int size = context.getResources() 270 | .getDimensionPixelSize(R.dimen.neko_display_size); 271 | holder.imageView.setImageIcon(mCats[position].createIcon(size, size)); 272 | holder.textView.setText(mCats[position].getName()); 273 | holder.itemView.setOnClickListener( 274 | (View v) -> onCatClick(mCats[holder.getAdapterPosition()])); 275 | holder.itemView.setOnLongClickListener((View v) -> { 276 | setContextGroupVisible(holder, true); 277 | return true; 278 | }); 279 | holder.delete.setOnClickListener((View v) -> { 280 | setContextGroupVisible(holder, false); 281 | new AlertDialog.Builder(NekoLand.this) 282 | .setTitle(getString(R.string.confirm_delete, mCats[position].getName())) 283 | .setNegativeButton(android.R.string.cancel, null) 284 | .setPositiveButton( 285 | android.R.string.ok, 286 | (DialogInterface dialog, int which) -> 287 | onCatRemove(mCats[holder.getAdapterPosition()])) 288 | .show(); 289 | }); 290 | holder.share.setOnClickListener((View v) -> { 291 | setContextGroupVisible(holder, false); 292 | shareCat(mCats[holder.getAdapterPosition()]); 293 | }); 294 | } 295 | 296 | @Override 297 | public int getItemCount() { 298 | return mCats.length; 299 | } 300 | } 301 | 302 | private void shareCat(final Cat cat) { 303 | if (Build.VERSION.SDK_INT >= 29) { 304 | shareCatV29(cat); 305 | } else { 306 | shareCatV24(cat); 307 | } 308 | } 309 | 310 | @SuppressWarnings("deprecation") 311 | private void shareCatV24(final Cat cat) { 312 | if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) 313 | != PackageManager.PERMISSION_GRANTED) { 314 | mPendingShareCat = cat; 315 | requestPermissions( 316 | new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 317 | STORAGE_PERM_REQUEST); 318 | return; 319 | } 320 | final File dir = new File( 321 | Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), 322 | DIRECTORY_NAME); 323 | if (!dir.exists() && !dir.mkdirs()) { 324 | Log.e(TAG, "save: error: can't create Pictures directory"); 325 | return; 326 | } 327 | final File png = new File(dir, getFilename(cat)); 328 | final Bitmap bitmap = cat.createBitmap(EXPORT_BITMAP_SIZE, EXPORT_BITMAP_SIZE); 329 | if (bitmap != null) { 330 | try { 331 | final OutputStream os = new FileOutputStream(png); 332 | bitmap.compress(Bitmap.CompressFormat.PNG, 0, os); 333 | os.close(); 334 | MediaScannerConnection.scanFile(this, new String[] {png.toString()}, 335 | new String[] {IMAGE_PNG}, 336 | (String path, Uri uri) -> { 337 | final Intent intent = new Intent(Intent.ACTION_SEND); 338 | intent.putExtra(Intent.EXTRA_STREAM, uri); 339 | intent.putExtra(Intent.EXTRA_SUBJECT, cat.getName()); 340 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 341 | intent.setType(IMAGE_PNG); 342 | startActivity(Intent.createChooser(intent, null)); 343 | }); 344 | } catch (IOException e) { 345 | Log.e(TAG, "save: error: " + e); 346 | } 347 | } 348 | } 349 | 350 | @TargetApi(29) 351 | private void shareCatV29(final Cat cat) { 352 | final Uri contentUri = 353 | MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY); 354 | final String filename = getFilename(cat); 355 | final ContentResolver resolver = getContentResolver(); 356 | // See if filename already exists; delete to imitate overwriting. 357 | final Cursor cursor = resolver.query(contentUri, PROJECTION, SELECTION, 358 | new String[] {filename, IMAGE_PNG, RELATIVE_PATH}, null); 359 | if (cursor != null) { 360 | final int count = cursor.getCount(); 361 | for (int i = 0; i < count; i++) { 362 | cursor.moveToPosition(i); 363 | try { 364 | resolver.delete( 365 | ContentUris.withAppendedId(contentUri, cursor.getLong(0)), null, null); 366 | } catch (Exception exception) { 367 | // Oh well... 368 | } 369 | } 370 | cursor.close(); 371 | } 372 | // Yay finally time to write this image! 373 | final Bitmap bitmap = cat.createBitmap(EXPORT_BITMAP_SIZE, EXPORT_BITMAP_SIZE); 374 | if (bitmap == null) { 375 | Log.e(TAG, "shareCat: got null bitmap"); 376 | return; 377 | } 378 | final ContentValues values = new ContentValues(); 379 | values.put(MediaStore.Images.Media.DISPLAY_NAME, filename); 380 | values.put(MediaStore.Images.Media.IS_PENDING, 1); 381 | values.put(MediaStore.Images.Media.MIME_TYPE, IMAGE_PNG); 382 | values.put(MediaStore.Images.Media.RELATIVE_PATH, RELATIVE_PATH); 383 | final Uri itemUri = resolver.insert(contentUri, values); 384 | if (itemUri == null) { 385 | Log.e(TAG, "shareCat: got null itemUri"); 386 | return; 387 | } 388 | OutputStream outputStream = null; 389 | try { 390 | outputStream = resolver.openOutputStream(itemUri); 391 | if (outputStream == null) { 392 | Log.e(TAG, "shareCat: got null outputStream"); 393 | resolver.delete(itemUri, null, null); 394 | return; 395 | } 396 | bitmap.compress(Bitmap.CompressFormat.PNG, 0, outputStream); 397 | } catch (IOException exception) { 398 | Log.e(TAG, "shareCat: IOException writing bitmap", exception); 399 | resolver.delete(itemUri, null, null); 400 | return; 401 | } finally { 402 | if (outputStream != null) { 403 | try { 404 | outputStream.close(); 405 | } catch (IOException exception) { 406 | Log.e(TAG, "shareCat: IOException closing outputStream", exception); 407 | } 408 | } 409 | } 410 | values.clear(); 411 | values.put(MediaStore.Images.Media.IS_PENDING, 0); 412 | resolver.update(itemUri, values, null, null); 413 | // Time to send off a share intent. 414 | final Intent intent = new Intent(Intent.ACTION_SEND); 415 | intent.putExtra(Intent.EXTRA_STREAM, itemUri); 416 | intent.putExtra(Intent.EXTRA_SUBJECT, cat.getName()); 417 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 418 | intent.setType(IMAGE_PNG); 419 | startActivity(Intent.createChooser(intent, null)); 420 | } 421 | 422 | @Override 423 | public void onRequestPermissionsResult( 424 | int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 425 | if (requestCode == STORAGE_PERM_REQUEST) { 426 | if (mPendingShareCat != null) { 427 | shareCat(mPendingShareCat); 428 | mPendingShareCat = null; 429 | } 430 | } 431 | } 432 | 433 | private static String getFilename(final Cat cat) { 434 | return cat.getName().replaceAll("[/ #:]+", "_") + ".png"; 435 | } 436 | 437 | private static class CatHolder extends RecyclerView.ViewHolder { 438 | private final ImageView imageView; 439 | private final TextView textView; 440 | private final View contextGroup; 441 | private final View delete; 442 | private final View share; 443 | 444 | CatHolder(View itemView) { 445 | super(itemView); 446 | imageView = itemView.findViewById(android.R.id.icon); 447 | textView = itemView.findViewById(android.R.id.title); 448 | contextGroup = itemView.findViewById(R.id.contextGroup); 449 | delete = itemView.findViewById(android.R.id.closeButton); 450 | share = itemView.findViewById(android.R.id.shareText); 451 | } 452 | } 453 | } 454 | --------------------------------------------------------------------------------