Пример #1
0
  private float getVerticalScrollFactorCompat() {
    if (this.mVerticalScrollFactor == 0.0F) {
      TypedValue var1 = new TypedValue();
      Context var2 = this.getContext();
      if (!var2.getTheme().resolveAttribute(16842829, var1, true)) {
        throw new IllegalStateException("Expected theme to define listPreferredItemHeight.");
      }

      this.mVerticalScrollFactor = var1.getDimension(var2.getResources().getDisplayMetrics());
    }

    return this.mVerticalScrollFactor;
  }
  /**
   * Gets the preferred height for each item in the ListView, in pixels, after accounting for screen
   * density. ImageLoader uses this value to resize thumbnail images to match the ListView item
   * height.
   *
   * @return The preferred height in pixels, based on the current theme.
   */
  private int getListPreferredItemHeight() {
    final TypedValue typedValue = new TypedValue();

    // Resolve list item preferred height theme attribute into typedValue
    getActivity()
        .getTheme()
        .resolveAttribute(android.R.attr.listPreferredItemHeight, typedValue, true);

    // Create a new DisplayMetrics object
    final DisplayMetrics metrics = new android.util.DisplayMetrics();

    // Populate the DisplayMetrics
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);

    // Return theme value based on DisplayMetrics
    return (int) typedValue.getDimension(metrics);
  }
Пример #3
0
  /* Stolen from PhoneWindow */
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int width = getMeasuredWidth();
    boolean measure = false;

    widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, EXACTLY);

    final TypedValue tv = isPortrait ? mMinWidthMinor : mMinWidthMajor;

    if (tv.type != TypedValue.TYPE_NULL) {
      final int min;
      if (tv.type == TypedValue.TYPE_DIMENSION) {
        min = (int) tv.getDimension(metrics);
      } else if (tv.type == TypedValue.TYPE_FRACTION) {
        min = (int) tv.getFraction(metrics.widthPixels, metrics.widthPixels);
      } else {
        min = 0;
      }

      if (width < min) {
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(min, EXACTLY);
        measure = true;
      }
    }

    // TODO: Support height?

    if (measure) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
  }