Search in sources :

Example 1 with StringBuilderPrinter

use of android.util.StringBuilderPrinter in project double-espresso by JakeWharton.

the class HumanReadables method describe.

/**
   * Transforms an arbitrary view into a string with (hopefully) enough debug info.
   *
   * @param v nullable view
   * @return a string for human consumption.
   */
public static String describe(View v) {
    if (null == v) {
        return "null";
    }
    ToStringHelper helper = Objects.toStringHelper(v).add("id", v.getId());
    if (v.getId() != -1 && v.getResources() != null) {
        try {
            helper.add("res-name", v.getResources().getResourceEntryName(v.getId()));
        } catch (Resources.NotFoundException ignore) {
        // Do nothing.
        }
    }
    if (null != v.getContentDescription()) {
        helper.add("desc", v.getContentDescription());
    }
    switch(v.getVisibility()) {
        case View.GONE:
            helper.add("visibility", "GONE");
            break;
        case View.INVISIBLE:
            helper.add("visibility", "INVISIBLE");
            break;
        case View.VISIBLE:
            helper.add("visibility", "VISIBLE");
            break;
        default:
            helper.add("visibility", v.getVisibility());
    }
    helper.add("width", v.getWidth()).add("height", v.getHeight()).add("has-focus", v.hasFocus()).add("has-focusable", v.hasFocusable()).add("has-window-focus", v.hasWindowFocus()).add("is-clickable", v.isClickable()).add("is-enabled", v.isEnabled()).add("is-focused", v.isFocused()).add("is-focusable", v.isFocusable()).add("is-layout-requested", v.isLayoutRequested()).add("is-selected", v.isSelected());
    if (null != v.getRootView()) {
        // pretty much only true in unit-tests.
        helper.add("root-is-layout-requested", v.getRootView().isLayoutRequested());
    }
    EditorInfo ei = new EditorInfo();
    InputConnection ic = v.onCreateInputConnection(ei);
    boolean hasInputConnection = ic != null;
    helper.add("has-input-connection", hasInputConnection);
    if (hasInputConnection) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        Printer p = new StringBuilderPrinter(sb);
        ei.dump(p, "");
        sb.append("]");
        helper.add("editor-info", sb.toString().replace("\n", " "));
    }
    if (Build.VERSION.SDK_INT > 10) {
        helper.add("x", v.getX()).add("y", v.getY());
    }
    if (v instanceof TextView) {
        innerDescribe((TextView) v, helper);
    }
    if (v instanceof Checkable) {
        innerDescribe((Checkable) v, helper);
    }
    if (v instanceof ViewGroup) {
        innerDescribe((ViewGroup) v, helper);
    }
    return helper.toString();
}
Also used : InputConnection(android.view.inputmethod.InputConnection) EditorInfo(android.view.inputmethod.EditorInfo) ViewGroup(android.view.ViewGroup) StringBuilderPrinter(android.util.StringBuilderPrinter) TextView(android.widget.TextView) Resources(android.content.res.Resources) Checkable(android.widget.Checkable) Printer(android.util.Printer) StringBuilderPrinter(android.util.StringBuilderPrinter) ToStringHelper(com.google.common.base.Objects.ToStringHelper)

Example 2 with StringBuilderPrinter

use of android.util.StringBuilderPrinter in project android_frameworks_base by ParanoidAndroid.

the class IntentResolver method compareMaps.

private void compareMaps(IntentFilter src, String name, HashMap<String, F[]> cur, HashMap<String, ArrayList<F>> old) {
    if (cur.size() != old.size()) {
        StringBuilder missing = new StringBuilder(128);
        for (Map.Entry<String, ArrayList<F>> e : old.entrySet()) {
            final F[] curArray = cur.get(e.getKey());
            if (curArray == null) {
                if (missing.length() > 0) {
                    missing.append(' ');
                }
                missing.append(e.getKey());
            }
        }
        StringBuilder extra = new StringBuilder(128);
        for (Map.Entry<String, F[]> e : cur.entrySet()) {
            if (old.get(e.getKey()) == null) {
                if (extra.length() > 0) {
                    extra.append(' ');
                }
                extra.append(e.getKey());
            }
        }
        StringBuilder srcStr = new StringBuilder(1024);
        StringBuilderPrinter printer = new StringBuilderPrinter(srcStr);
        src.dump(printer, "");
        ValidationFailure here = new ValidationFailure();
        here.fillInStackTrace();
        Log.wtf(TAG, "New map " + name + " size is " + cur.size() + "; old implementation is " + old.size() + "; missing: " + missing.toString() + "; extra: " + extra.toString() + "; src: " + srcStr.toString(), here);
        return;
    }
    for (Map.Entry<String, ArrayList<F>> e : old.entrySet()) {
        final F[] curArray = cur.get(e.getKey());
        int curLen = curArray != null ? curArray.length : 0;
        if (curLen == 0) {
            ValidationFailure here = new ValidationFailure();
            here.fillInStackTrace();
            Log.wtf(TAG, "New map " + name + " doesn't contain expected key " + e.getKey() + " (array=" + curArray + ")");
            return;
        }
        while (curLen > 0 && curArray[curLen - 1] == null) {
            curLen--;
        }
        final ArrayList<F> oldArray = e.getValue();
        final int oldLen = oldArray.size();
        if (curLen != oldLen) {
            ValidationFailure here = new ValidationFailure();
            here.fillInStackTrace();
            Log.wtf(TAG, "New map " + name + " entry " + e.getKey() + " size is " + curLen + "; old implementation is " + oldLen, here);
            return;
        }
        for (int i = 0; i < oldLen; i++) {
            F f = oldArray.get(i);
            boolean found = false;
            for (int j = 0; j < curLen; j++) {
                if (curArray[j] == f) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                ValidationFailure here = new ValidationFailure();
                here.fillInStackTrace();
                Log.wtf(TAG, "New map " + name + " entry + " + e.getKey() + " doesn't contain expected filter " + f, here);
            }
        }
        for (int i = 0; i < curLen; i++) {
            if (curArray[i] == null) {
                ValidationFailure here = new ValidationFailure();
                here.fillInStackTrace();
                Log.wtf(TAG, "New map " + name + " entry + " + e.getKey() + " has unexpected null at " + i + "; array: " + curArray, here);
                break;
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StringBuilderPrinter(android.util.StringBuilderPrinter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with StringBuilderPrinter

use of android.util.StringBuilderPrinter in project platform_frameworks_base by android.

the class BatteryStatsTimerTest method testLogState.

/**
     * Tests logState
     */
@SmallTest
public void testLogState() throws Exception {
    TimeBase timeBase = new TimeBase();
    MockClocks clocks = new MockClocks();
    TestTimer timer = new TestTimer(clocks, 0, timeBase);
    timer.setTotalTime(100);
    timer.setLoadedTime(200);
    timer.setLastTime(300);
    timer.setUnpluggedTime(400);
    timer.setTimeBeforeMark(500);
    timer.setCount(1);
    timer.setLoadedCount(2);
    timer.setLastCount(3);
    timer.setUnpluggedCount(4);
    timer.setTotalTime(9223372036854775807L);
    timer.setLoadedTime(9223372036854775806L);
    timer.setLastTime(9223372036854775805L);
    timer.setUnpluggedTime(9223372036854775804L);
    timer.setTimeBeforeMark(9223372036854775803L);
    StringBuilder sb = new StringBuilder();
    StringBuilderPrinter pw = new StringBuilderPrinter(sb);
    timer.logState(pw, "  ");
    Assert.assertEquals("  mCount=1 mLoadedCount=2 mLastCount=3 mUnpluggedCount=4\n" + "  mTotalTime=9223372036854775807 mLoadedTime=9223372036854775806\n" + "  mLastTime=9223372036854775805 mUnpluggedTime=9223372036854775804\n", sb.toString());
}
Also used : StringBuilderPrinter(android.util.StringBuilderPrinter) TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Example 4 with StringBuilderPrinter

use of android.util.StringBuilderPrinter in project android_frameworks_base by AOSPA.

the class BatteryStatsTimerTest method testLogState.

/**
     * Tests logState
     */
@SmallTest
public void testLogState() throws Exception {
    TimeBase timeBase = new TimeBase();
    MockClocks clocks = new MockClocks();
    TestTimer timer = new TestTimer(clocks, 0, timeBase);
    timer.setTotalTime(100);
    timer.setLoadedTime(200);
    timer.setLastTime(300);
    timer.setUnpluggedTime(400);
    timer.setTimeBeforeMark(500);
    timer.setCount(1);
    timer.setLoadedCount(2);
    timer.setLastCount(3);
    timer.setUnpluggedCount(4);
    timer.setTotalTime(9223372036854775807L);
    timer.setLoadedTime(9223372036854775806L);
    timer.setLastTime(9223372036854775805L);
    timer.setUnpluggedTime(9223372036854775804L);
    timer.setTimeBeforeMark(9223372036854775803L);
    StringBuilder sb = new StringBuilder();
    StringBuilderPrinter pw = new StringBuilderPrinter(sb);
    timer.logState(pw, "  ");
    Assert.assertEquals("  mCount=1 mLoadedCount=2 mLastCount=3 mUnpluggedCount=4\n" + "  mTotalTime=9223372036854775807 mLoadedTime=9223372036854775806\n" + "  mLastTime=9223372036854775805 mUnpluggedTime=9223372036854775804\n", sb.toString());
}
Also used : StringBuilderPrinter(android.util.StringBuilderPrinter) TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Example 5 with StringBuilderPrinter

use of android.util.StringBuilderPrinter in project android_frameworks_base by DirtyUnicorns.

the class BatteryStatsTimerTest method testLogState.

/**
     * Tests logState
     */
@SmallTest
public void testLogState() throws Exception {
    TimeBase timeBase = new TimeBase();
    MockClocks clocks = new MockClocks();
    TestTimer timer = new TestTimer(clocks, 0, timeBase);
    timer.setTotalTime(100);
    timer.setLoadedTime(200);
    timer.setLastTime(300);
    timer.setUnpluggedTime(400);
    timer.setTimeBeforeMark(500);
    timer.setCount(1);
    timer.setLoadedCount(2);
    timer.setLastCount(3);
    timer.setUnpluggedCount(4);
    timer.setTotalTime(9223372036854775807L);
    timer.setLoadedTime(9223372036854775806L);
    timer.setLastTime(9223372036854775805L);
    timer.setUnpluggedTime(9223372036854775804L);
    timer.setTimeBeforeMark(9223372036854775803L);
    StringBuilder sb = new StringBuilder();
    StringBuilderPrinter pw = new StringBuilderPrinter(sb);
    timer.logState(pw, "  ");
    Assert.assertEquals("  mCount=1 mLoadedCount=2 mLastCount=3 mUnpluggedCount=4\n" + "  mTotalTime=9223372036854775807 mLoadedTime=9223372036854775806\n" + "  mLastTime=9223372036854775805 mUnpluggedTime=9223372036854775804\n", sb.toString());
}
Also used : StringBuilderPrinter(android.util.StringBuilderPrinter) TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Aggregations

StringBuilderPrinter (android.util.StringBuilderPrinter)7 SmallTest (android.support.test.filters.SmallTest)5 TimeBase (com.android.internal.os.BatteryStatsImpl.TimeBase)5 Resources (android.content.res.Resources)1 Printer (android.util.Printer)1 ViewGroup (android.view.ViewGroup)1 EditorInfo (android.view.inputmethod.EditorInfo)1 InputConnection (android.view.inputmethod.InputConnection)1 Checkable (android.widget.Checkable)1 TextView (android.widget.TextView)1 ToStringHelper (com.google.common.base.Objects.ToStringHelper)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1