getParent ( )源码实例Demo

android.view.ViewParent#getParent ( )源码实例Demo

下面列出了android.view.ViewParent#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: htmlview   文件: HtmlView.java
/**
 * Scrolls to the element with the given label (<a name...) and focuses it
 * (if focusable).
 */
public void gotoLabel(String label) {
  View v = label == null ? this : labels.get(label);
  if (v != null) {
    if (v.isFocusable()) {
      v.requestFocus();
    }
    int y = v.getTop();
    ViewParent parent = v.getParent();
    while (parent instanceof View) {
      if (parent instanceof ScrollView) {
        ((ScrollView) parent).smoothScrollTo(0, y);
        break;
      }
      y += ((View) parent).getTop();
      parent = parent.getParent();
    }
  }
}
 
源代码2 项目: MaterialScrollBar   文件: MaterialScrollBar.java
void identifySwipeRefreshParents() {
    boolean cycle = true;
    ViewParent parent = getParent();
    if(parent != null) {
        while(cycle) {
            if(parent instanceof SwipeRefreshLayout) {
                swipeRefreshLayout = (SwipeRefreshLayout)parent;
                cycle = false;
            } else {
                if(parent.getParent() == null) {
                    cycle = false;
                } else {
                    parent = parent.getParent();
                }
            }
        }
    }
}
 
源代码3 项目: imsdk-android   文件: Jzvd.java
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
    Log.i(TAG, "bottomProgress onStopTrackingTouch [" + this.hashCode() + "] ");
    startProgressTimer();
    ViewParent vpup = getParent();
    while (vpup != null) {
        vpup.requestDisallowInterceptTouchEvent(false);
        vpup = vpup.getParent();
    }
    if (state != STATE_PLAYING &&
            state != STATE_PAUSE) return;
    long time = seekBar.getProgress() * getDuration() / 100;
    seekToManulPosition = seekBar.getProgress();
    mediaInterface.seekTo(time);
    Log.i(TAG, "seekTo " + time + " [" + this.hashCode() + "] ");
}
 
源代码4 项目: DevUtils   文件: ViewUtils.java
/**
 * 获取 android.R.id.content View
 * @param view {@link View}
 * @param <T>  泛型
 * @return {@link View}
 */
public static <T extends View> T getContentView(final View view) {
    if (view != null) {
        try {
            ViewParent parent = view.getParent();
            while (parent != null && parent instanceof View) {
                View root = (View) parent;
                if (root.getId() == android.R.id.content) {
                    return (T) root;
                }
                parent = parent.getParent();
            }
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "getContentView");
        }
    }
    return null;
}
 
源代码5 项目: JPPF   文件: SettingsFragment.java
/**
 * Sets up the action bar for an {@link PreferenceScreen}.
 * @param preferenceScreen the preference screen on which to set the action bar.
 */
private static void initializeActionBar(PreferenceScreen preferenceScreen) {
  final Dialog dialog = preferenceScreen.getDialog();
  if (dialog != null) {
    dialog.getActionBar().setDisplayHomeAsUpEnabled(true);
    View homeBtn = dialog.findViewById(android.R.id.home);
    if (homeBtn != null) {
      View.OnClickListener dismissDialogClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          dialog.dismiss();
        }
      };
      ViewParent homeBtnContainer = homeBtn.getParent();
      if (homeBtnContainer instanceof FrameLayout) {
        ViewGroup containerParent = (ViewGroup) homeBtnContainer.getParent();
        if (containerParent instanceof LinearLayout) containerParent.setOnClickListener(dismissDialogClickListener);
        else ((FrameLayout) homeBtnContainer).setOnClickListener(dismissDialogClickListener);
      } else  homeBtn.setOnClickListener(dismissDialogClickListener);
    }
  }
}
 
源代码6 项目: ZListVIew   文件: ZSwipeItem.java
private void performAdapterViewItemClick(MotionEvent e) {
	ViewParent t = getParent();

	Log.d(TAG, "performAdapterViewItemClick()");

	while (t != null) {
		if (t instanceof AdapterView) {
			@SuppressWarnings("rawtypes")
			AdapterView view = (AdapterView) t;
			int p = view.getPositionForView(ZSwipeItem.this);
			if (p != AdapterView.INVALID_POSITION
					&& view.performItemClick(
							view.getChildAt(p
									- view.getFirstVisiblePosition()), p,
							view.getAdapter().getItemId(p)))
				return;
		} else {
			if (t instanceof View && ((View) t).performClick())
				return;
		}

		t = t.getParent();
	}
}
 
源代码7 项目: Android-RobotoTextView   文件: RobotoInflater.java
private boolean shouldInheritContext(ViewParent parent) {
    if (parent == null) {
        // The initial parent is null so just return false
        return false;
    }
    final View windowDecor = mWindow.getDecorView();
    while (true) {
        if (parent == null) {
            // Bingo. We've hit a view which has a null parent before being terminated from
            // the loop. This is (most probably) because it's the root view in an inflation
            // call, therefore we should inherit. This works as the inflated layout is only
            // added to the hierarchy at the end of the inflate() call.
            return true;
        } else if (parent == windowDecor || !(parent instanceof View)
                || ViewCompat.isAttachedToWindow((View) parent)) {
            // We have either hit the window's decor view, a parent which isn't a View
            // (i.e. ViewRootImpl), or an attached view, so we know that the original parent
            // is currently added to the view hierarchy. This means that it has not be
            // inflated in the current inflate() call and we should not inherit the context.
            return false;
        }
        parent = parent.getParent();
    }
}
 
源代码8 项目: litho   文件: ComponentHost.java
@Override
public void requestLayout() {
  // Don't request a layout if it will be blocked by any parent. Requesting a layout that is
  // then ignored by an ancestor means that this host will remain in a state where it thinks that
  // it has requested layout, and will therefore ignore future layout requests. This will lead to
  // problems if a child (e.g. a ViewPager) requests a layout later on, since the request will be
  // wrongly ignored by this host.
  ViewParent parent = this;
  while (parent instanceof ComponentHost) {
    final ComponentHost host = (ComponentHost) parent;
    if (!host.shouldRequestLayout()) {
      return;
    }

    parent = parent.getParent();
  }

  super.requestLayout();
}
 
源代码9 项目: FuAgoraDemoDroid   文件: SeekBarCompatDontCrash.java
public static boolean isInScrollingContainer(ViewParent p) {
    while (p != null && p instanceof ViewGroup) {
        if (((ViewGroup) p).shouldDelayChildPressedState()) {
            return true;
        }
        p = p.getParent();
    }
    return false;
}
 
源代码10 项目: imsdk-android   文件: Jzvd.java
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
    Log.i(TAG, "bottomProgress onStartTrackingTouch [" + this.hashCode() + "] ");
    cancelProgressTimer();
    ViewParent vpdown = getParent();
    while (vpdown != null) {
        vpdown.requestDisallowInterceptTouchEvent(true);
        vpdown = vpdown.getParent();
    }
}
 
源代码11 项目: talk-android   文件: MaterialRippleLayout.java
private boolean isInScrollingContainer() {
    ViewParent p = getParent();
    while (p != null && p instanceof ViewGroup) {
        if (((ViewGroup) p).shouldDelayChildPressedState()) {
            return true;
        }
        p = p.getParent();
    }
    return false;
}
 
源代码12 项目: SwipeBack   文件: SeekBarCompatDontCrash.java
public static boolean isInScrollingContainer(ViewParent p) {
    while (p != null && p instanceof ViewGroup) {
        if (((ViewGroup) p).shouldDelayChildPressedState()) {
            return true;
        }
        p = p.getParent();
    }
    return false;
}
 
源代码13 项目: ScrollDownLayout   文件: ContentScrollView.java
@Override
protected void onAttachedToWindow() {
  super.onAttachedToWindow();
  ViewParent parent = this.getParent();
  while (parent != null) {
    if (parent instanceof ScrollDownLayout) {
      ((ScrollDownLayout) parent).setAssociatedScrollView(this);
      break;
    }
    parent = parent.getParent();
  }
}
 
@Nullable
private TextInputLayout getTextInputLayout() {
  ViewParent parent = getParent();
  while (parent instanceof View) {
    if (parent instanceof TextInputLayout) {
      return (TextInputLayout) parent;
    }
    parent = parent.getParent();
  }
  return null;
}
 
源代码15 项目: material-components-android   文件: BaseSlider.java
/**
 * If this returns true, we can't start dragging the Slider immediately when we receive a {@link
 * MotionEvent#ACTION_DOWN}. Instead, we must wait for a {@link MotionEvent#ACTION_MOVE}. Copied
 * from hidden method of {@link View} isInScrollingContainer.
 *
 * @return true if any of this View's parents is a scrolling View.
 */
private boolean isInScrollingContainer() {
  ViewParent p = getParent();
  while (p instanceof ViewGroup) {
    if (((ViewGroup) p).shouldDelayChildPressedState()) {
      return true;
    }
    p = p.getParent();
  }
  return false;
}
 
源代码16 项目: zhangshangwuda   文件: MenuDrawer.java
protected boolean isViewDescendant(View v) {
    ViewParent parent = v.getParent();
    while (parent != null) {
        if (parent == this) {
            return true;
        }

        parent = parent.getParent();
    }

    return false;
}
 
源代码17 项目: droidtestrec   文件: ActivityProcessor.java
private AdapterView getAdaptedView(View view) {
    ViewParent parent = view.getParent();
    while (parent != null) {
        if (parent instanceof AdapterView) {
            return (AdapterView) parent;
        }
        parent = parent.getParent();
    }
    return null;
}
 
源代码18 项目: Trojan   文件: LancetHook.java
/**
 * 如果是ListView或RecyclerView的ItemView的话就返回index
 *
 * @param view
 * @return
 */
private static void setIndexIfNeed(View view, List<String> msgList) {
    if (view == null) {
        return;
    }
    int index = 0;
    ViewParent parent = view.getParent();
    while (true) {
        if (index > MAX_HIERARCHY_COUNT) {
            return;
        }
        if (null == parent || !(parent instanceof View)) {
            return;
        }
        if (parent instanceof ListView) {
            msgList.add(getItemInfo((View) parent, view));
            return;
        }
        if (parent instanceof RecyclerView) {
            msgList.add(getItemInfo((View) parent, view));
            return;
        }
        parent = parent.getParent();
        ++index;
    }

}
 
/**
 * Returns whether a given {@link View} will be focusable by Google's TalkBack screen reader.
 *
 * @param view The {@link View} to evaluate.
 * @return {@code boolean} if the view will be ignored by TalkBack.
 */
public static boolean isTalkbackFocusable(View view) {
  if (view == null) {
    return false;
  }

  final int important = ViewCompat.getImportantForAccessibility(view);
  if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO
      || important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
    return false;
  }

  // Go all the way up the tree to make sure no parent has hidden its descendants
  ViewParent parent = view.getParent();
  while (parent instanceof View) {
    if (ViewCompat.getImportantForAccessibility((View) parent)
        == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
      return false;
    }
    parent = parent.getParent();
  }

  // Trying to evaluate the focusability of certain element types (mainly list views) can cause
  // problems when trying to determine the offset of the elements Rect relative to its parent in
  // ViewGroup.offsetRectBetweenParentAndChild. If this happens, simply return false, as this view
  // will not be focusable.
  AccessibilityNodeInfoCompat node;
  try {
    node = createNodeInfoFromView(view);
  } catch (IllegalArgumentException e) {
    return false;
  }

  if (node == null) {
    return false;
  }

  // Non-leaf nodes identical in size to their Window should not be focusable.
  if (areBoundsIdenticalToWindow(node, view) && node.getChildCount() > 0) {
    return false;
  }

  try {
    if (!node.isVisibleToUser()) {
      return false;
    }

    if (isAccessibilityFocusable(node, view)) {
      if (!hasVisibleChildren(view)) {
        // Leaves that are accessibility focusable are never ignored, even if they don't have a
        // speakable description
        return true;
      } else if (isSpeakingNode(node, view)) {
        // Node is focusable and has something to speak
        return true;
      }

      // Node is focusable and has nothing to speak
      return false;
    }

    // if view is not accessibility focusable, it needs to have text and no focusable ancestors.
    if (!hasText(node)) {
      return false;
    }

    if (!hasFocusableAncestor(node, view)) {
      return true;
    }

    return false;
  } finally {
    node.recycle();
  }
}
 
源代码20 项目: SimplePomodoro-android   文件: SettingActivity.java
/** Sets up the action bar for an {@link PreferenceScreen} */
   @SuppressLint("NewApi")
public static void initializeActionBar(PreferenceScreen preferenceScreen) {
       final Dialog dialog = preferenceScreen.getDialog();

       if (dialog != null) {
           // Inialize the action bar
           dialog.getActionBar().setDisplayHomeAsUpEnabled(true);

           // Apply custom home button area click listener to close the PreferenceScreen because PreferenceScreens are dialogs which swallow
           // events instead of passing to the activity
           // Related Issue: https://code.google.com/p/android/issues/detail?id=4611
           View homeBtn = dialog.findViewById(android.R.id.home);

           if (homeBtn != null) {
               OnClickListener dismissDialogClickListener = new OnClickListener() {
                   @Override
                   public void onClick(View v) {
                       dialog.dismiss();
                   }
               };

               // Prepare yourselves for some hacky programming
               ViewParent homeBtnContainer = homeBtn.getParent();

               // The home button is an ImageView inside a FrameLayout
               if (homeBtnContainer instanceof FrameLayout) {
                   ViewGroup containerParent = (ViewGroup) homeBtnContainer.getParent();

                   if (containerParent instanceof LinearLayout) {
                       // This view also contains the title text, set the whole view as clickable
                       ((LinearLayout) containerParent).setOnClickListener(dismissDialogClickListener);
                   } else {
                       // Just set it on the home button
                       ((FrameLayout) homeBtnContainer).setOnClickListener(dismissDialogClickListener);
                   }
               } else {
                   // The 'If all else fails' default case
                   homeBtn.setOnClickListener(dismissDialogClickListener);
               }
           }    
       }
   }
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 方法所在类