Java Code Examples for android.view.View#getRootView()

The following examples show how to use android.view.View#getRootView() . 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: InputMethodManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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 File: ViewServer.java    From COCOFramework with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: TextBubble.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * 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 4
Source File: ViewUtils.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/** 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 5
Source File: ViewServer.java    From fingen with Apache License 2.0 6 votes vote down vote up
/**
 * 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 File: ViewServer.java    From ZoomPreviewPicture with Apache License 2.0 6 votes vote down vote up
/**
 * 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 7
Source File: MainFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@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 8
Source File: PopupWindow.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** @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 9
Source File: UIHelpers.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
public static int getRelativeLeft(View myView)
{
	if (myView.getParent() == myView.getRootView())
		return myView.getLeft();
	else
		return myView.getLeft() + UIHelpers.getRelativeLeft((View) myView.getParent());
}
 
Example 10
Source File: ViewServer.java    From fingen with Apache License 2.0 5 votes vote down vote up
/**
 * 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 File: ViewServer.java    From COCOFramework with Apache License 2.0 5 votes vote down vote up
/**
 * 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 12
Source File: DailyQuotesFragment.java    From Travel-Mate with MIT License 5 votes vote down vote up
/**
 * 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 13
Source File: Util.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
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 14
Source File: ViewServer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 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 15
Source File: ViewServer.java    From UTubeTV with The Unlicense 5 votes vote down vote up
/**
 * 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 File: ViewServer.java    From KlyphMessenger with MIT License 5 votes vote down vote up
/**
* 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 File: SettingsAdapter.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
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 File: ViewServer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 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 File: PopupDialog.java    From zom-android-matrix with Apache License 2.0 4 votes vote down vote up
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 File: ViewUtil.java    From fab-transformation with MIT License 4 votes vote down vote up
public static int getRelativeTop(View view) {
    if (view.getParent() == view.getRootView())
        return view.getTop();
    else
        return view.getTop() + getRelativeTop((View) view.getParent());
}