示例#1
7
  public void showLikeQuickAction(int x, int y) {
    preShow();

    mWindow.setAnimationStyle(android.R.style.Animation_Dialog);
    int[] location = new int[2];
    mAnchor.getLocationOnScreen(location);

    Rect anchorRect =
        new Rect(
            location[0],
            location[1],
            location[0] + mAnchor.getWidth(),
            location[1] + mAnchor.getHeight());

    root.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    int rootW = root.getWidth(), rootH = root.getHeight();
    int screenW = mWManager.getDefaultDisplay().getWidth();

    int xpos = ((screenW - rootW) / 2) + x;
    int ypos = anchorRect.top - rootH + y;

    if (rootH > anchorRect.top) {
      ypos = anchorRect.bottom + y;
    }
    mWindow.showAtLocation(mAnchor, Gravity.NO_GRAVITY, xpos, ypos);
  }
  /**
   * Positions the popup window on screen. When the popup window is too tall to fit under the
   * anchor, a parent scroll view is seeked and scrolled up to reclaim space. If scrolling is not
   * possible or not enough, the popup window gets moved on top of the anchor.
   *
   * <p>The height must have been set on the layout parameters prior to calling this method.
   *
   * @param anchor the view on which the popup window must be anchored
   * @param p the layout parameters used to display the drop down
   * @return true if the popup is translated upwards to fit on screen
   */
  private boolean findDropDownPosition(
      View anchor, WindowManager.LayoutParams p, int xoff, int yoff) {
    anchor.getLocationInWindow(mDrawingLocation);
    p.x = mDrawingLocation[0] + xoff;
    p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff;

    boolean onTop = false;

    p.gravity = Gravity.LEFT | Gravity.TOP;

    anchor.getLocationOnScreen(mScreenLocation);
    final Rect displayFrame = new Rect();
    anchor.getWindowVisibleDisplayFrame(displayFrame);

    final View root = anchor.getRootView();
    if (mScreenLocation[1] + anchor.getMeasuredHeight() + yoff + mPopupHeight > displayFrame.bottom
        || p.x + mPopupWidth - root.getWidth() > 0) {
      // if the drop down disappears at the bottom of the screen. we try to
      // scroll a parent scrollview or move the drop down back up on top of
      // the edit box
      int scrollX = anchor.getScrollX();
      int scrollY = anchor.getScrollY();
      Rect r =
          new Rect(
              scrollX,
              scrollY,
              scrollX + mPopupWidth,
              scrollY + mPopupHeight + anchor.getMeasuredHeight());
      anchor.requestRectangleOnScreen(r, true);

      // now we re-evaluate the space available, and decide from that
      // whether the pop-up will go above or below the anchor.
      anchor.getLocationInWindow(mDrawingLocation);
      p.x = mDrawingLocation[0] + xoff;
      p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff;

      // determine whether there is more space above or below the anchor
      anchor.getLocationOnScreen(mScreenLocation);

      onTop =
          (displayFrame.bottom - mScreenLocation[1] - anchor.getMeasuredHeight() - yoff)
              < (mScreenLocation[1] - yoff - displayFrame.top);
      if (onTop) {
        p.gravity = Gravity.LEFT | Gravity.BOTTOM;
        p.y = root.getHeight() - mDrawingLocation[1] - yoff;
      } else {
        p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff;
      }
    }

    p.gravity |= Gravity.DISPLAY_CLIP_VERTICAL;

    return onTop;
  }
  /**
   * Show the controller on screen. It will go away automatically after 'timeout' milliseconds of
   * inactivity.
   *
   * @param timeout The timeout in milliseconds. Use 0 to show the controller until hide() is
   *     called.
   */
  public void show(int timeout) {

    if (!mShowing && mAnchor != null) {
      setProgress();

      int[] anchorpos = new int[2];
      mAnchor.getLocationOnScreen(anchorpos);

      WindowManager.LayoutParams p = new WindowManager.LayoutParams();
      p.gravity = Gravity.TOP;
      p.width = mAnchor.getWidth();
      p.height = LayoutParams.WRAP_CONTENT;
      p.x = 0;
      p.y = anchorpos[1] + mAnchor.getHeight() - p.height;
      p.format = PixelFormat.TRANSLUCENT;
      p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
      p.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
      p.token = null;
      p.windowAnimations = 0; // android.R.style.DropDownAnimationDown;
      mWindowManager.addView(mDecor, p);
      mShowing = true;
    }
    updatePausePlay();

    // cause the progress bar to be updated even if mShowing
    // was already true.  This happens, for example, if we're
    // paused with the progress bar showing the user hits play.
    mHandler.sendEmptyMessage(SHOW_PROGRESS);

    Message msg = mHandler.obtainMessage(FADE_OUT);
    if (timeout != 0) {
      mHandler.removeMessages(FADE_OUT);
      mHandler.sendMessageDelayed(msg, timeout);
    }
  }
  /**
   * Starts a drag. It creates a bitmap of the view being dragged. That bitmap is what you see
   * moving. The actual view can be repositioned if that is what the onDrop handle chooses to do.
   *
   * @param v The view that is being dragged
   * @param source An object representing where the drag originated
   * @param dragInfo The data associated with the object that is being dragged
   * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or {@link
   *     #DRAG_ACTION_COPY}
   */
  public void startDrag(View v, DragSource source, Object dragInfo, int dragAction) {
    // Start dragging, but only if the source has something to drag.
    boolean doDrag = source.allowDrag();
    if (!doDrag) return;

    mOriginator = v;

    Bitmap b = getViewBitmap(v);

    if (b == null) {
      // out of memory?
      return;
    }

    int[] loc = mCoordinatesTemp;
    v.getLocationOnScreen(loc);
    int screenX = loc[0];
    int screenY = loc[1];

    startDrag(b, screenX, screenY, 0, 0, b.getWidth(), b.getHeight(), source, dragInfo, dragAction);

    b.recycle();

    if (dragAction == DRAG_ACTION_MOVE) {
      v.setVisibility(View.GONE);
    }
  }
示例#5
0
  protected void showPopupWindow(
      View parentView, int viewWidth, int viewHeight, List<String> goodsColumnGroups) {
    View view = getLayoutInflater().inflate(R.layout.clasifyfragment, null);

    view.setFocusable(true); // 这个很重要color="#7a7a7a"
    view.setFocusableInTouchMode(true);
    expandableListView = (ListView) view.findViewById(R.id.expandableListView);
    expandadapter =
        new Expandadapter(
            this,
            goodsColumnGroups,
            mHandler,
            parentView.getId() == R.id.tab_all_layout
                ? StoreConstant.ALL_TYPE
                : StoreConstant.NEAR_TYPE);
    expandableListView.setAdapter(expandadapter);

    mPopupWindow = new PopupWindow(view, viewWidth, viewHeight, true);
    mPopupWindow.setFocusable(true);
    mPopupWindow.setBackgroundDrawable(getResources().getDrawable(android.R.color.transparent));
    if (null != parentView) {
      int[] location = new int[2];
      parentView.getLocationOnScreen(location);
      mPopupWindow.showAtLocation(
          parentView, Gravity.NO_GRAVITY, location[0], location[1] + parentView.getHeight());
      mPopupWindow.update();
    }

    //        findGoodsColumn();
  }
示例#6
0
  /**
   * Show the controller on screen. It will go away automatically after 'timeout' milliseconds of
   * inactivity.
   *
   * @param timeout The timeout in milliseconds. Use 0 to show the controller until hide() is
   *     called.
   */
  public void show(int timeout) {
    if (!mShowing && mAnchor != null && mAnchor.getWindowToken() != null) {
      if (mPauseButton != null) mPauseButton.requestFocus();

      if (mFromXml) {
        setVisibility(View.VISIBLE);
      } else {
        int[] location = new int[2];

        mAnchor.getLocationOnScreen(location);
        Rect anchorRect =
            new Rect(
                location[0],
                location[1],
                location[0] + mAnchor.getWidth(),
                location[1] + mAnchor.getHeight());

        mWindow.setAnimationStyle(mAnimStyle);
        setWindowLayoutType();
        mWindow.showAtLocation(mAnchor, Gravity.NO_GRAVITY, anchorRect.left, anchorRect.bottom);
      }
      mShowing = true;
      if (mShownListener != null) mShownListener.onShown();
    }
    updatePausePlay();
    mHandler.sendEmptyMessage(SHOW_PROGRESS);

    if (timeout != 0) {
      mHandler.removeMessages(FADE_OUT);
      mHandler.sendMessageDelayed(mHandler.obtainMessage(FADE_OUT), timeout);
    }
  }
示例#7
0
  private void dumpSubView(View view, Element pElem) {
    if (view == null) {
      final View[] views = this.viewFetcher.getWindowDecorViews();
      view = viewFetcher.getRecentDecorView(views);
    }

    if (!view.isShown()) return;

    Element elem = pElem.addElement(view.getClass().getSimpleName());
    int[] local = new int[2];
    view.getLocationOnScreen(local);
    elem.addAttribute("x", local[0] + "");
    elem.addAttribute("y", local[1] + "");
    elem.addAttribute("w", view.getWidth() + "");
    elem.addAttribute("h", view.getHeight() + "");

    int id = view.getId();
    if (id != -1) elem.addAttribute("id", id + "");

    Matcher match = Pattern.compile("(?<=:id/).*?(?=\\})").matcher(view.toString());
    if (match.find()) elem.addAttribute("resId", match.group());

    if (view instanceof TextView) elem.addAttribute("text", ((TextView) view).getText().toString());

    if (view instanceof ViewGroup) {
      ViewGroup group = (ViewGroup) view;
      for (int i = 0; i < group.getChildCount(); i++) {
        View v = group.getChildAt(i);
        dumpSubView(v, elem);
      }
    }
  }
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    if (mHeaderView == null) return super.dispatchTouchEvent(ev);

    if (mHeaderViewVisible) {
      final int x = (int) ev.getX();
      final int y = (int) ev.getY();
      mHeaderView.getLocationOnScreen(mLocation);
      mRect.left = mLocation[0];
      mRect.top = mLocation[1];
      mRect.right = mLocation[0] + mHeaderView.getWidth();
      mRect.bottom = mLocation[1] + mHeaderView.getHeight();

      if (mRect.contains(x, y)) {
        if (ev.getAction() == MotionEvent.ACTION_UP) {
          performViewClick(x, y);
        }
        return true;
      } else {
        return super.dispatchTouchEvent(ev);
      }
    } else {
      return super.dispatchTouchEvent(ev);
    }
  }
示例#9
0
    @Override
    public boolean onInterceptTouchEvent(View view, MotionEvent event) {
      // We need to account for scroll state for the touched view otherwise
      // tapping on an "empty" part of the view will still be considered a
      // valid touch event.
      if (view.getScrollX() != 0 || view.getScrollY() != 0) {
        Rect rect = new Rect();
        view.getHitRect(rect);
        rect.offset(-view.getScrollX(), -view.getScrollY());

        int[] viewCoords = new int[2];
        view.getLocationOnScreen(viewCoords);

        int x = (int) event.getRawX() - viewCoords[0];
        int y = (int) event.getRawY() - viewCoords[1];

        if (!rect.contains(x, y)) return false;
      }

      // If the tab tray is showing, hide the tab tray and don't send the event to content.
      if (event.getActionMasked() == MotionEvent.ACTION_DOWN && autoHideTabs()) {
        mIsHidingTabs = true;
        return true;
      }
      return false;
    }
示例#10
0
  /* Tap the "star" (bookmark) button to bookmark or un-bookmark the current page */
  public void toggleBookmark() {
    mActions.sendSpecialKey(Actions.SpecialKey.MENU);
    waitForText("Settings");

    // On ICS+ phones, there is no button labeled "Bookmarks"
    // instead we have to just dig through every button on the screen
    ArrayList<View> images = mSolo.getCurrentViews();
    for (int i = 0; i < images.size(); i++) {
      final View view = images.get(i);
      boolean found = false;
      found = "Bookmark".equals(view.getContentDescription());

      // on older android versions, try looking at the button's text
      if (!found) {
        if (view instanceof TextView) {
          found = "Bookmark".equals(((TextView) view).getText());
        }
      }

      if (found) {
        int[] xy = new int[2];
        view.getLocationOnScreen(xy);

        final int viewWidth = view.getWidth();
        final int viewHeight = view.getHeight();
        final float x = xy[0] + (viewWidth / 2.0f);
        float y = xy[1] + (viewHeight / 2.0f);

        mSolo.clickOnScreen(x, y);
      }
    }
  }
示例#11
0
    public void onClick(View v) {
      try {
        String pos = (String) v.getTag();
        Intent intent = new Intent(LauncherIntent.Action.ACTION_VIEW_CLICK);
        intent.setComponent(mAppWidgetProvider);
        intent
            .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId)
            .putExtra(LauncherIntent.Extra.EXTRA_APPWIDGET_ID, mAppWidgetId);
        intent.putExtra(LauncherIntent.Extra.EXTRA_VIEW_ID, v.getId());
        intent.putExtra(LauncherIntent.Extra.Scroll.EXTRA_LISTVIEW_ID, mListViewId);
        intent.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_POS, pos);

        Rect srcRect = new Rect();
        final int[] location = new int[2];
        v.getLocationOnScreen(location);
        srcRect.left = location[0];
        srcRect.top = location[1];
        srcRect.right = srcRect.left + v.getWidth();
        srcRect.bottom = srcRect.top + v.getHeight();
        intent.putExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS, srcRect);

        v.getContext().sendBroadcast(intent);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
示例#12
0
  /**
   * Call that method to display the {@link QuickActionWidget} anchored to the given view.
   *
   * @param anchor The view the {@link QuickActionWidget} will be anchored to.
   */
  public void show(View anchor) {

    final View contentView = getContentView();

    if (contentView == null) {
      throw new IllegalStateException(
          "You need to set the content view using the setContentView method");
    }

    // Replaces the background of the popup with a cleared background
    setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    final int[] loc = mLocation;
    anchor.getLocationOnScreen(loc);
    mRect.set(loc[0], loc[1], loc[0] + anchor.getWidth(), loc[1] + anchor.getHeight());

    if (mIsDirty) {
      clearQuickActions();
      populateQuickActions(mQuickActions);
    }

    onMeasureAndLayout(mRect, contentView);

    if ((mPrivateFlags & MEASURE_AND_LAYOUT_DONE) != MEASURE_AND_LAYOUT_DONE) {
      throw new IllegalStateException(
          "onMeasureAndLayout() did not set the widget specification by calling"
              + " setWidgetSpecs()");
    }

    showArrow();
    prepareAnimationStyle();
    showAtLocation(anchor, Gravity.NO_GRAVITY, 0, mPopupY);
  }
示例#13
0
  @Override
  public void onImageItemClick(View v, Image image) {
    // Interesting data to pass across are the thumbnail size/location, the
    // resourceId of the source bitmap, the picture description, and the
    // orientation (to avoid returning back to an obsolete configuration if
    // the device rotates again in the meantime)
    int[] screenLocation = new int[2];
    v.getLocationOnScreen(screenLocation);

    Intent showImageDetailsIntent = new Intent(getActivity(), ImageActivity.class);

    int orientation = getResources().getConfiguration().orientation;
    showImageDetailsIntent
        .putExtra(PACKAGE + ".orientation", orientation)
        .putExtra(PACKAGE + ".left", screenLocation[0])
        .putExtra(PACKAGE + ".top", screenLocation[1])
        .putExtra(PACKAGE + ".width", v.getWidth())
        .putExtra(PACKAGE + ".height", v.getHeight());

    Bundle bundle = new Bundle();
    bundle.putParcelable(IMAGE, image);
    showImageDetailsIntent.putExtras(bundle);

    getActivity().startActivity(showImageDetailsIntent);

    // Override transitions: we don't want the normal window animation in addition
    // to our custom one
    getActivity().overridePendingTransition(0, 0);
  }
示例#14
0
        public void handleMessage(android.os.Message msg) {

          if (getMess && "float".equals(mInsteadView.getTag())) {
            // this is float view and parent height minus in screen
            FloatScrollView.this.getLocationOnScreen(locations);
            mHeightInScreen = locations[1];
            floatHeight = floatView.getHeight();
            getMess = false;
          }

          underView.getLocationOnScreen(locations);
          int y2 = locations[1] - floatHeight;

          if (y2 <= mHeightInScreen) {
            if (!isFloat) {
              //                    Toast.makeText(context,
              // "执行浮动"+"y2:"+y2+",y1:"+mHeightInScreen+",isFloat:"+isFloat, 1).show();
              applyToFloat(floatView);
              isFloat = true;
              return;
            }
          }
          if (y2 > mHeightInScreen) {
            if (isFloat) {
              //                    Toast.makeText(context,
              // "取消浮动"+"y2:"+y2+",y1:"+mHeightInScreen+",isFloat:"+isFloat, 1).show();
              applyToNormal(floatView);
              if (isResetInnerPage && innerScrollView != null) {
                innerScrollView.scrollToTarget(0);
              }
              isFloat = false;
              return;
            }
          }
        };
示例#15
0
  /**
   * Displays like a QuickAction from the anchor view.
   *
   * @param xOffset offset in the X direction
   * @param yOffset offset in the Y direction
   */
  public static void showLikeQuickAction(
      PopupWindow window,
      View root,
      View anchor,
      WindowManager windowManager,
      int xOffset,
      int yOffset) {

    window.setAnimationStyle(R.style.Animations_GrowFromBottomRight);

    int[] location = new int[2];
    anchor.getLocationOnScreen(location);

    Rect anchorRect =
        new Rect(
            location[0],
            location[1],
            location[0] + anchor.getWidth(),
            location[1] + anchor.getHeight());

    root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    int rootWidth = root.getMeasuredWidth();
    int rootHeight = root.getMeasuredHeight();

    int screenWidth = windowManager.getDefaultDisplay().getWidth();
    int screenHeight = windowManager.getDefaultDisplay().getHeight();

    int xPos = ((screenWidth - rootWidth) / 2) + xOffset;
    int yPos = anchorRect.top - rootHeight + yOffset;

    window.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);
  }
示例#16
0
  public void showLikeQuickAction(int xOffset, int yOffset) {
    preShow();
    window.setAnimationStyle(R.style.Animations_PopUpMenu_Center);
    int[] location = new int[2];
    anchor.getLocationOnScreen(location);
    Rect anchorRect =
        new Rect(
            location[0],
            location[1],
            location[0] + anchor.getWidth(),
            location[1] + anchor.getHeight());

    root.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    root.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    int rootWidth = root.getMeasuredWidth();
    int rootHeight = root.getMeasuredHeight();
    int screenWidth = windowManager.getDefaultDisplay().getWidth();
    int xPos = ((screenWidth - rootWidth) / 2) + xOffset;
    int yPos = anchorRect.top - rootHeight + yOffset;

    //  display on bottom
    if (rootHeight > anchorRect.top) {
      yPos = anchorRect.bottom + yOffset;
      window.setAnimationStyle(R.style.Animations_PopDownMenu_Center);
    }
    window.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);
  }
示例#17
0
 private boolean findDropDownPosition(View anchor, android.view.WindowManager.LayoutParams p) {
   anchor.getLocationOnScreen(mDrawingLocation);
   p.x = mDrawingLocation[0];
   p.y = mDrawingLocation[1] + anchor.getMeasuredHeight();
   boolean onTop = false;
   View root = anchor.getRootView();
   int delta = (p.y + p.height) - root.getWindowTop() - root.getHeight();
   if (delta > 0) {
     if (p.y != anchor.getWindowBottom()) {
       ScrollView scrollView =
           (ScrollView) anchor.findParentViewOfType(android / widget / ScrollView);
       if (scrollView != null) {
         int bottom = anchor.getWindowBottom() + p.height;
         if (bottom > scrollView.getChildAt(scrollView.getChildCount() - 1).getWindowBottom())
           onTop = true;
         else if (bottom > scrollView.getWindowBottom()) {
           boolean enabled = scrollView.isVerticalScrollBarEnabled();
           if (enabled) scrollView.setVerticalScrollBarEnabled(false);
           scrollView.smoothScrollBy(0, delta);
           if (enabled) scrollView.setVerticalScrollBarEnabled(enabled);
           p.y -= delta;
         } else {
           onTop = true;
         }
       } else {
         onTop = true;
       }
     } else {
       onTop = true;
     }
     if (onTop) p.y -= anchor.getMeasuredHeight() + p.height;
   }
   return onTop;
 }
 private void setupContextMenuInitialPosition(View openingView) {
   final int[] openingViewLocation = new int[2];
   openingView.getLocationOnScreen(openingViewLocation);
   int additionalBottomMargin = Utils.dpToPx(16);
   contextMenuView.setTranslationX(openingViewLocation[0] - additionalBottomMargin * 3);
   contextMenuView.setTranslationY(
       openingViewLocation[1] - contextMenuView.getHeight() - additionalBottomMargin);
 }
示例#19
0
  private void showPopupWindow(View view) {
    View contentView =
        LayoutInflater.from(getActivity()).inflate(R.layout.wifi_more_popuwindow, null);
    final PopupWindow popupWindow =
        new PopupWindow(contentView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

    ListView sListView = (ListView) contentView.findViewById(R.id.wifi_popupwindow_listView);
    WifiPopupWindowAdapter sAdapter = new WifiPopupWindowAdapter(getActivity(), mTitle);
    sListView.setDivider(null);
    sListView.setAdapter(sAdapter);
    sListView.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            switch (arg2) {
              case 0:
                Toast.makeText(getActivity(), R.string.wifi_close, 0).show();
                break;
              case 1:
                mWiFiMainView.setVisibility(View.GONE);
                mWiFiConnectView.setVisibility(View.VISIBLE);
                // mWiFiConnectView.showPhotos(info);
                break;
              case 2:
                Toast.makeText(getActivity(), R.string.wifi_close, 0).show();
                break;

              default:
                break;
            }
          }
        });
    popupWindow.setTouchable(true);

    popupWindow.setTouchInterceptor(
        new OnTouchListener() {
          @Override
          public boolean onTouch(View arg0, MotionEvent arg1) {
            return false;
          }
        });

    // 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框
    // 我觉得这里是API的一个bug
    popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.wifi_more_bg));
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    contentView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    int popupWidth = contentView.getMeasuredWidth();
    int popupHeight = contentView.getMeasuredHeight() * mTitle.length;
    int[] location = new int[2];
    // 设置好参数之后再show
    view.getLocationOnScreen(location);
    popupWindow.showAtLocation(
        view, Gravity.NO_GRAVITY, (location[0] - view.getWidth()), location[1] - popupHeight);
  }
示例#20
0
 /**
  * Scrolls view horizontally.
  *
  * @param view the view to scroll
  * @param side the side to which to scroll; {@link Side#RIGHT} or {@link Side#LEFT}
  * @param scrollPosition the position to scroll to, from 0 to 1 where 1 is all the way. Example
  *     is: 0.55.
  * @param stepCount how many move steps to include in the scroll. Less steps results in a faster
  *     scroll
  */
 public void scrollViewToSide(View view, Side side, float scrollPosition, int stepCount) {
   int[] corners = new int[2];
   view.getLocationOnScreen(corners);
   int viewHeight = view.getHeight();
   int viewWidth = view.getWidth();
   float x = corners[0] + viewWidth * scrollPosition;
   float y = corners[1] + viewHeight / 2.0f;
   if (side == Side.LEFT) drag(corners[0], x, y, y, stepCount);
   else if (side == Side.RIGHT) drag(x, corners[0], y, y, stepCount);
 }
示例#21
0
 /** Determines if two views intersect in the window. */
 public static boolean viewsIntersect(View view1, View view2) {
   final int[] view1Loc = new int[2];
   view1.getLocationOnScreen(view1Loc);
   final Rect view1Rect =
       new Rect(
           view1Loc[0],
           view1Loc[1],
           view1Loc[0] + view1.getWidth(),
           view1Loc[1] + view1.getHeight());
   int[] view2Loc = new int[2];
   view2.getLocationOnScreen(view2Loc);
   final Rect view2Rect =
       new Rect(
           view2Loc[0],
           view2Loc[1],
           view2Loc[0] + view2.getWidth(),
           view2Loc[1] + view2.getHeight());
   return view1Rect.intersect(view2Rect);
 }
 private boolean isEventWithinView(MotionEvent e, View child) {
   Rect viewRect = new Rect();
   int[] childPosition = new int[2];
   child.getLocationOnScreen(childPosition);
   int left = childPosition[0];
   int right = left + child.getWidth();
   int top = childPosition[1];
   int bottom = top + child.getHeight();
   viewRect.set(left, top, right, bottom);
   return viewRect.contains((int) e.getRawX(), (int) e.getRawY());
 }
示例#23
0
  // Update the dynamic parts of mDecorLayoutParams
  // Must be called with mAnchor != NULL.
  private void updateFloatingWindowLayout() {
    int[] anchorPos = new int[2];
    mAnchor.getLocationOnScreen(anchorPos);

    WindowManager.LayoutParams p = mDecorLayoutParams;
    if (p != null) {
      p.width = mAnchor.getWidth();
      p.y = anchorPos[1] + mAnchor.getHeight();
      p.y -= mHeight;
    }
  }
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    final int x = (int) ev.getX();
    final int y = (int) ev.getY();

    // [shravan.mahankali] dynamically find the dragger object and let user drag the item
    // only if touched on dragger and not otherwise.
    if (action == MotionEvent.ACTION_DOWN) {
      int startPos = pointToPosition(x, y);
      if (startPos != INVALID_POSITION) {
        int mItemPosition = startPos - getFirstVisiblePosition();
        View grabber = getChildAt(mItemPosition).findViewById(draggerId);
        int mDragPointY = y - grabber.getTop();

        int[] grabberLocationOnScreen = new int[2];
        grabber.getLocationOnScreen(grabberLocationOnScreen);

        if (x >= grabber.getLeft()
            && x <= grabber.getRight()
            && mDragPointY >= grabber.getTop()
            && mDragPointY <= grabberLocationOnScreen[1]) mDragMode = true;
      }
    }

    if (!mDragMode) return super.onTouchEvent(ev);

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mStartPosition = pointToPosition(x, y);
        if (mStartPosition != INVALID_POSITION) {
          int mItemPosition = mStartPosition - getFirstVisiblePosition();
          mDragPointOffset = y - getChildAt(mItemPosition).getTop();
          mDragPointOffset -= ((int) ev.getRawY()) - y;
          startDrag(mItemPosition, y);
          drag(0, y); // replace 0 with x if desired
        }
        break;
      case MotionEvent.ACTION_MOVE:
        drag(0, y); // replace 0 with x if desired
        break;
      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
      default:
        mDragMode = false;
        mEndPosition = pointToPosition(x, y);
        stopDrag(mStartPosition - getFirstVisiblePosition());
        if (mDropListener != null
            && mStartPosition != INVALID_POSITION
            && mEndPosition != INVALID_POSITION) mDropListener.onDrop(mStartPosition, mEndPosition);
        break;
    }
    return true;
  }
 public void showPopupWindow(View parent) {
   int[] location = new int[2];
   parent.getLocationOnScreen(location);
   if (!this.isShowing()) {
     // this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 18);
     // this.showAsDropDown(parent, parent.getLayoutParams().width / 2-80, -30);
     this.showAtLocation(
         parent, Gravity.NO_GRAVITY, location[0], location[1] + parent.getHeight());
   } else {
     this.dismiss();
   }
 }
  /**
   * Returns true on success, false on failure. If successful, after calling, output buffer will be
   * {x, y, width, height}.
   */
  public void measure(int tag, int[] outputBuffer) {
    UiThreadUtil.assertOnUiThread();
    View v = mTagsToViews.get(tag);
    if (v == null) {
      throw new NoSuchNativeViewException("No native view for " + tag + " currently exists");
    }

    // Puts x/y in outputBuffer[0]/[1]
    v.getLocationOnScreen(outputBuffer);
    outputBuffer[2] = v.getWidth();
    outputBuffer[3] = v.getHeight();
  }
 public void testSayHiToJane() {
   assertTrue(getSolo().waitForView(getSolo().getView(R.id.swipe_menu_list_view)));
   SwipeMenuListView listView = (SwipeMenuListView) getSolo().getView(R.id.swipe_menu_list_view);
   View listItem1 = listView.getChildAt(1);
   int[] location = new int[2];
   listItem1.getLocationOnScreen(location);
   float x = (float) location[0] + (listItem1.getWidth() / 2);
   float y = (float) location[1] + (listItem1.getHeight() / 2);
   getSolo().drag(x, x - 150, y, y, 10);
   assertTrue(getSolo().waitForText(getSolo().getString(R.string.say_hi)));
   getSolo().clickOnText(getSolo().getString(R.string.say_hi));
 }
示例#28
0
 private boolean isViewHit(View view, int x, int y) {
   int[] viewLocation = new int[2];
   view.getLocationOnScreen(viewLocation);
   int[] parentLocation = new int[2];
   this.getLocationOnScreen(parentLocation);
   int screenX = parentLocation[0] + x;
   int screenY = parentLocation[1] + y;
   return screenX >= viewLocation[0]
       && screenX < viewLocation[0] + view.getWidth()
       && screenY >= viewLocation[1]
       && screenY < viewLocation[1] + view.getHeight();
 }
示例#29
0
 public void onClick(View v) {
   Object tag = v.getTag();
   if (tag instanceof ShortcutInfo) {
     // refactor this code from Folder
     ShortcutInfo item = (ShortcutInfo) tag;
     int[] pos = new int[2];
     v.getLocationOnScreen(pos);
     item.intent.setSourceBounds(
         new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()));
     mLauncher.startActivitySafely(item.intent, item);
   }
 }
示例#30
0
 private boolean isTouchPointInView(View view, int x, int y) {
   int[] location = new int[2];
   view.getLocationOnScreen(location);
   int left = location[0];
   int top = location[1];
   int right = left + view.getMeasuredWidth();
   int bottom = top + view.getMeasuredHeight();
   if (view.isClickable() && y >= top && y <= bottom && x >= left && x <= right) {
     return true;
   }
   return false;
 }