Copyright Notice:

This account published articles are from the public account, Chengxiang Moying (cxmyDev), chengxiang Moying all rights reserved.

Every week will be uniformly updated here, if you like, you can follow the public account to get the latest article.

Shall not be reproduced without permission.

One, foreword

Yesterday hair WM ADAPTS after the article, discovery seems still inconvenient. You need to modify parameters again and again to adjust device parameters. And usually, we develop page by page, so it would be a little more convenient if we could take screenshots of the display of one page at a time on different devices.

For more on the WM command, check out our previous article, “How to Do screen Adaptation when You Only have one Device.”

So I wrote a Python script, and I used it for fun, but not for fun.

Due to Python version differences, I note that my environment is 2.7.10.

Second, use Python to modify parameters and screenshots

Writing logical scripts in Python is still very convenient, probably using Python, ADB commands, WM commands, and so on.

Let’s start with the idea.

In fact, the logic is very simple, the steps are as follows:

  1. Use Python to calladb shell wmCommand to modify screen parameters.
  2. To useadb shell screencapTake a screenshot.
  3. Take the captured images and use themadb pullCommand to copy the file locally.
  4. Repeat the preceding logic based on the configured device information.

Logic is still very clear, directly on the code.

Start with a basic definition that extracts the unchanging commands and gets the directory address of the current script.

/s-fa.png

At initialization time, determine if the Devicescreen folder exists locally and create it if not.

/s-createf.png

To the most important method, according to the parameters passed, modify the screen information of the device, and save the screenshot to the local.

/s-changescreen.png

On some devices, after modifying parameters, the device will be stuck and refreshed, so after these operations, they will wait roughly for a while. I set 3s here.

/s-reset.png

After using, reset the screen to the original state.

At this point, the main logic has been written, and we just need to configure the device parameters we need. Here is a collection of common devices.

/s-runcode.png

When done, call Python start.py or run it directly in PyCharm. The result of the run is eventually saved in the local Devicescreen directory.

This is the structure of the whole project.

/s-project.png

In the Devicescreen directory, you can see the screenshots of the different devices we need.

/s-screen.png

I used the Nuggets’ home page here to see screenshots of how it looks on different devices.

/s-cap.jpg

Third, summary

In fact, the WM command still has some defects. The most common one is that the screen parameters are modified and the page is not refreshed correctly. At this time, it is good to exit the App and enter again.

This is used only as an aid, and a simple script will not work if you need to exit and re-enter a page that cannot be modified correctly.

So this script is only suitable for some scenarios, not all scenarios.

Although the key code text is available, but if you want the source code, you can reply to the public account with the keyword “adaptation script”.

Qr code. JPG

Like it or share it