Search in sources :

Example 31 with ViewRootImpl

use of android.view.ViewRootImpl in project platform_frameworks_base by android.

the class ActivityTransitionCoordinator method startInputWhenTransitionsComplete.

private void startInputWhenTransitionsComplete() {
    if (mViewsTransitionComplete && mSharedElementTransitionComplete) {
        final View decor = getDecor();
        if (decor != null) {
            final ViewRootImpl viewRoot = decor.getViewRootImpl();
            if (viewRoot != null) {
                viewRoot.setPausedForTransition(false);
            }
        }
        onTransitionsComplete();
    }
}
Also used : ViewRootImpl(android.view.ViewRootImpl) ImageView(android.widget.ImageView) GhostView(android.view.GhostView) View(android.view.View)

Example 32 with ViewRootImpl

use of android.view.ViewRootImpl in project platform_frameworks_base by android.

the class GridView method layoutChildren.

@Override
protected void layoutChildren() {
    final boolean blockLayoutRequests = mBlockLayoutRequests;
    if (!blockLayoutRequests) {
        mBlockLayoutRequests = true;
    }
    try {
        super.layoutChildren();
        invalidate();
        if (mAdapter == null) {
            resetList();
            invokeOnItemScrollListener();
            return;
        }
        final int childrenTop = mListPadding.top;
        final int childrenBottom = mBottom - mTop - mListPadding.bottom;
        int childCount = getChildCount();
        int index;
        int delta = 0;
        View sel;
        View oldSel = null;
        View oldFirst = null;
        View newSel = null;
        // Remember stuff we will need down below
        switch(mLayoutMode) {
            case LAYOUT_SET_SELECTION:
                index = mNextSelectedPosition - mFirstPosition;
                if (index >= 0 && index < childCount) {
                    newSel = getChildAt(index);
                }
                break;
            case LAYOUT_FORCE_TOP:
            case LAYOUT_FORCE_BOTTOM:
            case LAYOUT_SPECIFIC:
            case LAYOUT_SYNC:
                break;
            case LAYOUT_MOVE_SELECTION:
                if (mNextSelectedPosition >= 0) {
                    delta = mNextSelectedPosition - mSelectedPosition;
                }
                break;
            default:
                // Remember the previously selected view
                index = mSelectedPosition - mFirstPosition;
                if (index >= 0 && index < childCount) {
                    oldSel = getChildAt(index);
                }
                // Remember the previous first child
                oldFirst = getChildAt(0);
        }
        boolean dataChanged = mDataChanged;
        if (dataChanged) {
            handleDataChanged();
        }
        // and calling it a day
        if (mItemCount == 0) {
            resetList();
            invokeOnItemScrollListener();
            return;
        }
        setSelectedPositionInt(mNextSelectedPosition);
        AccessibilityNodeInfo accessibilityFocusLayoutRestoreNode = null;
        View accessibilityFocusLayoutRestoreView = null;
        int accessibilityFocusPosition = INVALID_POSITION;
        // Remember which child, if any, had accessibility focus. This must
        // occur before recycling any views, since that will clear
        // accessibility focus.
        final ViewRootImpl viewRootImpl = getViewRootImpl();
        if (viewRootImpl != null) {
            final View focusHost = viewRootImpl.getAccessibilityFocusedHost();
            if (focusHost != null) {
                final View focusChild = getAccessibilityFocusedChild(focusHost);
                if (focusChild != null) {
                    if (!dataChanged || focusChild.hasTransientState() || mAdapterHasStableIds) {
                        // The views won't be changing, so try to maintain
                        // focus on the current host and virtual view.
                        accessibilityFocusLayoutRestoreView = focusHost;
                        accessibilityFocusLayoutRestoreNode = viewRootImpl.getAccessibilityFocusedVirtualView();
                    }
                    // Try to maintain focus at the same position.
                    accessibilityFocusPosition = getPositionForView(focusChild);
                }
            }
        }
        // Pull all children into the RecycleBin.
        // These views will be reused if possible
        final int firstPosition = mFirstPosition;
        final RecycleBin recycleBin = mRecycler;
        if (dataChanged) {
            for (int i = 0; i < childCount; i++) {
                recycleBin.addScrapView(getChildAt(i), firstPosition + i);
            }
        } else {
            recycleBin.fillActiveViews(childCount, firstPosition);
        }
        // Clear out old views
        detachAllViewsFromParent();
        recycleBin.removeSkippedScrap();
        switch(mLayoutMode) {
            case LAYOUT_SET_SELECTION:
                if (newSel != null) {
                    sel = fillFromSelection(newSel.getTop(), childrenTop, childrenBottom);
                } else {
                    sel = fillSelection(childrenTop, childrenBottom);
                }
                break;
            case LAYOUT_FORCE_TOP:
                mFirstPosition = 0;
                sel = fillFromTop(childrenTop);
                adjustViewsUpOrDown();
                break;
            case LAYOUT_FORCE_BOTTOM:
                sel = fillUp(mItemCount - 1, childrenBottom);
                adjustViewsUpOrDown();
                break;
            case LAYOUT_SPECIFIC:
                sel = fillSpecific(mSelectedPosition, mSpecificTop);
                break;
            case LAYOUT_SYNC:
                sel = fillSpecific(mSyncPosition, mSpecificTop);
                break;
            case LAYOUT_MOVE_SELECTION:
                // Move the selection relative to its old position
                sel = moveSelection(delta, childrenTop, childrenBottom);
                break;
            default:
                if (childCount == 0) {
                    if (!mStackFromBottom) {
                        setSelectedPositionInt(mAdapter == null || isInTouchMode() ? INVALID_POSITION : 0);
                        sel = fillFromTop(childrenTop);
                    } else {
                        final int last = mItemCount - 1;
                        setSelectedPositionInt(mAdapter == null || isInTouchMode() ? INVALID_POSITION : last);
                        sel = fillFromBottom(last, childrenBottom);
                    }
                } else {
                    if (mSelectedPosition >= 0 && mSelectedPosition < mItemCount) {
                        sel = fillSpecific(mSelectedPosition, oldSel == null ? childrenTop : oldSel.getTop());
                    } else if (mFirstPosition < mItemCount) {
                        sel = fillSpecific(mFirstPosition, oldFirst == null ? childrenTop : oldFirst.getTop());
                    } else {
                        sel = fillSpecific(0, childrenTop);
                    }
                }
                break;
        }
        // Flush any cached views that did not get reused above
        recycleBin.scrapActiveViews();
        if (sel != null) {
            positionSelector(INVALID_POSITION, sel);
            mSelectedTop = sel.getTop();
        } else {
            final boolean inTouchMode = mTouchMode > TOUCH_MODE_DOWN && mTouchMode < TOUCH_MODE_SCROLL;
            if (inTouchMode) {
                // If the user's finger is down, select the motion position.
                final View child = getChildAt(mMotionPosition - mFirstPosition);
                if (child != null) {
                    positionSelector(mMotionPosition, child);
                }
            } else if (mSelectedPosition != INVALID_POSITION) {
                // If we had previously positioned the selector somewhere,
                // put it back there. It might not match up with the data,
                // but it's transitioning out so it's not a big deal.
                final View child = getChildAt(mSelectorPosition - mFirstPosition);
                if (child != null) {
                    positionSelector(mSelectorPosition, child);
                }
            } else {
                // Otherwise, clear selection.
                mSelectedTop = 0;
                mSelectorRect.setEmpty();
            }
        }
        // Attempt to restore accessibility focus, if necessary.
        if (viewRootImpl != null) {
            final View newAccessibilityFocusedView = viewRootImpl.getAccessibilityFocusedHost();
            if (newAccessibilityFocusedView == null) {
                if (accessibilityFocusLayoutRestoreView != null && accessibilityFocusLayoutRestoreView.isAttachedToWindow()) {
                    final AccessibilityNodeProvider provider = accessibilityFocusLayoutRestoreView.getAccessibilityNodeProvider();
                    if (accessibilityFocusLayoutRestoreNode != null && provider != null) {
                        final int virtualViewId = AccessibilityNodeInfo.getVirtualDescendantId(accessibilityFocusLayoutRestoreNode.getSourceNodeId());
                        provider.performAction(virtualViewId, AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
                    } else {
                        accessibilityFocusLayoutRestoreView.requestAccessibilityFocus();
                    }
                } else if (accessibilityFocusPosition != INVALID_POSITION) {
                    // Bound the position within the visible children.
                    final int position = MathUtils.constrain(accessibilityFocusPosition - mFirstPosition, 0, getChildCount() - 1);
                    final View restoreView = getChildAt(position);
                    if (restoreView != null) {
                        restoreView.requestAccessibilityFocus();
                    }
                }
            }
        }
        mLayoutMode = LAYOUT_NORMAL;
        mDataChanged = false;
        if (mPositionScrollAfterLayout != null) {
            post(mPositionScrollAfterLayout);
            mPositionScrollAfterLayout = null;
        }
        mNeedSync = false;
        setNextSelectedPositionInt(mSelectedPosition);
        updateScrollIndicators();
        if (mItemCount > 0) {
            checkSelectionChanged();
        }
        invokeOnItemScrollListener();
    } finally {
        if (!blockLayoutRequests) {
            mBlockLayoutRequests = false;
        }
    }
}
Also used : ViewRootImpl(android.view.ViewRootImpl) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) RemoteView(android.widget.RemoteViews.RemoteView) View(android.view.View) AccessibilityNodeProvider(android.view.accessibility.AccessibilityNodeProvider)

Example 33 with ViewRootImpl

use of android.view.ViewRootImpl in project platform_frameworks_base by android.

the class TextView method onEditorAction.

/**
     * Called when an attached input method calls
     * {@link InputConnection#performEditorAction(int)
     * InputConnection.performEditorAction()}
     * for this text view.  The default implementation will call your action
     * listener supplied to {@link #setOnEditorActionListener}, or perform
     * a standard operation for {@link EditorInfo#IME_ACTION_NEXT
     * EditorInfo.IME_ACTION_NEXT}, {@link EditorInfo#IME_ACTION_PREVIOUS
     * EditorInfo.IME_ACTION_PREVIOUS}, or {@link EditorInfo#IME_ACTION_DONE
     * EditorInfo.IME_ACTION_DONE}.
     *
     * <p>For backwards compatibility, if no IME options have been set and the
     * text view would not normally advance focus on enter, then
     * the NEXT and DONE actions received here will be turned into an enter
     * key down/up pair to go through the normal key handling.
     *
     * @param actionCode The code of the action being performed.
     *
     * @see #setOnEditorActionListener
     */
public void onEditorAction(int actionCode) {
    final Editor.InputContentType ict = mEditor == null ? null : mEditor.mInputContentType;
    if (ict != null) {
        if (ict.onEditorActionListener != null) {
            if (ict.onEditorActionListener.onEditorAction(this, actionCode, null)) {
                return;
            }
        }
        // app may be expecting.
        if (actionCode == EditorInfo.IME_ACTION_NEXT) {
            View v = focusSearch(FOCUS_FORWARD);
            if (v != null) {
                if (!v.requestFocus(FOCUS_FORWARD)) {
                    throw new IllegalStateException("focus search returned a view " + "that wasn't able to take focus!");
                }
            }
            return;
        } else if (actionCode == EditorInfo.IME_ACTION_PREVIOUS) {
            View v = focusSearch(FOCUS_BACKWARD);
            if (v != null) {
                if (!v.requestFocus(FOCUS_BACKWARD)) {
                    throw new IllegalStateException("focus search returned a view " + "that wasn't able to take focus!");
                }
            }
            return;
        } else if (actionCode == EditorInfo.IME_ACTION_DONE) {
            InputMethodManager imm = InputMethodManager.peekInstance();
            if (imm != null && imm.isActive(this)) {
                imm.hideSoftInputFromWindow(getWindowToken(), 0);
            }
            return;
        }
    }
    ViewRootImpl viewRootImpl = getViewRootImpl();
    if (viewRootImpl != null) {
        long eventTime = SystemClock.uptimeMillis();
        viewRootImpl.dispatchKeyFromIme(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE | KeyEvent.FLAG_EDITOR_ACTION));
        viewRootImpl.dispatchKeyFromIme(new KeyEvent(SystemClock.uptimeMillis(), eventTime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE | KeyEvent.FLAG_EDITOR_ACTION));
    }
}
Also used : ViewRootImpl(android.view.ViewRootImpl) KeyEvent(android.view.KeyEvent) InputMethodManager(android.view.inputmethod.InputMethodManager) RemoteView(android.widget.RemoteViews.RemoteView) View(android.view.View)

Example 34 with ViewRootImpl

use of android.view.ViewRootImpl in project android_frameworks_base by ParanoidAndroid.

the class StatusBarWindowView method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    latestItems = (NotificationRowLayout) findViewById(R.id.latestItems);
    mScrollView = (ScrollView) findViewById(R.id.scroll);
    mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
    int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
    int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
    mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight);
    mExpandHelper.setEventSource(this);
    mExpandHelper.setScrollView(mScrollView);
    // We really need to be able to animate while window animations are going on
    // so that activities may be started asynchronously from panel animations
    final ViewRootImpl root = getViewRootImpl();
    if (root != null) {
        root.setDrawDuringWindowsAnimating(true);
    }
}
Also used : ViewRootImpl(android.view.ViewRootImpl) ExpandHelper(com.android.systemui.ExpandHelper) Paint(android.graphics.Paint)

Example 35 with ViewRootImpl

use of android.view.ViewRootImpl in project android_frameworks_base by ParanoidAndroid.

the class WebViewClassic method setNewPicture.

void setNewPicture(final WebViewCore.DrawData draw, boolean updateBaseLayer) {
    if (mNativeClass == 0) {
        if (mDelaySetPicture != null) {
            throw new IllegalStateException("Tried to setNewPicture with" + " a delay picture already set! (memory leak)");
        }
        // Not initialized yet, delay set
        mDelaySetPicture = draw;
        return;
    }
    WebViewCore.ViewState viewState = draw.mViewState;
    boolean isPictureAfterFirstLayout = viewState != null;
    if (updateBaseLayer) {
        setBaseLayer(draw.mBaseLayer, getSettings().getShowVisualIndicator(), isPictureAfterFirstLayout);
    }
    final Point viewSize = draw.mViewSize;
    // We update the layout (i.e. request a layout from the
    // view system) if the last view size that we sent to
    // WebCore matches the view size of the picture we just
    // received in the fixed dimension.
    final boolean updateLayout = viewSize.x == mLastWidthSent && viewSize.y == mLastHeightSent;
    // Don't send scroll event for picture coming from webkit,
    // since the new picture may cause a scroll event to override
    // the saved history scroll position.
    mSendScrollEvent = false;
    recordNewContentSize(draw.mContentSize.x, draw.mContentSize.y, updateLayout);
    if (isPictureAfterFirstLayout) {
        // Reset the last sent data here since dealing with new page.
        mLastWidthSent = 0;
        mZoomManager.onFirstLayout(draw);
        int scrollX = viewState.mShouldStartScrolledRight ? getContentWidth() : viewState.mScrollX;
        int scrollY = viewState.mScrollY;
        contentScrollTo(scrollX, scrollY, false);
        if (!mDrawHistory) {
            // As we are on a new page, hide the keyboard
            hideSoftKeyboard();
        }
    }
    mSendScrollEvent = true;
    int functor = 0;
    boolean forceInval = isPictureAfterFirstLayout;
    ViewRootImpl viewRoot = mWebView.getViewRootImpl();
    if (mWebView.isHardwareAccelerated() && mWebView.getLayerType() != View.LAYER_TYPE_SOFTWARE && viewRoot != null) {
        functor = nativeGetDrawGLFunction(mNativeClass);
        if (functor != 0) {
            // force an invalidate if functor attach not successful
            forceInval |= !viewRoot.attachFunctor(functor);
        }
    }
    if (functor == 0 || forceInval || mWebView.getLayerType() != View.LAYER_TYPE_NONE) {
        // invalidate the screen so that the next repaint will show new content
        // TODO: partial invalidate
        mWebView.invalidate();
    }
    // update the zoom information based on the new picture
    if (mZoomManager.onNewPicture(draw))
        invalidate();
    if (isPictureAfterFirstLayout) {
        mViewManager.postReadyToDrawAll();
    }
    scrollEditWithCursor();
    if (mPictureListener != null) {
        if (!mWebView.isHardwareAccelerated() || mWebView.getLayerType() == View.LAYER_TYPE_SOFTWARE) {
            // trigger picture listener for software layers. Hardware layers are
            // triggered in pageSwapCallback
            Picture picture = mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR2 ? capturePicture() : null;
            mPictureListener.onNewPicture(getWebView(), picture);
        }
    }
}
Also used : ViewRootImpl(android.view.ViewRootImpl) Picture(android.graphics.Picture) Point(android.graphics.Point) Paint(android.graphics.Paint) Point(android.graphics.Point)

Aggregations

ViewRootImpl (android.view.ViewRootImpl)51 View (android.view.View)34 KeyEvent (android.view.KeyEvent)18 RemoteView (android.widget.RemoteViews.RemoteView)17 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)11 AccessibilityNodeProvider (android.view.accessibility.AccessibilityNodeProvider)11 GhostView (android.view.GhostView)10 ImageView (android.widget.ImageView)10 Paint (android.graphics.Paint)9 InputMethodManager (android.view.inputmethod.InputMethodManager)6 RemoteException (android.os.RemoteException)5 ViewManager (android.view.ViewManager)5 WindowManager (android.view.WindowManager)5 WebView (android.webkit.WebView)5 DecorView (com.android.internal.policy.DecorView)4 Point (android.graphics.Point)2 Display (android.view.Display)2 Activity (android.app.Activity)1 Picture (android.graphics.Picture)1 Rect (android.graphics.Rect)1