private void drawHelp(Canvas canvas, String header, String text) { headerPaint.setColor(Color.DKGRAY); canvas.drawText(header, 42, 2 + h / 2, headerPaint); headerPaint.setColor(Color.WHITE); canvas.drawText(header, 40, h / 2, headerPaint); int k = 0; String[] lines = breakText(text); textBounds.setEmpty(); textBounds.left = 40; textBounds.top = h / 2 + 10; int maxRight = 0; for (String string : lines) { textPaint.setColor(Color.DKGRAY); canvas.drawText( string, 42, 2 + headerFontSize / 2 + h / 2 + textLineHeight * (k) + 40, textPaint); textPaint.setColor(Color.WHITE); canvas.drawText( string, 40, headerFontSize / 2 + h / 2 + textLineHeight * (k++) + 40, textPaint); maxRight = Math.max(maxRight, 40 + (int) textPaint.measureText(string)); } textBounds.bottom = textBounds.top + (int) (textLineHeight * k); textBounds.set(40, h / 2 + 10, maxRight, textBounds.top + (int) (textLineHeight * k)); }
@Override protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfo node) { final boolean hasBounds = getBoundsForDay(virtualViewId, mTempRect); if (!hasBounds) { // The day is invalid, kill the node. mTempRect.setEmpty(); node.setContentDescription(""); node.setBoundsInParent(mTempRect); node.setVisibleToUser(false); return; } node.setText(getDayText(virtualViewId)); node.setContentDescription(getDayDescription(virtualViewId)); node.setBoundsInParent(mTempRect); final boolean isDayEnabled = isDayEnabled(virtualViewId); if (isDayEnabled) { node.addAction(AccessibilityAction.ACTION_CLICK); } node.setEnabled(isDayEnabled); if (virtualViewId == mActivatedDay) { // TODO: This should use activated once that's supported. node.setChecked(true); } }
/** * This is called with the size of the space not including the top or right insets, or the search * bar height in portrait (but including the search bar width in landscape, since we want to draw * under it. */ @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { // Layout each of the children int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { TaskView tv = (TaskView) getChildAt(i); if (tv.isFullScreenView()) { tv.layout(left, top, left + tv.getMeasuredWidth(), top + tv.getMeasuredHeight()); } else { if (tv.getBackground() != null) { tv.getBackground().getPadding(mTmpRect); } else { mTmpRect.setEmpty(); } tv.layout( mLayoutAlgorithm.mTaskRect.left - mTmpRect.left, mLayoutAlgorithm.mTaskRect.top - mTmpRect.top, mLayoutAlgorithm.mTaskRect.right + mTmpRect.right, mLayoutAlgorithm.mTaskRect.bottom + mTmpRect.bottom + tv.getMaxFooterHeight()); } } if (mAwaitingFirstLayout) { mAwaitingFirstLayout = false; onFirstLayout(); } }
private void updateRotation() { int oldRotation = rotation; rotation = getDeviceRotation(); if (oldRotation != rotation) { onKeyboardClose(); oldRect.setEmpty(); } }
@Override public void getItemOffsets( Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (parent.getChildAdapterPosition(view) == 0) { outRect.set(0, mLayout.getMeasuredHeight(), 0, 0); } else { outRect.setEmpty(); } }
public void invalidate(Rect dirtyRect) { if (dirtyRect != null) { mDirtyRect.set(dirtyRect); } else { mDirtyRect.setEmpty(); } mInvalidated = true; mWindowManagerService.scheduleAnimationLocked(); }
public void animation() { // TranslateAnimation ta = new TranslateAnimation(0, 0, inner.getTop(), // normal.top); // ta.setDuration(200); // inner.startAnimation(ta); ReBoundUtils.reBound_Translate(inner, inner.getTop(), normal.top); inner.layout(normal.left, normal.top, normal.right, normal.bottom); normal.setEmpty(); }
public void animation() { // 开启移动动画 TranslateAnimation ta = new TranslateAnimation(0, 0, inner.getTop(), normal.top); ta.setDuration(200); inner.startAnimation(ta); // 设置回到正常的布局位置 inner.layout(normal.left, normal.top, normal.right, normal.bottom); normal.setEmpty(); }
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); wasLayout = true; int opticalInsetLeft = 0; int opticalInsetRight = 0; if (mThumbDrawable != null) { final Rect trackPadding = mTempRect; if (mTrackDrawable != null) { mTrackDrawable.getPadding(trackPadding); } else { trackPadding.setEmpty(); } final Insets insets = Insets.NONE; opticalInsetLeft = Math.max(0, insets.left - trackPadding.left); opticalInsetRight = Math.max(0, insets.right - trackPadding.right); } final int switchRight; final int switchLeft; if (LocaleController.isRTL) { switchLeft = getPaddingLeft() + opticalInsetLeft; switchRight = switchLeft + mSwitchWidth - opticalInsetLeft - opticalInsetRight; } else { switchRight = getWidth() - getPaddingRight() - opticalInsetRight; switchLeft = switchRight - mSwitchWidth + opticalInsetLeft + opticalInsetRight; } final int switchTop; final int switchBottom; switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) { default: case Gravity.TOP: switchTop = getPaddingTop(); switchBottom = switchTop + mSwitchHeight; break; case Gravity.CENTER_VERTICAL: switchTop = (getPaddingTop() + getHeight() - getPaddingBottom()) / 2 - mSwitchHeight / 2; switchBottom = switchTop + mSwitchHeight; break; case Gravity.BOTTOM: switchBottom = getHeight() - getPaddingBottom(); switchTop = switchBottom - mSwitchHeight; break; } mSwitchLeft = switchLeft; mSwitchTop = switchTop; mSwitchBottom = switchBottom; mSwitchRight = switchRight; }
/** * Compute {@link Rect} in {@link #getParent()} coordinates that we should be clamped inside of, * usually from {@link #setValidRange(long, long)} style rules. */ private Rect computeClampRect(Rect parentContent) { // create two rectangles, and pick most restrictive combination final Rect rect = buildClampRect(parentContent, mValidAfter, mValidBefore, 0f); final Rect dynamicRect = buildClampRect( parentContent, getValidAfterDynamic(), getValidBeforeDynamic(), mNeighborMargin); if (!rect.intersect(dynamicRect)) { rect.setEmpty(); } return rect; }
@Implementation public boolean getGlobalVisibleRect(Rect rect, Point globalOffset) { if (globalVisibleRect == null) { /* * The global visible rect is not initialized. The value is not reliable as Robolectric does * not perform layouts in most cases. Use a substitute concept of visibility if no rect * had been set explicitly. */ rect.setEmpty(); return realView.isShown(); } if (!globalVisibleRect.isEmpty()) { rect.set(globalVisibleRect); if (globalOffset != null) { rect.offset(-globalOffset.x, -globalOffset.y); } return true; } rect.setEmpty(); return false; }
/** * You can call this function yourself to have the scroll view perform scrolling from a key event, * just as if the event had been dispatched to it by the view hierarchy. * * @param event The key event to execute. * @return Return true if the event was handled, else false. */ public boolean executeKeyEvent(KeyEvent event) { mTempRect.setEmpty(); if (!canScroll()) { if (isFocused()) { View currentFocused = findFocus(); if (currentFocused == this) currentFocused = null; View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN); return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN); } return false; } boolean handled = false; if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_UP: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_UP, false); } else { handled = fullScroll(View.FOCUS_UP, false); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_DOWN, false); } else { handled = fullScroll(View.FOCUS_DOWN, false); } break; case KeyEvent.KEYCODE_DPAD_LEFT: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_LEFT, true); } else { handled = fullScroll(View.FOCUS_LEFT, true); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_RIGHT, true); } else { handled = fullScroll(View.FOCUS_RIGHT, true); } break; } } return handled; }
private void handleFunctorStatus(View.AttachInfo attachInfo, int status) { // If the draw flag is set, functors will be invoked while executing // the tree of display lists if ((status & DisplayList.STATUS_DRAW) != 0) { if (mRedrawClip.isEmpty()) { attachInfo.mViewRootImpl.invalidate(); } else { attachInfo.mViewRootImpl.invalidateChildInParent(null, mRedrawClip); mRedrawClip.setEmpty(); } } if ((status & DisplayList.STATUS_INVOKE) != 0) { scheduleFunctors(attachInfo, true); } }
/** * You can call this function yourself to have the scroll view perform scrolling from a key event, * just as if the event had been dispatched to it by the view hierarchy. * * @param event The key event to execute. * @return Return true if the event was handled, else false. */ public boolean executeKeyEvent(KeyEvent event) { mTempRect.setEmpty(); boolean handled = false; if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { // case KeyEvent.KEYCODE_DPAD_LEFT: // if(canScrollH()){ // if (!event.isAltPressed()) { // handled = arrowScrollH(View.FOCUS_LEFT); // } else { // handled = fullScrollH(View.FOCUS_LEFT); // } // } // break; // case KeyEvent.KEYCODE_DPAD_RIGHT: // if(canScrollH()){ // if (!event.isAltPressed()) { // handled = arrowScrollH(View.FOCUS_RIGHT); // } else { // handled = fullScrollH(View.FOCUS_RIGHT); // } // } // break; case KeyEvent.KEYCODE_DPAD_UP: if (canScrollV()) { if (!event.isAltPressed()) { handled = arrowScrollV(View.FOCUS_UP); } else { handled = fullScrollV(View.FOCUS_UP); } } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (canScrollV()) { if (!event.isAltPressed()) { handled = arrowScrollV(View.FOCUS_DOWN); } else { handled = fullScrollV(View.FOCUS_DOWN); } } break; } } return handled; }
/** * This is called with the full window width and height to allow stack view children to perform * the full screen transition down. */ @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); // Compute our stack/task rects Rect taskStackBounds = new Rect(mTaskStackBounds); taskStackBounds.bottom -= mConfig.systemInsets.bottom; computeRects( width, height, taskStackBounds, mConfig.launchedWithAltTab, mConfig.launchedFromHome); // If this is the first layout, then scroll to the front of the stack and synchronize the // stack views immediately to load all the views if (mAwaitingFirstLayout) { mStackScroller.setStackScrollToInitialState(); requestSynchronizeStackViewsWithModel(); synchronizeStackViewsWithModel(); } // Measure each of the TaskViews int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { TaskView tv = (TaskView) getChildAt(i); if (tv.isFullScreenView()) { tv.measure(widthMeasureSpec, heightMeasureSpec); } else { if (tv.getBackground() != null) { tv.getBackground().getPadding(mTmpRect); } else { mTmpRect.setEmpty(); } tv.measure( MeasureSpec.makeMeasureSpec( mLayoutAlgorithm.mTaskRect.width() + mTmpRect.left + mTmpRect.right, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec( mLayoutAlgorithm.mTaskRect.height() + mTmpRect.top + mTmpRect.bottom + tv.getMaxFooterHeight(), MeasureSpec.EXACTLY)); } } setMeasuredDimension(width, height); }
@Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final Rect padding = mTempRect; int thumbWidth; int thumbHeight; if (mThumbDrawable != null) { mThumbDrawable.getPadding(padding); thumbWidth = mThumbDrawable.getIntrinsicWidth() - padding.left - padding.right; thumbHeight = mThumbDrawable.getIntrinsicHeight(); } else { thumbWidth = 0; thumbHeight = 0; } mThumbWidth = thumbWidth; int trackHeight; if (mTrackDrawable != null) { mTrackDrawable.getPadding(padding); trackHeight = mTrackDrawable.getIntrinsicHeight(); } else { padding.setEmpty(); trackHeight = 0; } int paddingLeft = padding.left; int paddingRight = padding.right; if (mThumbDrawable != null) { final Insets inset = Insets.NONE; paddingLeft = Math.max(paddingLeft, inset.left); paddingRight = Math.max(paddingRight, inset.right); } final int switchWidth = Math.max(mSwitchMinWidth, 2 * mThumbWidth + paddingLeft + paddingRight); final int switchHeight = Math.max(trackHeight, thumbHeight); mSwitchWidth = switchWidth; mSwitchHeight = switchHeight; super.onMeasure(widthMeasureSpec, heightMeasureSpec); final int measuredHeight = getMeasuredHeight(); if (measuredHeight < switchHeight) { setMeasuredDimension(switchWidth, switchHeight); } }
/** * Updates the selection rectangle and attempts to shift focus away from the provided view. Clears * active TTS. * * @param view */ private void announceSelectionLost(View view) { // TODO(alanv): Add an additional TYPE_VIEW_HOVER_OFF event type that // fires a KickBack vibration and (probably) clears active TalkBack // utterances. if (mSpeechAvailable) { mTTS.speak("", TextToSpeech.QUEUE_FLUSH, null); } if (mVibrator != null) { if (view.isFocusable()) { mVibrator.vibrate(mFocusLostFocusablePattern, -1); } else { mVibrator.vibrate(mFocusLostPattern, -1); } } mSelectedRect.setEmpty(); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Rect padding = mTempRect; final Drawable trackDrawable = mTrackDrawable; if (trackDrawable != null) { trackDrawable.getPadding(padding); } else { padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final int switchInnerTop = switchTop + padding.top; final int switchInnerBottom = switchBottom - padding.bottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { if (mSplitTrack && thumbDrawable != null) { final Insets insets = Insets.NONE; thumbDrawable.copyBounds(padding); padding.left += insets.left; padding.right -= insets.right; final int saveCount = canvas.save(); canvas.clipRect(padding, Region.Op.DIFFERENCE); trackDrawable.draw(canvas); canvas.restoreToCount(saveCount); } else { trackDrawable.draw(canvas); } } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } canvas.restoreToCount(saveCount); }
@Override public void draw(final Canvas canvas) { boolean verticalStartWhite = true; for (int i = 0; i <= mNumRectanglesVertical; i++) { boolean horizontalStartWhite = verticalStartWhite; for (int j = 0; j <= mNumRectanglesHorizontal; j++) { mRect.setEmpty(); mRect.top = i * mAlphaPatternSize + mBounds.top; mRect.left = j * mAlphaPatternSize + mBounds.left; mRect.bottom = Math.min(mRect.top + mAlphaPatternSize, mBounds.bottom); mRect.right = Math.min(mRect.left + mAlphaPatternSize, mBounds.right); mPaint.setColor(horizontalStartWhite ? Color.WHITE : Color.LTGRAY); canvas.drawRect(mRect, mPaint); horizontalStartWhite = !horizontalStartWhite; } verticalStartWhite = !verticalStartWhite; } }
private void rollBackAnimation() { TranslateAnimation tranAnim = new TranslateAnimation(0, 0, Math.abs(mInitTop - mCurrentTop), 0); tranAnim.setDuration(200); mHeader.startAnimation(tranAnim); mHeader.layout(mHeader.getLeft(), mInitTop, mHeader.getRight(), mInitBottom); // 开启移动动画 TranslateAnimation innerAnim = new TranslateAnimation(0, 0, mContentView.getTop(), mContentRect.top); innerAnim.setDuration(200); mContentView.startAnimation(innerAnim); mContentView.layout( mContentRect.left, mContentRect.top, mContentRect.right, mContentRect.bottom); mContentRect.setEmpty(); // 回调监听器 if (mCurrentTop > mInitTop + TURN_DISTANCE && mOnTurnListener != null) { mOnTurnListener.onTurn(); } }
// convert image of link to bitmap protected Bitmap doInBackground(String... args) { Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeStream((InputStream) new URL(args[0]).getContent()); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Rect padding = new Rect(); padding.setEmpty(); BitmapFactory.decodeStream((InputStream) new URL(args[0]).getContent(), padding, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, 192, 192); options.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeStream( (InputStream) new URL(args[0]).getContent(), padding, options); } catch (Exception e) { e.printStackTrace(); Log.d("failed to decode bitmap", "failed to decode bitmap"); } return bitmap; }
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Measure our width in whatever mode specified final int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); // Determine our height float height; final int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec); if (heightSpecMode == MeasureSpec.EXACTLY) { // We were told how big to be height = MeasureSpec.getSize(heightMeasureSpec); } else { // Calculate the text bounds mBounds.setEmpty(); mBounds.bottom = (int) (mPaintText.descent() - mPaintText.ascent()); height = mBounds.bottom - mBounds.top + mFooterLineHeight + mFooterPadding + mTopPadding; if (mFooterIndicatorStyle != IndicatorStyle.None) { height += mFooterIndicatorHeight; } } final int measuredHeight = (int) height; setMeasuredDimension(measuredWidth, measuredHeight); }
void startInputInner() { final View view; synchronized (mH) { view = mServedView; // Make sure we have a window token for the served view. if (DEBUG) Log.v(TAG, "Starting input: view=" + view); if (view == null) { if (DEBUG) Log.v(TAG, "ABORT input: no served view!"); return; } } // Now we need to get an input connection from the served view. // This is complicated in a couple ways: we can't be holding our lock // when calling out to the view, and we need to make sure we call into // the view on the same thread that is driving its view hierarchy. Handler vh = view.getHandler(); if (vh == null) { // If the view doesn't have a handler, something has changed out // from under us, so just bail. if (DEBUG) Log.v(TAG, "ABORT input: no handler for view!"); return; } if (vh.getLooper() != Looper.myLooper()) { // The view is running on a different thread than our own, so // we need to reschedule our work for over there. if (DEBUG) Log.v(TAG, "Starting input: reschedule to view thread"); vh.post( new Runnable() { public void run() { startInputInner(); } }); return; } // Okay we are now ready to call into the served view and have it // do its stuff. // Life is good: let's hook everything up! EditorInfo tba = new EditorInfo(); tba.packageName = view.getContext().getPackageName(); tba.fieldId = view.getId(); InputConnection ic = view.onCreateInputConnection(tba); if (DEBUG) Log.v(TAG, "Starting input: tba=" + tba + " ic=" + ic); synchronized (mH) { // Now that we are locked again, validate that our state hasn't // changed. if (mServedView != view || !mServedConnecting) { // Something else happened, so abort. if (DEBUG) Log.v( TAG, "Starting input: finished by someone else (view=" + mServedView + " conn=" + mServedConnecting + ")"); return; } // If we already have a text box, then this view is already // connected so we want to restart it. final boolean initial = mCurrentTextBoxAttribute == null; // Hook 'em up and let 'er rip. mCurrentTextBoxAttribute = tba; mServedConnecting = false; mServedInputConnection = ic; IInputContext servedContext; if (ic != null) { mCursorSelStart = tba.initialSelStart; mCursorSelEnd = tba.initialSelEnd; mCursorCandStart = -1; mCursorCandEnd = -1; mCursorRect.setEmpty(); servedContext = new ControlledInputConnectionWrapper(vh.getLooper(), ic); } else { servedContext = null; } try { if (DEBUG) Log.v(TAG, "START INPUT: " + view + " ic=" + ic + " tba=" + tba + " initial=" + initial); InputBindResult res = mService.startInput(mClient, servedContext, tba, initial, mCurMethod == null); if (DEBUG) Log.v(TAG, "Starting input: Bind result=" + res); if (res != null) { if (res.id != null) { mBindSequence = res.sequence; mCurMethod = res.method; } else { // This means there is no input method available. if (DEBUG) Log.v(TAG, "ABORT input: no input method!"); return; } } if (mCurMethod != null && mCompletions != null) { try { mCurMethod.displayCompletions(mCompletions); } catch (RemoteException e) { } } } catch (RemoteException e) { Log.w(TAG, "IME died: " + mCurId, e); } } }
public void recycle() { mWindowState = null; mTouchableRegion.setEmpty(); sPool.release(this); }
public Rect get() { Rect rect = super.get(); rect.setEmpty(); return rect; };