Exemple #1
1
  /**
   * Draw underline
   *
   * @param canvas The canvas
   */
  private void drawUnderline(Canvas canvas) {
    if (mShowUnderline) {
      View parent = (View) getParent();
      if (parent != null && (parent.getPaddingLeft() != 0 || parent.getPaddingRight() != 0)) {
        final int pPaddingLeft = parent.getPaddingLeft();
        final int pPaddingRight = parent.getPaddingRight();

        canvas.save();

        // allow drawing out of bounds
        Rect clipBounds = canvas.getClipBounds();
        clipBounds.inset(-(pPaddingLeft + pPaddingRight), 0);
        canvas.clipRect(clipBounds, Region.Op.REPLACE);

        if (mUnderlineGravity == UnderlineGravity.TOP) {
          // If on top ignore bottom padding
          canvas.drawRect(
              -pPaddingLeft,
              mUnderlinePaddingTop,
              getWidth() + pPaddingLeft + pPaddingRight,
              mUnderlineHeight + mUnderlinePaddingTop,
              mUnderlinePaint);
        } else {
          // If on bottom ignore top padding
          canvas.drawRect(
              -pPaddingLeft,
              getHeight() - mUnderlineHeight - mUnderlinePaddingBottom,
              getWidth() + pPaddingLeft + pPaddingRight,
              getHeight() - mUnderlinePaddingBottom,
              mUnderlinePaint);
        }

        canvas.restore();
      } else {
        if (mUnderlineGravity == UnderlineGravity.TOP) {
          // If on top ignore bottom padding
          canvas.drawRect(
              0,
              mUnderlinePaddingTop,
              getWidth(),
              mUnderlineHeight + mUnderlinePaddingTop,
              mUnderlinePaint);
        } else {
          // If on bottom ignore top padding
          canvas.drawRect(
              0,
              getHeight() - mUnderlineHeight - mUnderlinePaddingBottom,
              getWidth(),
              getHeight() - mUnderlinePaddingBottom,
              mUnderlinePaint);
        }
      }
    }
  }
Exemple #2
1
 public void updateVisibleText(View parent, Rect progressBar, Rect timeBounds) {
   if (mInfoText == null) {
     mVisibleText = null;
     return;
   }
   float tw = mInfoPaint.measureText(mInfoText);
   float space =
       progressBar.width()
           - timeBounds.width() * 2
           - parent.getPaddingLeft()
           - parent.getPaddingRight();
   if (tw > 0 && space > 0 && tw > space) {
     // we need to cut the info text for visible
     float originalNum = mInfoText.length();
     int realNum = (int) ((space - mEllipseLength) * originalNum / tw);
     if (LOG) {
       MtkLog.v(
           TAG,
           "updateVisibleText() infoText="
               + mInfoText
               + " text width="
               + tw
               + ", space="
               + space
               + ", originalNum="
               + originalNum
               + ", realNum="
               + realNum
               + ", getPaddingLeft()="
               + parent.getPaddingLeft()
               + ", getPaddingRight()="
               + parent.getPaddingRight()
               + ", progressBar="
               + progressBar
               + ", timeBounds="
               + timeBounds);
     }
     mVisibleText = mInfoText.substring(0, realNum) + ELLIPSE;
   } else {
     mVisibleText = mInfoText;
   }
   if (LOG) {
     MtkLog.v(
         TAG,
         "updateVisibleText() infoText="
             + mInfoText
             + ", visibleText="
             + mVisibleText
             + ", text width="
             + tw
             + ", space="
             + space);
   }
 }
 public AnimationBuilder wave() {
   for (View view : views) {
     float x =
         (view.getWidth() - view.getPaddingLeft() - view.getPaddingRight()) / 2
             + view.getPaddingLeft();
     float y = view.getHeight() - view.getPaddingBottom();
     rotation(12, -12, 3, -3, 0);
     pivotX(x, x, x, x, x);
     pivotY(y, y, y, y, y);
   }
   return this;
 }
 @Override
 public void prepare(View target) {
   float x =
       (target.getWidth() - target.getPaddingLeft() - target.getPaddingRight()) / 2
           + target.getPaddingLeft();
   float y = target.getHeight() - target.getPaddingBottom();
   getAnimatorAgent()
       .playTogether(
           ObjectAnimator.ofFloat(target, "pivotX", x, x, x, x, x),
           ObjectAnimator.ofFloat(target, "pivotY", y, y, y, y, y),
           ObjectAnimator.ofFloat(target, "rotationX", 55, -30, 15, -15, 0));
 }
 public AnimationBuilder standUp() {
   for (View view : views) {
     float x =
         (view.getWidth() - view.getPaddingLeft() - view.getPaddingRight()) / 2
             + view.getPaddingLeft();
     float y = view.getHeight() - view.getPaddingBottom();
     pivotX(x, x, x, x, x);
     pivotY(y, y, y, y, y);
     rotationX(55, -30, 15, -15, 0);
   }
   return this;
 }
Exemple #6
1
 public void setAction(String action) {
   if (action != null) {
     button.setText(action);
     button.setVisibility(View.VISIBLE);
     content.setPadding(
         content.getPaddingLeft(),
         0,
         (int) getResources().getDimension(R.dimen.carbon_paddingHalf),
         0);
   } else {
     content.setPadding(content.getPaddingLeft(), 0, content.getPaddingLeft(), 0);
     button.setVisibility(View.GONE);
   }
 }
  public void backTopAndCenterWithAnimation() {
    mStepLayout.setVisibility(View.VISIBLE);
    if (Build.VERSION.SDK_INT >= 11) {
      float centerHeight =
          mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_center_move_top_height);
      ObjectAnimator centerAnimator =
          ObjectAnimator.ofFloat(mCenterLayoutParent, "y", -centerHeight, 0f);
      centerAnimator.setDuration(ANIMATION_TIME);
      centerAnimator.start();

      float topHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_top_height);
      ObjectAnimator topAnimator = ObjectAnimator.ofFloat(mFirstTopView, "y", -topHeight, 0f);
      topAnimator.setDuration(ANIMATION_TIME);
      topAnimator.start();

    } else {
      mFirstTopView.setVisibility(View.VISIBLE);

      float topHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_top_height);
      float bottomHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_bottom_height);
      mCenterLayoutParent.setPadding(
          mCenterLayoutParent.getPaddingLeft(),
          Math.round(topHeight),
          mCenterLayoutParent.getPaddingRight(),
          Math.round(bottomHeight));
    }
  }
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int childCount = getChildCount();

    final int parentLeft = getPaddingLeft();
    final int parentTop = getPaddingTop();
    final int parentRight = r - l - getPaddingRight();
    final int parentBottom = b - t - getPaddingBottom();

    final int parentWidth = parentRight - parentLeft;
    final int parentHeight = parentBottom - parentTop;

    int unpaddedWidth, unpaddedHeight, parentUnpaddedWidth, parentUnpaddedHeight;
    int childPaddingLeft, childPaddingTop, childPaddingRight, childPaddingBottom;

    for (int i = 0; i < childCount; i++) {
      final View child = getChildAt(i);
      if (child.getVisibility() == GONE) {
        continue;
      }

      // Fit and center the child within the parent. Make sure not to consider padding
      // as part of the child's aspect ratio.

      childPaddingLeft = child.getPaddingLeft();
      childPaddingTop = child.getPaddingTop();
      childPaddingRight = child.getPaddingRight();
      childPaddingBottom = child.getPaddingBottom();

      unpaddedWidth = child.getMeasuredWidth() - childPaddingLeft - childPaddingRight;
      unpaddedHeight = child.getMeasuredHeight() - childPaddingTop - childPaddingBottom;

      parentUnpaddedWidth = parentWidth - childPaddingLeft - childPaddingRight;
      parentUnpaddedHeight = parentHeight - childPaddingTop - childPaddingBottom;

      if (parentUnpaddedWidth * unpaddedHeight > parentUnpaddedHeight * unpaddedWidth) {
        // The child view should be left/right letterboxed.
        final int scaledChildWidth =
            unpaddedWidth * parentUnpaddedHeight / unpaddedHeight
                + childPaddingLeft
                + childPaddingRight;
        child.layout(
            parentLeft + (parentWidth - scaledChildWidth) / 2,
            parentTop,
            parentRight - (parentWidth - scaledChildWidth) / 2,
            parentBottom);
      } else {
        // The child view should be top/bottom letterboxed.
        final int scaledChildHeight =
            unpaddedHeight * parentUnpaddedWidth / unpaddedWidth
                + childPaddingTop
                + childPaddingBottom;
        child.layout(
            parentLeft,
            parentTop + (parentHeight - scaledChildHeight) / 2,
            parentRight,
            parentTop + (parentHeight + scaledChildHeight) / 2);
      }
    }
  }
Exemple #9
1
  public static Bitmap getBitmapFromView(View v, boolean antiPadding) {
    Bitmap raw = getBitmapFromView(v);
    if (!antiPadding) {
      return raw;
    }

    final int w = v.getWidth() - (v.getPaddingLeft() + v.getPaddingRight());
    final int h = v.getHeight() - (v.getPaddingTop() + v.getPaddingBottom());
    if (w <= 0 || h <= 0) {
      return raw;
    }

    Bitmap cropped = Bitmap.createBitmap(raw, v.getPaddingLeft(), v.getPaddingTop(), w, h);
    raw.recycle();
    return cropped;
  }
  private void supportPadding(int widthHint, int heightHint, View view, PercentLayoutInfo info) {
    int left = view.getPaddingLeft(),
        right = view.getPaddingRight(),
        top = view.getPaddingTop(),
        bottom = view.getPaddingBottom();
    PercentLayoutInfo.PercentVal percentVal = info.paddingLeftPercent;
    if (percentVal != null) {
      int base = getBaseByModeAndVal(widthHint, heightHint, percentVal.basemode);
      left = (int) (base * percentVal.percent);
    }
    percentVal = info.paddingRightPercent;
    if (percentVal != null) {
      int base = getBaseByModeAndVal(widthHint, heightHint, percentVal.basemode);
      right = (int) (base * percentVal.percent);
    }

    percentVal = info.paddingTopPercent;
    if (percentVal != null) {
      int base = getBaseByModeAndVal(widthHint, heightHint, percentVal.basemode);
      top = (int) (base * percentVal.percent);
    }

    percentVal = info.paddingBottomPercent;
    if (percentVal != null) {
      int base = getBaseByModeAndVal(widthHint, heightHint, percentVal.basemode);
      bottom = (int) (base * percentVal.percent);
    }
    view.setPadding(left, top, right, bottom);
  }
  @Override
  protected void initViews() {
    super.initViews();

    // 转发时把输入框的大小稍微设置小一些
    mEditText.setMinimumHeight(DeviceUtils.dp2px(this, 80));
    mEditText.setHint(ResFinder.getString("umeng_comm_write_sth"));
    // 隐藏选择图片的图标
    mGridView.setVisibility(View.GONE);

    // 隐藏话题,地理位置、图片和拍照的图标
    findViewById(ResFinder.getId("umeng_community_loc_layout")).setVisibility(View.GONE);
    findViewById(ResFinder.getId("umeng_comm_loc_layout")).setVisibility(View.GONE);
    findViewById(ResFinder.getId("umeng_comm_topic_layout")).setVisibility(View.GONE);
    findViewById(ResFinder.getId("umeng_comm_take_photo_layout")).setVisibility(View.GONE);
    findViewById(ResFinder.getId("umeng_comm_pick_photo_layout")).setVisibility(View.GONE);
    // 设置转发时,图片跟文本layout可见
    findViewById(ResFinder.getId("umeng_comm_forward_layout")).setVisibility(View.VISIBLE);

    //
    mBottomTabLayout = findViewById(ResFinder.getId("umeng_community_post_tab_bar"));
    int paddingRight = getResources().getDisplayMetrics().widthPixels - DeviceUtils.dp2px(this, 80);
    mBottomTabLayout.setPadding(
        mBottomTabLayout.getPaddingLeft(),
        mBottomTabLayout.getPaddingTop(),
        paddingRight,
        mBottomTabLayout.getPaddingBottom());

    // 显示转发文本的TextView
    mFeedText = (TextView) findViewById(ResFinder.getId("umeng_comm_forward_text"));
    mFeedIcon = (ImageView) findViewById(ResFinder.getId("umeng_comm_forward_img"));
    mTopicTipView.setVisibility(View.GONE); // 转发页面不显示提示话题VIew
  }
 public AnimationBuilder rollIn() {
   for (View view : views) {
     alpha(0, 1);
     translationX(-(view.getWidth() - view.getPaddingLeft() - view.getPaddingRight()), 0);
     rotation(-120, 0);
   }
   return this;
 }
 public static cq a(View paramView) {
   cq localcq = new cq();
   a = paramView.getPaddingLeft();
   b = paramView.getPaddingTop();
   c = paramView.getPaddingRight();
   d = paramView.getPaddingBottom();
   return localcq;
 }
Exemple #14
0
 public void setBackground(View paramView, int paramInt) {
   int i = paramView.getPaddingBottom();
   int j = paramView.getPaddingTop();
   int k = paramView.getPaddingRight();
   int m = paramView.getPaddingLeft();
   paramView.setBackgroundResource(paramInt);
   paramView.setPadding(m, j, k, i);
 }
 private Rect getParentContentRect() {
   final View parent = (View) getParent();
   return new Rect(
       parent.getPaddingLeft(),
       parent.getPaddingTop(),
       parent.getWidth() - parent.getPaddingRight(),
       parent.getHeight() - parent.getPaddingBottom());
 }
 @Override
 public void getOutline(View view, Outline outline) {
   outline.setOval(
       view.getPaddingLeft(),
       view.getPaddingTop(),
       view.getWidth() - view.getPaddingRight(),
       view.getHeight() - view.getPaddingBottom());
 }
 public static void setBackgroundColorKeepPadding(View view, int color) {
   int bottom = view.getPaddingBottom();
   int top = view.getPaddingTop();
   int right = view.getPaddingRight();
   int left = view.getPaddingLeft();
   view.setBackgroundColor(color);
   view.setPadding(left, top, right, bottom);
 }
 /** @see android.view.View#getPaddingStart() */
 public static int getPaddingStart(View view) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
     return view.getPaddingStart();
   } else {
     // Before JB MR1, all layouts are left-to-right, so start == left.
     return view.getPaddingLeft();
   }
 }
 /**
  * 解决重新设置背景导致padding失效问题
  *
  * @param view 需要重新设置背景的view
  * @param resid 背景资源id
  */
 public static void setBackgroundKeepPadding(View view, int resid) {
   int bottom = view.getPaddingBottom();
   int top = view.getPaddingTop();
   int right = view.getPaddingRight();
   int left = view.getPaddingLeft();
   view.setBackgroundResource(resid);
   view.setPadding(left, top, right, bottom);
 }
 /**
  * 设置foot的底部边距
  *
  * @param topPadding
  */
 private void setFootBottomPadding(int bottomPadding) {
   footView.setPadding(
       footView.getPaddingLeft(),
       footView.getPaddingTop(),
       footView.getPaddingRight(),
       bottomPadding);
   footView.invalidate();
 }
Exemple #21
0
 public Rect getInfoBounds(View parent, Rect timeBounds) {
   Rect bounds =
       new Rect(
           parent.getPaddingLeft(),
           0,
           parent.getWidth() - parent.getPaddingRight(),
           (timeBounds.height() + mScrubberPadding) * 2);
   return bounds;
 }
Exemple #22
0
 private void setContentTopClearance(int clearance) {
   if (rootView != null) {
     rootView.setPadding(
         rootView.getPaddingLeft(),
         clearance,
         rootView.getPaddingRight(),
         rootView.getPaddingBottom());
   }
 }
Exemple #23
0
 /**
  * 重新计算view的Padding(严格模式)
  *
  * @param view
  * @return
  */
 public static boolean repadding(View view, float horizontalRatio, float verticalRatio) {
   if (view == null) return false;
   view.setPadding(
       (int) (view.getPaddingLeft() * horizontalRatio),
           (int) (view.getPaddingTop() * verticalRatio),
       (int) (view.getPaddingRight() * horizontalRatio),
           (int) (view.getPaddingBottom() * verticalRatio));
   return true;
 }
  public void moveTopAndCenterToUpWithAnimation() {
    if (Build.VERSION.SDK_INT >= 11) {
      float centerMoveHeight =
          mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_center_move_top_height);
      mStepLayout.setVisibility(View.INVISIBLE);
      ObjectAnimator centerAnimator =
          ObjectAnimator.ofFloat(mCenterLayoutParent, "y", 0f, -centerMoveHeight);
      centerAnimator.setDuration(ANIMATION_TIME);
      centerAnimator.start();

      float topHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_top_height);
      ObjectAnimator topAnimator = ObjectAnimator.ofFloat(mFirstTopView, "y", 0f, -topHeight);
      topAnimator.setDuration(ANIMATION_TIME);
      topAnimator.addListener(
          new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {}

            @Override
            public void onAnimationEnd(Animator animator) {
              mActivity.runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      if (null != mMenuListener) {
                        mMenuListener.onShowSecondAnimationEnd();
                      }
                    }
                  });
            }

            @Override
            public void onAnimationCancel(Animator animator) {}

            @Override
            public void onAnimationRepeat(Animator animator) {}
          });
      topAnimator.start();

    } else {
      mStepLayout.setVisibility(View.INVISIBLE);
      mFirstTopView.setVisibility(View.GONE);
      int centerMoveHeight =
          Math.round(
              mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_center_move_top_height));
      mCenterLayoutParent.setPadding(
          mCenterLayoutParent.getPaddingLeft(),
          mCenterLayoutParent.getPaddingTop() - centerMoveHeight,
          mCenterLayoutParent.getPaddingRight(),
          centerMoveHeight + mCenterLayoutParent.getPaddingBottom());
      if (null != mMenuListener) {
        mMenuListener.onShowSecondAnimationEnd();
      }
    }
  }
Exemple #25
0
 void populateFrom(
     String date, boolean from_me, String from, String message, int delivery_status) {
   //			Log.i(TAG, "populateFrom(" + from_me + ", " + from + ", " + message + ")");
   getDateView().setText(date);
   TypedValue tv = new TypedValue();
   if (from_me) {
     getTheme().resolveAttribute(R.attr.ChatMsgHeaderMeColor, tv, true);
     getDateView().setTextColor(tv.data);
     getFromView().setText(getString(R.string.chat_from_me));
     getFromView().setTextColor(tv.data);
   } else {
     getTheme().resolveAttribute(R.attr.ChatMsgHeaderYouColor, tv, true);
     getDateView().setTextColor(tv.data);
     getFromView().setText(from + ":");
     getFromView().setTextColor(tv.data);
   }
   switch (delivery_status) {
     case ChatConstants.DS_NEW:
       ColorDrawable layers[] = new ColorDrawable[2];
       getTheme().resolveAttribute(R.attr.ChatNewMessageColor, tv, true);
       layers[0] = new ColorDrawable(tv.data);
       if (from_me) {
         // message stored for later transmission
         getTheme().resolveAttribute(R.attr.ChatStoredMessageColor, tv, true);
         layers[1] = new ColorDrawable(tv.data);
       } else {
         layers[1] = new ColorDrawable(0x00000000);
       }
       TransitionDrawable backgroundColorAnimation = new TransitionDrawable(layers);
       int l = mRowView.getPaddingLeft();
       int t = mRowView.getPaddingTop();
       int r = mRowView.getPaddingRight();
       int b = mRowView.getPaddingBottom();
       mRowView.setBackgroundDrawable(backgroundColorAnimation);
       mRowView.setPadding(l, t, r, b);
       backgroundColorAnimation.setCrossFadeEnabled(true);
       backgroundColorAnimation.startTransition(DELAY_NEWMSG);
       getIconView().setImageResource(R.drawable.ic_chat_msg_status_queued);
       break;
     case ChatConstants.DS_SENT_OR_READ:
       getIconView().setImageResource(R.drawable.ic_chat_msg_status_unread);
       mRowView.setBackgroundColor(0x00000000); // default is transparent
       break;
     case ChatConstants.DS_ACKED:
       getIconView().setImageResource(R.drawable.ic_chat_msg_status_ok);
       mRowView.setBackgroundColor(0x00000000); // default is transparent
       break;
     case ChatConstants.DS_FAILED:
       getIconView().setImageResource(R.drawable.ic_chat_msg_status_failed);
       mRowView.setBackgroundColor(0x30ff0000); // default is transparent
       break;
   }
   getMessageView().setText(message);
   getMessageView().setTextSize(TypedValue.COMPLEX_UNIT_SP, chatWindow.mChatFontSize);
 }
 @Override
 public void prepare(View target) {
   float x = target.getPaddingLeft();
   float y = target.getHeight() - target.getPaddingBottom();
   getAnimatorAgent()
       .playTogether(
           ObjectAnimator.ofFloat(target, "alpha", 1, 0),
           ObjectAnimator.ofFloat(target, "rotation", 0, 90),
           ObjectAnimator.ofFloat(target, "pivotX", x, x),
           ObjectAnimator.ofFloat(target, "pivotY", y, y));
 }
 /**
  * 设置head的顶部边距
  *
  * @param topPadding
  */
 private void setHeadTopPadding(int topPadding) {
   if (topPadding > (headTotalHeight + 200)) {
     topPadding = headTotalHeight + 200;
   }
   headView.setPadding(
       headView.getPaddingLeft(),
       topPadding,
       headView.getPaddingRight(),
       headView.getPaddingBottom());
   headView.invalidate();
 }
 private void invalidatePadding(int index, View view) {
   int top = index == 0 ? R.dimen.tab_outer_padding_firstlast : R.dimen.tab_outer_padding_top;
   int bottom =
       index == (getCount() - 1)
           ? R.dimen.tab_outer_padding_firstlast
           : R.dimen.tab_outer_padding_top;
   view.setPadding(
       view.getPaddingLeft(),
       getContext().getResources().getDimensionPixelSize(top),
       view.getPaddingRight(),
       getContext().getResources().getDimensionPixelSize(bottom));
 }
Exemple #29
0
  @Override
  public void showMoreKeysPanel(
      View parentView,
      Controller controller,
      int pointX,
      int pointY,
      PopupWindow window,
      KeyboardActionListener listener) {
    mController = controller;
    mListener = listener;
    final View container = (View) getParent();
    final MiniKeyboard miniKeyboard = (MiniKeyboard) getKeyboard();

    parentView.getLocationInWindow(mCoordinates);
    final int miniKeyboardLeft =
        pointX - miniKeyboard.getDefaultCoordX() + parentView.getPaddingLeft();
    final int x =
        wrapUp(
            Math.max(
                    0,
                    Math.min(miniKeyboardLeft, parentView.getWidth() - miniKeyboard.mOccupiedWidth))
                - container.getPaddingLeft()
                + mCoordinates[0],
            container.getMeasuredWidth(),
            0,
            parentView.getWidth());
    final int y =
        pointY
            - (container.getMeasuredHeight() - container.getPaddingBottom())
            + parentView.getPaddingTop()
            + mCoordinates[1];

    window.setContentView(container);
    window.setWidth(container.getMeasuredWidth());
    window.setHeight(container.getMeasuredHeight());
    window.showAtLocation(parentView, Gravity.NO_GRAVITY, x, y);

    mOriginX = x + container.getPaddingLeft() - mCoordinates[0];
    mOriginY = y + container.getPaddingTop() - mCoordinates[1];
  }
        @Override
        public void getOutline(View view, Outline outline) {
          int outlineLeft = view.getPaddingLeft();
          int outlineTop = view.getPaddingTop();

          // Apply padding to shadow.
          outline.setRoundRect(
              outlineLeft,
              outlineTop,
              view.getWidth() - outlineLeft - view.getPaddingRight(),
              view.getHeight() - outlineTop - view.getPaddingBottom(),
              sRoundedRectCornerRadius);
        }