62

GitHub - whataa/pandora: an android library for debugging what we care about dir...

 5 years ago
source link: https://github.com/whataa/pandora
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

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

[点击查看中文版]

Pandora API platform License

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

image image

image image

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:v1.0.1'
    releaseImplementation 'com.github.whataa:pandora-no-op:v1.0.1'
}  

the latest version doc

library name release version pandora Release pandora-no-op Release

Usage

init Pandora in Application:

public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Pandora.init(this).enableShakeOpen();
    }
}

enableShakeOpen() is optional,indicates to enable the "Shake On" feature,Once turned on, shaking the phone on any Activity in your app can open the function panel to start debugging.

If this feature conflicts with your application, you can also implement your own trigger method and call the following method to open the function panel:

Pandora.get().open();

Close the function panel:

Pandora.get().close();

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(Pandora.get().getInterceptor())
    ...
    .build()

Extended features

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:

  • 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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK