Pandora

Additional

Language
Java
Version
v1.2.2 (Nov 15, 2018)
Created
Jun 27, 2018
Updated
Nov 16, 2018
Owner
linjiang (whataa)
Contributors
zularizal
linjiang (whataa)
joker-fu
pinguo-tangsong
4
Activity
Badge
Generate
Download
Source code
APK file

Commercial

an android library for debugging what we care about directly in app.

[点击查看中文版]

Pandora

Pandora is a tool box that allows you to inspect and modify what includes networks, databases, UIs, etc. directly in your application. It is suitable for rapid position of various problems in the development and testing stages.

Feature

  • Inspect the detailed log of each network request, such as headers, response, etc.

  • View the internal storage system of own app;

  • View all databases, and support ADD, DELETE, UPDATE, QUERY operations;

  • View and edit all Shared Preference;

  • Preview the current view Hierarchy, and can view/modify the properties of widgets;

  • Measure the distance between the views and detect whether the alignment is correct

  • You can select any view on the Activity to move the position, get the size of itself, display the relative relationship;

  • More features look forward to you exploring;

Some of the effects are as follows:

The display pictures are: network, database, UI, file

Set-up

  1. Add the JitPack repository to your root build file:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency to your app build.gradle (please use the latest version):
dependencies {
    ...
    debugImplementation 'com.github.whataa:pandora:${RELEASE}'
    releaseImplementation 'com.github.whataa:pandora-no-op:${RELEASE}'
}  

the latest version name, Please check the RELEASE for specific updates.

library name release version
pandora
pandora-no-op

Usage

Now, without adding any code, you can start using it directly in the app by shaking the device.

Pandora will display the function panel in the form of a floating window, so it needs the "floating window" permission, please open it manually.

By default, Pandora is opened with a "shake", if this feature conflicts with your application, you can solve it by the following two ways and then implement your own trigger method invoking Pandora.get().open() to open the function panel:

  1. Turn it off in the settings of the panel;

  2. Or directly call the following method in the application's onCreate: (the corresponding switch of the panel will be invalid)

    Pandora.get().disableShakeSwitch();
    

If your project uses OKHttp as the underlying network library, you can add the following interceptor to enable the function of the network debugging module:

Note: Please use Pandora as the last interceptor to prevent request-headers and request-params from getting;

new OkHttpClient.Builder()
    ...
    .addInterceptor(xxx)
    .addInterceptor(Pandora.get().getInterceptor())
    .build()

Extended features

Make the response of Http more readable

The result of Http request is usually the json format. In order to be more beautiful when viewing json, you can add a formatter to json in the following way:

  1. implement tech.linjiang.pandora.network.JsonFormatter interface,You can refer to the specific implementation of JsonFormatterImpl in the app-module:
public class JsonFormatterImpl implements JsonFormatter {
    @Override
    public String format(String result) {
        return JSON.toJSONString(JSON.parse(result));
    }
}
  1. Add new formatter to Pandora:
Pandora.get().getInterceptor().setJsonFormatter(new JsonFormatterImpl());

Inspect the View property

Pandora supports viewing and partially modifying the properties of View, ViewGroup, and common TextView and ImageView by default. If you want to inspect more view attributes, you can expand them in the following ways:

  1. implement tech.linjiang.pandora.inspector.attribute.IParser interface and specify the type of View that you are interested in. Here is an example of an already implemented ImageView:
public class ImageViewParser implements IParser<ImageView> {

    @Override
    public List<Attribute> getAttrs(ImageView view) {
        List<Attribute> attributes = new ArrayList<>();
        // Add the property of interest and return
        Attribute scaleTypeAttribute = new Attribute("scaleType", scaleTypeToStr(view.getScaleType()), Attribute.Edit.SCALE_TYPE);
        attributes.add(scaleTypeAttribute);
        return attributes;
    }
    ...
}
  1. Add new Parser to Pandora:
Pandora.get().getAttrFactory().addParser(new ImageViewParser());

After this, every time you click on the ImageView, the property list will automatically enumerate the values of the properties we are interested in.。

Inspect Shared Preference

Pandora reads by default the XML file in the default SP path in the application(data/data/<package-name>/shared_prefs/),If there exist other SP files that are not in the default path, they can be extended in the following ways:

  1. implement tech.linjiang.pandora.preference.protocol.IProvider interface,and return the corresponding file list:

(Specific details can refer to the default implementation in the librarySharedPrefProvider)

  1. Add new Provider to Pandora:
Pandora.get().getSharedPref().addProvider(new XXProvider());

Limit

  • Minimum supported Android SDK version is 14

  • Network debugging module: only supports the network library with OKHttp 3.x as the underlying network library;

  • Database debugging module: Only SQLite-based databases are supported, and viewing encrypted databases is temporarily not supported;

  • others;

Thanks

Pandora was developed on the shoulders of giants. Thanks to the following open source projects or person:

  • Logo and Icon are produced by the designer Zularizal.

  • Inspired by Flipboard's open source iOS platform debugging tool FLEX

  • Project database module ideas and part of the source code from Facebook's open source project stetho

  • The idea of selecting views in the UI module of the project and part of the source code from eleme's open source project UETool

  • The request API in the Demo module comes from jgilfelt's open source project chuck

License

Apache-2.0