コード例 #1
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    this.innerView.measure(widthMeasureSpec, heightMeasureSpec);
    ImageView iv1 = (ImageView) this.innerView.findViewById(R.id.top_item_1);
    LayoutParams lp = iv1.getLayoutParams();
    lp.height = iv1.getMeasuredWidth();
    iv1.setLayoutParams(lp);

    ImageView iv2 = (ImageView) this.innerView.findViewById(R.id.top_item_2);
    lp = iv2.getLayoutParams();
    lp.height = iv2.getMeasuredWidth();
    iv2.setLayoutParams(lp);

    ImageView iv3 = (ImageView) this.innerView.findViewById(R.id.top_item_3);
    lp = iv3.getLayoutParams();
    lp.height = iv3.getMeasuredWidth();
    iv3.setLayoutParams(lp);

    TextView tv = (TextView) this.innerView.findViewById(R.id.top_item_others);
    lp = tv.getLayoutParams();
    lp.height = iv3.getMeasuredWidth();
    tv.setLayoutParams(lp);

    this.innerView.measure(widthMeasureSpec, heightMeasureSpec);

    this.setMeasuredDimension(
        this.innerView.getMeasuredWidth(), this.innerView.getMeasuredHeight());
  }
コード例 #2
0
 @Override
 protected void onLayout(boolean changed, int l, int t, int r, int b) {
   mBgView.layout(l, t, r, b);
   int dragViewHeight = mHeaderView.getMeasuredHeight();
   int dragViewWidth = mHeaderView.getMeasuredWidth();
   mDragRange = mContentView.getMeasuredHeight(); // parentViewHeight -
   // dragViewHeight;
   if (Constants.hasEnterpriseAccountLoggedIn()) {
     mTop = 0;
   }
   LogUtil.d(
       TAG,
       "onLayout:"
           + "changed:"
           + changed
           + ",l:"
           + l
           + ",t:"
           + t
           + ",r:"
           + r
           + ",b:"
           + b
           + ",mDragRange"
           + mDragRange
           + ",mtop----"
           + mTop
           + " drageViewWidth----"
           + dragViewWidth
           + " dragViewHeight----"
           + dragViewHeight);
   mContentView.layout(0, 0, r, mTop);
   mHeaderView.layout(
       20, mTop + mHeaderView.getPaddingTop(), 20 + dragViewWidth, mTop + dragViewHeight);
 }
コード例 #3
0
  /**
   * Set animation style
   *
   * @param screenWidth screen width
   * @param requestedX distance from left edge
   * @param onTop flag to indicate where the popup should be displayed. Set TRUE if displayed on top
   *     of anchor view and vice versa
   */
  private void setAnimationStyle(int screenWidth, int requestedX, boolean onTop) {
    int arrowPos = requestedX - mArrowUp.getMeasuredWidth() / 2;
    /*
    switch (animStyle) {
    case ANIM_GROW_FROM_LEFT:
    	mWindow.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Left : R.style.Animations_PopDownMenu_Left);
    	break;

    case ANIM_GROW_FROM_RIGHT:
    	mWindow.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Right : R.style.Animations_PopDownMenu_Right);
    	break;

    case ANIM_GROW_FROM_CENTER:
    	mWindow.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Center : R.style.Animations_PopDownMenu_Center);
    break;

    case ANIM_REFLECT:
    	mWindow.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Reflect : R.style.Animations_PopDownMenu_Reflect);
    break;

    case ANIM_AUTO:
    	if (arrowPos <= screenWidth/4) {
    		mWindow.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Left : R.style.Animations_PopDownMenu_Left);
    	} else if (arrowPos > screenWidth/4 && arrowPos < 3 * (screenWidth/4)) {
    		mWindow.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Center : R.style.Animations_PopDownMenu_Center);
    	} else {
    		mWindow.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Right : R.style.Animations_PopDownMenu_Right);
    	}

    	break;
    }
    */
  }
コード例 #4
0
 private void arrowlistener() {
   int width = arrowicon.getMeasuredWidth();
   int height = arrowicon.getMeasuredHeight();
   LogUtils.D("onClick" + width + " " + height);
   Matrix matrix = new Matrix();
   count++;
   matrix.postRotate(180 * count, width / 2, height / 2);
   arrowicon.setImageMatrix(matrix);
   if (count % 2 != 0) {
     list_title.setVisibility(View.VISIBLE);
     list_content.setVisibility(View.VISIBLE);
     View view = (View) mViewPager.getParent();
     Bitmap bitmap =
         BitmapUtils.shot(
             getView(),
             (int) view.getX(),
             (int) view.getY(),
             mViewPager.getMeasuredWidth(),
             mViewPager.getMeasuredHeight());
     if (bitmap != null)
       list_content.setBackground(
           new BitmapDrawable(BitmapUtils.blurBitmap(bitmap, getActivity())));
     //                    list_content.setBackground(new
     // BitmapDrawable(BitmapUtils.compressBmpFromBmp(bitmap)));
     mItemHScrollView.setVisibility(View.GONE);
     mViewPager.setVisibility(View.GONE);
   } else {
     list_title.setVisibility(View.GONE);
     list_content.setVisibility(View.GONE);
     list_content.setBackground(null);
     mItemHScrollView.setVisibility(View.VISIBLE);
     mViewPager.setVisibility(View.VISIBLE);
   }
 }
コード例 #5
0
 // DownloadTaskListener
 @Override
 public void onComplete(String url, DownloadResponse downloadResponse) {
   if (downloadResponse != null && downloadResponse.getStatusCode() == HttpStatus.SC_OK) {
     final Bitmap companionAdBitmap = HttpResponses.asBitmap(downloadResponse);
     if (companionAdBitmap != null) {
       // If Bitmap fits in ImageView, then don't use MATCH_PARENT
       final int width = Dips.dipsToIntPixels(companionAdBitmap.getWidth(), getContext());
       final int height = Dips.dipsToIntPixels(companionAdBitmap.getHeight(), getContext());
       final int imageViewWidth = mCompanionAdImageView.getMeasuredWidth();
       final int imageViewHeight = mCompanionAdImageView.getMeasuredHeight();
       if (width < imageViewWidth && height < imageViewHeight) {
         mCompanionAdImageView.getLayoutParams().width = width;
         mCompanionAdImageView.getLayoutParams().height = height;
       }
       mCompanionAdImageView.setImageBitmap(companionAdBitmap);
       mCompanionAdImageView.setOnClickListener(
           new View.OnClickListener() {
             @Override
             public void onClick(View view) {
               if (mVastCompanionAd != null) {
                 handleClick(
                     mVastCompanionAd.getClickTrackers(), mVastCompanionAd.getClickThroughUrl());
               }
             }
           });
     }
   }
 }
コード例 #6
0
ファイル: VpHeaderAdapter.java プロジェクト: devzld/YunKeTang
  @Override
  public Object instantiateItem(ViewGroup container, int position) {

    //        Log.i(TAG, "instantiateItem: "+container.getLayoutParams().width);
    //        ImageView image = (ImageView) container.getChildAt(position);

    //        image.setLayoutParams(params);
    String url = mImageIds[position];
    ImageView imageView = new ImageView(mContext);
    imageView.setBackgroundColor(Color.RED);

    Log.i(TAG, "instantiateItem Width: " + imageView.getMeasuredWidth());
    Log.i(TAG, "instantiateItem Height " + imageView.getMeasuredHeight());
    /*ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(1200,600);
    imageView.setLayoutParams(params);*/
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setImageResource(R.mipmap.ic_launcher);
    /*        ViewGroup.LayoutParams lp= imageView.getLayoutParams();
    lp.width = 1200;
    lp.height = 600;
    imageView.setLayoutParams(lp);*/
    // Log.i(TAG, "instantiateItem: 123" + imageView.getLayoutParams().width);

    imageView.setTag(url);
    ImageLoader.getInstance().showBitmap(url, imageView);
    list.add(imageView);
    container.addView(imageView);
    return imageView;
  }
コード例 #7
0
ファイル: ImageTextView.java プロジェクト: MichaelSun/SiXin
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthSize = widthMeasureSpec & ~(0x3 << 30);
    final int widthMode = widthMeasureSpec & (0x3 << 30);
    final int heightSize = heightMeasureSpec & ~(0x3 << 30);
    final int heightMode = heightMeasureSpec & (0x3 << 30);

    boolean horizontal = (POSITION_LEFT.equals(mPosition) || POSITION_RIGHT.equals(mPosition));

    if (widthMode == MeasureSpec.UNSPECIFIED || heightMode == MeasureSpec.UNSPECIFIED) {
      throw new InflateException("MeasureSpec.UNSPECIFIED is not support.");
    }

    if (mImageHeight > 0
        && mImageWidth > 0
        && mImageHeight < heightSize - verticalPadding() - (horizontal ? 0 : mSpacing)
        && mImageWidth < widthSize - horizontalPadding() - (horizontal ? mSpacing : 0)) {
      // the image's size must not larger than the given size. and if the size is 0, we won't
      // measure it.
      measureChild(mImage, (int) (mImageWidth + widthMode), (int) (mImageHeight + heightMode));
    } else {
      mNeedLayout = false;
    }

    if (horizontal) {
      int textWidth = (int) (widthSize - horizontalPadding() - mSpacing - mImageWidth);
      measureChild(mText, textWidth + widthMode, heightSize + heightMode);
    } else {
      int textHeight = (int) (heightSize - verticalPadding() - mSpacing - mImageHeight);
      measureChild(mText, widthSize + widthMode, textHeight + heightMode);
    }

    int width = 0;
    int height = 0;

    if (widthMode == MeasureSpec.EXACTLY) {
      width = widthSize;
    } else if (widthMode == MeasureSpec.AT_MOST) {
      width =
          (int)
              (mImage.getMeasuredWidth()
                  + mText.getMeasuredWidth()
                  + horizontalPadding()
                  + (horizontal ? mSpacing : 0));
    }

    if (heightMode == MeasureSpec.EXACTLY) {
      height = heightSize;
    } else if (heightMode == MeasureSpec.AT_MOST) {
      height =
          (int)
              (mImage.getMeasuredHeight()
                  + mText.getMeasuredHeight()
                  + verticalPadding()
                  + (horizontal ? 0 : mSpacing));
    }

    setMeasuredDimension(width, height);
  }
コード例 #8
0
  /**
   * Asynchronously fulfills the request into the specified {@link ImageView} and invokes the target
   * {@link Callback} if it's not {@code null}.
   *
   * <p><em>Note:</em> The {@link Callback} param is a strong reference and will prevent your {@link
   * android.app.Activity} or {@link android.app.Fragment} from being garbage collected. If you use
   * this method, it is <b>strongly</b> recommended you invoke an adjacent {@link
   * Picasso#cancelRequest(android.widget.ImageView)} call to prevent temporary leaking.
   */
  public void into(ImageView target, Callback callback) {
    if (target == null) {
      throw new IllegalArgumentException("Target must not be null.");
    }

    if (!data.hasImage()) {
      picasso.cancelRequest(target);
      PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable);
      return;
    }

    if (deferred) {
      if (data.hasSize()) {
        throw new IllegalStateException("Fit cannot be used with resize.");
      }
      int measuredWidth = target.getMeasuredWidth();
      int measuredHeight = target.getMeasuredHeight();
      if (measuredWidth == 0 || measuredHeight == 0) {
        PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable);
        picasso.defer(target, new DeferredRequestCreator(this, target, callback));
        return;
      }
      data.resize(measuredWidth, measuredHeight);
    }

    Request finalData = picasso.transformRequest(data.build());
    String requestKey = createKey(finalData);

    if (!skipMemoryCache) {
      Bitmap bitmap = picasso.quickMemoryCacheCheck(requestKey);
      if (bitmap != null) {
        picasso.cancelRequest(target);
        PicassoDrawable.setBitmap(
            target, picasso.context, bitmap, MEMORY, noFade, picasso.indicatorsEnabled);
        if (callback != null) {
          callback.onSuccess();
        }
        return;
      }
    }

    PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable);

    Action action =
        new ImageViewAction(
            picasso,
            target,
            finalData,
            skipMemoryCache,
            noFade,
            errorResId,
            errorDrawable,
            requestKey,
            callback);

    picasso.enqueueAndSubmit(action);
  }
コード例 #9
0
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    ImageView view = (ImageView) v;

    if (v == imgText) {
      switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
          savedMatrix.set(matrix);
          start.set(event.getX(), event.getY());
          mode = DRAG;
          lastEvent = null;
          break;
        case MotionEvent.ACTION_POINTER_DOWN:
          oldDist = spacing(event);
          if (oldDist > 10f) {
            savedMatrix.set(matrix);
            midPoint(mid, event);
            mode = ZOOM;
          }
          lastEvent = new float[4];
          lastEvent[0] = event.getX(0);
          lastEvent[1] = event.getX(1);
          lastEvent[2] = event.getY(0);
          lastEvent[3] = event.getY(1);
          d = rotation(event);
          break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
          mode = NONE;
          lastEvent = null;
          break;
        case MotionEvent.ACTION_MOVE:
          if (mode == DRAG) {
            // ...
            matrix.set(savedMatrix);
            matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
          } else if (mode == ZOOM && event.getPointerCount() == 2) {
            float newDist = spacing(event);
            matrix.set(savedMatrix);
            if (newDist > 10f) {
              float scale = newDist / oldDist;
              matrix.postScale(scale, scale, mid.x, mid.y);
            }
            if (lastEvent != null) {
              newRot = rotation(event);
              float r = newRot - d;
              matrix.postRotate(r, view.getMeasuredWidth() / 2, view.getMeasuredHeight() / 2);
            }
          }
          break;
      }

      view.setImageMatrix(matrix);
      return true;
    } else return false;
  }
コード例 #10
0
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "Test {@link ImageView#onMeasure(int, int)}",
     method = "onMeasure",
     args = {int.class, int.class}
 )
 public void testOnMeasure() {
     mImageView = findImageViewById(R.id.imageview);
     mImageView.measure(200, 150);
     assertTrue(mImageView.getMeasuredWidth() <= 200);
     assertTrue(mImageView.getMeasuredHeight() <= 150);
 }
コード例 #11
0
  /** Show the correct call-out arrow based on a {@link R.id} reference. */
  private void showArrow(int whichArrow, int requestedX) {
    final View showArrow = (whichArrow == R.id.arrow_up) ? mArrowUp : mArrowDown;
    final View hideArrow = (whichArrow == R.id.arrow_up) ? mArrowDown : mArrowUp;

    final int arrowWidth = mArrowUp.getMeasuredWidth();

    showArrow.setVisibility(View.VISIBLE);
    ViewGroup.MarginLayoutParams param = (ViewGroup.MarginLayoutParams) showArrow.getLayoutParams();
    param.leftMargin = requestedX - arrowWidth / 2;

    hideArrow.setVisibility(View.INVISIBLE);
  }
コード例 #12
0
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    int contentLeft = left;
    int contentRight = right;
    bottom = bottom - top;
    top = 0;

    int height = bottom - top;

    if (leftImage != null && leftImage.getVisibility() != GONE) {
      int w = leftImage.getMeasuredWidth();
      int h = leftImage.getMeasuredHeight();
      int leftMargin = LEFT_MARGIN;

      contentLeft += w + leftMargin;
      int offset = (height - h) / 2;
      leftImage.layout(left + leftMargin, top + offset, left + leftMargin + w, top + offset + h);
    }

    if (rightImage != null && rightImage.getVisibility() != GONE) {
      int w = rightImage.getMeasuredWidth();
      int h = rightImage.getMeasuredHeight();
      int rightMargin = RIGHT_MARGIN;

      contentRight -= w + rightMargin;
      int offset = (height - h) / 2;
      rightImage.layout(
          right - w - rightMargin, top + offset, right - rightMargin, top + offset + h);
    }

    if (hasControls) {
      contentLeft = left + LEFT_MARGIN;
      contentRight = right - RIGHT_MARGIN;
    }

    if (content != null) {
      content.layout(contentLeft, top, contentRight, bottom);
    }
  }
コード例 #13
0
 @Override
 public Bitmap transform(Bitmap source) {
   int targetWidth = ivMoviePoster.getMeasuredWidth();
   double aspectRatio = (double) source.getHeight() / (double) source.getWidth();
   int targetHeight = (int) (targetWidth * aspectRatio);
   if (targetHeight > 0 && targetWidth > 0) {
     Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
     if (result != source) {
       // Same bitmap is returned if sizes are the same
       source.recycle();
     }
     return result;
   }
   return source;
 }
コード例 #14
0
 public static void blur(Context context, Bitmap bkg, ImageView view) {
   float radius = 2;
   float scaleFactor = 8;
   Bitmap overlay =
       Bitmap.createBitmap(
           (int) (view.getMeasuredWidth() / scaleFactor),
           (int) (view.getMeasuredHeight() / scaleFactor),
           Bitmap.Config.ARGB_8888);
   Canvas canvas = new Canvas(overlay);
   canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
   canvas.scale(1 / scaleFactor, 1 / scaleFactor);
   Paint paint = new Paint();
   paint.setFlags(Paint.FILTER_BITMAP_FLAG);
   canvas.drawBitmap(bkg, 0, 0, paint);
   overlay = doBlur(overlay, (int) radius, true);
   view.setImageDrawable(new BitmapDrawable(context.getResources(), overlay));
 }
コード例 #15
0
 protected void moveCursor() {
   float y = viewHue.getMeasuredHeight() - (getHue() * viewHue.getMeasuredHeight() / 360.f);
   if (y == viewHue.getMeasuredHeight()) y = 0.f;
   RelativeLayout.LayoutParams layoutParams =
       (RelativeLayout.LayoutParams) viewCursor.getLayoutParams();
   layoutParams.leftMargin =
       (int)
           (viewHue.getLeft()
               - Math.floor(viewCursor.getMeasuredWidth() / 2)
               - viewContainer.getPaddingLeft());
   layoutParams.topMargin =
       (int)
           (viewHue.getTop()
               + y
               - Math.floor(viewCursor.getMeasuredHeight() / 2)
               - viewContainer.getPaddingTop());
   viewCursor.setLayoutParams(layoutParams);
 }
コード例 #16
0
  /**
   * Initializes mPinchToZoomTransformation.
   *
   * <p>After initialization subsequent calls will be ignored.
   *
   * <p>Must be called after Android finished layout measurements and after drawable was set on
   * ImageView.
   */
  private void initialize() {
    if (mPinchToZoomTransformation == null
        && mImageView != null
        && mImageView.getDrawable() != null) {
      int imageWidth = mImageView.getDrawable().getIntrinsicWidth();
      int imageHeight = mImageView.getDrawable().getIntrinsicHeight();
      mImageViewWidth = mImageView.getMeasuredWidth();
      mImageViewHeight = mImageView.getMeasuredHeight();

      mPinchToZoomTransformation =
          new PinchToZoomTransformation(imageWidth, imageHeight, mImageViewWidth, mImageViewHeight);
      mPinchToZoomTransformation.setMaxScale(5);

      mImageView.setScaleType(ImageView.ScaleType.MATRIX);
      mPinchToZoomTransformation.setScaleToFitInCenter();

      updateImageView();
    }
  }
コード例 #17
0
 protected void moveTarget() {
   float x = getSat() * viewSatVal.getMeasuredWidth();
   float y = (1.f - getVal()) * viewSatVal.getMeasuredHeight();
   RelativeLayout.LayoutParams layoutParams =
       (RelativeLayout.LayoutParams) viewTarget.getLayoutParams();
   layoutParams.leftMargin =
       (int)
           (viewSatVal.getLeft()
               + x
               - Math.floor(viewTarget.getMeasuredWidth() / 2)
               - viewContainer.getPaddingLeft());
   layoutParams.topMargin =
       (int)
           (viewSatVal.getTop()
               + y
               - Math.floor(viewTarget.getMeasuredHeight() / 2)
               - viewContainer.getPaddingTop());
   viewTarget.setLayoutParams(layoutParams);
 }
コード例 #18
0
ファイル: ActionBarView.java プロジェクト: kairon007/UpMobile
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      measureChildWithMargins(mUpView, widthMeasureSpec, 0, heightMeasureSpec, 0);
      final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams();
      mUpWidth = upLp.leftMargin + mUpView.getMeasuredWidth() + upLp.rightMargin;
      int width = mUpView.getVisibility() == GONE ? 0 : mUpWidth;
      int height = upLp.topMargin + mUpView.getMeasuredHeight() + upLp.bottomMargin;
      measureChildWithMargins(mIconView, widthMeasureSpec, width, heightMeasureSpec, 0);
      final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
      width += iconLp.leftMargin + mIconView.getMeasuredWidth() + iconLp.rightMargin;
      height =
          Math.max(height, iconLp.topMargin + mIconView.getMeasuredHeight() + iconLp.bottomMargin);

      final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
      final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
      final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
      final int heightSize = MeasureSpec.getSize(heightMeasureSpec);

      switch (widthMode) {
        case MeasureSpec.AT_MOST:
          width = Math.min(width, widthSize);
          break;
        case MeasureSpec.EXACTLY:
          width = widthSize;
          break;
        case MeasureSpec.UNSPECIFIED:
        default:
          break;
      }
      switch (heightMode) {
        case MeasureSpec.AT_MOST:
          height = Math.min(height, heightSize);
          break;
        case MeasureSpec.EXACTLY:
          height = heightSize;
          break;
        case MeasureSpec.UNSPECIFIED:
        default:
          break;
      }
      setMeasuredDimension(width, height);
    }
コード例 #19
0
ファイル: ActionBarView.java プロジェクト: kairon007/UpMobile
 @Override
 protected void onLayout(boolean changed, int l, int t, int r, int b) {
   final int vCenter = (b - t) / 2;
   // UNUSED int width = r - l;
   int upOffset = 0;
   if (mUpView.getVisibility() != GONE) {
     final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams();
     final int upHeight = mUpView.getMeasuredHeight();
     final int upWidth = mUpView.getMeasuredWidth();
     final int upTop = vCenter - upHeight / 2;
     mUpView.layout(0, upTop, upWidth, upTop + upHeight);
     upOffset = upLp.leftMargin + upWidth + upLp.rightMargin;
     // UNUSED width -= upOffset;
     l += upOffset;
   }
   final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
   final int iconHeight = mIconView.getMeasuredHeight();
   final int iconWidth = mIconView.getMeasuredWidth();
   final int hCenter = (r - l) / 2;
   final int iconLeft = upOffset + Math.max(iconLp.leftMargin, hCenter - iconWidth / 2);
   final int iconTop = Math.max(iconLp.topMargin, vCenter - iconHeight / 2);
   mIconView.layout(iconLeft, iconTop, iconLeft + iconWidth, iconTop + iconHeight);
 }
コード例 #20
0
 @Override
 public void onWindowFocusChanged(boolean hasWindowFocus) {
   driveLayout.setImageViewHeight(imageView.getMeasuredHeight());
   driveLayout.setImageViewWidth(imageView.getMeasuredWidth());
 }
コード例 #21
0
ファイル: ImageTextView.java プロジェクト: MichaelSun/SiXin
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int width = r - l;
    final int height = b - t;
    final int imageWidth = mImage.getMeasuredWidth();
    final int imageHeight = mImage.getMeasuredHeight();
    final int textWidth = mText.getMeasuredWidth();
    final int textHeight = mText.getMeasuredHeight();
    int left = getPaddingLeft();
    int top = getPaddingTop();
    int right = r - getPaddingRight();
    int bottom = b - getPaddingBottom();

    /*added by chengran sun for better performing*/
    int widthNoPadding = width - getPaddingLeft() - getPaddingRight();
    int heightNoPadding = height - getPaddingTop() - getPaddingBottom();

    if (POSITION_LEFT.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            left,
            (heightNoPadding - textHeight) / 2,
            left += textWidth,
            (heightNoPadding + textHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left += textWidth, top + textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(left, bottom - textHeight, left += textWidth, bottom);
      }

      if (!mNeedLayout) {
        return;
      }

      left += mSpacing;

      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            left,
            (heightNoPadding - imageHeight) / 2,
            left += imageWidth,
            (heightNoPadding + imageHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left += imageWidth, top + imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(left, bottom - imageHeight, left += imageWidth, bottom);
      }
    } else if (POSITION_RIGHT.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            left,
            (heightNoPadding - imageHeight) / 2,
            left += imageWidth,
            (heightNoPadding + imageHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left += imageWidth, top + imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(left, bottom - imageHeight, left += imageWidth, bottom);
      }

      if (!mNeedLayout) {
        return;
      }

      left += mSpacing;

      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            left,
            (heightNoPadding - textHeight) / 2,
            left += textWidth,
            (heightNoPadding + textHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left += textWidth, top + textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(left, bottom - textHeight, left += textWidth, bottom);
      }
    } else if (POSITION_TOP.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            (widthNoPadding - textWidth) / 2,
            top,
            (widthNoPadding + textWidth) / 2,
            top += textHeight);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left + textWidth, top += textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(right - textWidth, top, right, top += textHeight);
      }

      if (!mNeedLayout) {
        return;
      }

      top += mSpacing;

      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            (widthNoPadding - imageWidth) / 2,
            top,
            (widthNoPadding + imageWidth) / 2,
            top += imageHeight);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left + imageWidth, top += imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(right - imageWidth, top, right, top += imageHeight);
      }
    } else if (POSITION_BOTTOM.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            (widthNoPadding - imageWidth) / 2,
            top,
            (widthNoPadding + imageWidth) / 2,
            top += imageHeight);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left + imageWidth, top += imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(right - imageWidth, top, right, top += imageHeight);
      }

      if (!mNeedLayout) {
        return;
      }

      top += mSpacing;

      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            (widthNoPadding - textWidth) / 2,
            top,
            (widthNoPadding + textWidth) / 2,
            top += textHeight);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left + textWidth, top += textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(right - textWidth, top, right, top += textHeight);
      }
    }
  }
コード例 #22
0
 private void slideInCoffeeCup(ImageView coffee_cup) {
   coffee_cup.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
   float width = coffee_cup.getMeasuredWidth();
   coffee_cup.animate().translationX(width).setDuration(1000);
 }
 /**
  * Get the measured tab width. Must be called after {@link Slider#measure()}.
  *
  * @return
  */
 public int getTabWidth() {
   return tab.getMeasuredWidth();
 }
コード例 #24
0
  @Override
  public void onClick(View v) {
    ld.show();
    switch (v.getId()) {
      case R.id.btn_string:
        NetApi.getInstance()
            .stringRequest(
                this,
                "https://www.baidu.com",
                new HashMap<String, String>(),
                new BaseNetApi.OnNetCallback<String>() {
                  @Override
                  public void onSuccess(String result) {
                    ld.dismiss();
                    tv_result.setText(result);
                  }

                  @Override
                  public void onFail(NetError error) {
                    ld.dismiss();
                    tv_result.setText(error.errorMessage);
                  }
                });
        break;
      case R.id.btn_jsonObject:
        NetApi.getInstance()
            .jsonObjectRequest(
                this,
                "http://www.weather.com.cn/data/sk/101280601.html",
                new HashMap<String, String>(),
                new BaseNetApi.OnNetCallback<JSONObject>() {
                  @Override
                  public void onSuccess(JSONObject result) {
                    ld.dismiss();
                    tv_result.setText(result.toString());
                  }

                  @Override
                  public void onFail(NetError error) {
                    ld.dismiss();
                    tv_result.setText(error.errorMessage);
                  }
                });
        break;
      case R.id.btn_jsonArray:
        ld.dismiss();
        break;
      case R.id.btn_xml:
        NetApi.getInstance()
            .xmlRequest(
                this,
                "https://www.baidu.com/",
                new HashMap<String, String>(),
                new BaseNetApi.OnNetCallback<XmlPullParser>() {
                  @Override
                  public void onSuccess(XmlPullParser result) {
                    ld.dismiss();
                    tv_result.setText(result.toString());
                  }

                  @Override
                  public void onFail(NetError error) {
                    ld.dismiss();
                    tv_result.setText(error.errorMessage);
                  }
                });
        break;
      case R.id.btn_image:
        ld.dismiss();
        //                ImageLoader.getInstance().loadImage("http://www.baidu.com/img/bdlogo.png",
        // iv_content);
        //                ImageLoader.getInstance().loadImage("http://www.baidu.com/img/bdlogo.png",
        // new ImageLoader.OnLoadCallBack() {
        //                    @Override
        //                    public void onLoadSuccess(Bitmap bitmap, String url) {
        //                        iv_content.setImageBitmap(bitmap);
        //                    }
        //
        //                    @Override
        //                    public void onLoadFail(NetError error) {
        //
        //                    }
        //                });
        //                ImageLoader.getInstance().loadImage("http://www.baidu.com/img/bdlogo.png",
        //                        iv_content.getMeasuredWidth(), iv_content.getMeasuredHeight(), new
        // ImageLoader.OnLoadCallBack() {
        //                            @Override
        //                            public void onLoadSuccess(Bitmap bitmap, String url) {
        //                                iv_content.setImageBitmap(bitmap);
        //                            }
        //
        //                            @Override
        //                            public void onLoadFail(NetError error) {
        //
        //                            }
        //                        });
        ImageLoader.getInstance()
            .loadImage(
                "http://www.baidu.com/img/bdlogo.png",
                iv_content.getMeasuredWidth(),
                iv_content.getMeasuredHeight(),
                iv_content,
                R.mipmap.ic_refresh,
                R.mipmap.ic_refresh_close);
        break;
    }
  }
コード例 #25
0
  private void updateLayoutParams() {
    int startMargin = 0;
    int locationBarLayoutChildIndex = -1;
    for (int i = 0; i < getChildCount(); i++) {
      View childView = getChildAt(i);
      if (childView.getVisibility() != GONE) {
        LayoutParams childLayoutParams = (LayoutParams) childView.getLayoutParams();
        if (ApiCompatibilityUtils.getMarginStart(childLayoutParams) != startMargin) {
          ApiCompatibilityUtils.setMarginStart(childLayoutParams, startMargin);
          childView.setLayoutParams(childLayoutParams);
        }
        if (childView == mLocationBarFrameLayout) {
          locationBarLayoutChildIndex = i;
          break;
        }
        int widthMeasureSpec;
        int heightMeasureSpec;
        if (childLayoutParams.width == LayoutParams.WRAP_CONTENT) {
          widthMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST);
        } else if (childLayoutParams.width == LayoutParams.MATCH_PARENT) {
          widthMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY);
        } else {
          widthMeasureSpec =
              MeasureSpec.makeMeasureSpec(childLayoutParams.width, MeasureSpec.EXACTLY);
        }
        if (childLayoutParams.height == LayoutParams.WRAP_CONTENT) {
          heightMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST);
        } else if (childLayoutParams.height == LayoutParams.MATCH_PARENT) {
          heightMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY);
        } else {
          heightMeasureSpec =
              MeasureSpec.makeMeasureSpec(childLayoutParams.height, MeasureSpec.EXACTLY);
        }
        childView.measure(widthMeasureSpec, heightMeasureSpec);
        startMargin += childView.getMeasuredWidth();
      }
    }

    assert locationBarLayoutChildIndex != -1;
    int locationBarLayoutEndMargin = 0;
    for (int i = locationBarLayoutChildIndex + 1; i < getChildCount(); i++) {
      View childView = getChildAt(i);
      if (childView.getVisibility() != GONE) {
        locationBarLayoutEndMargin += childView.getMeasuredWidth();
      }
    }
    LayoutParams urlLayoutParams = (LayoutParams) mLocationBarFrameLayout.getLayoutParams();

    if (ApiCompatibilityUtils.getMarginEnd(urlLayoutParams) != locationBarLayoutEndMargin) {
      ApiCompatibilityUtils.setMarginEnd(urlLayoutParams, locationBarLayoutEndMargin);
      mLocationBarFrameLayout.setLayoutParams(urlLayoutParams);
    }

    // Update left margin of mTitleUrlContainer here to make sure the security icon is always
    // placed left of the urlbar.
    LayoutParams lp = (LayoutParams) mTitleUrlContainer.getLayoutParams();
    if (mSecurityButton.getVisibility() == View.GONE) {
      lp.leftMargin = 0;
    } else {
      lp.leftMargin = mSecurityButton.getMeasuredWidth();
    }
    mTitleUrlContainer.setLayoutParams(lp);
  }
コード例 #26
0
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int buttonsHorizontalCenter =
        mLabelsPosition == LABELS_POSITION_LEFT
            ? r - l - mMaxButtonWidth / 2 - getPaddingRight()
            : mMaxButtonWidth / 2 + getPaddingLeft();
    boolean openUp = mOpenDirection == OPEN_UP;

    int menuButtonTop =
        openUp ? b - t - mMenuButton.getMeasuredHeight() - getPaddingBottom() : getPaddingTop();
    int menuButtonLeft = buttonsHorizontalCenter - mMenuButton.getMeasuredWidth() / 2;

    mMenuButton.layout(
        menuButtonLeft,
        menuButtonTop,
        menuButtonLeft + mMenuButton.getMeasuredWidth(),
        menuButtonTop + mMenuButton.getMeasuredHeight());

    int imageLeft = buttonsHorizontalCenter - mImageToggle.getMeasuredWidth() / 2;
    int imageTop =
        menuButtonTop + mMenuButton.getMeasuredHeight() / 2 - mImageToggle.getMeasuredHeight() / 2;

    mImageToggle.layout(
        imageLeft,
        imageTop,
        imageLeft + mImageToggle.getMeasuredWidth(),
        imageTop + mImageToggle.getMeasuredHeight());

    int nextY =
        openUp
            ? menuButtonTop - mButtonSpacing
            : menuButtonTop + mMenuButton.getMeasuredHeight() + mButtonSpacing;

    for (int i = mButtonsCount - 1; i >= 0; i--) {
      View child = getChildAt(i);

      if (child == mImageToggle) continue;

      FloatingActionButton fab = (FloatingActionButton) child;

      if (fab == mMenuButton || fab.getVisibility() == GONE) continue;

      int childX = buttonsHorizontalCenter - fab.getMeasuredWidth() / 2;
      int childY = openUp ? nextY - fab.getMeasuredHeight() : nextY;
      fab.layout(childX, childY, childX + fab.getMeasuredWidth(), childY + fab.getMeasuredHeight());

      if (!mMenuOpened) {
        fab.hide(false);
      }

      View label = (View) fab.getTag(R.id.fab_label);
      if (label != null) {
        int labelsOffset = fab.getMeasuredWidth() / 2 + mLabelsMargin;
        int labelXNearButton =
            mLabelsPosition == LABELS_POSITION_LEFT
                ? buttonsHorizontalCenter - labelsOffset
                : buttonsHorizontalCenter + labelsOffset;

        int labelXAwayFromButton =
            mLabelsPosition == LABELS_POSITION_LEFT
                ? labelXNearButton - label.getMeasuredWidth()
                : labelXNearButton + label.getMeasuredWidth();

        int labelLeft =
            mLabelsPosition == LABELS_POSITION_LEFT ? labelXAwayFromButton : labelXNearButton;

        int labelRight =
            mLabelsPosition == LABELS_POSITION_LEFT ? labelXNearButton : labelXAwayFromButton;

        int labelTop =
            childY
                - mLabelsVerticalOffset
                + (fab.getMeasuredHeight() - label.getMeasuredHeight()) / 2;

        label.layout(labelLeft, labelTop, labelRight, labelTop + label.getMeasuredHeight());

        if (!mMenuOpened) {
          label.setVisibility(INVISIBLE);
        }
      }

      nextY =
          openUp ? childY - mButtonSpacing : childY + child.getMeasuredHeight() + mButtonSpacing;
    }
  }
コード例 #27
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int w = MeasureSpec.getSize(widthMeasureSpec);
    int wMode = MeasureSpec.getMode(widthMeasureSpec);
    int h = MeasureSpec.getSize(heightMeasureSpec);
    int hMode = MeasureSpec.getMode(heightMeasureSpec);
    int imageHMargin = 0;

    int leftImageWidth = 0;
    int leftImageHeight = 0;
    if (leftImage != null && leftImage.getVisibility() != View.GONE) {
      measureChild(leftImage, widthMeasureSpec, heightMeasureSpec);
      leftImageWidth = leftImage.getMeasuredWidth();
      leftImageHeight = leftImage.getMeasuredHeight();
      imageHMargin += LEFT_MARGIN;
    }

    int rightImageWidth = 0;
    int rightImageHeight = 0;
    if (rightImage != null && rightImage.getVisibility() != View.GONE) {
      measureChild(rightImage, widthMeasureSpec, heightMeasureSpec);
      rightImageWidth = rightImage.getMeasuredWidth();
      rightImageHeight = rightImage.getMeasuredHeight();
      imageHMargin += RIGHT_MARGIN;
    }

    int adjustedWidth = w - leftImageWidth - rightImageWidth - imageHMargin;
    // int adjustedWidth = w;

    if (content != null) {
      measureChild(content, MeasureSpec.makeMeasureSpec(adjustedWidth, wMode), heightMeasureSpec);
      if (hMode == MeasureSpec.UNSPECIFIED) {
        TableViewProxy table = ((TableViewRowProxy) item.proxy).getTable();
        int minRowHeight = -1;
        if (table != null && table.hasProperty(TiC.PROPERTY_MIN_ROW_HEIGHT)) {
          minRowHeight =
              TiConvert.toTiDimension(
                      TiConvert.toString(table.getProperty(TiC.PROPERTY_MIN_ROW_HEIGHT)),
                      TiDimension.TYPE_HEIGHT)
                  .getAsPixels(this);
        }

        if (height == null) {
          h =
              Math.max(
                  h,
                  Math.max(
                      content.getMeasuredHeight(), Math.max(leftImageHeight, rightImageHeight)));
          h = Math.max(h, minRowHeight);
        } else {
          h = Math.max(minRowHeight, height.getAsPixels(this));
        }
        if (DBG) {
          Log.d(LCAT, "Row content measure (" + adjustedWidth + "x" + h + ")");
        }
        measureChild(
            content,
            MeasureSpec.makeMeasureSpec(adjustedWidth, wMode),
            MeasureSpec.makeMeasureSpec(h, hMode));
      }
    }

    setMeasuredDimension(w, Math.max(h, Math.max(leftImageHeight, rightImageHeight)));
  }
コード例 #28
0
 /**
  * Sets the custom height of the whole figure. This recalculates the text-sizes inside the Canvas.
  *
  * @param customHeight the desired height in dp.
  */
 public void setCustomHeight(float customHeight) {
   driveLayout.setCustomHeight(customHeight);
   driveLayout.setImageViewHeight(imageView.getMeasuredHeight());
   driveLayout.setImageViewWidth(imageView.getMeasuredWidth());
 }
コード例 #29
0
  /**
   * Function used to ensure that the items of a given list row gets wrapped up and do not extend
   * the UI width and height
   */
  private void populateLinks(
      LinearLayout ll, ArrayList<RouteStep> collection, Route route, TextView realTimeText) {

    Display display = activity.getWindowManager().getDefaultDisplay();
    int maxWidth = display.getWidth() - 100;

    /*
    Only if route object contains steps array, allow wrap content
     */
    if (collection.size() > 0) {
      LinearLayout llAlso = new LinearLayout(activity.getApplicationContext());
      llAlso.setLayoutParams(
          new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
      llAlso.setOrientation(LinearLayout.HORIZONTAL);

      int widthSoFar = 0;
      for (int pos = 0; pos < collection.size(); pos++) {
        RouteStep samItem = collection.get(pos);

        TextView image = new TextView(activity.getApplicationContext());
        if (samItem.isTransit()) {
          image.setText(samItem.getDeparture().getTravelTime());

          /*
          Assign an ID to the textview so that when application
          gets the real time data, it can strike off the scheduled arrival time
           */
          image.setId(pos);

          /*
          If the route step is the BUS, check if its the first public transport
          step of the journey, then strike the scheduled bus arrival time
          with the actual arrival time of the BUS retrieved from our application
          server.
           */
          if (samItem.getTransportName() == R.string.tr_bus
              && (pos == 0 || (pos > 0 && !collection.get(pos - 1).isTransit()))
              && !TextUtils.isEmpty(realTimeText.getText())
              && realTimeText.getText().toString().compareTo("Not Available") != 0) {
            image.setPaintFlags(image.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
          }
        } else {
          /*
          Display the time when the user has to start this particular step
          of the journey.
           */
          if (pos == 0) {
            image.setText(route.getDeparture().getTravelTime());
          } else {
            RouteStep item = collection.get(pos - 1);
            image.setText(item.getArrival().getTravelTime());
          }

          // image = new ImageView(activity.getApplicationContext());
          // ((ImageView)image).setImageResource(samItem.getIconId());
          // image.measure(0, 0);
        }

        /*
        display an image corresponding to the mode of travel.
         */
        int id = samItem.getIconId();
        image.setCompoundDrawablesWithIntrinsicBounds(
            0, // left
            0, // top
            0, // right
            id); // bottom);
        image.setTextColor(Color.parseColor("#996633"));
        image.setTypeface(null, Typeface.BOLD);
        image.measure(0, 0);
        widthSoFar += image.getMeasuredWidth();

        /*
        if the components added so far has extended the UI width, wrap
        the contents of the corresponding list row
         */
        if (widthSoFar >= maxWidth) {
          ll.addView(llAlso);

          llAlso = new LinearLayout(activity.getApplicationContext());
          llAlso.setLayoutParams(
              new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
          llAlso.setOrientation(LinearLayout.HORIZONTAL);

          llAlso.addView(image);
          widthSoFar = image.getMeasuredWidth();
        } else {
          llAlso.addView(image);
        }

        /*
        Display the transit vehicle line number and check if
        the components added so far has not extended the UI width. If yes then wrap
        the contents of the corresponding list row
         */
        if (samItem.getShortName() != "" && !samItem.getShortName().equals("")) {
          TextView name = new TextView(activity.getApplicationContext());
          name.setText(samItem.getShortName());
          LinearLayout.LayoutParams params =
              new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
          params.setMargins(0, 50, 0, 0);
          name.setLayoutParams(params);
          name.setTextColor(Color.parseColor("#FFA500"));
          name.setTypeface(null, Typeface.BOLD);

          name.measure(0, 0);
          widthSoFar += name.getMeasuredWidth();

          if (widthSoFar >= maxWidth) {
            ll.addView(llAlso);

            llAlso = new LinearLayout(activity.getApplicationContext());
            llAlso.setLayoutParams(
                new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            llAlso.setOrientation(LinearLayout.HORIZONTAL);

            llAlso.addView(name);
            widthSoFar = name.getMeasuredWidth();
          } else {
            llAlso.addView(name);
          }
        }
        if (pos < collection.size() - 1) {
          ImageView next = new ImageView(activity.getApplicationContext());
          next.setImageResource(R.drawable.ic_action_next_item);
          next.measure(0, 0);
          widthSoFar += next.getMeasuredWidth();

          if (widthSoFar >= maxWidth) {
            ll.addView(llAlso);

            llAlso = new LinearLayout(activity.getApplicationContext());
            llAlso.setLayoutParams(
                new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            llAlso.setOrientation(LinearLayout.HORIZONTAL);

            llAlso.addView(next);
            widthSoFar = next.getMeasuredWidth();
          } else {
            llAlso.addView(next);
          }
        }
      }

      ll.addView(llAlso);
    }
  }