public boolean a(View paramView1, View paramView2)
 {
   if ((paramView1.getVisibility() == 0) && (paramView2.getVisibility() == 0))
   {
     Rect localRect = j;
     if (paramView1.getParent() != this)
     {
       bool = true;
       a(paramView1, bool, localRect);
       paramView1 = k;
       if (paramView2.getParent() == this) {
         break label115;
       }
     }
     label115:
     for (boolean bool = true;; bool = false)
     {
       a(paramView2, bool, paramView1);
       if ((left > right) || (top > bottom) || (right < left) || (bottom < top)) {
         break label120;
       }
       return true;
       bool = false;
       break;
     }
     label120:
     return false;
   }
   return false;
 }
 @Override
 public void onDestroyView() {
   super.onDestroyView();
   if (mContextView != null && mContextView.getParent() != null) {
     ((ViewGroup) mContextView.getParent()).removeView(mContextView);
   }
 }
  /**
   * @param index 小于0则顺序插入(插入至最末尾);大于等于0则按指定索引值(index)插入
   * @param childView
   * @return
   */
  public boolean addChildView(int index, View childView) {
    if (childViews.contains(childView)) {
      return false;
    }

    if (null == childView.getTag()) {
      // 结构层操作
      // tag为null说明此view在添加至文件夹内之前是处于桌面上的,所以需要将其从根文件夹对象中删除
      GlobalDataCacheForMemorySingleton.getInstance
          .getRootDirectory()
          .getListFiles()
          .remove(((DragView) childView).getBookFile());
    } else {
      ((BookFolderLayout) childView.getTag()).removeChildView(childView, true);
    }

    if (null != childView.getParent()) {
      ((ViewGroup) childView.getParent()).removeView(childView);
    }

    if (index < 0) {
      childViews.add(childView);
    } else {
      childViews.add(index, childView);
    }

    // 生成缩略图控件
    BookThumbnailLayout bookThumbnailLayout = new BookThumbnailLayout(getContext());
    bookThumbnailLayout.bind((BookShelfBookCell) childView);
    childView.setTag(R.id.bookThumbnailView, bookThumbnailLayout);

    MyGridLayout.LayoutParams layoutParams = new MyGridLayout.LayoutParams();
    layoutParams.width = (int) getResources().getDimension(R.dimen.book_cell_width) / 3;
    layoutParams.height = (int) getResources().getDimension(R.dimen.book_image_height) / 3;
    layoutParams.topMargin = 4;
    layoutParams.leftMargin = 4;
    layoutParams.rightMargin = 4;
    layoutParams.bottomMargin = 4;

    // 顺序插入时,封面只显示前4本书
    if (index < 0) {
      if (gridLayout.getChildCount() < 4) {
        gridLayout.addView(bookThumbnailLayout, layoutParams);
      }
    }

    // 指定插入时,若索引值小于4则需将封面上多余的一张缩略图(即原第4张)删除
    else if (index < 4) {
      if (gridLayout.getChildCount() == 4) {
        gridLayout.removeViewAt(3);
      }
      gridLayout.addView(bookThumbnailLayout, index, layoutParams);
    }

    childView.setTag(this);

    updateFrontCover(); // 刷新封面

    return true;
  }
Beispiel #4
0
  /*
   * Attach the BadgeView to the target view
   *
   * @param target the view to attach the BadgeView
   */
  public void setTargetView(View target) {
    if (getParent() != null) {
      ((ViewGroup) getParent()).removeView(this);
    }

    if (target == null) {
      return;
    }

    if (target.getParent() instanceof FrameLayout) {
      ((FrameLayout) target.getParent()).addView(this);

    } else if (target.getParent() instanceof ViewGroup) {
      // use a new Framelayout container for adding badge
      ViewGroup parentContainer = (ViewGroup) target.getParent();
      int groupIndex = parentContainer.indexOfChild(target);
      parentContainer.removeView(target);

      FrameLayout badgeContainer = new FrameLayout(getContext());
      ViewGroup.LayoutParams parentLayoutParams = target.getLayoutParams();

      badgeContainer.setLayoutParams(parentLayoutParams);
      target.setLayoutParams(
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

      parentContainer.addView(badgeContainer, groupIndex, parentLayoutParams);
      badgeContainer.addView(target);

      badgeContainer.addView(this);
    } else if (target.getParent() == null) {
      Log.e(getClass().getSimpleName(), "ParentView is needed");
    }
  }
    public void updateRow(View v, int i) {
      RelativeLayout rl = (RelativeLayout) v.getParent();
      TextView tvQuantity = (TextView) rl.findViewById(R.id.salesitemrowquantity);
      int q = (Integer.valueOf(tvQuantity.getText().toString())) + i;
      tvQuantity.setText("" + q);

      TextView tvPrice = (TextView) rl.findViewById(R.id.salesitemrowprice);
      BigDecimal p = new BigDecimal(tvPrice.getText().toString());

      TextView tvTotal = (TextView) rl.findViewById(R.id.salesitemrowtotalcost);
      tvTotal.setText(p.multiply(new BigDecimal(q)).setScale(2).toString());

      UpdateSalesItemLocator ucl = (UpdateSalesItemLocator) tvQuantity.getTag();

      ArrayList<SalesItemsSold> list = FundraiserCounterActivity.readGsFilex(v.getContext());
      SalesItemsSold gscs = list.get(ucl.personRow);
      SalesItem row = gscs.getItemsSoldList().get(ucl.getSalesItemRow());
      row.setQuantity(q);
      FundraiserCounterActivity.saveGsFilex(v.getContext(), list);

      LinearLayout ll = (LinearLayout) v.getParent().getParent();

      RelativeLayout rlTotalRow = (RelativeLayout) ll.findViewById(R.id.rlsalesitemtotalrow);
      TextView tvTotalQuantity = (TextView) rlTotalRow.findViewById(R.id.salesitemrowquantity);
      TextView tvTotalTotal = (TextView) rlTotalRow.findViewById(R.id.salesitemrowtotalcost);

      tvTotalQuantity.setText("" + (Integer.parseInt(tvTotalQuantity.getText().toString()) + i));

      BigDecimal bd = new BigDecimal(tvTotalTotal.getText().toString());
      if (i == 1) bd = bd.add(row.getCost());
      if (i == -1) bd = bd.subtract(row.getCost());
      tvTotalTotal.setText(bd.toString());
    }
  @Override
  public void addView(View child, int left, int top) {
    if (child.getParent() instanceof ViewGroup) {
      ViewGroup parent = (ViewGroup) child.getParent();
      LayoutTransition layoutTransition = null;
      if (parent.getLayoutTransition() != null) {
        layoutTransition = parent.getLayoutTransition();
        parent.setLayoutTransition(null);
      }
      parent.removeView(child);
      if (layoutTransition != null) {
        parent.setLayoutTransition(layoutTransition);
      }

      if (child.getParent() != null) {
        // LayoutTransition will cause the child to delay removal - cancel it
        ViewGroupUtils.cancelLayoutTransition(parent);
        // fail-safe if view is still attached for any reason
        if (child.getParent() != null && FIELD_VIEW_PARENT != null) {
          ReflectionUtils.setFieldValue(child, FIELD_VIEW_PARENT, null);
        }
      }
      if (child.getParent() != null) {
        return;
      }
    }
    child.setTag(R.id.overlay_layout_params_backup, child.getLayoutParams());
    addView(child, initParams(child, left, top));
    invalidate();
  }
Beispiel #7
0
 @Override
 public void onDestroyView() {
   if (rootView.getParent() != null) {
     ((ViewGroup) rootView.getParent()).removeView(rootView);
   }
   super.onDestroyView();
 }
Beispiel #8
0
 // invalidate a rectangle relative to the view's coordinate system all the way up the view
 // hierarchy
 @SuppressLint("NewApi")
 public static void invalidateGlobalRegion(View view, RectF childBounds) {
   // childBounds.offset(view.getTranslationX(), view.getTranslationY());
   if (DEBUG_INVALIDATE) if (DebugLog.DEBUG) DebugLog.d(TAG, "-------------");
   while (view.getParent() != null && view.getParent() instanceof View) {
     view = (View) view.getParent();
     view.getMatrix().mapRect(childBounds);
     view.invalidate(
         (int) Math.floor(childBounds.left),
         (int) Math.floor(childBounds.top),
         (int) Math.ceil(childBounds.right),
         (int) Math.ceil(childBounds.bottom));
     if (DebugLog.DEBUG) {
       DebugLog.v(
           TAG,
           "INVALIDATE("
               + (int) Math.floor(childBounds.left)
               + ","
               + (int) Math.floor(childBounds.top)
               + ","
               + (int) Math.ceil(childBounds.right)
               + ","
               + (int) Math.ceil(childBounds.bottom));
     }
   }
 }
  // used in the web dialog popup /res/layout/web_menu_popup.xml
  public void webviewActionClicked(View v) {
    switch (v.getId()) {
      case R.id.saveimage:
        dismissDialog();
        String url = ((LinearLayout) v.getParent()).getTag().toString();
        Tools.DownloadAsyncTask download = new Tools.DownloadAsyncTask(url);
        download.execute(url);

        break;
      case R.id.openinnewtab:
        dismissDialog();
        webWindows.add(new CustomWebView(MainActivity.this, null, null));
        ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).removeAllViews();
        webWindows
            .get(webWindows.size() - 1)
            .loadUrl(((LinearLayout) v.getParent()).getTag().toString());
        ((ViewGroup) webLayout.findViewById(R.id.webviewholder))
            .addView(webWindows.get(webWindows.size() - 1));
        ((EditText) bar.findViewById(R.id.browser_searchbar)).setText("");
        browserListViewAdapter.notifyDataSetChanged();
        break;
      case R.id.copyurl:
        dismissDialog();
        String url2 = ((LinearLayout) v.getParent()).getTag().toString();

        // Gets a handle to the Clipboard Manager
        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("Copied URL", url2);
        clipboard.setPrimaryClip(clip);
        break;
    }
  }
Beispiel #10
0
 /** Attach the sub window to the content view. */
 @Override
 public void attachSubWindow(View container) {
   if (container.getParent() != null) {
     // already attached, remove first
     ((ViewGroup) container.getParent()).removeView(container);
   }
   mContentView.addView(container, COVER_SCREEN_PARAMS);
 }
 @Override
 public void onBinderItemClick(View view, int pos) {
   if (view.getParent().equals(guideRecyclerView)) {
     guideLogic(pos);
   } else if (view.getParent().equals(recyclerView)) {
     dealLogic(pos);
   }
 }
 private static void a(View paramView, RectF paramRectF)
 {
   while ((paramView.getParent() instanceof View))
   {
     paramView = (View)paramView.getParent();
     paramView.getMatrix().mapRect(paramRectF);
     paramView.invalidate((int)Math.floor(left), (int)Math.floor(top), (int)Math.ceil(right), (int)Math.ceil(bottom));
   }
 }
Beispiel #13
0
 public void applyFocusOverride(ViewParent parent) {
   if (requestFocusOverride) {
     View ancestor = (View) parent;
     while (ancestor.getParent() != null) {
       ancestor = (View) ancestor.getParent();
     }
     ancestor.clearFocus();
   }
 }
 public static View debugViewIds(View view, String logtag) {
   Log.v(logtag, "traversing: " + view.getClass().getSimpleName() + ", id: " + view.getId());
   if (view.getParent() != null && (view.getParent() instanceof ViewGroup)) {
     return debugViewIds((View) view.getParent(), logtag);
   } else {
     debugChildViewIds(view, logtag, 0);
     return view;
   }
 }
 void setCellLayoutPressedOrFocusedIcon() {
   final View shortcutView = (View) getParent();
   if (shortcutView != null) {
     final View cellLayoutChildren = (View) shortcutView.getParent();
     if (cellLayoutChildren != null && cellLayoutChildren instanceof CellLayoutChildren) {
       CellLayout layout = (CellLayout) cellLayoutChildren.getParent();
       layout.setPressedOrFocusedIcon((mPressedOrFocusedBackground != null) ? this : null);
     }
   }
 }
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   if (mViewRoot == null) {
     mViewRoot = inflater.inflate(R.layout.layout_horizontal, container, false);
   } else if (mViewRoot.getParent() != null) {
     ((ViewGroup) mViewRoot.getParent()).removeView(mViewRoot);
   }
   return mViewRoot;
 }
Beispiel #17
0
  public static void replaceView(View oldChild, View newChild, boolean transferLayoutParams) {
    final ViewGroup parent =
        oldChild.getParent() instanceof ViewGroup ? (ViewGroup) oldChild.getParent() : null;
    final int index = parent.indexOfChild(oldChild);

    parent.removeViewInLayout(oldChild);

    final LayoutParams layoutParams = (transferLayoutParams ? oldChild.getLayoutParams() : null);
    if (layoutParams != null) parent.addView(newChild, index, layoutParams);
    else parent.addView(newChild, index);
  }
 private void createSingleImageView() {
   View view = mMediaViewCollection.getView(0);
   if (view.getParent() != null) ((ViewGroup) view.getParent()).removeView(view);
   if (mAllowFullScreenMediaViewing) {
     view.setOnClickListener(
         new OnMediaItemClickedListener(mMediaViewCollection.getContentForView(view)));
   } else {
     view.setOnClickListener(null);
     view.setClickable(false);
   }
   this.addView(view);
 }
  /**
   * @param childView 要删除的视图
   * @param isDeleteFolder 是否删除只剩一本书的文件夹
   */
  public void removeChildView(View childView, boolean isDeleteFolder) {
    childView.setTag(null);

    if (childViews.contains(childView)) {
      childViews.remove(childView);
    }

    View bookThumbnailView = (View) childView.getTag(R.id.bookThumbnailView);
    int bookFaceIndex = gridLayout.indexOfChild(bookThumbnailView);
    gridLayout.removeView(bookThumbnailView); // 删除文件夹封面上显示的书籍缩略图

    /** 如果删除的是前4本书中的其中一本,且删除后文件夹内至少还有4本书,则需要更新文件夹封面,将第4本书的缩略图进行补位 */
    if (bookFaceIndex >= 0 && childViews.size() >= 4) {
      View bookFaceImageView = (View) childViews.get(3).getTag(R.id.bookThumbnailView);
      if (bookFaceImageView.getParent() != null) {
        ((ViewGroup) bookFaceImageView.getParent()).removeView(bookFaceImageView);
      }

      MyGridLayout.LayoutParams layoutParams = new MyGridLayout.LayoutParams();
      layoutParams.width = (int) getResources().getDimension(R.dimen.book_cell_width) / 3;
      layoutParams.height = (int) getResources().getDimension(R.dimen.book_image_height) / 3;
      layoutParams.topMargin = 4;
      layoutParams.leftMargin = 4;
      layoutParams.rightMargin = 4;
      layoutParams.bottomMargin = 4;

      gridLayout.addView(bookFaceImageView, 3, layoutParams);
    }

    if (null != childView.getParent()) {
      ((ViewGroup) childView.getParent()).removeView(childView);
    }

    // 结构层操作
    bookFile.getListFiles().remove(((DragView) childView).getBookFile());

    // 如果不需要自动删除只剩一本书籍的文件夹则在此处直接返回,终止方法体
    if (!isDeleteFolder) {
      return;
    }

    updateFrontCover(); // 刷新封面

    /** 该文件夹没有书籍时,则删除该文件夹 */
    if (0 == childViews.size()) {
      ViewGroup viewGroup = (ViewGroup) this.getParent();
      BookFile rootBookFile = GlobalDataCacheForMemorySingleton.getInstance.getRootDirectory();
      viewGroup.removeView(this);
      // 结构层操作
      rootBookFile.getListFiles().remove(bookFile);
    }
  }
Beispiel #20
0
 protected Rect getRelativePosition(View child) {
   View t = child;
   Rect r = new Rect(t.getLeft(), t.getTop(), 0, 0);
   while (t.getParent() != null && t != getRootView()) {
     t = (View) t.getParent();
     if (t == this) break;
     r.left += t.getLeft();
     r.top += t.getTop();
   }
   r.right = r.left + child.getMeasuredWidth();
   r.bottom = r.top + child.getMeasuredHeight();
   return r;
 }
Beispiel #21
0
  @Test
  public void removeFromParent_shouldRemoveViewFromParent() throws Exception {
    assertThat(parent.getChildCount()).isEqualTo(0);

    parent.addView(subject);
    assertThat(parent.getChildCount()).isEqualTo(1);
    assertThat(subject.getParent()).isEqualTo(parent);

    Views.removeFromParent(subject);

    assertThat(parent.getChildCount()).isEqualTo(0);
    assertThat(subject.getParent()).isNull();
  }
 /**
  * Set view show when list is empty
  *
  * @param view Empty View
  */
 public void setEmptyView(View view) {
   if (mEmptyView == view) return;
   if (mEmptyView != null) removeViewInLayout(mEmptyView);
   mEmptyView = view;
   if (mEmptyView.getParent() != null) {
     ((ViewGroup) mEmptyView.getParent()).removeView(mEmptyView);
   }
   mEmptyView.setVisibility(GONE);
   if (mTargetView != null)
     addView(
         mEmptyView, 1, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
   else
     addView(mEmptyView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
 }
 @Test
 public void removeView_resetsParentOnlyIfViewIsInViewGroup() throws Exception {
   assertThat(root.getChildCount(), equalTo(3));
   root.removeView(child3a);
   assertThat(root.getChildCount(), equalTo(3));
   assertThat(child3a.getParent(), sameInstance((ViewParent) child3));
 }
  private void applyTo(View target) {

    LayoutParams lp = target.getLayoutParams();
    ViewParent parent = target.getParent();
    FrameLayout container = new FrameLayout(context);

    if (target instanceof TabWidget) {

      // set target to the relevant tab child container
      target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
      this.target = target;

      ((ViewGroup) target)
          .addView(container, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

      this.setVisibility(View.GONE);
      container.addView(this);

    } else {

      // TODO verify that parent is indeed a ViewGroup
      ViewGroup group = (ViewGroup) parent;
      int index = group.indexOfChild(target);

      group.removeView(target);
      group.addView(container, index, lp);

      container.addView(target);

      this.setVisibility(View.GONE);
      container.addView(this);

      group.invalidate();
    }
  }
  /**
   * Try to find a MenuItemActionBar/MenuItemDefault with the given text set as contentDescription /
   * text.
   *
   * <p>When using legacy menus, make sure the menu has been opened to the appropriate level (i.e.
   * base menu or "More" menu) to ensure the appropriate menu views are in memory. TODO: ^ Maybe we
   * just need to have opened the "More" menu and the current one doesn't matter.
   *
   * <p>This method is dependent on not having two views with equivalent contentDescription / text.
   */
  private View findAppMenuItemView(String text) {
    mSolo.waitForText(text, 1, MAX_WAITTIME_FOR_MENU_UPDATE_IN_MS);

    final List<View> views = mSolo.getViews();

    final List<MenuItemActionBar> menuItemActionBarList =
        RobotiumUtils.filterViews(MenuItemActionBar.class, views);
    for (MenuItemActionBar menuItem : menuItemActionBarList) {
      if (TextUtils.equals(menuItem.getContentDescription(), text)) {
        return menuItem;
      }
    }

    final List<MenuItemDefault> menuItemDefaultList =
        RobotiumUtils.filterViews(MenuItemDefault.class, views);
    for (MenuItemDefault menuItem : menuItemDefaultList) {
      if (TextUtils.equals(menuItem.getText(), text)) {
        return menuItem;
      }
    }

    // On Android 2.3, menu items may be instances of
    // com.android.internal.view.menu.ListMenuItemView, each with a child
    // android.widget.RelativeLayout which in turn has a child
    // TextView with the appropriate text.
    final List<TextView> textViewList = RobotiumUtils.filterViews(TextView.class, views);
    for (TextView textView : textViewList) {
      if (TextUtils.equals(textView.getText(), text)) {
        View relativeLayout = (View) textView.getParent();
        View listMenuItemView = (View) relativeLayout.getParent();
        return listMenuItemView;
      }
    }
    return null;
  }
  /**
   * Sets the Empty View to be used by the Adapter View.
   *
   * <p>We need it handle it ourselves so that we can Pull-to-Refresh when the Empty View is shown.
   *
   * <p>Please note, you do <strong>not</strong> usually need to call this method yourself. Calling
   * setEmptyView on the AdapterView will automatically call this method and set everything up. This
   * includes when the Android Framework automatically sets the Empty View based on it's ID.
   *
   * @param newEmptyView - Empty View to be used
   */
  public final void setEmptyView(View newEmptyView) {
    FrameLayout refreshableViewWrapper = getRefreshableViewWrapper();

    if (null != newEmptyView) {
      // New view needs to be clickable so that Android recognizes it as a
      // target for Touch Events
      newEmptyView.setClickable(true);

      ViewParent newEmptyViewParent = newEmptyView.getParent();
      if (null != newEmptyViewParent && newEmptyViewParent instanceof ViewGroup) {
        ((ViewGroup) newEmptyViewParent).removeView(newEmptyView);
      }

      // We need to convert any LayoutParams so that it works in our
      // FrameLayout
      FrameLayout.LayoutParams lp = convertEmptyViewLayoutParams(newEmptyView.getLayoutParams());
      if (null != lp) {
        refreshableViewWrapper.addView(newEmptyView, lp);
      } else {
        refreshableViewWrapper.addView(newEmptyView);
      }
    }

    if (mRefreshableView instanceof EmptyViewMethodAccessor) {
      ((EmptyViewMethodAccessor) mRefreshableView).setEmptyViewInternal(newEmptyView);
    } else {
      mRefreshableView.setEmptyView(newEmptyView);
    }
    mEmptyView = newEmptyView;
  }
 protected void onScrollChanged(int i, int j, int k, int l) {
   super.onScrollChanged(i, j, k, l);
   if (mTrackedChild == null) {
     if (getChildCount() > 0) {
       mTrackedChild = getChildInTheMiddle();
       mTrackedChildPrevTop = mTrackedChild.getTop();
       mTrackedChildPrevPosition = getPositionForView(mTrackedChild);
     }
     return;
   }
   if (mTrackedChild.getParent() == this
       && getPositionForView(mTrackedChild) == mTrackedChildPrevPosition) {
     i = 1;
   } else {
     i = 0;
   }
   if (i != 0) {
     i = mTrackedChild.getTop();
     if (mScrollDeltaListener != null) {
       j = mTrackedChildPrevTop;
       mScrollDeltaListener.onScroll(i - j);
     }
     mTrackedChildPrevTop = i;
     return;
   } else {
     mTrackedChild = null;
     return;
   }
 }
 public void close() {
   if (mIsVisible) {
     mIsVisible = false;
     ((ViewGroup) mView.getParent()).removeView(mView);
     onClose();
   }
 }
Beispiel #29
0
 public static void moveToBack(View currentView) {
   ViewGroup vg = ((ViewGroup) currentView.getParent());
   int index = vg.indexOfChild(currentView);
   for (int i = 0; i < index; i++) {
     vg.bringChildToFront(vg.getChildAt(0));
   }
 }
 /** 初始化 */
 private void init() {
   params = view.getLayoutParams();
   if (null != view.getParent()) {
     parentView = (ViewGroup) view.getParent();
   } else {
     parentView = (ViewGroup) view.getRootView().findViewById(android.R.id.content);
   }
   int count = parentView.getChildCount();
   for (int index = 0; index < count; index++) {
     if (view == parentView.getChildAt(index)) {
       viewIndex = index;
       break;
     }
   }
   currentView = view;
 }