GithubHelp home page GithubHelp logo

materialcoldstart's Introduction

MaterialColdStart

Utilize 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.

This project comes with some templates for Material Designed apps, but you can also roll your own if you wish.

Preview

Blank cold start (Glitch on status bar and appbar) v.s. Material cold start (Preserves visual consistency):

Blank cold start Material cold start

(I deliberately picked a slower device to show the effect clearer, but this improvement is also delightful on faster devices.)

When your app process is cached in memory but main activity is relaunched, this technique gives the illusion of a much quicker start up.

Normal case

Notice the small period of time when appbar and status bar is "drawn" but no text is shown — this is the trick.

Without the help of our cold start window background, users will see a glitch of whiteness over the appbar and statusbar.

Inspiration

This project was inspired by the pro-tip Use cold start time effectively with a branded launch theme — Pro-tip by +Ian Lake.

But 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.

This project has been around in my mind for several months, until I found my way to generate drawables with templates.

Implementation

This project generates nine-patch drawables for use as android:windowBackground.

Why nine-patch?

Only 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.

How to generate nine-patch?

However, 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.

I 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.

The solution, a "new" format called shsvg (Shell SVG), is implemented as in zhanghai/AndroidSVGScripts and used by this project.

Usage

Note: To generate your own image assets, you will probably need a Linux installation. I may upload some pre-built assets later.

  1. (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.

  2. Run gen-png.sh and copy the output in gen/ to your res directory. (requires bash, bc, gcalccmd (from gnome-calculator) and inkscape)

  3. Make a new theme for your main activity:

    <style name="AppTheme.MaterialColdStart">
        <item name="android:windowBackground">@drawable/window_background_statusbar_toolbar_tab</item>
    </style>
  4. And set the new theme in your AndroidManifest.xml:

    <activity
        android:name=".MainActivity"
        android:theme="@style/AppTheme.MaterialColdStart">
    
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  5. Finally in your MainActivity.java, set the theme back for the normal window background, which will be transitioned into:

    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
    
            // Make sure this line comes before calling super.onCreate().
            setTheme(R.style.AppTheme);
    
            super.onCreate(savedInstanceState);
        }
    }
  6. Enjoy the updated cold start experience!

Pre-built assets

// TODO

License

Copyright 2015 Zhang Hai

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

materialcoldstart's People

Contributors

vanniktech avatar zhanghai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

materialcoldstart's Issues

9-Patch for the demo

Can you please add the 9-Patch files you used in the demo? It will be easier to some people (like me) to simply use this files and adjusting them instead of generating them.

Support only Toolbar without TabLayout

If you have an application which only uses the Toolbar and no TabLayout the generated nine patch drawable is too big.

Having an option to say if you use both, Toolbar and TabLayout or only Toolbar and hence changing the height would solve that problem.

Not working in 4.4.2 devices

In Samsung Galaxy S2 i9100 with CyanogenMod 4.4.2 and in Nexus One 4.4.2 (AOSP) it's not working, I get this:

device-2016-01-17-234133

Resources NotFoundException on tablets running Android 4.0.3 - 4.0.4

I'm seeing the following exception on tablets running Android 4.0.3 - 4.0.4. I have no idea why it is not using the res/drawable-sw600dp-xxxhdpi/window_background_statusbar_toolbar_tab.9.png drawable!

android.content.res.Resources$NotFoundException: File res/drawable-sw600dp-xxxhdpi-v13/window_background_statusbar_toolbar_tab.9.png from drawable resource ID #0x7f020119

AAPT error

Hi,
I followed all steps and when I want to build the app, I get this error:

:app:mergeDebugResources
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-xxhdpi/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-sw600dp-mdpi/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.

AAPT err(Facade for 1365012081) : No Delegate set : lost message:ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-mdpi/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT err(Facade for 1365012081) : No Delegate set : lost message:       Must have one-pixel frame that is either transparent or white.

AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-xxxhdpi/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-xhdpi-v23/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-sw600dp-xhdpi-v23/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-sw600dp-xxhdpi/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-sw600dp-xxxhdpi/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-xxhdpi-v23/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-sw600dp-xhdpi/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-sw600dp-xxxhdpi-v23/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-sw600dp-mdpi-v23/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-xxxhdpi-v23/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-hdpi/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-hdpi-v23/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-xhdpi/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-sw600dp-xxhdpi-v23/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-sw600dp-hdpi-v23/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-sw600dp-hdpi/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
AAPT: ERROR: 9-patch image /Users/david/dev/step-up-labs/settle-up-android/app/src/main/res/drawable-mdpi-v23/window_background_statusbar_toolbar_tab.9.png malformed.
AAPT:        Must have one-pixel frame that is either transparent or white.
:app:mergeDebugResources FAILED

command not found

bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
bash: line 1: gcalccmd: command not found
bash: line 1: bc: command not found
xargs: printf: terminated by signal 13
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found

Command not found.

I am sure that the two projects have clone,but still wrong.
bash: line 1: gcalccmd: command not found
../shsvg/shsvgdpi.sh: line 67: inkscape: command not found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.