public void setDrawerPosition(float value) {
    drawerPosition = value;
    if (drawerPosition > drawerLayout.getMeasuredWidth()) {
      drawerPosition = drawerLayout.getMeasuredWidth();
    } else if (drawerPosition < 0) {
      drawerPosition = 0;
    }
    requestLayout();

    final int newVisibility = drawerPosition > 0 ? VISIBLE : GONE;
    if (drawerLayout.getVisibility() != newVisibility) {
      drawerLayout.setVisibility(newVisibility);
    }
    setScrimOpacity(drawerPosition / (float) drawerLayout.getMeasuredWidth());
  }
  public void closeDrawer(boolean fast) {
    cancelCurrentAnimation();
    AnimatorSetProxy animatorSet = new AnimatorSetProxy();
    animatorSet.playTogether(ObjectAnimatorProxy.ofFloat(this, "drawerPosition", 0));
    animatorSet.setInterpolator(new DecelerateInterpolator());
    if (fast) {
      animatorSet.setDuration(
          Math.max((int) (200.0f / drawerLayout.getMeasuredWidth() * drawerPosition), 50));
    } else {
      animatorSet.setDuration(300);
    }
    animatorSet.addListener(
        new AnimatorListenerAdapterProxy() {
          @Override
          public void onAnimationEnd(Object animator) {
            onDrawerAnimationEnd(false);
          }

          @Override
          public void onAnimationCancel(Object animator) {
            onDrawerAnimationEnd(false);
          }
        });
    animatorSet.start();
  }
 /** Sets the touchable region of this popup to be the area occupied by its content. */
 private void setContentAreaAsTouchableSurface() {
   if (!mPopupWindow.isShowing()) {
     mContentContainer.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
   }
   int width = mContentContainer.getMeasuredWidth();
   int height = mContentContainer.getMeasuredHeight();
   mTouchableRegion.set(
       (int) mContentContainer.getX(),
       (int) mContentContainer.getY(),
       (int) mContentContainer.getX() + width,
       (int) mContentContainer.getY() + height);
 }
  public void openDrawer(boolean fast) {
    if (!allowOpenDrawer) {
      return;
    }
    if (AndroidUtilities.isTablet()
        && parentActionBarLayout != null
        && parentActionBarLayout.parentActivity != null) {
      AndroidUtilities.hideKeyboard(parentActionBarLayout.parentActivity.getCurrentFocus());
    }
    cancelCurrentAnimation();
    AnimatorSetProxy animatorSet = new AnimatorSetProxy();
    animatorSet.playTogether(
        ObjectAnimatorProxy.ofFloat(this, "drawerPosition", drawerLayout.getMeasuredWidth()));
    animatorSet.setInterpolator(new DecelerateInterpolator());
    if (fast) {
      animatorSet.setDuration(
          Math.max(
              (int)
                  (200.0f
                      / drawerLayout.getMeasuredWidth()
                      * (drawerLayout.getMeasuredWidth() - drawerPosition)),
              50));
    } else {
      animatorSet.setDuration(300);
    }
    animatorSet.addListener(
        new AnimatorListenerAdapterProxy() {
          @Override
          public void onAnimationEnd(Object animator) {
            onDrawerAnimationEnd(true);
          }

          @Override
          public void onAnimationCancel(Object animator) {
            onDrawerAnimationEnd(true);
          }
        });
    animatorSet.start();
    currentAnimation = animatorSet;
  }
 @Override
 /**
  * Determines where in the ActionBar various views should go. Gives priority to HIGH Priority
  * buttons, then the title, then LOW Priority buttons. If the title won't fit, force it to by
  * cutting off excess. If any buttons won't fit, move them to the OverflowMenu. *
  */
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   if (mLayoutFinished && mNeedsLayout) {
     mController.onMeasure(
         mControllerContainer.getMeasuredWidth(), mControllerContainer.getMeasuredHeight());
     mNeedsLayout = false;
   }
 }
示例#6
0
  private void measureCroutonView() {
    View view = getView();
    int widthSpec;
    if (null != viewGroup) {
      widthSpec =
          View.MeasureSpec.makeMeasureSpec(viewGroup.getMeasuredWidth(), View.MeasureSpec.AT_MOST);
    } else {
      widthSpec =
          View.MeasureSpec.makeMeasureSpec(
              activity.getWindow().getDecorView().getMeasuredWidth(), View.MeasureSpec.AT_MOST);
    }

    view.measure(widthSpec, View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
  }
示例#7
0
    public void onto(final ViewGroup target) {
      factor.width = target.getMeasuredWidth();
      factor.height = target.getMeasuredHeight();

      if (async) {
        BlurTask task =
            new BlurTask(
                target,
                factor,
                new BlurTask.Callback() {
                  @Override
                  public void done(BitmapDrawable drawable) {
                    addView(target, drawable);
                  }
                });
        task.execute();
      } else {
        Drawable drawable = new BitmapDrawable(context.getResources(), Blur.rs(target, factor));
        addView(target, drawable);
      }
    }
  @Override
  public void getDisplayAdResponse(View adView) {
    gmEventAdapterLog("tapjoy->getDisplayAdResponse");
    AdWhirlLayout adLayout = getAdwhirlLayout();
    if (adLayout != null) {
      mTapjoyADView = adView;
      LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
      int width = mADView.getMeasuredWidth();
      // Resize if it's too big.
      if (mTapjoyADView.getLayoutParams().width > width) {
        // 6.4 ratio
        lp = new LayoutParams(width, (width * 10) / 64);
        mTapjoyADView.setLayoutParams(lp);
      }

      Handler handler = adLayout.getHandler();
      if (handler != null) {
        mUpdateADViewFlag = true;
        handler.post(mUpdateADViewRunnable);
      }
    }
  }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    Rect windowRect = new Rect();
    mDecorView.getWindowVisibleDisplayFrame(windowRect);

    if (mSlideTarget == SLIDE_TARGET_WINDOW) {
      mDrawerContent.layout(left, top + windowRect.top, right, bottom);
      mDecorContent.layout(
          mDecorContent.getLeft(), mDecorContent.getTop(), mDecorContent.getLeft() + right, bottom);
    } else {
      mDrawerContent.layout(left, 0, right, bottom);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mDecorContent.layout(mDecorContent.getLeft(), 0, mDecorContent.getLeft() + right, bottom);
      } else {
        mDecorContent.layout(mDecorContent.getLeft(), top, mDecorContent.getLeft() + right, bottom);
      }
    }

    mDrawerWidth = mDrawerContent.getMeasuredWidth();
    if (mDrawerWidth > right - mTouchTargetWidth) {
      mDrawerContent.setPadding(0, 0, mTouchTargetWidth, 0);
      mDrawerWidth -= mTouchTargetWidth;
    }
  }
 /**
  * Returns how big this panel's view should be. This method should only be called when the view
  * has not been attached to a parent otherwise it will throw an illegal state.
  */
 public Size measure() throws IllegalStateException {
   Preconditions.checkState(mContentView.getParent() == null);
   mContentView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
   return new Size(mContentView.getMeasuredWidth(), mContentView.getMeasuredHeight());
 }
    /** Override {@link #getChildView(int, int, boolean, View, ViewGroup)} instead. */
    @Override
    public final View getChildView(
        final int groupPosition,
        int childPosition,
        boolean isLastChild,
        View convertView,
        final ViewGroup parent) {
      final GroupInfo info = getGroupInfo(groupPosition);

      if (info.animating) {
        // If this group is animating, return the a DummyView...
        if (convertView instanceof DummyView == false) {
          convertView = new DummyView(parent.getContext());
          convertView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 0));
        }

        if (childPosition < info.firstChildPosition) {
          // The reason why we do this is to support the collapse
          // this group when the group view is not visible but the
          // children of this group are. When notifyDataSetChanged
          // is called, the ExpandableListView tries to keep the
          // list position the same by saving the first visible item
          // and jumping back to that item after the views have been
          // refreshed. Now the problem is, if a group has 2 items
          // and the first visible item is the 2nd child of the group
          // and this group is collapsed, then the dummy view will be
          // used for the group. But now the group only has 1 item
          // which is the dummy view, thus when the ListView is trying
          // to restore the scroll position, it will try to jump to
          // the second item of the group. But this group no longer
          // has a second item, so it is forced to jump to the next
          // group. This will cause a very ugly visual glitch. So
          // the way that we counteract this is by creating as many
          // dummy views as we need to maintain the scroll position
          // of the ListView after notifyDataSetChanged has been
          // called.
          convertView.getLayoutParams().height = 0;
          return convertView;
        }

        final ExpandableListView listView = (ExpandableListView) parent;

        final DummyView dummyView = (DummyView) convertView;

        // Clear the views that the dummy view draws.
        dummyView.clearViews();

        // Set the style of the divider
        dummyView.setDivider(
            listView.getDivider(), parent.getMeasuredWidth(), listView.getDividerHeight());

        // Make measure specs to measure child views
        final int measureSpecW =
            MeasureSpec.makeMeasureSpec(parent.getWidth(), MeasureSpec.EXACTLY);
        final int measureSpecH = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

        int totalHeight = 0;
        int clipHeight = parent.getHeight();

        final int len = getRealChildrenCount(groupPosition);
        for (int i = info.firstChildPosition; i < len; i++) {
          View childView = getRealChildView(groupPosition, i, (i == len - 1), null, parent);

          LayoutParams p = (LayoutParams) childView.getLayoutParams();
          if (p == null) {
            p = (LayoutParams) generateDefaultLayoutParams();
            childView.setLayoutParams(p);
          }

          int lpHeight = p.height;

          int childHeightSpec;
          if (lpHeight > 0) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
          } else {
            childHeightSpec = measureSpecH;
          }

          childView.measure(measureSpecW, childHeightSpec);
          totalHeight += childView.getMeasuredHeight();

          if (totalHeight < clipHeight) {
            // we only need to draw enough views to fool the user...
            dummyView.addFakeView(childView);
          } else {
            dummyView.addFakeView(childView);

            // if this group has too many views, we don't want to
            // calculate the height of everything... just do a light
            // approximation and break
            int averageHeight = totalHeight / (i + 1);
            totalHeight += (len - i - 1) * averageHeight;
            break;
          }
        }

        Object o;
        int state = (o = dummyView.getTag()) == null ? STATE_IDLE : (Integer) o;

        if (info.expanding && state != STATE_EXPANDING) {
          ExpandAnimation ani = new ExpandAnimation(dummyView, 0, totalHeight, info);
          ani.setDuration(this.parent.getAnimationDuration());
          ani.setAnimationListener(
              new AnimationListener() {

                @Override
                public void onAnimationEnd(Animation animation) {
                  stopAnimation(groupPosition);
                  notifyDataSetChanged();
                  dummyView.setTag(STATE_IDLE);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {}

                @Override
                public void onAnimationStart(Animation animation) {}
              });
          dummyView.startAnimation(ani);
          dummyView.setTag(STATE_EXPANDING);
        } else if (!info.expanding && state != STATE_COLLAPSING) {
          if (info.dummyHeight == -1) {
            info.dummyHeight = totalHeight;
          }

          ExpandAnimation ani = new ExpandAnimation(dummyView, info.dummyHeight, 0, info);
          ani.setDuration(this.parent.getAnimationDuration());
          ani.setAnimationListener(
              new AnimationListener() {

                @Override
                public void onAnimationEnd(Animation animation) {
                  stopAnimation(groupPosition);
                  listView.collapseGroup(groupPosition);
                  notifyDataSetChanged();
                  info.dummyHeight = -1;
                  dummyView.setTag(STATE_IDLE);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {}

                @Override
                public void onAnimationStart(Animation animation) {}
              });
          dummyView.startAnimation(ani);
          dummyView.setTag(STATE_COLLAPSING);
        }

        return convertView;
      } else {
        return getRealChildView(groupPosition, childPosition, isLastChild, convertView, parent);
      }
    }
示例#12
0
 public boolean onTouchEvent(MotionEvent ev) {
   if (!parentActionBarLayout.checkTransitionAnimation()) {
     if (drawerOpened && ev != null && ev.getX() > drawerPosition && !startedTracking) {
       if (ev.getAction() == MotionEvent.ACTION_UP) {
         closeDrawer(false);
       }
       return true;
     }
     if (allowOpenDrawer && parentActionBarLayout.fragmentsStack.size() == 1) {
       if (ev != null
           && (ev.getAction() == MotionEvent.ACTION_DOWN
               || ev.getAction() == MotionEvent.ACTION_MOVE)
           && !startedTracking
           && !maybeStartTracking) {
         startedTrackingPointerId = ev.getPointerId(0);
         maybeStartTracking = true;
         startedTrackingX = (int) ev.getX();
         startedTrackingY = (int) ev.getY();
         cancelCurrentAnimation();
         if (velocityTracker != null) {
           velocityTracker.clear();
         }
       } else if (ev != null
           && ev.getAction() == MotionEvent.ACTION_MOVE
           && ev.getPointerId(0) == startedTrackingPointerId) {
         if (velocityTracker == null) {
           velocityTracker = VelocityTracker.obtain();
         }
         float dx = (int) (ev.getX() - startedTrackingX);
         float dy = Math.abs((int) ev.getY() - startedTrackingY);
         velocityTracker.addMovement(ev);
         if (maybeStartTracking
             && !startedTracking
             && (dx > 0
                     && dx / 3.0f > Math.abs(dy)
                     && Math.abs(dx) >= AndroidUtilities.getPixelsInCM(0.2f, true)
                 || dx < 0
                     && Math.abs(dx) >= Math.abs(dy)
                     && Math.abs(dx) >= AndroidUtilities.getPixelsInCM(0.4f, true))) {
           prepareForDrawerOpen(ev);
           startedTrackingX = (int) ev.getX();
           requestDisallowInterceptTouchEvent(true);
         } else if (startedTracking) {
           if (!beginTrackingSent) {
             if (((Activity) getContext()).getCurrentFocus() != null) {
               AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
             }
             beginTrackingSent = true;
           }
           moveDrawerByX(dx);
           startedTrackingX = (int) ev.getX();
         }
       } else if (ev == null
           || ev != null
               && ev.getPointerId(0) == startedTrackingPointerId
               && (ev.getAction() == MotionEvent.ACTION_CANCEL
                   || ev.getAction() == MotionEvent.ACTION_UP
                   || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
         if (velocityTracker == null) {
           velocityTracker = VelocityTracker.obtain();
         }
         velocityTracker.computeCurrentVelocity(1000);
         /*if (!startedTracking) {
             float velX = velocityTracker.getXVelocity();
             float velY = velocityTracker.getYVelocity();
             if (Math.abs(velX) >= 3500 && Math.abs(velX) > Math.abs(velY)) {
                 prepareForDrawerOpen(ev);
                 if (!beginTrackingSent) {
                     if (((Activity)getContext()).getCurrentFocus() != null) {
                         AndroidUtilities.hideKeyboard(((Activity)getContext()).getCurrentFocus());
                     }
                     beginTrackingSent = true;
                 }
             }
         }*/
         if (startedTracking
             || drawerPosition != 0 && drawerPosition != drawerLayout.getMeasuredWidth()) {
           float velX = velocityTracker.getXVelocity();
           float velY = velocityTracker.getYVelocity();
           boolean backAnimation =
               drawerPosition < drawerLayout.getMeasuredWidth() / 2.0f
                       && (velX < 3500 || Math.abs(velX) < Math.abs(velY))
                   || velX < 0 && Math.abs(velX) >= 3500;
           if (!backAnimation) {
             openDrawer(!drawerOpened && Math.abs(velX) >= 3500);
           } else {
             closeDrawer(drawerOpened && Math.abs(velX) >= 3500);
           }
           startedTracking = false;
         } else {
           maybeStartTracking = false;
           startedTracking = false;
         }
         if (velocityTracker != null) {
           velocityTracker.recycle();
           velocityTracker = null;
         }
       }
     }
     return startedTracking;
   }
   return false;
 }