类android.view.ViewDebug源码实例Demo

下面列出了怎么用android.view.ViewDebug的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: android_9.0.0_r45   文件: DdmHandleViewDebug.java
/**
 * 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);
}
 
源代码2 项目: weex   文件: ViewDescriptor.java
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));
  }
}
 
源代码3 项目: android_9.0.0_r45   文件: DdmHandleViewDebug.java
/**
 * 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);
}
 
源代码4 项目: android_9.0.0_r45   文件: DdmHandleViewDebug.java
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);
}
 
源代码5 项目: Klyph   文件: AbsHListView.java
@Override
@ViewDebug.ExportedProperty
public View getSelectedView() {
	if ( mItemCount > 0 && mSelectedPosition >= 0 ) {
		return getChildAt( mSelectedPosition - mFirstPosition );
	} else {
		return null;
	}
}
 
源代码6 项目: EverMemo   文件: PLA_ListView.java
/**
 * 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;
}
 
源代码7 项目: SimplifyReader   文件: PLAListView.java
/**
 * 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;
}
 
源代码8 项目: ResourceInspector   文件: RIViewDescriptor.java
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;
    }
}
 
源代码9 项目: ResourceInspector   文件: RIViewDescriptor.java
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);
    }
}
 
源代码10 项目: ResourceInspector   文件: RIViewDescriptor.java
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);
    }
}
 
源代码11 项目: ResourceInspector   文件: RIViewDescriptor.java
public MethodBackedCSSProperty(
        Method method,
        String cssName,
        @Nullable ViewDebug.ExportedProperty annotation) {
    super(cssName, annotation);
    mMethod = method;
    mMethod.setAccessible(true);
}
 
源代码12 项目: stetho   文件: ViewDescriptor.java
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);
  }
}
 
源代码13 项目: weex   文件: IntegerFormatter.java
@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);
}
 
源代码14 项目: weex   文件: ViewDescriptor.java
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;
  }
}
 
源代码15 项目: weex   文件: ViewDescriptor.java
public MethodBackedCSSProperty(
    Method method,
    String cssName,
    @Nullable ViewDebug.ExportedProperty annotation) {
  super(cssName, annotation);
  mMethod = method;
  mMethod.setAccessible(true);
}
 
源代码16 项目: Carbon   文件: RadioButton.java
@ViewDebug.ExportedProperty
public boolean isChecked() {
    return checked;
}
 
源代码17 项目: EverMemo   文件: PLA_AdapterView.java
/**
 * @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;
}
 
源代码18 项目: android-apps   文件: IcsAdapterView.java
/**
 * @return The id corresponding to the currently selected item, or {@link #INVALID_ROW_ID}
 * if nothing is selected.
 */
@ViewDebug.CapturedViewProperty
public long getSelectedItemId() {
    return mNextSelectedRowId;
}
 
源代码19 项目: android-tv-launcher   文件: AdapterView.java
@ViewDebug.CapturedViewProperty
public int getSelectedItemPosition() {
	return this.mNextSelectedPosition;
}
 
源代码20 项目: android-apps   文件: MenuItemImpl.java
@ViewDebug.CapturedViewProperty
public CharSequence getTitle() {
    return mTitle;
}
 
源代码21 项目: EverMemo   文件: PLA_AbsListView.java
/**
 * Move all views remaining in mActiveViews to mScrapViews.
 */
@SuppressWarnings("deprecation")
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 = ((PLA_AbsListView.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.dispatchStartTemporaryDetach();
			dispatchFinishTemporaryDetach(victim);
			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();
}
 
源代码22 项目: Klyph   文件: AdapterView.java
/**
 * @return The number of items owned by the Adapter associated with this AdapterView. (This is the number of data items, which
 *         may be larger than the number of visible views.)
 */
@ViewDebug.CapturedViewProperty
public int getCount() {
	return mItemCount;
}
 
@ViewDebug.ExportedProperty
public boolean isIndeterminate() {
    return mIndeterminate;
}
 
源代码24 项目: android_9.0.0_r45   文件: CheckedTextView.java
@ViewDebug.ExportedProperty
public boolean isChecked() {
    return mChecked;
}
 
源代码25 项目: ZrcListView   文件: ZrcAbsListView.java
@ViewDebug.ExportedProperty(category = "drawing")
public int getCacheColorHint() {
	return mCacheColorHint;
}
 
源代码26 项目: android_9.0.0_r45   文件: AdapterView.java
/**
 * @return The id corresponding to the currently selected item, or {@link #INVALID_ROW_ID}
 * if nothing is selected.
 */
@ViewDebug.CapturedViewProperty
public long getSelectedItemId() {
    return mNextSelectedRowId;
}
 
源代码27 项目: Lay-s   文件: PLAAdapterView.java
/**
 * @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;
}
 
@ViewDebug.CapturedViewProperty
public int getItemId() {
    return mId;
}
 
@Override
@ViewDebug.ExportedProperty
public boolean isChecked() {
    return this.mChecked;
}
 
源代码30 项目: stetho   文件: ViewDescriptor.java
public ViewCSSProperty(String cssName, @Nullable ViewDebug.ExportedProperty annotation) {
  mCSSName = cssName;
  mAnnotation = annotation;
}
 
 类所在包
 同包方法