List of usage examples for android.graphics Rect Rect
public Rect()
From source file:org.cryptsecure.Utility.java
/** * Cut text into one line.//from w w w .j a va 2 s . c om * * @param text * the text * @param maxWidth * the max width * @param textSize * the text size * @return the string */ public static String cutTextIntoOneLine(String text, int maxWidth, int textSize) { try { Paint paint = new Paint(); Rect bounds = new Rect(); int textWidth = 0; paint.setTypeface(Typeface.DEFAULT);// your preference here paint.setTextSize(textSize);// have this the same as your text size String outText = text; String outText2 = text; boolean modified = false; boolean cutDown = false; while (true) { if (modified) { paint.getTextBounds(outText2, 0, outText2.length(), bounds); } else { paint.getTextBounds(outText, 0, outText.length(), bounds); } textWidth = bounds.width(); if (textWidth <= maxWidth) { break; } else { modified = true; if (!cutDown) { cutDown = true; int estimatedLen = (outText.length() * maxWidth) / textWidth; estimatedLen += 20; // be carefull! if (estimatedLen > outText.length()) { estimatedLen = outText.length(); } outText = outText.substring(0, estimatedLen); outText2 = outText + "..."; } else { // reduce by one character outText = outText.substring(0, outText.length() - 1); outText2 = outText + "..."; } } } if (modified) { return outText2; } else { return outText; } } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static Bitmap getColorPreviewBitmap(final Context context, final int color) { if (context == null) return null; final float density = context.getResources().getDisplayMetrics().density; final int width = (int) (32 * density), height = (int) (32 * density); final Bitmap bm = Bitmap.createBitmap(width, height, Config.ARGB_8888); final Canvas canvas = new Canvas(bm); final int rectrangle_size = (int) (density * 5); final int numRectanglesHorizontal = (int) Math.ceil(width / rectrangle_size); final int numRectanglesVertical = (int) Math.ceil(height / rectrangle_size); final Rect r = new Rect(); boolean verticalStartWhite = true; for (int i = 0; i <= numRectanglesVertical; i++) { boolean isWhite = verticalStartWhite; for (int j = 0; j <= numRectanglesHorizontal; j++) { r.top = i * rectrangle_size; r.left = j * rectrangle_size; r.bottom = r.top + rectrangle_size; r.right = r.left + rectrangle_size; final Paint paint = new Paint(); paint.setColor(isWhite ? Color.WHITE : Color.GRAY); canvas.drawRect(r, paint);//from w ww . jav a 2 s . c o m isWhite = !isWhite; } verticalStartWhite = !verticalStartWhite; } canvas.drawColor(color); final Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setStrokeWidth(2.0f); final float[] points = new float[] { 0, 0, width, 0, 0, 0, 0, height, width, 0, width, height, 0, height, width, height }; canvas.drawLines(points, paint); return bm; }
From source file:android.support.v7.widget.SearchView.java
private void adjustDropDownSizeAndPosition() { if (mDropDownAnchor.getWidth() > 1) { Resources res = getContext().getResources(); int anchorPadding = mSearchPlate.getPaddingLeft(); Rect dropDownPadding = new Rect(); final boolean isLayoutRtl = ViewUtils.isLayoutRtl(this); int iconOffset = mIconifiedByDefault ? res.getDimensionPixelSize(R.dimen.abc_dropdownitem_icon_width) + res.getDimensionPixelSize(R.dimen.abc_dropdownitem_text_padding_left) : 0;//from w w w. j a v a 2s . c om mSearchSrcTextView.getDropDownBackground().getPadding(dropDownPadding); int offset; if (isLayoutRtl) { offset = -dropDownPadding.left; } else { offset = anchorPadding - (dropDownPadding.left + iconOffset); } mSearchSrcTextView.setDropDownHorizontalOffset(offset); final int width = mDropDownAnchor.getWidth() + dropDownPadding.left + dropDownPadding.right + iconOffset - anchorPadding; mSearchSrcTextView.setDropDownWidth(width); } }
From source file:android.support.v7.app.AppCompatDelegateImplV7.java
/** * Updates the status bar guard//from w ww .j av a2 s .c om * * @param insetTop the current top system window inset * @return the new top system window inset */ private int updateStatusGuard(int insetTop) { boolean showStatusGuard = false; // Show the status guard when the non-overlay contextual action bar is showing if (mActionModeView != null) { if (mActionModeView.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) mActionModeView.getLayoutParams(); boolean mlpChanged = false; if (mActionModeView.isShown()) { if (mTempRect1 == null) { mTempRect1 = new Rect(); mTempRect2 = new Rect(); } final Rect insets = mTempRect1; final Rect localInsets = mTempRect2; insets.set(0, insetTop, 0, 0); ViewUtils.computeFitSystemWindows(mSubDecor, insets, localInsets); final int newMargin = localInsets.top == 0 ? insetTop : 0; if (mlp.topMargin != newMargin) { mlpChanged = true; mlp.topMargin = insetTop; if (mStatusGuard == null) { mStatusGuard = new View(mContext); mStatusGuard.setBackgroundColor( mContext.getResources().getColor(R.color.abc_input_method_navigation_guard)); mSubDecor.addView(mStatusGuard, -1, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, insetTop)); } else { ViewGroup.LayoutParams lp = mStatusGuard.getLayoutParams(); if (lp.height != insetTop) { lp.height = insetTop; mStatusGuard.setLayoutParams(lp); } } } // The action mode's theme may differ from the app, so // always show the status guard above it. showStatusGuard = mStatusGuard != null; // We only need to consume the insets if the action // mode is overlaid on the app content (e.g. it's // sitting in a FrameLayout, see // screen_simple_overlay_action_mode.xml). if (!mOverlayActionMode && showStatusGuard) { insetTop = 0; } } else { // reset top margin if (mlp.topMargin != 0) { mlpChanged = true; mlp.topMargin = 0; } } if (mlpChanged) { mActionModeView.setLayoutParams(mlp); } } } if (mStatusGuard != null) { mStatusGuard.setVisibility(showStatusGuard ? View.VISIBLE : View.GONE); } return insetTop; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static boolean isValidImage(final InputStream is) { if (is == null) return false; final BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true;//from w w w . jav a 2s .c om BitmapFactory.decodeStream(is, new Rect(), o); return o.outHeight > 0 && o.outWidth > 0; }
From source file:VerticalViewPager.java
private Rect getChildRectInPagerCoordinates(Rect outRect, View child) { if (outRect == null) { outRect = new Rect(); }/*from w w w . ja v a 2s. c o m*/ if (child == null) { outRect.set(0, 0, 0, 0); return outRect; } outRect.left = child.getLeft(); outRect.right = child.getRight(); outRect.top = child.getTop(); outRect.bottom = child.getBottom(); ViewParent parent = child.getParent(); while (parent instanceof ViewGroup && parent != this) { final ViewGroup group = (ViewGroup) parent; outRect.left += group.getLeft(); outRect.right += group.getRight(); outRect.top += group.getTop(); outRect.bottom += group.getBottom(); parent = group.getParent(); } return outRect; }
From source file:com.skytree.epubtest.BookViewActivity.java
public void moveSkyBox(SkyBox box, int boxWidth, int boxHeight, Rect startRect, Rect endRect) { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) box.getLayoutParams(); int topMargin = ps(80); int bottomMargin = ps(80); int boxTop = 0; int boxLeft = 0; int arrowX;/*from w w w .j a v a 2s .c o m*/ boolean isArrowDown; if (startRect.top - topMargin > boxHeight) { boxTop = startRect.top - boxHeight - ps(10); boxLeft = (startRect.left + startRect.width() / 2 - boxWidth / 2); arrowX = (startRect.left + startRect.width() / 2); isArrowDown = true; } else if ((this.getHeight() - endRect.bottom) - bottomMargin > boxHeight) { // ????????? ????????? ????????? ?????????. boxTop = endRect.bottom + ps(10); boxLeft = (endRect.left + endRect.width() / 2 - boxWidth / 2); arrowX = (endRect.left + endRect.width() / 2); isArrowDown = false; } else { boxTop = ps(100); boxLeft = (startRect.left + startRect.width() / 2 - boxWidth / 2); arrowX = (startRect.left + startRect.width() / 2); isArrowDown = true; } if (boxLeft + boxWidth > this.getWidth() * .9) { boxLeft = (int) (this.getWidth() * .9) - boxWidth; } else if (boxLeft < this.getWidth() * .1) { boxLeft = (int) (this.getWidth() * .1); } box.setArrowPosition(arrowX, boxLeft, boxWidth); box.setArrowDirection(isArrowDown); params.leftMargin = boxLeft; params.topMargin = boxTop; params.width = boxWidth; params.height = boxHeight; box.setLayoutParams(params); box.invalidate(); boxFrame = new Rect(); boxFrame.left = boxLeft; boxFrame.top = boxTop; boxFrame.right = boxLeft + boxWidth; boxFrame.bottom = boxTop + boxHeight; }
From source file:cc.flydev.launcher.Page.java
public void onFlingToDelete(PointF vel) { final long startTime = AnimationUtils.currentAnimationTimeMillis(); // NOTE: Because it takes time for the first frame of animation to actually be // called and we expect the animation to be a continuation of the fling, we have // to account for the time that has elapsed since the fling finished. And since // we don't have a startDelay, we will always get call to update when we call // start() (which we want to ignore). final TimeInterpolator tInterpolator = new TimeInterpolator() { private int mCount = -1; private long mStartTime; private float mOffset; /* Anonymous inner class ctor */ { mStartTime = startTime;/*w ww .j a va 2 s. c o m*/ } @Override public float getInterpolation(float t) { if (mCount < 0) { mCount++; } else if (mCount == 0) { mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION); mCount++; } return Math.min(1f, mOffset + t); } }; final Rect from = new Rect(); final View dragView = mDragView; from.left = (int) dragView.getTranslationX(); from.top = (int) dragView.getTranslationY(); AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION); final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView); // Create and start the animation ValueAnimator mDropAnim = new ValueAnimator(); mDropAnim.setInterpolator(tInterpolator); mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION); mDropAnim.setFloatValues(0f, 1f); mDropAnim.addUpdateListener(updateCb); mDropAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { onAnimationEndRunnable.run(); } }); mDropAnim.start(); mDeferringForDelete = true; }
From source file:cc.flydev.launcher.Workspace.java
boolean createUserFolderIfNecessary(View newView, long container, CellLayout target, int[] targetCell, float distance, boolean external, DragView dragView, Runnable postAnimationRunnable) { if (distance > mMaxDistanceForFolderCreation) return false; View v = target.getChildAt(targetCell[0], targetCell[1]); boolean hasntMoved = false; if (mDragInfo != null) { CellLayout cellParent = getParentCellLayoutForView(mDragInfo.cell); hasntMoved = (mDragInfo.cellX == targetCell[0] && mDragInfo.cellY == targetCell[1]) && (cellParent == target); }/*from w w w.ja va 2s . c o m*/ if (v == null || hasntMoved || !mCreateUserFolderOnDrop) return false; mCreateUserFolderOnDrop = false; final long screenId = (targetCell == null) ? mDragInfo.screenId : getIdForScreen(target); boolean aboveShortcut = (v.getTag() instanceof ShortcutInfo); boolean willBecomeShortcut = (newView.getTag() instanceof ShortcutInfo); if (aboveShortcut && willBecomeShortcut) { ShortcutInfo sourceInfo = (ShortcutInfo) newView.getTag(); ShortcutInfo destInfo = (ShortcutInfo) v.getTag(); // if the drag started here, we need to remove it from the workspace if (!external) { getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell); } Rect folderLocation = new Rect(); float scale = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(v, folderLocation); target.removeView(v); FolderIcon fi = mLauncher.addFolder(target, container, screenId, targetCell[0], targetCell[1]); destInfo.cellX = -1; destInfo.cellY = -1; sourceInfo.cellX = -1; sourceInfo.cellY = -1; // If the dragView is null, we can't animate boolean animate = dragView != null; if (animate) { fi.performCreateAnimation(destInfo, v, sourceInfo, dragView, folderLocation, scale, postAnimationRunnable); } else { fi.addItem(destInfo); fi.addItem(sourceInfo); } return true; } return false; }