List of usage examples for android.graphics Rect set
public void set(int left, int top, int right, int bottom)
From source file:com.android.gallery3d.ui.TileImageView.java
private void getRange(Rect out, int cX, int cY, int level, float scale, int rotation) { double radians = Math.toRadians(-rotation); double w = getWidth(); double h = getHeight(); double cos = Math.cos(radians); double sin = Math.sin(radians); int width = (int) Math.ceil(Math.max(Math.abs(cos * w - sin * h), Math.abs(cos * w + sin * h))); int height = (int) Math.ceil(Math.max(Math.abs(sin * w + cos * h), Math.abs(sin * w - cos * h))); int left = (int) Math.floor(cX - width / (2f * scale)); int top = (int) Math.floor(cY - height / (2f * scale)); int right = (int) Math.ceil(left + width / scale); int bottom = (int) Math.ceil(top + height / scale); // align the rectangle to tile boundary int size = sTileSize << level; left = Math.max(0, size * (left / size)); top = Math.max(0, size * (top / size)); right = Math.min(mImageWidth, right); bottom = Math.min(mImageHeight, bottom); out.set(left, top, right, bottom); }
From source file:pl.skyman.android.view.SuperStaggeredGridView.java
void positionSelector(View sel) { /*if(sel.getBottom() > getHeight()) { offsetChildren(getHeight() - sel.getBottom() + mItemMargin); return;//from ww w.j a va 2s . co m } else if(sel.getTop() < 0) { offsetChildren( - sel.getTop() - mItemMargin); return; }*/ final Rect selectorRect = mSelectorRect; selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom()); /*if (sel instanceof AbsListView.SelectionBoundsAdjuster) { ((AbsListView.SelectionBoundsAdjuster)sel).adjustListItemSelectionBounds(selectorRect); }*/ positionSelector(selectorRect.left, selectorRect.top, selectorRect.right, selectorRect.bottom); /*final boolean isChildViewEnabled = mIsChildViewEnabled; if (sel.isEnabled() != isChildViewEnabled) { mIsChildViewEnabled = !isChildViewEnabled; if (getSelectedItemPosition() != INVALID_POSITION) { refreshDrawableState(); } }*/ invalidate(); }
From source file:com.android.fastergallery.ui.TileImageView.java
private void getRange(Rect out, int cX, int cY, int level, float scale, int rotation) { double radians = Math.toRadians(-rotation); double w = getWidth(); double h = getHeight(); double cos = Math.cos(radians); double sin = Math.sin(radians); int width = (int) Math.ceil(Math.max(Math.abs(cos * w - sin * h), Math.abs(cos * w + sin * h))); int height = (int) Math.ceil(Math.max(Math.abs(sin * w + cos * h), Math.abs(sin * w - cos * h))); int left = (int) FloatMath.floor(cX - width / (2f * scale)); int top = (int) FloatMath.floor(cY - height / (2f * scale)); int right = (int) FloatMath.ceil(left + width / scale); int bottom = (int) FloatMath.ceil(top + height / scale); // align the rectangle to tile boundary int size = sTileSize << level; left = Math.max(0, size * (left / size)); top = Math.max(0, size * (top / size)); right = Math.min(mImageWidth, right); bottom = Math.min(mImageHeight, bottom); out.set(left, top, right, bottom); }
From source file:com.aidy.launcher3.photos.views.TiledImageRenderer.java
private void getRange(Rect out, int cX, int cY, int level, float scale, int rotation) { double radians = Math.toRadians(-rotation); double w = mViewWidth; double h = mViewHeight; double cos = Math.cos(radians); double sin = Math.sin(radians); int width = (int) Math.ceil(Math.max(Math.abs(cos * w - sin * h), Math.abs(cos * w + sin * h))); int height = (int) Math.ceil(Math.max(Math.abs(sin * w + cos * h), Math.abs(sin * w - cos * h))); int left = (int) Math.floor(cX - width / (2f * scale)); int top = (int) Math.floor(cY - height / (2f * scale)); int right = (int) Math.ceil(left + width / scale); int bottom = (int) Math.ceil(top + height / scale); // align the rectangle to tile boundary int size = mTileSize << level; left = Math.max(0, size * (left / size)); top = Math.max(0, size * (top / size)); right = Math.min(mImageWidth, right); bottom = Math.min(mImageHeight, bottom); out.set(left, top, right, bottom); }
From source file:com.delexus.imitationzhihu.MySearchView.java
private void getChildBoundsWithinSearchView(View view, Rect rect) { view.getLocationInWindow(mTemp);/*from ww w . j a v a2 s .c o m*/ getLocationInWindow(mTemp2); final int top = mTemp[1] - mTemp2[1]; final int left = mTemp[0] - mTemp2[0]; rect.set(left, top, left + view.getWidth(), top + view.getHeight()); }
From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java
/** * Calculates the bounds of the specified day. * * @param id the day of the month * @param outBounds the rect to populate with bounds *//* ww w. j a va 2s. c o m*/ private boolean getBoundsForDay(int id, Rect outBounds) { if (!isValidDayOfMonth(id)) { return false; } final int index = id - 1 + findDayOffset(); // Compute left edge, taking into account RTL. final int col = index % DAYS_IN_WEEK; final int colWidth = mCellWidth; final int left; if (SUtils.isLayoutRtlCompat(this)) { left = getWidth() - getPaddingRight() - (col + 1) * colWidth; } else { left = getPaddingLeft() + col * colWidth; } // Compute top edge. final int row = index / DAYS_IN_WEEK; final int rowHeight = mDayHeight; final int headerHeight = mMonthHeight + mDayOfWeekHeight; final int top = getPaddingTop() + headerHeight + row * rowHeight; outBounds.set(left, top, left + colWidth, top + rowHeight); return true; }
From source file:com.example.SmartBoard.DrawingView.java
public boolean onTouchDragEvent(MotionEvent event) { boolean handled = false; JSONObject mObjectTouched;/* w w w. j av a 2 s.co m*/ int X; int Y; int pointerId; int actionIndex = event.getActionIndex(); //get coordinates and make object transparent switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: dragFinished = false; //it's the first pointer, so clear all existing pointers data mObjectPointers.clear(); X = (int) event.getX(actionIndex); Y = (int) event.getY(actionIndex); dragX = X; dragY = Y; String objectType = ""; //check if we've touched inside some object mObjectTouched = getTouchedObject(X, Y); if (mObjectTouched == null) { return true; } else { objectType = getObjectType(mObjectTouched); } if (objectType.compareTo("Circle") == 0) { try { mObjectTouched.put("x", X); mObjectTouched.put("y", Y); } catch (JSONException e) { e.printStackTrace(); } } else if (objectType.compareTo("Rectangle") == 0) { Rect tempRect = Rect.unflattenFromString(mObjectTouched.optString("dimens")); tempRect.set(X, Y, X + tempRect.width(), Y + tempRect.height()); try { mObjectTouched.put("dimens", tempRect.flattenToString()); } catch (JSONException e) { } } else if (objectType.compareTo("Line") == 0) { if (lengthOfLine(X, Y, mObjectTouched.optInt("startx"), mObjectTouched.optInt("starty")) < lengthOfLine(X, Y, mObjectTouched.optInt("stopx"), mObjectTouched.optInt("stopy"))) { try { mObjectTouched.put("startx", X); mObjectTouched.put("starty", Y); mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("stopx"), mObjectTouched.optInt("stopy"))); } catch (JSONException e) { e.printStackTrace(); } dragLineStart = true; } else { try { mObjectTouched.put("stopx", X); mObjectTouched.put("stopy", Y); mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("startx"), mObjectTouched.optInt("starty"))); } catch (JSONException e) { e.printStackTrace(); } dragLineStart = false; } } else if (objectType.compareTo("Text") == 0) { try { mObjectTouched.put("x", X); mObjectTouched.put("y", Y); Rect tempRect = Rect.unflattenFromString(mObjectTouched.getString("region")); tempRect.set(X, Y, tempRect.width() + X, tempRect.height() + Y); mObjectTouched.put("region", tempRect.flattenToString()); } catch (JSONException e) { e.printStackTrace(); } } mObjectPointers.put(event.getPointerId(0), mObjectTouched); if (mObjectTouched != null) { mqtt.publishObject(mObjectTouched); } invalidate(); handled = true; break; case MotionEvent.ACTION_POINTER_DOWN: break; case MotionEvent.ACTION_MOVE: dragFinished = false; final int pointerCount = event.getPointerCount(); for (actionIndex = 0; actionIndex < pointerCount; actionIndex++) { //some pointer has moved, search it by pointer id pointerId = event.getPointerId(actionIndex); X = (int) event.getX(actionIndex); Y = (int) event.getY(actionIndex); dragX = X; dragY = Y; mObjectTouched = mObjectPointers.get(pointerId); if (mObjectTouched == null) continue; // if null no object was touched so skip if (mObjectTouched.optString("type").compareTo("Circle") == 0) { try { mObjectTouched.put("x", X); mObjectTouched.put("y", Y); } catch (JSONException e) { } } else if (mObjectTouched.optString("type").compareTo("Rectangle") == 0) { Rect tempRect = Rect.unflattenFromString(mObjectTouched.optString("dimens")); tempRect.set(X, Y, X + tempRect.width(), Y + tempRect.height()); try { mObjectTouched.put("dimens", tempRect.flattenToString()); } catch (JSONException e) { } } else if (mObjectTouched.optString("type").compareTo("Text") == 0) { try { mObjectTouched.put("x", X); mObjectTouched.put("y", Y); Rect tempRect = Rect.unflattenFromString(mObjectTouched.getString("region")); tempRect.set(X, Y, tempRect.width() + X, tempRect.height() + Y); mObjectTouched.put("region", tempRect.flattenToString()); } catch (JSONException e) { e.printStackTrace(); } } else if (mObjectTouched.optString("type").compareTo("Line") == 0) { if (dragLineStart) { try { mObjectTouched.put("startx", X); mObjectTouched.put("starty", Y); mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("stopx"), mObjectTouched.optInt("stopy"))); //mObjectTouched.put("stopx", tempStopX); // mObjectTouched.put("stopy", tempStopY); } catch (JSONException e) { e.printStackTrace(); } } else { try { mObjectTouched.put("stopx", X); mObjectTouched.put("stopy", Y); mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("startx"), mObjectTouched.optInt("starty"))); //mObjectTouched.put("stopx", tempStopX); // mObjectTouched.put("stopy", tempStopY); } catch (JSONException e) { e.printStackTrace(); } } } if (mObjectTouched != null) { mqtt.publishObject(mObjectTouched); } } invalidate(); handled = true; break; case MotionEvent.ACTION_UP: dragFinished = true; mObjectPointers.clear(); invalidate(); handled = true; break; case MotionEvent.ACTION_CANCEL: handled = true; break; default: // do nothing break; } return super.onTouchEvent(event) || handled; }
From source file:android.support.v7.app.AppCompatDelegateImplV7.java
/** * Updates the status bar guard// w w w . ja v a 2 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.taobao.weex.ui.component.WXComponent.java
public Rect getComponentSize() { Rect size = new Rect(); if (mHost != null) { int[] location = new int[2]; int[] anchor = new int[2]; mHost.getLocationOnScreen(location); mInstance.getContainerView().getLocationOnScreen(anchor); int left = location[0] - anchor[0]; int top = (location[1] - mStickyOffset) - anchor[1]; int width = (int) mDomObj.getLayoutWidth(); int height = (int) mDomObj.getLayoutHeight(); size.set(left, top, left + width, top + height); }/*from w w w . jav a 2 s. com*/ return size; }
From source file:xyz.zpayh.hdimage.HDImageView.java
private Rect sourceToViewRect(Rect sourceRect, Rect viewTarget) { viewTarget.set((int) sourceToViewX(sourceRect.left), (int) sourceToViewY(sourceRect.top), (int) sourceToViewX(sourceRect.right), (int) sourceToViewY(sourceRect.bottom)); return viewTarget; }