android.view.View#getRootView ( )源码实例Demo

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

源代码1 项目: android_9.0.0_r45   文件: InputMethodManager.java
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);
}
 
源代码2 项目: android_9.0.0_r45   文件: PopupWindow.java
/** @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;
}
 
源代码3 项目: prayer-times-android   文件: MainFragment.java
@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);
    }
}
 
源代码4 项目: ZoomPreviewPicture   文件: ViewServer.java
/**
 * 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();
}
 
源代码5 项目: fingen   文件: ViewServer.java
/**
 * 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();
}
 
源代码6 项目: material-components-android   文件: ViewUtils.java
/** 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;
}
 
源代码7 项目: 365browser   文件: TextBubble.java
/**
 * 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));
}
 
源代码8 项目: COCOFramework   文件: ViewServer.java
/**
 * 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();
}
 
源代码9 项目: UTubeTV   文件: ViewServer.java
/**
 * 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();
}
 
源代码10 项目: COCOFramework   文件: ViewServer.java
/**
 * 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();
}
 
源代码11 项目: CameraV   文件: UIHelpers.java
public static int getRelativeLeft(View myView)
{
	if (myView.getParent() == myView.getRootView())
		return myView.getLeft();
	else
		return myView.getLeft() + UIHelpers.getRelativeLeft((View) myView.getParent());
}
 
源代码12 项目: fingen   文件: ViewServer.java
/**
 * 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();
}
 
源代码13 项目: Travel-Mate   文件: DailyQuotesFragment.java
/**
 * 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;
}
 
源代码14 项目: RetroMusicPlayer   文件: Util.java
public static Bitmap getScreenShot(View view) {
    View screenView = view.getRootView();
    screenView.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
    screenView.setDrawingCacheEnabled(false);
    return bitmap;
}
 
源代码15 项目: UltimateAndroid   文件: ViewServer.java
/**
 * 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();
}
 
源代码16 项目: KlyphMessenger   文件: ViewServer.java
/**
* 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();
    }
 
源代码17 项目: wallpaperboard   文件: SettingsAdapter.java
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);
    }
}
 
源代码18 项目: UltimateAndroid   文件: ViewServer.java
/**
 * 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();
}
 
源代码19 项目: zom-android-matrix   文件: PopupDialog.java
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;
}
 
源代码20 项目: fab-transformation   文件: ViewUtil.java
public static int getRelativeTop(View view) {
    if (view.getParent() == view.getRootView())
        return view.getTop();
    else
        return view.getTop() + getRelativeTop((View) view.getParent());
}
 
 方法所在类
 同类方法