{"id":13538214,"url":"https://github.com/zhanghai/MaterialColdStart","last_synced_at":"2025-04-02T05:31:07.161Z","repository":{"id":38250810,"uuid":"45349407","full_name":"zhanghai/MaterialColdStart","owner":"zhanghai","description":"Utilize the window background during cold start time to make your app look faster.","archived":true,"fork":false,"pushed_at":"2019-05-16T04:02:18.000Z","size":3199,"stargazers_count":1226,"open_issues_count":1,"forks_count":97,"subscribers_count":27,"default_branch":"master","last_synced_at":"2024-08-11T17:10:07.169Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhanghai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-01T17:09:19.000Z","updated_at":"2024-08-11T17:10:07.169Z","dependencies_parsed_at":"2022-09-08T11:32:17.275Z","dependency_job_id":null,"html_url":"https://github.com/zhanghai/MaterialColdStart","commit_stats":null,"previous_names":["dreamingincodezh/materialcoldstart"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanghai%2FMaterialColdStart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanghai%2FMaterialColdStart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanghai%2FMaterialColdStart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanghai%2FMaterialColdStart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhanghai","download_url":"https://codeload.github.com/zhanghai/MaterialColdStart/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246763800,"owners_count":20829794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T09:01:08.046Z","updated_at":"2025-04-02T05:31:06.752Z","avatar_url":"https://github.com/zhanghai.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"# MaterialColdStart\n\nUtilize the window background during cold start time (the time between user launches your app and `Activity.onCreate()` is called) to make your app look faster.\n\nThis project comes with some templates for Material Designed apps, but you can also roll your own if you wish.\n\n## Preview\n\nBlank cold start (Glitch on status bar and appbar) v.s. Material cold start (Preserves visual consistency):\n\n![Blank cold start](preview/blank_cold_start.gif)\n![Material cold start](preview/material_cold_start.gif)\n\n(I deliberately picked a slower device to show the effect clearer, but this improvement is also delightful on faster devices.)\n\nWhen your app process is cached in memory but main activity is relaunched, this technique gives the illusion of a much quicker start up.\n\n![Normal case](preview/normal_case.gif)\n\nNotice the small period of time when appbar and status bar is \"drawn\" but no text is shown — **this is the trick**.\n\nWithout the help of our cold start window background, users will see a glitch of whiteness over the appbar and statusbar.\n\n## Inspiration\n\nThis project was inspired by the pro-tip [Use cold start time effectively with a branded launch theme — Pro-tip by +Ian Lake](https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd).\n\nBut instead of using a short transient product logo as preview, I want to use a background with an `AppBar` on it, just like the old days with framework-managed `ActionBar`, which gives user the illusion of a quicker start up and ensures visual consistency.\n\nThis project has been around in my mind for several months, until I found my way to generate drawables with templates.\n\n## Implementation\n\nThis project generates nine-patch drawables for use as `android:windowBackground`.\n\n### Why nine-patch?\n\nOnly static drawables can be loaded by framework as preview, and all other drawables will only retain aspect ratio when width/height is set. So we need to use nine-patch.\n\n### How to generate nine-patch?\n\nHowever, nine-patches need to be bitmaps, but we have various dimension sizes changing with configuration, and we still have to retain the one-pixel border while scaling up the content area.\n\nI don't want to keep a separate file for each combination of configuration (which can be 20 if you support tablet), but instead use a single template for nine-patch generation. After a lot of (painful) trial-and-error with `XSLT` and `sed`, I suddenly found the good old `bash` (which is string-oriented) a viable solution for this problem.\n\nThe solution, a \"new\" format called `shsvg` (Shell SVG), is implemented as in [zhanghai/AndroidSVGScripts](https://github.com/zhanghai/AndroidSVGScripts) and used by this project.\n\n## Usage\n\n\u003e Note: To generate your own image assets, you will probably need a Linux installation. I may upload some pre-built assets later.\n\n1. (Optional) Adjust the appbar height (and more if you want). The default configuration assumes that your app have a `TabLayout`. If however your app does not, you need to modify each `window_background_statusbar_toolbar_tab.9.shsvg.conf` file in the given raw directories and change the `APPBAR_HEIGHT` from `112` to `64` and `104` to `56`.\n\n2. Run `gen-png.sh` and copy the output in `gen/` to your `res` directory. (requires `bash`, `bc`, `gcalccmd` (from `gnome-calculator`) and `inkscape`)\n\n3. Make a new theme for your main activity:\n\n    ```xml\n    \u003cstyle name=\"AppTheme.MaterialColdStart\"\u003e\n        \u003citem name=\"android:windowBackground\"\u003e@drawable/window_background_statusbar_toolbar_tab\u003c/item\u003e\n    \u003c/style\u003e\n    ```\n\n4. And set the new theme in your `AndroidManifest.xml`:\n\n    ```xml\n    \u003cactivity\n        android:name=\".MainActivity\"\n        android:theme=\"@style/AppTheme.MaterialColdStart\"\u003e\n\n        \u003cintent-filter\u003e\n            \u003caction android:name=\"android.intent.action.MAIN\" /\u003e\n            \u003ccategory android:name=\"android.intent.category.LAUNCHER\" /\u003e\n        \u003c/intent-filter\u003e\n    \u003c/activity\u003e\n    ```\n\n5. Finally in your `MainActivity.java`, set the theme back for the normal window background, which will be transitioned into:\n\n    ```java\n    public class MainActivity extends AppCompatActivity {\n\n        @Override\n        protected void onCreate(Bundle savedInstanceState) {\n\n            // Make sure this line comes before calling super.onCreate().\n            setTheme(R.style.AppTheme);\n\n            super.onCreate(savedInstanceState);\n        }\n    }\n    ```\n\n6. Enjoy the updated cold start experience!\n\n## Pre-built assets\n\n// TODO\n\n## License\n\n```\nCopyright 2015 Zhang Hai\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanghai%2FMaterialColdStart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhanghai%2FMaterialColdStart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanghai%2FMaterialColdStart/lists"}