android.widget.ProgressBar#measure ( )源码实例Demo

下面列出了android.widget.ProgressBar#measure ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Test that the sizes of the progressBars are setup correctly
 */
public void testProgressBarSizes() {
  for (String style : styleList) {
    ProgressBar newProgressBar =
        new ProgressBar(getContext(), null, styles.get(style));
    final int spec = View.MeasureSpec.makeMeasureSpec(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        View.MeasureSpec.UNSPECIFIED);
    newProgressBar.measure(spec, spec);
    final int expectedHeight = newProgressBar.getMeasuredHeight();

    // verify correct size of view containing ProgressBar
    View viewContainingProgressBar = getViewByTestId(mRootView, style);
    assertEquals(expectedHeight, viewContainingProgressBar.getHeight());

    assertTrue(((ViewGroup) viewContainingProgressBar).getChildAt(0) instanceof ProgressBar);
  }
}
 
@Override
public long measure(
    YogaNode node,
    float width,
    YogaMeasureMode widthMode,
    float height,
    YogaMeasureMode heightMode) {
  final int style = ReactProgressBarViewManager.getStyleFromString(getStyle());
  if (!mMeasured.contains(style)) {
    ProgressBar progressBar = ReactProgressBarViewManager.createProgressBar(getThemedContext(), style);
    final int spec = View.MeasureSpec.makeMeasureSpec(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        View.MeasureSpec.UNSPECIFIED);
    progressBar.measure(spec, spec);
    mHeight.put(style, progressBar.getMeasuredHeight());
    mWidth.put(style, progressBar.getMeasuredWidth());
    mMeasured.add(style);
  }

  return YogaMeasureOutput.make(mWidth.get(style), mHeight.get(style));
}
 
源代码3 项目: react-native-GPay   文件: ProgressBarShadowNode.java
@Override
public long measure(
    YogaNode node,
    float width,
    YogaMeasureMode widthMode,
    float height,
    YogaMeasureMode heightMode) {
  final int style = ReactProgressBarViewManager.getStyleFromString(getStyle());
  if (!mMeasured.contains(style)) {
    ProgressBar progressBar = ReactProgressBarViewManager.createProgressBar(getThemedContext(), style);
    final int spec = View.MeasureSpec.makeMeasureSpec(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        View.MeasureSpec.UNSPECIFIED);
    progressBar.measure(spec, spec);
    mHeight.put(style, progressBar.getMeasuredHeight());
    mWidth.put(style, progressBar.getMeasuredWidth());
    mMeasured.add(style);
  }

  return YogaMeasureOutput.make(mWidth.get(style), mHeight.get(style));
}
 
源代码4 项目: react-native-GPay   文件: ProgressBarTestCase.java
/**
 * Test that the sizes of the progressBars are setup correctly
 */
public void testProgressBarSizes() {
  for (String style : styleList) {
    ProgressBar newProgressBar =
        new ProgressBar(getContext(), null, styles.get(style));
    final int spec = View.MeasureSpec.makeMeasureSpec(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        View.MeasureSpec.UNSPECIFIED);
    newProgressBar.measure(spec, spec);
    final int expectedHeight = newProgressBar.getMeasuredHeight();

    // verify correct size of view containing ProgressBar
    View viewContainingProgressBar = getViewByTestId(mRootView, style);
    assertEquals(expectedHeight, viewContainingProgressBar.getHeight());

    assertTrue(((ViewGroup) viewContainingProgressBar).getChildAt(0) instanceof ProgressBar);
  }
}
 
源代码5 项目: BookReader   文件: PageFactory.java
public void convertBetteryBitmap() {
    batteryView = (ProgressBar) LayoutInflater.from(mContext).inflate(R.layout.layout_battery_progress, null);
    batteryView.setProgressDrawable(ContextCompat.getDrawable(mContext,
            SettingManager.getInstance().getReadTheme() < 4 ?
                    R.drawable.seekbar_battery_bg : R.drawable.seekbar_battery_night_bg));
    batteryView.setProgress(battery);
    batteryView.setDrawingCacheEnabled(true);
    batteryView.measure(View.MeasureSpec.makeMeasureSpec(ScreenUtils.dpToPxInt(26), View.MeasureSpec.EXACTLY),
            View.MeasureSpec.makeMeasureSpec(ScreenUtils.dpToPxInt(14), View.MeasureSpec.EXACTLY));
    batteryView.layout(0, 0, batteryView.getMeasuredWidth(), batteryView.getMeasuredHeight());
    batteryView.buildDrawingCache();
    //batteryBitmap = batteryView.getDrawingCache();
    // tips: @link{https://github.com/JustWayward/BookReader/issues/109}
    batteryBitmap = Bitmap.createBitmap(batteryView.getDrawingCache());
    batteryView.setDrawingCacheEnabled(false);
    batteryView.destroyDrawingCache();
}
 
源代码6 项目: fangzhuishushenqi   文件: PageFactory.java
public void convertBetteryBitmap() {
    batteryView = (ProgressBar) LayoutInflater.from(mContext).inflate(R.layout.layout_battery_progress, null);
    batteryView.setProgressDrawable(ContextCompat.getDrawable(mContext,
            SettingManager.getInstance().getReadTheme() < 4 ?
                    R.drawable.seekbar_battery_bg : R.drawable.seekbar_battery_night_bg));
    batteryView.setProgress(battery);
    batteryView.setDrawingCacheEnabled(true);
    batteryView.measure(View.MeasureSpec.makeMeasureSpec(ScreenUtils.dpToPxInt(26), View.MeasureSpec.EXACTLY),
            View.MeasureSpec.makeMeasureSpec(ScreenUtils.dpToPxInt(14), View.MeasureSpec.EXACTLY));
    batteryView.layout(0, 0, batteryView.getMeasuredWidth(), batteryView.getMeasuredHeight());
    batteryView.buildDrawingCache();
    batteryBitmap = batteryView.getDrawingCache();
}