android.view.ViewDebug Java Examples

The following examples show how to use android.view.ViewDebug. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ViewDescriptor.java    From weex with Apache License 2.0 6 votes vote down vote up
private void getStyleFromInteger(
    String name,
    Integer value,
    @Nullable ViewDebug.ExportedProperty annotation,
    StyleAccumulator styles) {

  String intValueStr = IntegerFormatter.getInstance().format(value, annotation);

  if (canIntBeMappedToString(annotation)) {
    styles.store(
        name,
        intValueStr + " (" + mapIntToStringUsingAnnotation(value, annotation) + ")",
        false);
  } else if (canFlagsBeMappedToString(annotation)) {
    styles.store(
        name,
        intValueStr + " (" + mapFlagsToStringUsingAnnotation(value, annotation) + ")",
        false);
  } else {
    styles.store(name, intValueStr, isDefaultValue(value, annotation));
  }
}
 
Example #2
Source File: DdmHandleViewDebug.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the view hierarchy and/or view properties starting at the provided view.
 * Based on the input options, the return data may include:
 *  - just the view hierarchy
 *  - view hierarchy & the properties for each of the views
 *  - just the view properties for a specific view.
 *  TODO: Currently this only returns views starting at the root, need to fix so that
 *  it can return properties of any view.
 */
private Chunk dumpHierarchy(View rootView, ByteBuffer in) {
    boolean skipChildren = in.getInt() > 0;
    boolean includeProperties = in.getInt() > 0;
    boolean v2 = in.hasRemaining() && in.getInt() > 0;

    long start = System.currentTimeMillis();

    ByteArrayOutputStream b = new ByteArrayOutputStream(2*1024*1024);
    try {
        if (v2) {
            ViewDebug.dumpv2(rootView, b);
        } else {
            ViewDebug.dump(rootView, skipChildren, includeProperties, b);
        }
    } catch (IOException | InterruptedException e) {
        return createFailChunk(1, "Unexpected error while obtaining view hierarchy: "
                + e.getMessage());
    }

    long end = System.currentTimeMillis();
    Log.d(TAG, "Time to obtain view hierarchy (ms): " + (end - start));

    byte[] data = b.toByteArray();
    return new Chunk(CHUNK_VURT, data, 0, data.length);
}
 
Example #3
Source File: DdmHandleViewDebug.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Theme dump of the provided view.
 */
private Chunk dumpTheme(View rootView) {
    ByteArrayOutputStream b = new ByteArrayOutputStream(1024);
    try {
        ViewDebug.dumpTheme(rootView, b);
    } catch (IOException e) {
        return createFailChunk(1, "Unexpected error while dumping the theme: "
                + e.getMessage());
    }

    byte[] data = b.toByteArray();
    return new Chunk(CHUNK_VURT, data, 0, data.length);
}
 
Example #4
Source File: ViewDescriptor.java    From stetho with MIT License 5 votes vote down vote up
private void getStyleFromInteger(
    String name,
    Integer value,
    @Nullable ViewDebug.ExportedProperty annotation,
    StyleAccumulator styles) {

  String intValueStr = IntegerFormatter.getInstance().format(value, annotation);

  if (canIntBeMappedToString(annotation)) {
    styles.store(
        name,
        intValueStr + " (" + mapIntToStringUsingAnnotation(value, annotation) + ")",
        false);
  } else if (canFlagsBeMappedToString(annotation)) {
    styles.store(
        name,
        intValueStr + " (" + mapFlagsToStringUsingAnnotation(value, annotation) + ")",
        false);
  } else {
    Boolean defaultValue = true;
    // Mappable ints should always be shown, because enums don't necessarily have
    // logical "default" values. Thus we mark all of them as not default, so that they
    // show up in the inspector.
    if (value != 0 ||
        canFlagsBeMappedToString(annotation) ||
        canIntBeMappedToString(annotation)) {
      defaultValue = false;
    }
    styles.store(name, intValueStr, defaultValue);
  }
}
 
Example #5
Source File: IntegerFormatter.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public String format(Integer integer, @Nullable ViewDebug.ExportedProperty annotation) {
  if (annotation != null && annotation.formatToHexString()) {
    return "0x" + Integer.toHexString(integer);
  }

  return super.format(integer, annotation);
}
 
Example #6
Source File: RIViewDescriptor.java    From ResourceInspector with Apache License 2.0 5 votes vote down vote up
private void getStyleFromInteger(
        String name,
        Integer value,
        @Nullable ViewDebug.ExportedProperty annotation,
        StyleAccumulator styles) {

    String intValueStr = IntegerFormatter.getInstance().format(value, annotation);

    if (canIntBeMappedToString(annotation)) {
        styles.store(
                name,
                intValueStr + " (" + mapIntToStringUsingAnnotation(value, annotation) + ")",
                false);
    } else if (canFlagsBeMappedToString(annotation)) {
        styles.store(
                name,
                intValueStr + " (" + mapFlagsToStringUsingAnnotation(value, annotation) + ")",
                false);
    } else {
        Boolean defaultValue = true;
        // Mappable ints should always be shown, because enums don't necessarily have
        // logical "default" values. Thus we mark all of them as not default, so that they
        // show up in the inspector.
        if (value != 0 ||
                canFlagsBeMappedToString(annotation) ||
                canIntBeMappedToString(annotation)) {
            defaultValue = false;
        }
        styles.store(name, intValueStr, defaultValue);
    }
}
 
Example #7
Source File: ViewDescriptor.java    From weex with Apache License 2.0 5 votes vote down vote up
private static String mapFlagsToStringUsingAnnotation(
    int value,
    @Nullable ViewDebug.ExportedProperty annotation) {
  if (!canFlagsBeMappedToString(annotation)) {
    throw new IllegalStateException("Cannot map using this annotation");
  }

  StringBuilder stringBuilder = null;
  boolean atLeastOneFlag = false;

  for (ViewDebug.FlagToString flagToString : annotation.flagMapping()) {
    if (flagToString.outputIf() == ((value & flagToString.mask()) == flagToString.equals())) {
      if (stringBuilder == null) {
        stringBuilder = new StringBuilder();
      }

      if (atLeastOneFlag) {
        stringBuilder.append(" | ");
      }

      stringBuilder.append(flagToString.name());
      atLeastOneFlag = true;
    }
  }

  if (atLeastOneFlag) {
    return stringBuilder.toString();
  } else {
    return NONE_MAPPING;
  }
}
 
Example #8
Source File: AbsHListView.java    From Klyph with MIT License 5 votes vote down vote up
@Override
@ViewDebug.ExportedProperty
public View getSelectedView() {
	if ( mItemCount > 0 && mSelectedPosition >= 0 ) {
		return getChildAt( mSelectedPosition - mFirstPosition );
	} else {
		return null;
	}
}
 
Example #9
Source File: RIViewDescriptor.java    From ResourceInspector with Apache License 2.0 5 votes vote down vote up
private void getStyleFromValue(
        View element,
        String name,
        Object value,
        @Nullable ViewDebug.ExportedProperty annotation,
        StyleAccumulator styles) {

    if (name.equals(ID_NAME)) {
        getIdStyle(element, styles);
    } else if (value instanceof Integer) {
        getStyleFromInteger(name, (Integer) value, annotation, styles);
    } else if (value instanceof Float) {
        styles.store(name, String.valueOf(value), ((Float) value) == 0.0f);
    } else if (value instanceof Boolean) {
        styles.store(name, String.valueOf(value), false);
    } else if (value instanceof Short) {
        styles.store(name, String.valueOf(value), ((Short) value) == 0);
    } else if (value instanceof Long) {
        styles.store(name, String.valueOf(value), ((Long) value) == 0);
    } else if (value instanceof Double) {
        styles.store(name, String.valueOf(value), ((Double) value) == 0.0d);
    } else if (value instanceof Byte) {
        styles.store(name, String.valueOf(value), ((Byte) value) == 0);
    } else if (value instanceof Character) {
        styles.store(name, String.valueOf(value), ((Character) value) == Character.MIN_VALUE);
    } else if (value instanceof CharSequence) {
        styles.store(name, String.valueOf(value), ((CharSequence) value).length() == 0);
    } else {
        getStylesFromObject(element, name, value, annotation, styles);
    }
}
 
Example #10
Source File: ViewDescriptor.java    From weex with Apache License 2.0 5 votes vote down vote up
public MethodBackedCSSProperty(
    Method method,
    String cssName,
    @Nullable ViewDebug.ExportedProperty annotation) {
  super(cssName, annotation);
  mMethod = method;
  mMethod.setAccessible(true);
}
 
Example #11
Source File: DdmHandleViewDebug.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private Chunk captureView(View rootView, View targetView) {
    ByteArrayOutputStream b = new ByteArrayOutputStream(1024);
    try {
        ViewDebug.capture(rootView, b, targetView);
    } catch (IOException e) {
        return createFailChunk(1, "Unexpected error while capturing view: "
                + e.getMessage());
    }

    byte[] data = b.toByteArray();
    return new Chunk(CHUNK_VUOP, data, 0, data.length);
}
 
Example #12
Source File: RIViewDescriptor.java    From ResourceInspector with Apache License 2.0 5 votes vote down vote up
private static String mapFlagsToStringUsingAnnotation(
        int value,
        @Nullable ViewDebug.ExportedProperty annotation) {
    if (!canFlagsBeMappedToString(annotation)) {
        throw new IllegalStateException("Cannot map using this annotation");
    }

    StringBuilder stringBuilder = null;
    boolean atLeastOneFlag = false;

    for (ViewDebug.FlagToString flagToString : annotation.flagMapping()) {
        if (flagToString.outputIf() == ((value & flagToString.mask()) == flagToString.equals())) {
            if (stringBuilder == null) {
                stringBuilder = new StringBuilder();
            }

            if (atLeastOneFlag) {
                stringBuilder.append(" | ");
            }

            stringBuilder.append(flagToString.name());
            atLeastOneFlag = true;
        }
    }

    if (atLeastOneFlag) {
        return stringBuilder.toString();
    } else {
        return NONE_MAPPING;
    }
}
 
Example #13
Source File: RIViewDescriptor.java    From ResourceInspector with Apache License 2.0 5 votes vote down vote up
public MethodBackedCSSProperty(
        Method method,
        String cssName,
        @Nullable ViewDebug.ExportedProperty annotation) {
    super(cssName, annotation);
    mMethod = method;
    mMethod.setAccessible(true);
}
 
Example #14
Source File: PLAListView.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the view and add it to our list of children. The view can be made
 * fresh, converted from an unused view, or used as is if it was in the
 * recycle bin.
 *
 * @param position Logical position in the list
 * @param childrenBottomOrTop Top or bottom edge of the view to add
 * @param flow If flow is true, align top edge to y. If false, align bottom
 *        edge to y.
 * @param selected Is this position selected?
 * @return View that was added
 */
@SuppressWarnings("deprecation")
private View makeAndAddView(int position, int childrenBottomOrTop, boolean flow,
        boolean selected) {
    View child;

    int childrenLeft;
    if (!mDataChanged) {
        // Try to use an exsiting view for this position
        child = mRecycler.getActiveView(position);
        if (child != null) {

            if (ViewDebug.TRACE_RECYCLER) {
                ViewDebug.trace(child, ViewDebug.RecyclerTraceType.RECYCLE_FROM_ACTIVE_HEAP,
                        position, getChildCount());
            }

            // Found it -- we're using an existing child
            // This just needs to be positioned
            childrenLeft = getItemLeft(position);
            setupChild(child, position, childrenBottomOrTop, flow, childrenLeft, selected, true);
            return child;
        }
    }

    //Notify new item is added to view.

    onItemAddedToList( position, flow );
    childrenLeft = getItemLeft( position );

    // Make a new view for this position, or convert an unused view if possible
    child = obtainView(position, mIsScrap);

    // This needs to be positioned and measured
    setupChild(child, position, childrenBottomOrTop, flow, childrenLeft, selected, mIsScrap[0]);

    return child;
}
 
Example #15
Source File: PLA_ListView.java    From EverMemo with MIT License 5 votes vote down vote up
/**
 * Obtain the view and add it to our list of children. The view can be made
 * fresh, converted from an unused view, or used as is if it was in the
 * recycle bin.
 *
 * @param position Logical position in the list
 * @param childrenBottomOrTop Top or bottom edge of the view to add
 * @param flow If flow is true, align top edge to y. If false, align bottom
 *        edge to y.
 * @param childrenLeft Left edge where children should be positioned
 * @param selected Is this position selected?
 * @return View that was added
 */
@SuppressWarnings("deprecation")
private View makeAndAddView(int position, int childrenBottomOrTop, boolean flow,
		boolean selected) {
	View child;

	int childrenLeft;
	if (!mDataChanged) {
		// Try to use an exsiting view for this position
		child = mRecycler.getActiveView(position);
		if (child != null) {

			if (ViewDebug.TRACE_RECYCLER) {
				ViewDebug.trace(child, ViewDebug.RecyclerTraceType.RECYCLE_FROM_ACTIVE_HEAP,
						position, getChildCount());
			}

			// Found it -- we're using an existing child
			// This just needs to be positioned
			childrenLeft = getItemLeft(position);
			setupChild(child, position, childrenBottomOrTop, flow, childrenLeft, selected, true);
			return child;
		}
	}

	//Notify new item is added to view.
	
	onItemAddedToList( position, flow );
	childrenLeft = getItemLeft( position );

	// Make a new view for this position, or convert an unused view if possible
	child = obtainView(position, mIsScrap);

	// This needs to be positioned and measured
	setupChild(child, position, childrenBottomOrTop, flow, childrenLeft, selected, mIsScrap[0]);

	return child;
}
 
Example #16
Source File: TwoWayAbsListView.java    From recent-images with MIT License 4 votes vote down vote up
/**
 * Move all views remaining in mActiveViews to mScrapViews.
 */
void scrapActiveViews() {
	final View[] activeViews = mActiveViews;
	final boolean hasListener = mRecyclerListener != null;
	final boolean multipleScraps = mViewTypeCount > 1;

	ArrayList<View> scrapViews = mCurrentScrap;
	final int count = activeViews.length;
	for (int i = count - 1; i >= 0; i--) {
		final View victim = activeViews[i];
		if (victim != null) {
			int whichScrap = ((TwoWayAbsListView.LayoutParams) victim.getLayoutParams()).viewType;

			activeViews[i] = null;

			if (!shouldRecycleViewType(whichScrap)) {
				// Do not move views that should be ignored
				if (whichScrap != ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
					removeDetachedView(victim, false);
				}
				continue;
			}

			if (multipleScraps) {
				scrapViews = mScrapViews[whichScrap];
			}
			victim.onStartTemporaryDetach();
			scrapViews.add(victim);

			if (hasListener) {
				mRecyclerListener.onMovedToScrapHeap(victim);
			}

			if (ViewDebug.TRACE_RECYCLER) {
				ViewDebug.trace(victim,
						ViewDebug.RecyclerTraceType.MOVE_FROM_ACTIVE_TO_SCRAP_HEAP,
						mFirstActivePosition + i, -1);
			}
		}
	}

	pruneScrapViews();
}
 
Example #17
Source File: IndeterminateRadioButton.java    From simpletask-android with GNU General Public License v3.0 4 votes vote down vote up
@ViewDebug.ExportedProperty
public boolean isIndeterminate() {
    return mIndeterminate;
}
 
Example #18
Source File: TwoWayAbsListView.java    From recent-images with MIT License 4 votes vote down vote up
/**
 * Get a view and have it show the data associated with the specified
 * position. This is called when we have already discovered that the view is
 * not available for reuse in the recycle bin. The only choices left are
 * converting an old view or making a new one.
 *
 * @param position The position to display
 * @param isScrap Array of at least 1 boolean, the first entry will become true if
 *                the returned view was taken from the scrap heap, false if otherwise.
 * 
 * @return A view displaying the data associated with the specified position
 */
View obtainView(int position, boolean[] isScrap) {
	isScrap[0] = false;
	View scrapView;

	scrapView = mRecycler.getScrapView(position);

	View child;
	if (scrapView != null) {
		if (ViewDebug.TRACE_RECYCLER) {
			ViewDebug.trace(scrapView, ViewDebug.RecyclerTraceType.RECYCLE_FROM_SCRAP_HEAP,
					position, -1);
		}

		child = mAdapter.getView(position, scrapView, this);

		if (ViewDebug.TRACE_RECYCLER) {
			ViewDebug.trace(child, ViewDebug.RecyclerTraceType.BIND_VIEW,
					position, getChildCount());
		}

		if (child != scrapView) {
			mRecycler.addScrapView(scrapView);
			if (mCacheColorHint != 0) {
				child.setDrawingCacheBackgroundColor(mCacheColorHint);
			}
			if (ViewDebug.TRACE_RECYCLER) {
				ViewDebug.trace(scrapView, ViewDebug.RecyclerTraceType.MOVE_TO_SCRAP_HEAP,
						position, -1);
			}
		} else {
			isScrap[0] = true;
			child.onFinishTemporaryDetach();
		}
	} else {
		child = mAdapter.getView(position, null, this);
		if (mCacheColorHint != 0) {
			child.setDrawingCacheBackgroundColor(mCacheColorHint);
		}
		if (ViewDebug.TRACE_RECYCLER) {
			ViewDebug.trace(child, ViewDebug.RecyclerTraceType.NEW_VIEW,
					position, getChildCount());
		}
	}

	return child;
}
 
Example #19
Source File: ZrcAbsListView.java    From ZrcListView with MIT License 4 votes vote down vote up
@ViewDebug.ExportedProperty
public boolean isSmoothScrollbarEnabled() {
	return mSmoothScrollbarEnabled;
}
 
Example #20
Source File: ViewDescriptor.java    From stetho with MIT License 4 votes vote down vote up
private static boolean canIntBeMappedToString(@Nullable ViewDebug.ExportedProperty annotation) {
  return annotation != null
      && annotation.mapping() != null
      && annotation.mapping().length > 0;
}
 
Example #21
Source File: ViewDescriptor.java    From weex with Apache License 2.0 4 votes vote down vote up
private void getStylesFromObject(
    View view,
    String name,
    Object value,
    @Nullable ViewDebug.ExportedProperty annotation,
    StyleAccumulator styles) {
  if (annotation == null || !annotation.deepExport() || value == null) {
    return;
  }

  Field[] fields = value.getClass().getFields();

  for (Field field : fields) {
    int modifiers = field.getModifiers();
    if (Modifier.isStatic(modifiers)) {
      continue;
    }

    Object propertyValue;
    try {
        field.setAccessible(true);
        propertyValue = field.get(value);
    } catch (IllegalAccessException e) {
      LogUtil.e(
          e,
          "failed to get property of name: \"" + name + "\" of object: " + String.valueOf(value));
      return;
    }

    String propertyName = field.getName();

    switch (propertyName) {
      case "bottomMargin":
        propertyName = "margin-bottom";
        break;
      case "topMargin":
        propertyName = "margin-top";
        break;
      case "leftMargin":
        propertyName = "margin-left";
        break;
      case "rightMargin":
        propertyName = "margin-right";
        break;
      default:
        String annotationPrefix = annotation.prefix();
        propertyName = convertViewPropertyNameToCSSName(
            (annotationPrefix == null) ? propertyName : (annotationPrefix + propertyName));
        break;
    }

    ViewDebug.ExportedProperty subAnnotation =
        field.getAnnotation(ViewDebug.ExportedProperty.class);

    getStyleFromValue(
        view,
        propertyName,
        propertyValue,
        subAnnotation,
        styles);
  }
}
 
Example #22
Source File: PLA_AdapterView.java    From EverMemo with MIT License 4 votes vote down vote up
/**
 * @return The id corresponding to the currently selected item, or {@link #INVALID_ROW_ID}
 * if nothing is selected.
 */
@ViewDebug.CapturedViewProperty
public long getSelectedItemId() {
	return INVALID_ROW_ID;
}
 
Example #23
Source File: ViewDescriptor.java    From weex with Apache License 2.0 4 votes vote down vote up
private static boolean canIntBeMappedToString(@Nullable ViewDebug.ExportedProperty annotation) {
  return annotation != null
      && annotation.mapping() != null
      && annotation.mapping().length > 0;
}
 
Example #24
Source File: IndeterminateRadioButton.java    From indeterminate-checkbox with Apache License 2.0 4 votes vote down vote up
@ViewDebug.ExportedProperty
public Boolean getState() {
    return mIndeterminate ? null : isChecked();
}
 
Example #25
Source File: ZrcAbsListView.java    From AndroidStudyDemo with GNU General Public License v2.0 4 votes vote down vote up
@ViewDebug.ExportedProperty(category = "drawing")
public int getCacheColorHint() {
    return mCacheColorHint;
}
 
Example #26
Source File: RIViewDescriptor.java    From ResourceInspector with Apache License 2.0 4 votes vote down vote up
private void getStylesFromObject(
        View view,
        String name,
        Object value,
        @Nullable ViewDebug.ExportedProperty annotation,
        StyleAccumulator styles) {
    if (annotation == null || !annotation.deepExport() || value == null) {
        return;
    }

    Field[] fields = value.getClass().getFields();

    for (Field field : fields) {
        int modifiers = field.getModifiers();
        if (Modifier.isStatic(modifiers)) {
            continue;
        }

        Object propertyValue;
        try {
            field.setAccessible(true);
            propertyValue = field.get(value);
        } catch (IllegalAccessException e) {
            LogUtil.e(
                    e,
                    "failed to get property of name: \"" + name + "\" of object: " + String.valueOf(value));
            return;
        }

        String propertyName = field.getName();

        switch (propertyName) {
            case "bottomMargin":
                propertyName = "margin-bottom";
                break;
            case "topMargin":
                propertyName = "margin-top";
                break;
            case "leftMargin":
                propertyName = "margin-left";
                break;
            case "rightMargin":
                propertyName = "margin-right";
                break;
            default:
                String annotationPrefix = annotation.prefix();
                propertyName = convertViewPropertyNameToCSSName(
                        (annotationPrefix == null) ? propertyName : (annotationPrefix + propertyName));
                break;
        }

        ViewDebug.ExportedProperty subAnnotation =
                field.getAnnotation(ViewDebug.ExportedProperty.class);

        getStyleFromValue(
                view,
                propertyName,
                propertyValue,
                subAnnotation,
                styles);
    }
}
 
Example #27
Source File: RIViewDescriptor.java    From ResourceInspector with Apache License 2.0 4 votes vote down vote up
private static boolean canFlagsBeMappedToString(@Nullable ViewDebug.ExportedProperty annotation) {
    return annotation != null
            && annotation.flagMapping() != null
            && annotation.flagMapping().length > 0;
}
 
Example #28
Source File: RIViewDescriptor.java    From ResourceInspector with Apache License 2.0 4 votes vote down vote up
private static boolean canIntBeMappedToString(@Nullable ViewDebug.ExportedProperty annotation) {
    return annotation != null
            && annotation.mapping() != null
            && annotation.mapping().length > 0;
}
 
Example #29
Source File: MenuItemImpl.java    From Libraries-for-Android-Developers with MIT License 4 votes vote down vote up
@ViewDebug.CapturedViewProperty
public CharSequence getTitle() {
    return mTitle;
}
 
Example #30
Source File: IndeterminateCheckBox.java    From simpletask-android with GNU General Public License v3.0 4 votes vote down vote up
@ViewDebug.ExportedProperty
public boolean isIndeterminate() {
    return mIndeterminate;
}