Esempio n. 1
0
 public override int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm)
 {
     LOCAL_PAINT.set(paint);
     applyCustomTypeFace(LOCAL_PAINT, type);
     LOCAL_PAINT.getTextBounds(icon, 0, 1, TEXT_BOUNDS);
     if (fm != null)
     {
         fm.descent = (int)(TEXT_BOUNDS.height() * BASELINE_RATIO);
         fm.ascent  = -(TEXT_BOUNDS.height() - fm.descent);
         fm.top     = fm.ascent;
         fm.bottom  = fm.descent;
     }
     return(TEXT_BOUNDS.width());
 }
Esempio n. 2
0
        protected internal override void onBoundsChange(android.graphics.Rect bounds)
        {
            android.graphics.Rect r = mTmpRect;
            bool min   = mScaleState.mUseIntrinsicSizeAsMin;
            int  level = getLevel();
            int  w     = bounds.width();

            if (mScaleState.mScaleWidth > 0)
            {
                int iw = min ? mScaleState.mDrawable.getIntrinsicWidth() : 0;
                w -= (int)((w - iw) * (10000 - level) * mScaleState.mScaleWidth / 10000);
            }
            int h = bounds.height();

            if (mScaleState.mScaleHeight > 0)
            {
                int ih = min ? mScaleState.mDrawable.getIntrinsicHeight() : 0;
                h -= (int)((h - ih) * (10000 - level) * mScaleState.mScaleHeight / 10000);
            }
            int layoutDirection = getResolvedLayoutDirectionSelf();

            android.view.Gravity.apply(mScaleState.mGravity, w, h, bounds, r, layoutDirection
                                       );
            if (w > 0 && h > 0)
            {
                mScaleState.mDrawable.setBounds(r.left, r.top, r.right, r.bottom);
            }
        }
Esempio n. 3
0
        public virtual bool onLongClick(android.view.View v)
        {
            if (hasText())
            {
                // Don't show the cheat sheet for items that already show text.
                return(false);
            }
            int[] screenPos = new int[2];
            android.graphics.Rect displayFrame = new android.graphics.Rect();
            getLocationOnScreen(screenPos);
            getWindowVisibleDisplayFrame(displayFrame);
            android.content.Context context = getContext();
            int width       = getWidth();
            int height      = getHeight();
            int midy        = screenPos[1] + height / 2;
            int screenWidth = context.getResources().getDisplayMetrics().widthPixels;

            android.widget.Toast cheatSheet = android.widget.Toast.makeText(context, mItemData
                                                                            .getTitle(), android.widget.Toast.LENGTH_SHORT);
            if (midy < displayFrame.height())
            {
                // Show along the top; follow action buttons
                cheatSheet.setGravity(android.view.Gravity.TOP | android.view.Gravity.RIGHT, screenWidth
                                      - screenPos[0] - width / 2, height);
            }
            else
            {
                // Show along the bottom center
                cheatSheet.setGravity(android.view.Gravity.BOTTOM | android.view.Gravity.CENTER_HORIZONTAL
                                      , 0, height);
            }
            cheatSheet.show();
            return(true);
        }
 private static int getPageHeight(android.widget.TextView widget)
 {
     // This calculation does not take into account the view transformations that
     // may have been applied to the child or its containers.  In case of scaling or
     // rotation, the calculated page height may be incorrect.
     android.graphics.Rect rect = new android.graphics.Rect();
     return(widget.getGlobalVisibleRect(rect) ? rect.height() : 0);
 }
Esempio n. 5
0
		private static int getPageHeight(android.widget.TextView widget)
		{
			// This calculation does not take into account the view transformations that
			// may have been applied to the child or its containers.  In case of scaling or
			// rotation, the calculated page height may be incorrect.
			android.graphics.Rect rect = new android.graphics.Rect();
			return widget.getGlobalVisibleRect(rect) ? rect.height() : 0;
		}
Esempio n. 6
0
        public override void draw(android.graphics.Canvas canvas)
        {
            bool vertical    = mVertical;
            int  extent      = mExtent;
            int  range       = mRange;
            bool drawTrack_1 = true;
            bool drawThumb_1 = true;

            if (extent <= 0 || range <= extent)
            {
                drawTrack_1 = vertical ? mAlwaysDrawVerticalTrack : mAlwaysDrawHorizontalTrack;
                drawThumb_1 = false;
            }
            android.graphics.Rect r = getBounds();
            if (canvas.quickReject(r.left, r.top, r.right, r.bottom, android.graphics.Canvas.EdgeType
                                   .AA))
            {
                return;
            }
            if (drawTrack_1)
            {
                drawTrack(canvas, r, vertical);
            }
            if (drawThumb_1)
            {
                int size      = vertical ? r.height() : r.width();
                int thickness = vertical ? r.width() : r.height();
                int length    = Sharpen.Util.Round((float)size * extent / range);
                int offset    = Sharpen.Util.Round((float)(size - length) * mOffset / (range - extent
                                                                                       ));
                // avoid the tiny thumb
                int minLength = thickness * 2;
                if (length < minLength)
                {
                    length = minLength;
                }
                // avoid the too-big thumb
                if (offset + length > size)
                {
                    offset = size - length;
                }
                drawThumb(canvas, r, offset, length, vertical);
            }
        }
Esempio n. 7
0
        void drawCenter(string text, float yMultiply)
        {
            var r = new android.graphics.Rect();

            frameCanvas.getClipBounds(r);
            paint.setTextAlign(android.graphics.Paint.Align.LEFT);
            paint.getTextBounds(text, 0, text.Length, r);
            float x = frameWidth / 2f - r.width() / 2f - r.left;
            float y = frameHeight / 2f + (r.height() * yMultiply) / 2f - r.bottom;

            frameCanvas.drawText(text, x, y, paint);
        }
Esempio n. 8
0
        protected internal override void onDraw(Canvas canvas)
        {
            // Setup gravity.
            if ((mGravity & GRAVITY_START) > 0)
            {
                mRect.set(0, mRect.top, mRect.width(), mRect.bottom);
            }
            else if ((mGravity & GRAVITY_TOP) > 0)
            {
                mRect.set(mRect.left, 0, mRect.right, mRect.height());
            }
            else if ((mGravity & GRAVITY_END) > 0)
            {
                mRect.set(canvas.Width - mRect.width(), mRect.top, canvas.Width, mRect.bottom);
            }
            else if ((mGravity & GRAVITY_BOTTOM) > 0)
            {
                mRect.set(mRect.left, canvas.Height - mRect.height(), mRect.right, canvas.Height);
            }

            if ((mGravity & GRAVITY_CENTER) > 0)
            {
                mRect.set((canvas.Width / 2) - (mRect.width() / 2), (canvas.Height / 2) - (mRect.height() / 2), (canvas.Width / 2) - (mRect.width() / 2) + mRect.width(), (canvas.Height / 2) - (mRect.height() / 2) + mRect.height());
            }
            else if ((mGravity & GRAVITY_CENTER_HORIZONTAL) > 0)
            {
                mRect.set((canvas.Width / 2) - (mRect.width() / 2), mRect.top, (canvas.Width / 2) - (mRect.width() / 2) + mRect.width(), mRect.bottom);
            }
            else if ((mGravity & GRAVITY_CENTER_VERTICAL) > 0)
            {
                mRect.set(mRect.left, (canvas.Height / 2) - (mRect.height() / 2), mRect.right, (canvas.Height / 2) - (mRect.height() / 2) + mRect.height());
            }

            // Merge offset.
            mRect.offset(mOffset.x, mOffset.y);

            canvas.drawRect(mRect, mPaint);
        }
Esempio n. 9
0
 private void updateShape()
 {
     if (mShapeState.mShape != null)
     {
         android.graphics.Rect r = getBounds();
         int w = r.width();
         int h = r.height();
         mShapeState.mShape.resize(w, h);
         if (mShapeState.mShaderFactory != null)
         {
             mShapeState.mPaint.setShader(mShapeState.mShaderFactory.resize(w, h));
         }
     }
     invalidateSelf();
 }
        public override void draw(Canvas canvas)
        {
            Rect  r     = Bounds;
            Paint paint = mPaint;

            // only draw shape if it may affect output
            if (paint.Alpha != 0 || paint.Xfermode != null)
            {
                //            canvas.drawRect(r, paint);
                Rect textBounds = TextBounds;
                canvas.drawText(mText, r.left + r.width() / 2, r.top + r.height() / 2 + textBounds.height() / 2, paint);
            }

            // restore
        }
Esempio n. 11
0
            /// <summary>Returns the index of the child mipmap drawable that will best fit the provided bounds.
            ///     </summary>
            /// <remarks>
            /// Returns the index of the child mipmap drawable that will best fit the provided bounds.
            /// This index is determined by comparing bounds' height and children intrinsic heights.
            /// The returned mipmap index is the smallest mipmap which height is greater or equal than
            /// the bounds' height. If the bounds' height is larger than the largest mipmap, the largest
            /// mipmap index is returned.
            /// </remarks>
            /// <param name="bounds">The bounds of the MipMapDrawable.</param>
            /// <returns>
            /// The index of the child Drawable that will best fit these bounds, or -1 if there
            /// are no children mipmaps.
            /// </returns>
            public int indexForBounds(android.graphics.Rect bounds)
            {
                int boundsHeight = bounds.height();
                int N            = getChildCount();

                {
                    for (int i = 0; i < N; i++)
                    {
                        if (boundsHeight <= mMipmapHeights[i])
                        {
                            return(i);
                        }
                    }
                }
                // No mipmap larger than bounds found. Use largest one which will be scaled up.
                if (N > 0)
                {
                    return(N - 1);
                }
                // No Drawable mipmap at all
                return(-1);
            }
Esempio n. 12
0
        private void adjustRectangle(android.graphics.Rect rect)
        {
            int width  = rect.width();
            int height = rect.height();

            if (mFormat == android.graphics.ImageFormat.NV21)
            {
                // Make sure left, top, width and height are all even.
                width      &= ~1;
                height     &= ~1;
                rect.left  &= ~1;
                rect.top   &= ~1;
                rect.right  = rect.left + width;
                rect.bottom = rect.top + height;
            }
            if (mFormat == android.graphics.ImageFormat.YUY2)
            {
                // Make sure left and width are both even.
                width     &= ~1;
                rect.left &= ~1;
                rect.right = rect.left + width;
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Find the distance on the minor axis w.r.t the direction to the nearest
        /// edge of the destination rectange.
        /// </summary>
        /// <remarks>
        /// Find the distance on the minor axis w.r.t the direction to the nearest
        /// edge of the destination rectange.
        /// </remarks>
        /// <param name="direction">the direction (up, down, left, right)</param>
        /// <param name="source">The source rect.</param>
        /// <param name="dest">The destination rect.</param>
        /// <returns>The distance.</returns>
        internal static int minorAxisDistance(int direction, android.graphics.Rect source
                                              , android.graphics.Rect dest)
        {
            switch (direction)
            {
            case android.view.View.FOCUS_LEFT:
            case android.view.View.FOCUS_RIGHT:
            {
                // the distance between the center verticals
                return(System.Math.Abs(((source.top + source.height() / 2) - ((dest.top + dest.height
                                                                                   () / 2)))));
            }

            case android.view.View.FOCUS_UP:
            case android.view.View.FOCUS_DOWN:
            {
                // the distance between the center horizontals
                return(System.Math.Abs(((source.left + source.width() / 2) - ((dest.left + dest.width
                                                                                   () / 2)))));
            }
            }
            throw new System.ArgumentException("direction must be one of " + "{FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}."
                                               );
        }
Esempio n. 14
0
        public override void draw(android.graphics.Canvas canvas)
        {
            if (mClipState.mDrawable.getLevel() == 0)
            {
                return;
            }
            android.graphics.Rect r      = mTmpRect;
            android.graphics.Rect bounds = getBounds();
            int level = getLevel();
            int w     = bounds.width();
            int iw    = 0;

            //mClipState.mDrawable.getIntrinsicWidth();
            if ((mClipState.mOrientation & HORIZONTAL) != 0)
            {
                w -= (w - iw) * (10000 - level) / 10000;
            }
            int h  = bounds.height();
            int ih = 0;

            //mClipState.mDrawable.getIntrinsicHeight();
            if ((mClipState.mOrientation & VERTICAL) != 0)
            {
                h -= (h - ih) * (10000 - level) / 10000;
            }
            int layoutDirection = getResolvedLayoutDirectionSelf();

            android.view.Gravity.apply(mClipState.mGravity, w, h, bounds, r, layoutDirection);
            if (w > 0 && h > 0)
            {
                canvas.save();
                canvas.clipRect(r);
                mClipState.mDrawable.draw(canvas);
                canvas.restore();
            }
        }
Esempio n. 15
0
        private android.view.View findNextFocus(android.view.ViewGroup root, android.view.View
                                                focused, android.graphics.Rect focusedRect, int direction)
        {
            java.util.ArrayList <android.view.View> focusables = root.getFocusables(direction);
            if (focusables.isEmpty())
            {
                // The focus cannot change.
                return(null);
            }
            if (direction == android.view.View.FOCUS_FORWARD || direction == android.view.View
                .FOCUS_BACKWARD)
            {
                if (focused != null && !focusables.contains(focused))
                {
                    // Add the currently focused view to the list to have it sorted
                    // along with the other views.
                    focusables.add(focused);
                }
                try
                {
                    // Note: This sort is stable.
                    mSequentialFocusComparator.setRoot(root);
                    java.util.Collections.sort(focusables, mSequentialFocusComparator);
                }
                finally
                {
                    mSequentialFocusComparator.recycle();
                }
                int count = focusables.size();
                switch (direction)
                {
                case android.view.View.FOCUS_FORWARD:
                {
                    if (focused != null)
                    {
                        int position = focusables.lastIndexOf(focused);
                        if (position >= 0 && position + 1 < count)
                        {
                            return(focusables.get(position + 1));
                        }
                    }
                    return(focusables.get(0));
                }

                case android.view.View.FOCUS_BACKWARD:
                {
                    if (focused != null)
                    {
                        int position = focusables.indexOf(focused);
                        if (position > 0)
                        {
                            return(focusables.get(position - 1));
                        }
                    }
                    return(focusables.get(count - 1));
                }
                }
                return(null);
            }
            // initialize the best candidate to something impossible
            // (so the first plausible view will become the best choice)
            mBestCandidateRect.set(focusedRect);
            switch (direction)
            {
            case android.view.View.FOCUS_LEFT:
            {
                mBestCandidateRect.offset(focusedRect.width() + 1, 0);
                break;
            }

            case android.view.View.FOCUS_RIGHT:
            {
                mBestCandidateRect.offset(-(focusedRect.width() + 1), 0);
                break;
            }

            case android.view.View.FOCUS_UP:
            {
                mBestCandidateRect.offset(0, focusedRect.height() + 1);
                break;
            }

            case android.view.View.FOCUS_DOWN:
            {
                mBestCandidateRect.offset(0, -(focusedRect.height() + 1));
                break;
            }
            }
            android.view.View closest = null;
            int numFocusables         = focusables.size();

            {
                for (int i = 0; i < numFocusables; i++)
                {
                    android.view.View focusable = focusables.get(i);
                    // only interested in other non-root views
                    if (focusable == focused || focusable == root)
                    {
                        continue;
                    }
                    // get visible bounds of other view in same coordinate system
                    focusable.getDrawingRect(mOtherRect);
                    root.offsetDescendantRectToMyCoords(focusable, mOtherRect);
                    if (isBetterCandidate(direction, focusedRect, mOtherRect, mBestCandidateRect))
                    {
                        mBestCandidateRect.set(mOtherRect);
                        closest = focusable;
                    }
                }
            }
            return(closest);
        }
Esempio n. 16
0
		public virtual bool onLongClick(android.view.View v)
		{
			if (hasText())
			{
				// Don't show the cheat sheet for items that already show text.
				return false;
			}
			int[] screenPos = new int[2];
			android.graphics.Rect displayFrame = new android.graphics.Rect();
			getLocationOnScreen(screenPos);
			getWindowVisibleDisplayFrame(displayFrame);
			android.content.Context context = getContext();
			int width = getWidth();
			int height = getHeight();
			int midy = screenPos[1] + height / 2;
			int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
			android.widget.Toast cheatSheet = android.widget.Toast.makeText(context, mItemData
				.getTitle(), android.widget.Toast.LENGTH_SHORT);
			if (midy < displayFrame.height())
			{
				// Show along the top; follow action buttons
				cheatSheet.setGravity(android.view.Gravity.TOP | android.view.Gravity.RIGHT, screenWidth
					 - screenPos[0] - width / 2, height);
			}
			else
			{
				// Show along the bottom center
				cheatSheet.setGravity(android.view.Gravity.BOTTOM | android.view.Gravity.CENTER_HORIZONTAL
					, 0, height);
			}
			cheatSheet.show();
			return true;
		}
Esempio n. 17
0
 /// <summary>
 /// Apply additional gravity behavior based on the overall "display" that an
 /// object exists in.
 /// </summary>
 /// <remarks>
 /// Apply additional gravity behavior based on the overall "display" that an
 /// object exists in.  This can be used after
 /// <see cref="apply(int, int, int, android.graphics.Rect, int, int, android.graphics.Rect)
 ///     ">apply(int, int, int, android.graphics.Rect, int, int, android.graphics.Rect)</see>
 /// to place the object
 /// within a visible display.  By default this moves or clips the object
 /// to be visible in the display; the gravity flags
 /// <see cref="DISPLAY_CLIP_HORIZONTAL">DISPLAY_CLIP_HORIZONTAL</see>
 /// and
 /// <see cref="DISPLAY_CLIP_VERTICAL">DISPLAY_CLIP_VERTICAL</see>
 /// can be used to change this behavior.
 /// </remarks>
 /// <param name="gravity">
 /// Gravity constants to modify the placement within the
 /// display.
 /// </param>
 /// <param name="display">
 /// The rectangle of the display in which the object is
 /// being placed.
 /// </param>
 /// <param name="inoutObj">
 /// Supplies the current object position; returns with it
 /// modified if needed to fit in the display.
 /// </param>
 public static void applyDisplay(int gravity, android.graphics.Rect display, android.graphics.Rect
                                 inoutObj)
 {
     if ((gravity & DISPLAY_CLIP_VERTICAL) != 0)
     {
         if (inoutObj.top < display.top)
         {
             inoutObj.top = display.top;
         }
         if (inoutObj.bottom > display.bottom)
         {
             inoutObj.bottom = display.bottom;
         }
     }
     else
     {
         int off = 0;
         if (inoutObj.top < display.top)
         {
             off = display.top - inoutObj.top;
         }
         else
         {
             if (inoutObj.bottom > display.bottom)
             {
                 off = display.bottom - inoutObj.bottom;
             }
         }
         if (off != 0)
         {
             if (inoutObj.height() > (display.bottom - display.top))
             {
                 inoutObj.top    = display.top;
                 inoutObj.bottom = display.bottom;
             }
             else
             {
                 inoutObj.top    += off;
                 inoutObj.bottom += off;
             }
         }
     }
     if ((gravity & DISPLAY_CLIP_HORIZONTAL) != 0)
     {
         if (inoutObj.left < display.left)
         {
             inoutObj.left = display.left;
         }
         if (inoutObj.right > display.right)
         {
             inoutObj.right = display.right;
         }
     }
     else
     {
         int off = 0;
         if (inoutObj.left < display.left)
         {
             off = display.left - inoutObj.left;
         }
         else
         {
             if (inoutObj.right > display.right)
             {
                 off = display.right - inoutObj.right;
             }
         }
         if (off != 0)
         {
             if (inoutObj.width() > (display.right - display.left))
             {
                 inoutObj.left  = display.left;
                 inoutObj.right = display.right;
             }
             else
             {
                 inoutObj.left  += off;
                 inoutObj.right += off;
             }
         }
     }
 }