Original text: blog.fiftykg.com/

preface

In this article, you can (1) learn about a special splash screen (2) learn how android version eggs work (3) Get a demo of android versions of eggs

Special flash screen

When EXPERIENCING the App, I found an App called “Tuling” with a very special flash screen. As you can see from the image below, it is a page with a desktop wallpaper as the background.

The flash screen effect is quite impressive, so I’m curious about how it works. In the case of not cracking APK (cracking failure, there is Tencent Legu reinforcement ==), I guess several ways to achieve:

Get the wallpaper from the Api and set the background for your ActivityCopy the code

Before verifying the conjecture one by one, I came up with a page implementation that is very similar to the flash screen of ‘Tulling’, which is the Android version egg (Settings – about mobile phone -Android version click 3 times). The source code is available on this page.

With the source code

Open the Egg page and execute the following command to see that the name of the Activity is PlatLogoActivity.

adb shell dumpsys activity | grep "Focus"

mFocusedActivity: ActivityRecord{2829baa u0 android/com.android.internal.app.PlatLogoActivity t4844}
mFocusedStack=ActivityStack{d93bf0d stackId=1, 4 tasks} mLastFocusedStack=ActivityStack{d93bf0d stackId=1, 4 tasks}
Copy the code

(或者 adb shell dumpsys activity top)

PlatLogoActivity. Java is not the focus of PlatLogoActivity. Java is the focus of AndroidManifest, theme is the key! That’s the second conjecture we started with.

<activity android:name="com.android.internal.app.PlatLogoActivity"
android:theme="@style/Theme.Wallpaper.NoTitleBar.Fullscreen"
android:configChanges="orientation|keyboardHidden"
android:process=":ui">
</activity>
Copy the code

Give it a try

Through the source code basic understanding of the implementation principle, but did not run the Demo is not reliable. The implementation of PlatLogoActivity is very independent and does not have many dependencies. So I copied each version of PlatLogoActivity and made a Demo.

Making: github.com/PortgasAce/…

To explore the

Now we already know that theme is a convenient way to achieve the splash screen effect of ‘Tuling’. Can the code do that? Is there any official API open?

The answers to these questions can be found in how theme is implemented. PhoneWindow#generateLayout has this code for parsing the theme tag:

. // A lot of tag parsing is omittedif (a.getBoolean(R.styleable.Window_windowSwipeToDismiss, false)) {
requestFeature(FEATURE_SWIPE_TO_DISMISS);
}

if (a.getBoolean(R.styleable.Window_windowFullscreen, false)) {
setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN & (~getForcedWindowFlags())); }... // A lot of tag parsing is omittedCopy the code

The main implementation of theme is to change the style through the Windows #requestFeature and Windows #setFlags methods.

Copy the wrote Theme. Which Wallpaper. NoTitleBar. Fullscreen Java implementation, see lot: PlatLogoActivityNoStyle main code:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().getDecorView().setWillNotDraw(true);
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
Copy the code

At this point, Guess 2 is verified by both the Theme and Java implementations. So what about the other guesses? The answer, of course, is yes. You can obtain the desktop wallpaper through the WallpaperManager provided by the SDK.

Drawable bg = WallpaperManager.getInstance(context).getDrawable();
rootView.setBackground(bg);
Copy the code

This code sets the Activity’s background as the desktop wallpaper.

But there’s a problem. In live wallpapewr, the drawable obtained by this method does not move and is a wrong picture.

LiveWallpaper gets the correct position from wallpaperManager#getWallpaperInfo#loadThumbnail:

  private Drawable getWallpaperDrawable(a) {
    Drawable wallpaperDrawable;
    PackageManager pm = getApplicationContext().getPackageManager();
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
    if(wallpaperManager.getWallpaperInfo() ! =null) {
      /* * Wallpaper info is not equal to null, that is if the live wallpaper * is set, then get the drawable image from the package for the * live wallpaper */
      wallpaperDrawable = wallpaperManager
          .getWallpaperInfo().loadThumbnail(pm);
    } else {
      /* * Else, if static wallpapers are set, then directly get the * wallpaper image */
      wallpaperDrawable = wallpaperManager.getDrawable();
    }
    return wallpaperDrawable;
  }
Copy the code

But the problem is still not completely solved, the background will not move! Each call to loadThumbnail returns the same image, so guess 1 is only used for static wallpaper.

The above.

Shoulders of giants

Principle and Style in the android/Theme Activity interface file selection process analyses: blog.csdn.net/qinjuning/a…