Java Code Examples for android.view.View#getRootView()
The following examples show how to use
android.view.View#getRootView() .
These examples are extracted from open source projects.
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 Project: android_9.0.0_r45 File: InputMethodManager.java License: Apache License 2.0 | 6 votes |
void focusInLocked(View view) { if (DEBUG) Log.v(TAG, "focusIn: " + dumpViewInfo(view)); if (view != null && view.isTemporarilyDetached()) { // This is a request from a view that is temporarily detached from a window. if (DEBUG) Log.v(TAG, "Temporarily detached view, ignoring"); return; } if (mCurRootView != view.getRootView()) { // This is a request from a window that isn't in the window with // IME focus, so ignore it. if (DEBUG) Log.v(TAG, "Not IME target window, ignoring"); return; } mNextServedView = view; scheduleCheckFocusLocked(view); }
Example 2
Source Project: android_9.0.0_r45 File: PopupWindow.java License: Apache License 2.0 | 6 votes |
/** @hide */ protected void attachToAnchor(View anchor, int xoff, int yoff, int gravity) { detachFromAnchor(); final ViewTreeObserver vto = anchor.getViewTreeObserver(); if (vto != null) { vto.addOnScrollChangedListener(mOnScrollChangedListener); } anchor.addOnAttachStateChangeListener(mOnAnchorDetachedListener); final View anchorRoot = anchor.getRootView(); anchorRoot.addOnAttachStateChangeListener(mOnAnchorRootDetachedListener); anchorRoot.addOnLayoutChangeListener(mOnLayoutChangeListener); mAnchor = new WeakReference<>(anchor); mAnchorRoot = new WeakReference<>(anchorRoot); mIsAnchorRootAttached = anchorRoot.isAttachedToWindow(); mParentRootView = mAnchorRoot; mAnchorXoff = xoff; mAnchorYoff = yoff; mAnchoredGravity = gravity; }
Example 3
Source Project: prayer-times-android File: MainFragment.java License: Apache License 2.0 | 6 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (Preferences.SHOW_COMPASS_NOTE.get()) { final ViewGroup root = (ViewGroup) (view.getRootView()); final View toast = LayoutInflater.from(getActivity()).inflate(R.layout.compass_toast_menu, root, false); root.addView(toast); toast.setOnClickListener(v -> root.removeView(toast)); toast.postDelayed(() -> { if (toast.getRootView() == root) root.removeView(toast); }, 10000); } }
Example 4
Source Project: ZoomPreviewPicture File: ViewServer.java License: Apache License 2.0 | 6 votes |
/** * Invoke this method to unregister a view hierarchy. * * @param view A view that belongs to the view hierarchy/window to unregister * * @see #addWindow(View, String) */ public void removeWindow(View view) { View rootView; mWindowsLock.writeLock().lock(); try { rootView = view.getRootView(); mWindows.remove(rootView); } finally { mWindowsLock.writeLock().unlock(); } mFocusLock.writeLock().lock(); try { if (mFocusedWindow == rootView) { mFocusedWindow = null; } } finally { mFocusLock.writeLock().unlock(); } fireWindowsChangedEvent(); }
Example 5
Source Project: fingen File: ViewServer.java License: Apache License 2.0 | 6 votes |
/** * Invoke this method to unregister a view hierarchy. * * @param view A view that belongs to the view hierarchy/window to unregister * * @see #addWindow(View, String) */ public void removeWindow(View view) { View rootView; mWindowsLock.writeLock().lock(); try { rootView = view.getRootView(); mWindows.remove(rootView); } finally { mWindowsLock.writeLock().unlock(); } mFocusLock.writeLock().lock(); try { if (mFocusedWindow == rootView) { mFocusedWindow = null; } } finally { mFocusLock.writeLock().unlock(); } fireWindowsChangedEvent(); }
Example 6
Source Project: material-components-android File: ViewUtils.java License: Apache License 2.0 | 6 votes |
/** Returns the content view that is the parent of the provided view. */ @Nullable public static ViewGroup getContentView(@Nullable View view) { if (view == null) { return null; } View rootView = view.getRootView(); ViewGroup contentView = rootView.findViewById(android.R.id.content); if (contentView != null) { return contentView; } // Account for edge cases: Parent's parent can be null without ever having found // android.R.id.content (e.g. if view is in an overlay during a transition). // Additionally, sometimes parent's parent is neither a ViewGroup nor a View (e.g. if view // is in a PopupWindow). if (rootView != view && rootView instanceof ViewGroup) { return (ViewGroup) rootView; } return null; }
Example 7
Source Project: 365browser File: TextBubble.java License: Apache License 2.0 | 6 votes |
/** * Constructs a {@link TextBubble} instance. * @param context Context to draw resources from. * @param rootView The {@link View} to use for size calculations and for display. * @param stringId The id of the string resource for the text that should be shown. * @param accessibilityStringId The id of the string resource of the accessibility text. */ public TextBubble(Context context, View rootView, @StringRes int stringId, @StringRes int accessibilityStringId) { mContext = context; mRootView = rootView.getRootView(); mStringId = stringId; mAccessibilityStringId = accessibilityStringId; mPopupWindow = new PopupWindow(mContext); mDrawable = new ArrowBubbleDrawable(context); mHandler = new Handler(); mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); mPopupWindow.setBackgroundDrawable(mDrawable); mPopupWindow.setAnimationStyle(R.style.TextBubbleAnimation); mPopupWindow.setTouchInterceptor(this); mPopupWindow.setOnDismissListener(mDismissListener); mMarginPx = context.getResources().getDimensionPixelSize(R.dimen.text_bubble_margin); // Set predefined styles for the TextBubble. mDrawable.setBubbleColor( ApiCompatibilityUtils.getColor(mContext.getResources(), R.color.google_blue_500)); }
Example 8
Source Project: COCOFramework File: ViewServer.java License: Apache License 2.0 | 6 votes |
/** * Invoke this method to unregister a view hierarchy. * * @param view A view that belongs to the view hierarchy/window to unregister * @see #addWindow(View, String) */ public void removeWindow(View view) { View rootView; mWindowsLock.writeLock().lock(); try { rootView = view.getRootView(); mWindows.remove(rootView); } finally { mWindowsLock.writeLock().unlock(); } mFocusLock.writeLock().lock(); try { if (mFocusedWindow == rootView) { mFocusedWindow = null; } } finally { mFocusLock.writeLock().unlock(); } fireWindowsChangedEvent(); }
Example 9
Source Project: UTubeTV File: ViewServer.java License: The Unlicense | 5 votes |
/** * Invoke this method to change the currently focused window. * * @param view A view that belongs to the view hierarchy/window that has focus, * or null to remove focus */ public void setFocusedWindow(View view) { mFocusLock.writeLock().lock(); try { mFocusedWindow = view == null ? null : view.getRootView(); } finally { mFocusLock.writeLock().unlock(); } fireFocusChangedEvent(); }
Example 10
Source Project: COCOFramework File: ViewServer.java License: Apache License 2.0 | 5 votes |
/** * Invoke this method to change the currently focused window. * * @param view A view that belongs to the view hierarchy/window that has focus, * or null to remove focus */ public void setFocusedWindow(View view) { mFocusLock.writeLock().lock(); try { mFocusedWindow = view == null ? null : view.getRootView(); } finally { mFocusLock.writeLock().unlock(); } fireFocusChangedEvent(); }
Example 11
Source Project: CameraV File: UIHelpers.java License: GNU General Public License v3.0 | 5 votes |
public static int getRelativeLeft(View myView) { if (myView.getParent() == myView.getRootView()) return myView.getLeft(); else return myView.getLeft() + UIHelpers.getRelativeLeft((View) myView.getParent()); }
Example 12
Source Project: fingen File: ViewServer.java License: Apache License 2.0 | 5 votes |
/** * Invoke this method to change the currently focused window. * * @param view A view that belongs to the view hierarchy/window that has focus, * or null to remove focus */ public void setFocusedWindow(View view) { mFocusLock.writeLock().lock(); try { mFocusedWindow = view == null ? null : view.getRootView(); } finally { mFocusLock.writeLock().unlock(); } fireFocusChangedEvent(); }
Example 13
Source Project: Travel-Mate File: DailyQuotesFragment.java License: MIT License | 5 votes |
/** * Takes screenshot of current screen * * @param view to be taken screenshot of * @return bitmap of the screenshot */ private static Bitmap getScreenShot(View view) { View screenView = view.getRootView(); screenView.setDrawingCacheEnabled(true); Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache()); screenView.setDrawingCacheEnabled(false); return bitmap; }
Example 14
Source Project: RetroMusicPlayer File: Util.java License: GNU General Public License v3.0 | 5 votes |
public static Bitmap getScreenShot(View view) { View screenView = view.getRootView(); screenView.setDrawingCacheEnabled(true); Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache()); screenView.setDrawingCacheEnabled(false); return bitmap; }
Example 15
Source Project: UltimateAndroid File: ViewServer.java License: Apache License 2.0 | 5 votes |
/** * Invoke this method to change the currently focused window. * * @param view A view that belongs to the view hierarchy/window that has focus, * or null to remove focus */ public void setFocusedWindow(View view) { mFocusLock.writeLock().lock(); try { mFocusedWindow = view == null ? null : view.getRootView(); } finally { mFocusLock.writeLock().unlock(); } fireFocusChangedEvent(); }
Example 16
Source Project: KlyphMessenger File: ViewServer.java License: MIT License | 5 votes |
/** * Invoke this method to change the currently focused window. * * @param view A view that belongs to the view hierarchy/window that has focus, * or null to remove focus */ public void setFocusedWindow(View view) { mFocusLock.writeLock().lock(); try { mFocusedWindow = view == null ? null : view.getRootView(); } finally { mFocusLock.writeLock().unlock(); } fireFocusChangedEvent(); }
Example 17
Source Project: wallpaperboard File: SettingsAdapter.java License: Apache License 2.0 | 5 votes |
FooterViewHolder(View itemView) { super(itemView); if (!Preferences.get(mContext).isShadowEnabled()) { View shadow = itemView.findViewById(R.id.shadow); shadow.setVisibility(View.GONE); View root = shadow.getRootView(); root.setPadding(0, 0, 0, 0); } }
Example 18
Source Project: UltimateAndroid File: ViewServer.java License: Apache License 2.0 | 5 votes |
/** * Invoke this method to change the currently focused window. * * @param view A view that belongs to the view hierarchy/window that has focus, * or null to remove focus */ public void setFocusedWindow(View view) { mFocusLock.writeLock().lock(); try { mFocusedWindow = view == null ? null : view.getRootView(); } finally { mFocusLock.writeLock().unlock(); } fireFocusChangedEvent(); }
Example 19
Source Project: zom-android-matrix File: PopupDialog.java License: Apache License 2.0 | 4 votes |
public static Dialog showPopupFromAnchor(final View anchor, int idLayout, boolean cancelable) { try { if (anchor == null || idLayout == 0) { return null; } final Context context = anchor.getContext(); View rootView = anchor.getRootView(); Rect rectAnchor = new Rect(); int[] location = new int[2]; anchor.getLocationInWindow(location); rectAnchor.set(location[0], location[1], location[0] + anchor.getWidth(), location[1] + anchor.getHeight()); Rect rectRoot = new Rect(); rootView.getLocationInWindow(location); rectRoot.set(location[0], location[1], location[0] + rootView.getWidth(), location[1] + rootView.getHeight()); final Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar); View dialogView = LayoutInflater.from(context).inflate(idLayout, (ViewGroup)anchor.getRootView(), false); dialogView.measure( View.MeasureSpec.makeMeasureSpec(rectRoot.width(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec((rectAnchor.top - rectRoot.top), View.MeasureSpec.AT_MOST)); dialog.setTitle(null); dialog.setContentView(dialogView); dialog.setCancelable(true); // Setting dialogview Window window = dialog.getWindow(); WindowManager.LayoutParams wlp = window.getAttributes(); wlp.x = rectAnchor.left - PopupDialog.dpToPx(20, context); wlp.y = rectAnchor.top - dialogView.getMeasuredHeight(); wlp.width = dialogView.getMeasuredWidth(); wlp.height = dialogView.getMeasuredHeight(); wlp.gravity = Gravity.TOP | Gravity.START; wlp.dimAmount = 0.6f; wlp.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND; window.setAttributes(wlp); if (cancelable) { dialog.setCanceledOnTouchOutside(true); } View btnClose = dialogView.findViewById(R.id.btnClose); if (btnClose != null) { btnClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); } dialog.show(); return dialog; } catch (Exception e) { e.printStackTrace(); } return null; }
Example 20
Source Project: fab-transformation File: ViewUtil.java License: MIT License | 4 votes |
public static int getRelativeTop(View view) { if (view.getParent() == view.getRootView()) return view.getTop(); else return view.getTop() + getRelativeTop((View) view.getParent()); }