Java Code Examples for android.view.ViewParent#getParent()
The following examples show how to use
android.view.ViewParent#getParent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsFragment.java From JPPF with Apache License 2.0 | 8 votes |
/** * 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); } } }
Example 2
Source File: HtmlView.java From htmlview with Apache License 2.0 | 6 votes |
/** * 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(); } } }
Example 3
Source File: ComponentHost.java From litho with Apache License 2.0 | 6 votes |
@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(); }
Example 4
Source File: MaterialScrollBar.java From MaterialScrollBar with Apache License 2.0 | 6 votes |
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(); } } } } }
Example 5
Source File: RobotoInflater.java From Android-RobotoTextView with Apache License 2.0 | 6 votes |
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(); } }
Example 6
Source File: Jzvd.java From imsdk-android with MIT License | 6 votes |
@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() + "] "); }
Example 7
Source File: ViewUtils.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 获取 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; }
Example 8
Source File: ZSwipeItem.java From ZListVIew with Apache License 2.0 | 6 votes |
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(); } }
Example 9
Source File: LancetHook.java From Trojan with Apache License 2.0 | 5 votes |
/** * 如果是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; } }
Example 10
Source File: ActivityProcessor.java From droidtestrec with Apache License 2.0 | 5 votes |
private AdapterView getAdaptedView(View view) { ViewParent parent = view.getParent(); while (parent != null) { if (parent instanceof AdapterView) { return (AdapterView) parent; } parent = parent.getParent(); } return null; }
Example 11
Source File: MenuDrawer.java From zhangshangwuda with Apache License 2.0 | 5 votes |
protected boolean isViewDescendant(View v) { ViewParent parent = v.getParent(); while (parent != null) { if (parent == this) { return true; } parent = parent.getParent(); } return false; }
Example 12
Source File: BaseSlider.java From material-components-android with Apache License 2.0 | 5 votes |
/** * 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; }
Example 13
Source File: TextInputEditText.java From material-components-android with Apache License 2.0 | 5 votes |
@Nullable private TextInputLayout getTextInputLayout() { ViewParent parent = getParent(); while (parent instanceof View) { if (parent instanceof TextInputLayout) { return (TextInputLayout) parent; } parent = parent.getParent(); } return null; }
Example 14
Source File: ContentScrollView.java From ScrollDownLayout with Apache License 2.0 | 5 votes |
@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(); } }
Example 15
Source File: SeekBarCompatDontCrash.java From SwipeBack with GNU General Public License v3.0 | 5 votes |
public static boolean isInScrollingContainer(ViewParent p) { while (p != null && p instanceof ViewGroup) { if (((ViewGroup) p).shouldDelayChildPressedState()) { return true; } p = p.getParent(); } return false; }
Example 16
Source File: MaterialRippleLayout.java From talk-android with MIT License | 5 votes |
private boolean isInScrollingContainer() { ViewParent p = getParent(); while (p != null && p instanceof ViewGroup) { if (((ViewGroup) p).shouldDelayChildPressedState()) { return true; } p = p.getParent(); } return false; }
Example 17
Source File: Jzvd.java From imsdk-android with MIT License | 5 votes |
@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(); } }
Example 18
Source File: SeekBarCompatDontCrash.java From FuAgoraDemoDroid with MIT License | 5 votes |
public static boolean isInScrollingContainer(ViewParent p) { while (p != null && p instanceof ViewGroup) { if (((ViewGroup) p).shouldDelayChildPressedState()) { return true; } p = p.getParent(); } return false; }
Example 19
Source File: SettingActivity.java From SimplePomodoro-android with MIT License | 4 votes |
/** 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); } } } }
Example 20
Source File: AccessibilityUtil.java From screenshot-tests-for-android with Apache License 2.0 | 4 votes |
/** * 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(); } }