List of usage examples for android.graphics Rect Rect
public Rect(int left, int top, int right, int bottom)
From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java
/** * Handle the the release of a dragged view. * @param x The current x coordinate where the drag was released. * @param y The current y coordinate where the drag was released. */// ww w.j a v a 2 s. c om private void handleDrop(int x, int y) { if (!mReorderHelper.hasReorderListener()) { updateReorderStates(ReorderUtils.DRAG_STATE_NONE); return; } if (mReorderHelper.isOverReorderingArea()) { // Store the location of the drag shadow at where dragging stopped // for animation if a reordering has just happened. Since the drag // shadow is drawn as a WindowManager view, its coordinates are // absolute. However, for views inside the grid, we need to operate // with coordinate values that's relative to this grid, so we need // to subtract the offset to absolute screen coordinates that have // been added to mWindowParams. final int left = mWindowParams.x - mOffsetToAbsoluteX; final int top = mWindowParams.y - mOffsetToAbsoluteY; mCachedDragViewRect = new Rect(left, top, left + mDragView.getWidth(), top + mDragView.getHeight()); if (getChildCount() > 0) { final View view = getChildAt(0); final LayoutParams lp = (LayoutParams) view.getLayoutParams(); if (lp.position > mReorderHelper.getDraggedChildPosition()) { // If the adapter position of the first child in view is // greater than the position of the original dragged child, // this means that the user has scrolled the child out of // view. Those off screen views would have been recycled. If // mFirstPosition is currently x, after the reordering // operation, the child[mFirstPosition] will be // at mFirstPosition-1. We want to adjust mFirstPosition so // that we render the view in the correct location after // reordering completes. // // If the user has not scrolled the original dragged child // out of view, then the view has not been recycled and is // still in view. // When onLayout() gets called, we'll automatically fill in // the empty space that the child leaves behind from the // reordering operation. mFirstPosition--; } } // Get the current scroll position so that after reordering // completes, we can restore the scroll position of mFirstPosition. mCurrentScrollState = getScrollState(); } final boolean reordered = mReorderHelper.handleDrop(new Point(x, y)); if (reordered) { updateReorderStates(ReorderUtils.DRAG_STATE_RELEASED_REORDER); } else { updateReorderStates(ReorderUtils.DRAG_STATE_NONE); } }
From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java
private void readexcel() { WorkbookSettings ws = new WorkbookSettings(); File file = new File(Tabs1.Siteslistlocation); long size = file.length(); int sizeint = (int) size; ws.setInitialFileSize(sizeint);//from w w w. java2 s .com Workbook workbook = null; try { workbook = Workbook.getWorkbook(file, ws); } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String[] sheets = workbook.getSheetNames(); int sheetnum = 0; for (int r = 0; r < sheets.length; r++) { try { if (sheets[r].equals(Tabs1.floorplanname)) { sheetnum = r; int worksheet = sheetnum; Sheet sheet = workbook.getSheet(worksheet); int startcolumn = 0; ArrayList<String> rectleft = u.getcol(sheet, startcolumn++, 1); ArrayList<String> recttop = u.getcol(sheet, startcolumn++, 1); ArrayList<String> rectright = u.getcol(sheet, startcolumn++, 1); ArrayList<String> rectbottom = u.getcol(sheet, startcolumn++, 1); ArrayList<String> type = u.getcol(sheet, startcolumn++, 1); ArrayList<String> tempsensorcount = u.getcol(sheet, startcolumn++, 1); ArrayList<String> percentsize = u.getcol(sheet, startcolumn++, 1); ArrayList<String> samscount = u.getcol(sheet, startcolumn++, 1); ArrayList<String> masterelcnumber = u.getcol(sheet, startcolumn++, 1); ArrayList<String> displaynumber = u.getcol(sheet, startcolumn++, 1); ArrayList<String> scaledx = u.getcol(sheet, startcolumn++, 1); ArrayList<String> scaledy = u.getcol(sheet, startcolumn++, 1); ArrayList<String> x = u.getcol(sheet, startcolumn++, 1); ArrayList<String> y = u.getcol(sheet, startcolumn++, 1); ArrayList<String> string = u.getcol(sheet, startcolumn++, 1); ArrayList<String> fontsize = u.getcol(sheet, startcolumn++, 1); ArrayList<String> fontcolor = u.getcol(sheet, startcolumn++, 1); ArrayList<String> metersperpixel = u.getcol(sheet, startcolumn++, 1); ArrayList<String> floorplannumber = u.getcol(sheet, startcolumn++, 1); ArrayList<String> elcdisplaynumber = u.getcol(sheet, startcolumn++, 1); ArrayList<String> tabnumber = u.getcol(sheet, startcolumn++, 1); ArrayList<String> tabitemnumber = u.getcol(sheet, startcolumn++, 1); ArrayList<String> textoffsetx = u.getcol(sheet, startcolumn++, 1); ArrayList<String> textoffsety = u.getcol(sheet, startcolumn++, 1); int numberofitems = rectleft.size(); for (int t = 0; t < numberofitems; t++) { // view.ITEMrect[t].left=u.i(rectleft.get(t)); // view.ITEMrect[t].top=u.i(rectleft.get(t)); // view.ITEMrect[t].right=u.i(rectleft.get(t)); // view.ITEMrect[t].bottom=u.i(rectleft.get(t)); view.ITEMrect[t] = new Rect(u.i(rectleft.get(t)), u.i(recttop.get(t)), u.i(rectright.get(t)), u.i(rectbottom.get(t))); view.ITEMtype[t] = u.i(type.get(t)); view.ITEMtempsensorcount[t] = u.i(tempsensorcount.get(t)); view.ITEMsizepercent[t] = u.i(percentsize.get(t)); view.ITEMsamscount[t] = u.i(samscount.get(t)); view.ITEMmasterelcnumber[t] = u.i(masterelcnumber.get(t)); view.ITEMdisplaynumber[t] = u.i(displaynumber.get(t)); view.SCALEDITEMx[t] = Float.parseFloat(scaledx.get(t)); view.SCALEDITEMy[t] = Float.parseFloat(scaledy.get(t)); view.ITEMx[t] = Float.parseFloat(x.get(t)); view.ITEMy[t] = Float.parseFloat(y.get(t)); view.ITEMstring[t] = string.get(t); view.ITEMfontsize[t] = u.i(fontsize.get(t)); view.ITEMfontcolor[t] = u.i(fontcolor.get(t)); view.ITEMmetersperpixel[t] = Float.parseFloat(metersperpixel.get(t)); view.ITEMfloorplannumber[t] = u.i(floorplannumber.get(t)); view.ELCdisplaynumber[t] = u.i(elcdisplaynumber.get(t)); view.ITEMLINKtabnumber[t] = u.i(tabnumber.get(t)); view.ITEMLINKtabitemnumber[t] = u.i(tabitemnumber.get(t)); view.ITEMtextoffsetx[t] = u.i(textoffsetx.get(t)); view.ITEMtextoffsetx[t] = u.i(textoffsety.get(t)); Log.d("item found", u.s((int) view.ITEMx[t])); } view.i = numberofitems; int i = 0; for (i = 0; i < numberofitems; i++) { assignbitmaps(i); } if (i != 0) { resizeiconsseekbar.setProgress(view.ITEMsizepercent[i - 1]); } } } catch (ArrayIndexOutOfBoundsException e) { } } }
From source file:self.philbrown.droidQuery.Ajax.java
/** * Parses the HTTP response as a Bitmap//from w w w . j a va 2s . c o m * @param stream the response to parse * @return a Bitmap response */ private Bitmap parseImage(InputStream stream) throws IllegalStateException, IOException { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inSampleSize = 1; opt.inPurgeable = true; opt.inInputShareable = false; if (options.imageWidth() >= 0) opt.outWidth = options.imageWidth(); if (options.imageHeight() >= 0) opt.outHeight = options.imageHeight(); WeakReference<Bitmap> bitmap = new WeakReference<Bitmap>( BitmapFactory.decodeStream(stream, new Rect(0, 0, 0, 0), opt)); if (bitmap == null || bitmap.get() == null) { return null; } if (bitmap.get().isRecycled()) { return null; } return bitmap.get(); }
From source file:com.example.SmartBoard.DrawingView.java
public void onDrawText(Canvas canvas) { if (finished) { Bitmap bm = textToBitmap(textBoxData, drawPaint.getColor(), textPosX, textPosY, textViewSize); // create a rectangle to define the boundary Rect region = new Rect((int) textPosX - 5, (int) textPosY - 5, (int) textPosX + bm.getWidth() + 5, (int) textPosY + bm.getHeight() + 5); JSONObject textJson = new JSONObject(); try {//from w w w . j av a 2s. c o m String key = UUID.randomUUID().toString(); textJson.put("type", "Text"); textJson.put("id", key); textJson.put("clientId", client.getClientId()); textJson.put("x", textPosX); textJson.put("y", textPosY); textJson.put("region", region.flattenToString()); textJson.put("color", drawPaint.getColor()); textJson.put("size", textViewSize); textJson.put("textBitmap", mqtt.bitmapToString(bm)); textJson.put("text", textBoxData); // objectDrawables.put(key, textJson); textObjects.put(key, textJson); } catch (JSONException e) { e.printStackTrace(); } mqtt.publishtext(textJson); finished = false; placed = true; } }
From source file:de.madvertise.android.sdk.MadvertiseView.java
/** * Draw the ad background for a text banner * * @param canvas//www . j a v a 2 s.c o m * @param rectangle * @param backgroundColor * @param mTextColor */ private void drawTextBannerBackground(final Canvas canvas, final Rect rectangle, final int backgroundColor, int shineColor) { Paint paint = new Paint(); paint.setColor(backgroundColor); paint.setAntiAlias(true); canvas.drawRect(rectangle, paint); int upperColor = Color.argb(GRADIENT_TOP_ALPHA, Color.red(shineColor), Color.green(shineColor), Color.blue(shineColor)); int[] gradientColors = { upperColor, shineColor }; GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, gradientColors); int stop = (int) (rectangle.height() * GRADIENT_STOP) + rectangle.top; gradientDrawable.setBounds(rectangle.left, rectangle.top, rectangle.right, stop); gradientDrawable.draw(canvas); Rect shadowRect = new Rect(rectangle.left, stop, rectangle.right, rectangle.bottom); Paint shadowPaint = new Paint(); shadowPaint.setColor(shineColor); canvas.drawRect(shadowRect, shadowPaint); }
From source file:com.breakout.main.GameState.java
/** * Renders debug features./*from w w w . j ava 2 s .com*/ * <p> * This function is allowed to violate the "don't allocate objects" rule. */ void drawDebugStuff() { // Draw a red outline rectangle around the ball. This shows the area that was // examined for collisions during the "coarse" pass. OutlineAlignedRect.prepareToDraw(); mDebugCollisionRect.draw(); OutlineAlignedRect.finishedDrawing(); // Draw the entire message texture so we can see what it looks like. if (true) { int textureWidth = mTextRes.getTextureWidth(); int textureHeight = mTextRes.getTextureHeight(); float scale = (ARENA_WIDTH * STATUS_MESSAGE_WIDTH_PERC) / textureWidth; // Draw an orange rect around the texture. OutlineAlignedRect outline = new OutlineAlignedRect(); outline.setPosition(ARENA_WIDTH / 2, ARENA_HEIGHT / 2); outline.setScale(textureWidth * scale + 2, textureHeight * scale + 2); outline.setColor(1.0f, 0.65f, 0.0f); OutlineAlignedRect.prepareToDraw(); outline.draw(); OutlineAlignedRect.finishedDrawing(); // Draw the full texture. Note you can set the background to opaque white in // TextResources to see what the drop shadow looks like. Rect boundsRect = new Rect(0, 0, textureWidth, textureHeight); TexturedAlignedRect msgBox = mGameStatusMessages; msgBox.setTextureCoords(boundsRect); msgBox.setScale(textureWidth * scale, textureHeight * scale); TexturedAlignedRect.prepareToDraw(); msgBox.draw(); TexturedAlignedRect.finishedDrawing(); // Draw a rectangle around each individual text item. We draw a different one each // time to get a flicker effect, so it doesn't fully obscure the text. if (true) { outline.setColor(1.0f, 1.0f, 1.0f); int stringNum = mDebugFramedString; mDebugFramedString = (mDebugFramedString + 1) % TextResources.getNumStrings(); boundsRect = mTextRes.getTextureRect(stringNum); // The bounds rect is in bitmap coordinates, with (0,0) in the top left. Translate // it to an offset from the center of the bitmap, and find the center of the rect. float boundsCenterX = boundsRect.exactCenterX() - (textureWidth / 2); float boundsCenterY = boundsRect.exactCenterY() - (textureHeight / 2); // Now scale it to arena coordinates, using the same scale factor we used to // draw the texture with all the messages, and translate it to the center of // the arena. We need to invert Y to match GL conventions. boundsCenterX = ARENA_WIDTH / 2 + (boundsCenterX * scale); boundsCenterY = ARENA_HEIGHT / 2 - (boundsCenterY * scale); // Set the values and draw the rect. outline.setPosition(boundsCenterX, boundsCenterY); outline.setScale(boundsRect.width() * scale, boundsRect.height() * scale); OutlineAlignedRect.prepareToDraw(); outline.draw(); OutlineAlignedRect.finishedDrawing(); } } }
From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java
private void readdb() { String dbtablename = "floorplan"; int startcolumn = 1; Log.d("reading from db started", "true"); Tabs1.db.showtableslog();/*w ww.jav a2 s .co m*/ Tabs1.db.showfulldblog(dbtablename); ArrayList<String> rectleft = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> recttop = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> rectright = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> rectbottom = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> type = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> tempsensorcount = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> percentsize = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> samscount = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> masterelcnumber = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> displaynumber = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> scaledx = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> scaledy = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> x = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> y = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> string = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> fontsize = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> fontcolor = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> metersperpixel = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> floorplannumber = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> elcdisplaynum = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> tabnumber = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> tabitemnumber = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> textoffsetx = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); ArrayList<String> textoffsety = Tabs1.db.getcolumn(dbtablename, startcolumn++, Tabs1.db.KEY_FLOORPLAN_TITLES); int numberofitems = rectleft.size(); for (int t = 0; t < numberofitems; t++) { try { // view.ITEMrect[t].left=u.i(rectleft.get(t)); // view.ITEMrect[t].top=u.i(rectleft.get(t)); // view.ITEMrect[t].right=u.i(rectleft.get(t)); // view.ITEMrect[t].bottom=u.i(rectleft.get(t)); view.ITEMrect[t] = new Rect(u.i(rectleft.get(t)), u.i(recttop.get(t)), u.i(rectright.get(t)), u.i(rectbottom.get(t))); view.ITEMtype[t] = u.i(type.get(t)); view.ITEMtempsensorcount[t] = u.i(tempsensorcount.get(t)); view.ITEMsizepercent[t] = u.i(percentsize.get(t)); view.ITEMsamscount[t] = u.i(samscount.get(t)); view.ITEMmasterelcnumber[t] = u.i(masterelcnumber.get(t)); view.ITEMdisplaynumber[t] = u.i(displaynumber.get(t)); view.SCALEDITEMx[t] = Float.parseFloat(scaledx.get(t)); view.SCALEDITEMy[t] = Float.parseFloat(scaledy.get(t)); view.ITEMx[t] = Float.parseFloat(x.get(t)); System.out.println("t=" + t); view.ITEMy[t] = Float.parseFloat(y.get(t)); view.ITEMstring[t] = string.get(t); try { view.ITEMfontsize[t] = u.i(fontsize.get(t)); } catch (Throwable e) { e.printStackTrace(); view.ITEMfontsize[t] = view.defaulttextsize; } view.ITEMfontcolor[t] = u.i(fontcolor.get(t)); view.ITEMmetersperpixel[t] = Float.parseFloat(metersperpixel.get(t)); view.ITEMfloorplannumber[t] = u.i(floorplannumber.get(t)); view.ELCdisplaynumber[t] = u.i(elcdisplaynum.get(t)); view.ITEMLINKtabnumber[t] = u.i(tabnumber.get(t)); view.ITEMLINKtabitemnumber[t] = u.i(tabitemnumber.get(t)); view.ITEMtextoffsetx[t] = u.i(textoffsetx.get(t)); view.ITEMtextoffsety[t] = u.i(textoffsety.get(t)); Log.d("item found", u.s((int) view.ITEMx[t])); } catch (NullPointerException e) { System.out.println("couldn't find item t=" + t); } } view.i = numberofitems; Log.d("i on readdb", u.s(view.i)); int i = 0; for (i = 0; i < numberofitems; i++) { assignbitmaps(i); } for (i = 0; i < numberofitems; i++) { view.commenceresizeofitem(i, false); } }
From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java
/** * Once source image and view dimensions are known, creates a map of sample * size to tile grid./*from w ww.ja v a2 s . c om*/ */ private void initialiseTileMap(Point maxTileDimensions) { this.tileMap = new LinkedHashMap<Integer, List<Tile>>(); int sampleSize = fullImageSampleSize; int xTiles = 1; int yTiles = 1; while (true) { int sTileWidth = sWidth() / xTiles; int sTileHeight = sHeight() / yTiles; int subTileWidth = sTileWidth / sampleSize; int subTileHeight = sTileHeight / sampleSize; while (subTileWidth > maxTileDimensions.x || (subTileWidth > getWidth() * 1.25 && sampleSize < fullImageSampleSize)) { xTiles += 1; sTileWidth = sWidth() / xTiles; subTileWidth = sTileWidth / sampleSize; } while (subTileHeight > maxTileDimensions.y || (subTileHeight > getHeight() * 1.25 && sampleSize < fullImageSampleSize)) { yTiles += 1; sTileHeight = sHeight() / yTiles; subTileHeight = sTileHeight / sampleSize; } List<Tile> tileGrid = new ArrayList<Tile>(xTiles * yTiles); for (int x = 0; x < xTiles; x++) { for (int y = 0; y < yTiles; y++) { Tile tile = new Tile(); tile.sampleSize = sampleSize; tile.visible = sampleSize == fullImageSampleSize; tile.sRect = new Rect(x * sTileWidth, y * sTileHeight, (x + 1) * sTileWidth, (y + 1) * sTileHeight); tileGrid.add(tile); } } tileMap.put(sampleSize, tileGrid); if (sampleSize == 1) { break; } else { sampleSize /= 2; } } }
From source file:com.VVTeam.ManHood.Fragment.HistogramFragment.java
private Bitmap makeSnapshot() { contentRelative.setDrawingCacheEnabled(true); contentRelative.buildDrawingCache(); Bitmap bm = contentRelative.getDrawingCache(); int width = bm.getWidth(); int height = bm.getHeight(); Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.histogram_bg); Bitmap logo = BitmapFactory.decodeResource(getResources(), R.drawable.manhoodlogo); Bitmap cs = null;/*from w w w . ja va 2s. c o m*/ cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas comboImage = new Canvas(cs); Rect src = new Rect(0, 0, background.getWidth() - 1, background.getHeight() - 1); Rect dest = new Rect(0, 0, width - 1, height - 1); comboImage.drawBitmap(background, src, dest, null); comboImage.drawBitmap(bm, 0f, 0f, null); comboImage.drawBitmap(logo, 7.0f, height - logo.getHeight() - 4.0f, null); return cs; }