List of usage examples for android.graphics Rect height
public final int height()
From source file:com.android.hcframe.DraggableGridViewPager.java
private void animateDragged() { if (mLastDragged >= 0) { final View v = getChildAt(mLastDragged); final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); r.inset(-r.width() / 20, -r.height() / 20); v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY)); v.layout(r.left, r.top, r.right, r.bottom); AnimationSet animSet = new AnimationSet(true); ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2); scale.setDuration(ANIMATION_DURATION); AlphaAnimation alpha = new AlphaAnimation(1, .5f); alpha.setDuration(ANIMATION_DURATION); animSet.addAnimation(scale);//from www.j a va 2 s . c o m animSet.addAnimation(alpha); animSet.setFillEnabled(true); animSet.setFillAfter(true); v.clearAnimation(); v.startAnimation(animSet); } }
From source file:uk.co.senab.photoview.PhotoViewAttacher.java
public void renderBitmap() { Log.d("RenderBitmap", "Rendering bitmap!!!"); ImageView iv = getImageView(); if (iv != null) { RectF rect = getDisplayRect();// ww w . j a va2 s.c om if (rect == null || rect.isEmpty()) { rect = new RectF(0, 0, originalBitmapSize.x, originalBitmapSize.y); } float ratioX = originalBitmapSize.x / (float) iv.getWidth(); float ratioY = originalBitmapSize.y / (float) iv.getHeight(); rect.set(rect.left * ratioX, rect.top * ratioY, rect.right * ratioX, rect.bottom * ratioY); Rect bounds = new Rect(); rect.round(bounds); Bitmap bitmap = Bitmap.createBitmap(originalBitmapSize.x, originalBitmapSize.y, Bitmap.Config.ARGB_8888); pdfiumCore.renderPageBitmap(pdfDocument, bitmap, pageIndex, bounds.left, bounds.top, bounds.width(), bounds.height()); iv.setImageBitmap(bitmap); } }
From source file:com.mwm.loyal.libs.zxing.ViewfinderView.java
@SuppressLint("DrawAllocation") @Override// w w w.j a v a 2s . co m public void onDraw(Canvas canvas) { if (cameraManager == null) { return; // not ready yet, early draw before done configuring } Rect frame = cameraManager.getFramingRect(); Rect previewFrame = cameraManager.getFramingRectInPreview(); if (frame == null || previewFrame == null) { return; } int width = canvas.getWidth(); int height = canvas.getHeight(); // Draw the exterior (i.e. outside the framing rect) darkened paint.setColor(resultBitmap != null ? resultColor : maskColor); canvas.drawRect(0, 0, width, frame.top, paint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint); canvas.drawRect(0, frame.bottom + 1, width, height, paint); if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle paint.setAlpha(CURRENT_POINT_OPACITY); canvas.drawBitmap(resultBitmap, null, frame, paint); } else { // Draw a red "laser scanner" line through the middle to permissionDialog decoding is active paint.setColor(laserColor); paint.setAlpha(SCANNER_ALPHA[scannerAlpha]); scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length; int middle = frame.height() / 2 + frame.top; canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint); float scaleX = frame.width() / (float) previewFrame.width(); float scaleY = frame.height() / (float) previewFrame.height(); List<ResultPoint> currentPossible = possibleResultPoints; List<ResultPoint> currentLast = lastPossibleResultPoints; int frameLeft = frame.left; int frameTop = frame.top; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new ArrayList<>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(CURRENT_POINT_OPACITY); paint.setColor(resultPointColor); synchronized (currentPossible) { for (ResultPoint point : currentPossible) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint); } } } if (currentLast != null) { paint.setAlpha(CURRENT_POINT_OPACITY / 2); paint.setColor(resultPointColor); synchronized (currentLast) { float radius = POINT_SIZE / 2.0f; for (ResultPoint point : currentLast) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), radius, paint); } } } // Request another update at the animation interval, but only repaint the laser line, // not the entire viewfinder mask. postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE); } }
From source file:com.dynamixsoftware.printingsample.PrintServiceFragment.java
@Override public void onClick(View v) { final Context appContext = requireContext().getApplicationContext(); switch (v.getId()) { case R.id.set_license: printingSdk.setLicense("YOUR_LICENSE_HERE", new ISetLicenseCallback.Stub() { @Override//from ww w. j a v a 2 s .co m public void start() { Toast.makeText(appContext, "set license start", Toast.LENGTH_SHORT).show(); } @Override public void serverCheck() { Toast.makeText(appContext, "set license check server", Toast.LENGTH_SHORT).show(); } @Override public void finish(Result result) { Toast.makeText(appContext, "set license finish " + (result == Result.OK ? "ok" : "error"), Toast.LENGTH_SHORT).show(); } }); break; case R.id.init_current_and_recent_printers: try { printingSdk.initRecentPrinters(new ISetupPrinterListener.Stub() { @Override public void start() { toastInMainThread(appContext, "ISetupPrinterListener start"); } @Override public void libraryPackInstallationProcess(int arg0) { toastInMainThread(appContext, "ISetupPrinterListener libraryPackInstallationProcess " + arg0 + " %"); } @Override public void finish(Result arg0) { toastInMainThread(appContext, "ISetupPrinterListener finish " + arg0.name()); if (arg0.getType().equals(ResultType.ERROR_LIBRARY_PACK_NOT_INSTALLED)) { // printingSdk.setup should be called with forceInstall = true to download required drivers } } }); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.get_current_printer: try { Printer currentPrinter = printingSdk.getCurrentPrinter(); showDialog(getString(R.string.success), "Current printer:\n" + (currentPrinter != null ? currentPrinter.getName() : "null")); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.get_recent_printers: try { List<Printer> recentPrinters = printingSdk.getRecentPrintersList(); String message = ""; for (Printer printer : recentPrinters) message += printer.getName() + "\n"; if (message.length() == 0) message = "No recent printers"; showDialog(getString(R.string.success), message); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.discover_wifi: try { printingSdk.startDiscoverWiFi(new IDiscoverListener.Stub() { @Override public void start() { toastInMainThread(appContext, "IDiscoverListener start"); } @Override public void printerFound(List<Printer> arg0) { toastInMainThread(appContext, "IDiscoverListener printerFound"); discoveredPrinters.clear(); discoveredPrinters.addAll(arg0); } @Override public void finish(Result arg0) { toastInMainThread(appContext, "IDiscoverListener finish " + arg0.name()); } }); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.discover_bluetooth: try { printingSdk.startDiscoverBluetooth(new IDiscoverListener.Stub() { @Override public void start() { toastInMainThread(appContext, "IDiscoverListener start"); } @Override public void printerFound(List<Printer> arg0) { toastInMainThread(appContext, "IDiscoverListener printerFound"); discoveredPrinters.clear(); discoveredPrinters.addAll(arg0); } @Override public void finish(Result arg0) { toastInMainThread(appContext, "IDiscoverListener finish " + arg0.name()); } }); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.discover_google_cloud: try { printingSdk.startDiscoverCloud("YOUR_GOOGLE_ACCOUNT_NAME", new IDiscoverCloudListener.Stub() { @Override public void start() { toastInMainThread(appContext, "IDiscoverCloudListener start"); } @Override public void showAuthorization(Intent arg0) { // Launch Intent arg0 to show authorization activity } @Override public void printerFound(List<Printer> arg0) { toastInMainThread(appContext, "IDiscoverCloudListener printerFound"); discoveredPrinters.clear(); discoveredPrinters.addAll(arg0); } @Override public void finish(Result arg0) { toastInMainThread(appContext, "IDiscoverCloudListener finish " + arg0.name()); } }); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.discover_smb: try { discoverSmb = printingSdk.startDiscoverSmb(new IDiscoverSmbListener.Stub() { @Override public void start() { toastInMainThread(appContext, "IDiscoverSmbListener start"); } @Override public void smbFilesFound(List<SmbFile> arg0) { // Show list of SMB files. This listener is used for navigation. // You should call discoverSmbControl.move(arg0) to change location. } @Override public void showAuthorization() { // You have to ask user for authorization credentials and call discoverSmbControl.login(arg0, arg1); } @Override public void printerFound(List<Printer> arg0) { toastInMainThread(appContext, "IDiscoverSmbListener printerFound"); discoveredPrinters.clear(); discoveredPrinters.addAll(arg0); } @Override public void finish(Result arg0) { toastInMainThread(appContext, "IDiscoverSmbListener finish " + arg0.name()); } }); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.discover_usb: try { printingSdk.startDiscoverUSB(new IDiscoverListener.Stub() { @Override public void start() { toastInMainThread(appContext, "IDiscoverListener start"); } @Override public void printerFound(List<Printer> arg0) { toastInMainThread(appContext, "IDiscoverListener printerFound"); discoveredPrinters.clear(); discoveredPrinters.addAll(arg0); } @Override public void finish(Result arg0) { toastInMainThread(appContext, "IDiscoverListener finish " + arg0.name()); } }); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.find_driver: if (!discoveredPrinters.isEmpty()) { Printer printer = discoveredPrinters.get(0); try { printingSdk.findDrivers(printer, new IFindDriversListener.Stub() { @Override public void start() { toastInMainThread(appContext, "IFindDriversListener start"); } @Override public void finish(List<DriversSearchEntry> arg0) { toastInMainThread(appContext, "IFindDriversListener finish; Found " + arg0.size() + " drivers entries;" + ((arg0.size() == 0) ? "" : "")); driversSearchEntries.clear(); driversSearchEntries.addAll(arg0); } }); } catch (RemoteException e) { e.printStackTrace(); } } else showDialog(getString(R.string.error), "Discover printers first"); break; case R.id.get_drivers: if (!discoveredPrinters.isEmpty()) { Printer printer = discoveredPrinters.get(0); TransportType transportType = printer.getTransportTypes().get(0); if (transportType != null) { try { printingSdk.getDriversList(printer, transportType, new IGetDriversListener.Stub() { @Override public void start() { toastInMainThread(appContext, "IGetDriversListener start"); } @Override public void finish(List<DriverHandleEntry> arg0) { toastInMainThread(appContext, "IGetDriversListener finish"); driverHandleEntries.clear(); driverHandleEntries.addAll(arg0); } }); } catch (RemoteException e) { e.printStackTrace(); } } } else showDialog(getString(R.string.error), "Discover printers first"); break; case R.id.setup_recent_printer: try { List<Printer> printerList = printingSdk.getRecentPrintersList(); if (!printerList.isEmpty()) printingSdk.setup(printerList.get(0), true, new ISetupPrinterListener.Stub() { @Override public void start() { toastInMainThread(appContext, "ISetupPrinterListener start"); } @Override public void libraryPackInstallationProcess(int arg0) { toastInMainThread(appContext, "ISetupPrinterListener libraryPackInstallationProcess " + arg0 + " %"); } @Override public void finish(Result arg0) { toastInMainThread(appContext, "ISetupPrinterListener finish " + arg0.name()); if (arg0.getType().equals(ResultType.ERROR_LIBRARY_PACK_NOT_INSTALLED)) { // printingSdk.setup should be called with forceInstall = true to download required drivers } } }); else showDialog(getString(R.string.error), "No recent printers"); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.setup_discovered_printer: if (!discoveredPrinters.isEmpty()) { if (!driversSearchEntries.isEmpty()) { Printer printer = discoveredPrinters.get(0); DriversSearchEntry driversSearchEntry = driversSearchEntries.get(0); try { printingSdk.setup(printer, driversSearchEntry.getDriverHandlesList().get(0), driversSearchEntry.getTransportType(), false, new ISetupPrinterListener.Stub() { @Override public void start() { toastInMainThread(appContext, "ISetupPrinterListener start"); } @Override public void libraryPackInstallationProcess(int arg0) { toastInMainThread(appContext, "ISetupPrinterListener libraryPackInstallationProcess " + arg0 + " %"); } @Override public void finish(Result arg0) { toastInMainThread(appContext, "ISetupPrinterListener finish " + arg0.name()); if (arg0.getType().equals(ResultType.ERROR_LIBRARY_PACK_NOT_INSTALLED)) { // printingSdk.setup should be called with forceInstall = true to download required drivers } } }); } catch (RemoteException e) { e.printStackTrace(); } } else showDialog(getString(R.string.error), "Find driver first"); } else showDialog(getString(R.string.error), "Discover printers first"); break; case R.id.change_options: try { Printer currentPrinter = printingSdk.getCurrentPrinter(); if (currentPrinter != null) { List<PrinterOption> options = currentPrinter.getOptions(); if (options.size() > 0) { Random random = new Random(); PrinterOption option = options.get(random.nextInt(options.size())); PrinterOptionValue currentValue = option.getOptionValue(); List<PrinterOptionValue> valuesList = option.getOptionValueList(); PrinterOptionValue newValue = valuesList.get(random.nextInt(valuesList.size())); printingSdk.setCurrentPrinterOptionValue(option, newValue); Toast.makeText(requireContext().getApplicationContext(), "option " + option.getName() + " changed from " + currentValue + " to " + newValue, Toast.LENGTH_LONG).show(); } } else showDialog(getString(R.string.error), "Setup printer first"); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.print_image: try { if (printingSdk.getCurrentPrinter() != null) { List<IPage> pages = new ArrayList<>(); pages.add(new IPage() { @Override public Bitmap getBitmapFragment(Rect fragment) { Printer printer = null; try { printer = printingSdk.getCurrentPrinter(); } catch (RemoteException e) { e.printStackTrace(); } if (printer != null) { Bitmap bitmap = Bitmap.createBitmap(fragment.width(), fragment.height(), Bitmap.Config.ARGB_8888); for (int i = 0; i < 3; i++) try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = false; if (i > 0) { options.inSampleSize = 1 << i; } Bitmap imageBMP = BitmapFactory.decodeStream(new FileInputStream( FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG)), null, options); Paint p = new Paint(); int imageWidth = 0; int imageHeight = 0; if (imageBMP != null) { imageWidth = imageBMP.getWidth(); imageHeight = imageBMP.getHeight(); } int xDpi = printer.getContext().getHResolution(); int yDpi = printer.getContext().getVResolution(); // in dots int paperWidth = printer.getContext().getPaperWidth() * xDpi / 72; int paperHeight = printer.getContext().getPaperHeight() * yDpi / 72; float aspectH = (float) imageHeight / (float) paperHeight; float aspectW = (float) imageWidth / (float) paperWidth; RectF dst = new RectF(0, 0, fragment.width() * aspectW, fragment.height() * aspectH); float sLeft = 0; float sTop = fragment.top * aspectH; float sRight = imageWidth; float sBottom = fragment.top * aspectH + fragment.bottom * aspectH; RectF source = new RectF(sLeft, sTop, sRight, sBottom); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.WHITE); // move image to actual printing area dst.offsetTo(dst.left - fragment.left, dst.top - fragment.top); Matrix matrix = new Matrix(); matrix.setRectToRect(source, dst, Matrix.ScaleToFit.FILL); canvas.drawBitmap(imageBMP, matrix, p); break; } catch (IOException ex) { ex.printStackTrace(); break; } catch (OutOfMemoryError ex) { if (bitmap != null) { bitmap.recycle(); bitmap = null; } continue; } return bitmap; } else return null; } }); try { printingSdk.print(pages, 1, new IPrintListener.Stub() { @Override public void startingPrintJob() { toastInMainThread(appContext, "IPrintListener startingPrintJob"); } @Override public void start() { toastInMainThread(appContext, "IPrintListener start"); } @Override public void sendingPage(int arg0, int arg1) { toastInMainThread(appContext, "IPrintListener sendingPage " + arg0 + "; progress " + arg1 + "%"); } @Override public void preparePage(int arg0) { toastInMainThread(appContext, "IPrintListener preparePage " + arg0); } @Override public boolean needCancel() { toastInMainThread(appContext, "IPrintListener needCancel"); // Return false if cancel needed. return false; } @Override public void finishingPrintJob() { toastInMainThread(appContext, "IPrintListener finishingPrintJob"); } @Override public void finish(Result arg0, int arg1, int arg2) { toastInMainThread(appContext, "IPrintListener finish Result " + arg0 + "; Result type " + arg0.getType() + "; Total pages " + arg1 + "; Pages sent " + arg2); } }); } catch (RemoteException e) { e.printStackTrace(); } } else showDialog(getString(R.string.error), "You must setup printer before print"); } catch (RemoteException e) { e.printStackTrace(); } break; } }
From source file:com.dirkgassen.wator.ui.view.RollingGraphView.java
/** * Paints the data points of one series horizontally. * * @param c canvas to paint to/*from www. j a v a 2 s .co m*/ * @param nameBounds bounds of the label * @param seriesNo index of the series to paint * @param width width of the view * @param height height of the view * @param maxValue calculated possible maximum data value */ private void paintSeriesHorizontal(Canvas c, Rect nameBounds, int seriesNo, int width, int height, float maxValue) { float paddingLeft = getPaddingLeft(); float paddingTop = getPaddingTop(); float paddingRight = getPaddingRight(); float paddingBottom = getPaddingBottom(); float x = width - nameBounds.width() - paddingRight; float y; if (currentValue == -1) { y = height - (height - paddingBottom - paddingTop) / (seriesNames.length + 1) * (seriesNo + 1) + paddingTop; } else { if (dataValues == null) { Log.e("Wa-Tor", "NO DATA VALUES although currentValue is " + currentValue); } else if (dataValues[currentValue] == null) { Log.e("Wa-Tor", "NO SERIES DATA although currentValue is " + currentValue); } y = height - paddingBottom - dataValues[currentValue][seriesNo] * (height - paddingBottom - paddingTop) / maxValue; } c.drawText(seriesNames[seriesNo], x, y + nameBounds.height() / 2, seriesPaints[seriesNo]); float scale = seriesPaints[seriesNo].getStrokeWidth(); x -= 6f * scale; c.drawLine(x, y, x + 3f * scale, y, seriesPaints[seriesNo]); c.drawLine(x, y, x + 1.5f * scale, y + 1.5f * scale, seriesPaints[seriesNo]); c.drawLine(x, y, x + 1.5f * scale, y - 1.5f * scale, seriesPaints[seriesNo]); if (currentValue != -1) { int no = currentValue; do { if (dataValues[no] == null) { break; } float newX = x - 1; float newY = height - paddingBottom - dataValues[no][seriesNo] * (height - paddingBottom - paddingTop) / maxValue; c.drawLine(x, y, newX, newY, seriesPaints[seriesNo]); x = newX; y = newY; no = no == 0 ? dataValues.length - 1 : no - 1; } while (no != oldestValue && x > paddingLeft); } }
From source file:com.android.hcframe.DraggableGridViewPager.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int childCount = getChildCount(); mPageCount = (childCount + mPageSize - 1) / mPageSize; mGridWidth = (getWidth() - mPaddingLeft - mPaddingRight - (mColCount - 1) * mGridGap) / mColCount; mGridHeight = (getHeight() - mPaddingTop - mPaddingButtom - (mRowCount - 1) * mGridGap) / mRowCount; // mGridWidth = mGridHeight = Math.min(mGridWidth, mGridHeight); mMaxOverScrollSize = mGridWidth / 2; mEdgeSize = mGridWidth / 2;//from w ww . j av a 2 s . c o m newPositions.clear(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final Rect rect = getRectByPosition(i); child.measure(MeasureSpec.makeMeasureSpec(rect.width(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(rect.height(), MeasureSpec.EXACTLY)); child.layout(rect.left, rect.top, rect.right, rect.bottom); newPositions.add(-1); } if (mCurItem > 0 && mCurItem < mPageCount) { final int curItem = mCurItem; mCurItem = 0; setCurrentItem(curItem); } }
From source file:com.owen.tvrecyclerview.widget.TvRecyclerView.java
@Override public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) { final int parentLeft = getPaddingLeft(); final int parentTop = getPaddingTop(); final int parentRight = getWidth() - getPaddingRight(); final int parentBottom = getHeight() - getPaddingBottom(); final int childLeft = child.getLeft() + rect.left; final int childTop = child.getTop() + rect.top; final int childRight = childLeft + rect.width(); final int childBottom = childTop + rect.height(); final int offScreenLeft = Math.min(0, childLeft - parentLeft - mSelectedItemOffsetStart); final int offScreenTop = Math.min(0, childTop - parentTop - mSelectedItemOffsetStart); final int offScreenRight = Math.max(0, childRight - parentRight + mSelectedItemOffsetEnd); final int offScreenBottom = Math.max(0, childBottom - parentBottom + mSelectedItemOffsetEnd); final boolean canScrollHorizontal = getLayoutManager().canScrollHorizontally(); final boolean canScrollVertical = getLayoutManager().canScrollVertically(); // Favor the "start" layout direction over the end when bringing one side or the other // of a large rect into view. If we decide to bring in end because start is already // visible, limit the scroll such that start won't go out of bounds. final int dx; if (canScrollHorizontal) { if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL) { dx = offScreenRight != 0 ? offScreenRight : Math.max(offScreenLeft, childRight - parentRight); } else {//from www . j ava2 s . c o m dx = offScreenLeft != 0 ? offScreenLeft : Math.min(childLeft - parentLeft, offScreenRight); } } else { dx = 0; } // Favor bringing the top into view over the bottom. If top is already visible and // we should scroll to make bottom visible, make sure top does not go out of bounds. final int dy; if (canScrollVertical) { dy = offScreenTop != 0 ? offScreenTop : Math.min(childTop - parentTop, offScreenBottom); } else { dy = 0; } if (cannotScrollForwardOrBackward(isVertical() ? dy : dx)) { mOffset = -1; } else { mOffset = isVertical() ? dy : dx; if (dx != 0 || dy != 0) { if (immediate) { scrollBy(dx, dy); } else { smoothScrollBy(dx, dy); } return true; } } // ?item?getChildDrawingOrder postInvalidate(); return false; }
From source file:cn.ismartv.tvrecyclerview.widget.GridLayoutManager.java
@Override public void setMeasuredDimension(Rect childrenBounds, int wSpec, int hSpec) { if (mCachedBorders == null) { super.setMeasuredDimension(childrenBounds, wSpec, hSpec); }// w w w.j a v a2 s . co m final int width, height; final int horizontalPadding = getPaddingLeft() + getPaddingRight(); final int verticalPadding = getPaddingTop() + getPaddingBottom(); if (mOrientation == VERTICAL) { final int usedHeight = childrenBounds.height() + verticalPadding; height = chooseSize(hSpec, usedHeight, getMinimumHeight()); width = chooseSize(wSpec, mCachedBorders[mCachedBorders.length - 1] + horizontalPadding, getMinimumWidth()); } else { final int usedWidth = childrenBounds.width() + horizontalPadding; width = chooseSize(wSpec, usedWidth, getMinimumWidth()); height = chooseSize(hSpec, mCachedBorders[mCachedBorders.length - 1] + verticalPadding, getMinimumHeight()); } setMeasuredDimension(width, height); }
From source file:cn.dev4mob.app.ui.animationsdemo.ZoomActivity.java
/** * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in" * image view and animating its bounds to fit the entire activity content area. More * specifically://from w w w.j a va 2 s . co m * * <ol> * <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li> * <li>Calculate the starting and ending bounds for the expanded view.</li> * <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y) * simultaneously, from the starting bounds to the ending bounds.</li> * <li>Zoom back out by running the reverse animation on click.</li> * </ol> * * @param thumbView The thumbnail view to zoom in. * @param imageResId The high-resolution version of the image represented by the thumbnail. */ private void zoomImageFromThumb(final View thumbView, int imageResId) { // If there's an animation in progress, cancel it immediately and proceed with this one. if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Load the high-resolution "zoomed-in" image. final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image); expandedImageView.setImageResource(imageResId); // Calculate the starting and ending bounds for the zoomed-in image. This step // involves lots of math. Yay, math. final Rect startBounds = new Rect(); final Rect finalBounds = new Rect(); final Point globalOffset = new Point(); // The start bounds are the global visible rectangle of the thumbnail, and the // final bounds are the global visible rectangle of the container view. Also // set the container view's offset as the origin for the bounds, since that's // the origin for the positioning animation properties (X, Y). thumbView.getGlobalVisibleRect(startBounds); Timber.d("thumbview startBounds = %s", startBounds); findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset); Timber.d("thumbview finalBoundst = %s", finalBounds); Timber.d("thumbview globalOffset = %s", globalOffset); startBounds.offset(-globalOffset.x, -globalOffset.y); finalBounds.offset(-globalOffset.x, -globalOffset.y); // Adjust the start bounds to be the same aspect ratio as the final bounds using the // "center crop" technique. This prevents undesirable stretching during the animation. // Also calculate the start scaling factor (the end scaling factor is always 1.0). float startScale; if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) { // Extend start bounds horizontally startScale = (float) startBounds.height() / finalBounds.height(); float startWidth = startScale * finalBounds.width(); float deltaWidth = (startWidth - startBounds.width()) / 2; startBounds.left -= deltaWidth; startBounds.right += deltaWidth; } else { // Extend start bounds vertically startScale = (float) startBounds.width() / finalBounds.width(); Timber.d("startSCale = %f", startScale); float startHeight = startScale * finalBounds.height(); float deltaHeight = (startHeight - startBounds.height()) / 2; startBounds.top -= deltaHeight; startBounds.bottom += deltaHeight; } // Hide the thumbnail and show the zoomed-in view. When the animation begins, // it will position the zoomed-in view in the place of the thumbnail. thumbView.setAlpha(0f); expandedImageView.setVisibility(View.VISIBLE); // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of // the zoomed-in view (the default is the center of the view). expandedImageView.setPivotX(0f); expandedImageView.setPivotY(0f); // Construct and run the parallel animation of the four translation and scale properties // (X, Y, SCALE_X, and SCALE_Y). AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; // Upon clicking the zoomed-in image, it should zoom back down to the original bounds // and show the thumbnail instead of the expanded image. final float startScaleFinal = startScale; expandedImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Animate the four positioning/sizing properties in parallel, back to their // original values. AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; } }); }
From source file:lewa.support.v7.internal.view.menu.ActionMenuItemView.java
@Override public boolean onLongClick(View v) { if (hasText()) { // Don't show the cheat sheet for items that already show text. return false; }//from ww w . j a v a2s. com final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); ///LEWA MODIFY BEGIN final int height = Injector.getHeight(this); final int midy = Injector.measureMidy(this, screenPos[1], height); //final int height = getHeight(); //final int midy = screenPos[1] + height / 2; ///LEWA MODIFY END int referenceX = screenPos[0] + width / 2; if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) { final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; referenceX = screenWidth - referenceX; // mirror } Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, height); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); return true; }