Ever hid debug functions in your UI? Here is now a clean way to do it!

 

DebugKit lib for Android allows you to use a fancy hovering debug tool to trigger some actions directly in the app. This tool is very useful to trigger some event at runtime, and to have a written feedback directly on your testing phone screen.

 

dark theme

 

light theme

 

Requirements

  • Android SDK 15+

Installation

repositories {
    jcenter()
}

dependencies {
    compile 'com.hulab.android:debugkit:1.0.3'
}

 

Download Sourecode

Usage Code

 

final DevTool.Builder builder = new DevTool.Builder(mContext);

builder.addFunction(new DebugFunction() {
            @Override
            public String call() throws Exception {
                log("doing some stuff...");
                doSomeStuff();
                return "Some stuff was done.";
            }
        }).addFunction(new DebugFunction() {
            @Override
            public String call() throws Exception {
                log("doing some other stuff...");
                doSomeStuff();
                return "Some stuff was done.";
            }
        }).addFunction(new DebugFunction() {
            @Override
            public String call() throws Exception {
                log("doing some stuff again and again...");
                doSomeStuff();
                return "Some stuff was done.";
            }
        });                

// optional, DevToolFragment.DevToolTheme.DARK is set by default
builder.setTheme(DevToolFragment.DevToolTheme.DARK)
       .build();

 

Result

Here we have 3 debug tools, from top to bottom:

  • LIGHT theme with 5 defined functions
  • Minified mode (clicking on the top left corner arrow)
  • DARK theme with 3 defined functions and the logged text when clicking on each F1, F2 and F3

Screenshot.png

 

Ex code

public class ExampleActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

    private int mTextSize = 12;
    private SeekBar mSeekbar;
    private DevToolFragment.DevToolTheme mTheme = DevToolFragment.DevToolTheme.DARK;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_example);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        final TextView functionNumber = (TextView) findViewById(R.id.functions_number);
        final Spinner themeSpinner = (Spinner) findViewById(R.id.theme_spinner);

        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.debugkit_themes, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        themeSpinner.setAdapter(adapter);
        themeSpinner.setOnItemSelectedListener(this);

        mSeekbar = (SeekBar) findViewById(R.id.seekBar);
        mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                functionNumber.setText(Integer.toString(progress));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        functionNumber.setText(Integer.toString(mSeekbar.getProgress()));

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                final DevTool.Builder builder = new DevTool.Builder(ExampleActivity.this);

                if (mSeekbar != null) {
                    for (int i = 0; i < mSeekbar.getProgress(); i++) {
                        builder.addFunction(doSomeStuff());
                    }
                }
                builder.setTextSize(mTextSize)
                        .setTheme(mTheme)
                        .build();
                // After the tool has been built, you can set:
                // builder.getTool().changeConsoleTextSize(mTextSize);
            }
        });
    }

    private DebugFunction doSomeStuff() {
        return new DebugFunction() {
            @Override
            public String call() throws Exception {
                // Do some kind of really debugging stuff...
                return "Some stuff was done.";
            }
        };
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        mTheme = position == 0 ? DevToolFragment.DevToolTheme.DARK : DevToolFragment.DevToolTheme.LIGHT;
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
        mTheme = DevToolFragment.DevToolTheme.DARK;
    }

 

By Ponglang Petrung

Administrator and PJ at Kamibit Thailand, Android Developer at CodeGears Co., Ltd. and Android Developer, and iOS Application Developer at Appdever

Share your thoughts

Leave a Reply

Loading Facebook Comments ...
Loading Disqus Comments ...