@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);
 }
  /** Measures and layouts the scrollbar and decorations. */
  public void updatePopAlphabetLayout() {
    // Prevent re-entry when RTL properties change as a side-effect of
    // resolving padding.
    if (mUpdatingLayout) {
      return;
    }

    mUpdatingLayout = true;

    updateContainerRect();

    final Rect bounds = mTempBounds;
    measurePreview(mPrimaryText, bounds);
    applyLayout(mPrimaryText, bounds);
    measurePreview(mSecondaryText, bounds);
    applyLayout(mSecondaryText, bounds);

    if (mPreviewImage != null) {
      // Apply preview image padding.
      bounds.left -= mPreviewImage.getPaddingLeft();
      bounds.top -= mPreviewImage.getPaddingTop();
      bounds.right += mPreviewImage.getPaddingRight();
      bounds.bottom += mPreviewImage.getPaddingBottom();
      applyLayout(mPreviewImage, bounds);
    }
  }
  // initialize moving to center animation
  private void startAnimateToCenter(long duration) {
    startFlingX = ring.getPaddingLeft();
    startFlingY = ring.getPaddingTop();
    endFlingX = (mDisplayWidth - ringWidth) / 2;
    endFlingY = (mDisplayHeight - ringHeight) / 2;
    startTime = System.currentTimeMillis();
    endTime = startTime + duration;
    interpolator = new DecelerateInterpolator();
    isFlinging = true;

    if (DBG)
      Log.i(
          TAG,
          "startAnimateToCenter: sx="
              + startFlingX
              + " sy="
              + startFlingY
              + " ex="
              + endFlingX
              + " ey="
              + endFlingY);
    post(
        new Runnable() {
          @Override
          public void run() {
            animateToCenterStep();
          }
        });
  }
  // handles touch event
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (!isFlinging) {
      int orgLeft = ring.getPaddingLeft();
      int orgTop = ring.getPaddingTop();
      int left = (int) (event.getRawX() - ringWidth / 2 - 10);
      int top = (int) (event.getRawY() - ringHeight / 2 - 20);
      // check touch position
      int dist = (left - orgLeft) * (left - orgLeft) + (top - orgTop) * (top - orgTop);
      if (DBG) Log.i(TAG, "distance : " + dist);

      if (dist < ringWidth * ringHeight) {
        // move the ring
        moveRing(left, top);
        // and check flinging
        // gestureDetector.onTouchEvent(event);

        // released?
        if (event.getAction() == MotionEvent.ACTION_UP) {
          // check place,
          if ((int) (top + ringWidth / 2) < 3 * mDisplayHeight / 4) {
            // start moving to center animation
            startAnimateToCenter(150);
          }
        }
      }
    }
    return false;
  }
  /**
   * Measures the preview text bounds, taking preview image padding into account. This method should
   * only be called after {@link #layoutThumb()} and {@link #layoutTrack()} have both been called at
   * least once.
   *
   * @param v The preview text view to measure.
   * @param out Rectangle into which measured bounds are placed.
   */
  private void measurePreview(View v, Rect out) {
    // Apply the preview image's padding as layout margins.
    final Rect margins = mTempMargins;
    margins.left = mPreviewImage.getPaddingLeft();
    margins.top = mPreviewImage.getPaddingTop();
    margins.right = mPreviewImage.getPaddingRight();
    margins.bottom = mPreviewImage.getPaddingBottom();

    measureFloating(v, margins, out);
  }
  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();

    final ImageView image = (ImageView) findViewById(R.id.widget_preview);
    mOriginalImagePadding.left = image.getPaddingLeft();
    mOriginalImagePadding.top = image.getPaddingTop();
    mOriginalImagePadding.right = image.getPaddingRight();
    mOriginalImagePadding.bottom = image.getPaddingBottom();
  }
  private boolean setupTitle(LinearLayout topPanel) {
    boolean hasTitle = true;

    if (mCustomTitleView != null) {
      // Add the custom title view directly to the topPanel layout
      LinearLayout.LayoutParams lp =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

      topPanel.addView(mCustomTitleView, 0, lp);

      // Hide the title template
      View titleTemplate = mWindow.findViewById(R.id.title_template);
      titleTemplate.setVisibility(View.GONE);
    } else {
      mIconView = (ImageView) mWindow.findViewById(R.id.icon);

      final boolean hasTextTitle = !TextUtils.isEmpty(mTitle);
      if (hasTextTitle) {
        // Display the title if a title is supplied, else hide it.
        mTitleView = (TextView) mWindow.findViewById(R.id.alertTitle);
        mTitleView.setText(mTitle);

        // Do this last so that if the user has supplied any icons we
        // use them instead of the default ones. If the user has
        // specified 0 then make it disappear.
        if (mIconId != 0) {
          mIconView.setImageResource(mIconId);
        } else if (mIcon != null) {
          mIconView.setImageDrawable(mIcon);
        } else {
          // Apply the padding from the icon to ensure the title is
          // aligned correctly.
          mTitleView.setPadding(
              mIconView.getPaddingLeft(),
              mIconView.getPaddingTop(),
              mIconView.getPaddingRight(),
              mIconView.getPaddingBottom());
          mIconView.setVisibility(View.GONE);
        }
      } else {
        // Hide the title template
        final View titleTemplate = mWindow.findViewById(R.id.title_template);
        titleTemplate.setVisibility(View.GONE);
        mIconView.setVisibility(View.GONE);
        topPanel.setVisibility(View.GONE);
        hasTitle = false;
      }
    }
    return hasTitle;
  }
Example #8
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   final int mPosition = position;
   Semester semester = (Semester) mData.get(mPosition).get("semester");
   convertView = super.getView(position, convertView, parent);
   final ImageView img = (ImageView) convertView.findViewById(R.id.select);
   if (localSemesterId == semester.id) {
     img.setImageResource(R.drawable.check);
     img.setPadding(
         img.getPaddingLeft(),
         img.getPaddingTop(),
         img.getPaddingRight() + ImageHlp.changeToSystemUnitFromDP(convertView.getContext(), 3),
         img.getPaddingBottom());
   }
   return convertView;
 }
  /**
   * Transitions the preview text to a new section. Handles animation, measurement, and layout. If
   * the new preview text is empty, returns false.
   *
   * @param sectionIndex The section index to which the preview should transition.
   * @return False if the new preview text is empty.
   */
  private boolean transitionPreviewLayout(int sectionIndex) {
    String text = mAlphabetList.get(sectionIndex).firstAlphabet;

    final Rect bounds = mTempBounds;
    final TextView showing;
    final TextView target;
    if (mShowingPrimary) {
      showing = mPrimaryText;
      target = mSecondaryText;
    } else {
      showing = mSecondaryText;
      target = mPrimaryText;
    }

    // Set and layout target immediately.
    target.setText(text);
    measurePreview(target, bounds);
    applyLayout(target, bounds);

    if (mPreviewAnimation != null) {
      mPreviewAnimation.cancel();
    }

    // Cross-fade preview text.
    final Animator showTarget = animateAlpha(target, 1f).setDuration(DURATION_CROSS_FADE);
    final Animator hideShowing = animateAlpha(showing, 0f).setDuration(DURATION_CROSS_FADE);
    hideShowing.addListener(mSwitchPrimaryListener);

    // Apply preview image padding and animate bounds, if necessary.
    bounds.left -= mPreviewImage.getPaddingLeft();
    bounds.top -= mPreviewImage.getPaddingTop();
    bounds.right += mPreviewImage.getPaddingRight();
    bounds.bottom += mPreviewImage.getPaddingBottom();
    /*final Animator resizePreview = animateBounds(preview, bounds);
    resizePreview.setDuration(DURATION_RESIZE);*/

    mPreviewAnimation = new AnimatorSet();
    mPreviewAnimation.play(hideShowing).with(showTarget);
    mPreviewAnimation.start();

    return !TextUtils.isEmpty(text);
  }
Example #10
0
 private int getImageViewHeight(ImageView imageView) {
   if (null == imageView) return 0;
   return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
 }