MaterialColdStart


Source link: https://github.com/DreaminginCodeZH/MaterialColdStart

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):

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

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 DreaminginCodeZH/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. 

Resources

Project is inspired by ig-json-parser. It basically do the same thing as ig-json-parser, but the differences are:

  • do not use annotations to generate the parsers. but use Scala raw value
  • including a class JsonToSpec which can generate the spec from a folder of json samples. so you not even need to write the spec if you have a working backend. but most of time you will want to customize the result by editing the result spec
  • you can write converter code to convert between types
  • it is dead simple

Great set of colors from http://flatuicolors.com and converted into Android colors.xml

You can easily access the top of the screen in Android. Like a iPhone 6 & 6 Plus.

android-resource-navigator is a a Google Chrome Extension providing enhanced resource navigation for GitHub hosted Android projects.

A custom view that displays an error image, a title, and a subtitle given an HTTP status code. It can be used for various other purposes like displaying other kinds of errors, or just messages with images.

Easier creation of Dagger ObjectGraph scopes with Retrofit and Butterknife niceties

What is Scopes?

Have you ever tried to set up scoped ObjectGraphs with Dagger and failed miserably? Scopes a compile time annotation processor that is here to help!

What does Scopes do? It allows to separate portions of your Application in logical "flows". It generates "BaseActivitys" that contain common dependencies that other Activities that are part of the same flow could use.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes