Example usage for android.graphics RectF RectF

List of usage examples for android.graphics RectF RectF

Introduction

In this page you can find the example usage for android.graphics RectF RectF.

Prototype

public RectF(float left, float top, float right, float bottom) 

Source Link

Document

Create a new rectangle with the specified coordinates.

Usage

From source file:com.askjeffreyliu.camera2barcode.camera.CameraSource.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *//*w  ww. jav a  2  s  . com*/
private void configureTransform(int viewWidth, int viewHeight) {
    if (null == mTextureView || null == mPreviewSize) {
        return;
    }
    int rotation = mDisplayOrientation;
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}

From source file:com.frank.protean.photoview.PhotoViewAttacher.java

/**
 * Calculate Matrix for FIT_CENTER/* w  w  w.ja v a2s. com*/
 *
 * @param drawable - Drawable being displayed
 */
private void updateBaseMatrix(Drawable drawable) {
    if (drawable == null) {
        return;
    }

    final float viewWidth = getImageViewWidth(mImageView);
    final float viewHeight = getImageViewHeight(mImageView);
    final int drawableWidth = drawable.getIntrinsicWidth();
    final int drawableHeight = drawable.getIntrinsicHeight();

    mBaseMatrix.reset();

    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;

    if (mScaleType == ScaleType.CENTER) {
        mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);

    } else if (mScaleType == ScaleType.CENTER_CROP) {
        float scale = Math.max(widthScale, heightScale);
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
        float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);

        if ((int) mBaseRotation % 180 != 0) {
            mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth);
        }

        switch (mScaleType) {
        case FIT_CENTER:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
            break;

        case FIT_START:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
            break;

        case FIT_END:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
            break;

        case FIT_XY:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
            break;

        default:
            break;
        }
    }

    resetMatrix();
}

From source file:edu.ptu.navpattern.tooltip.Tooltip.java

public static RectF calculateRectInWindow(View view) {
    int[] location = new int[2];
    view.getLocationInWindow(location);/* w w w .j  a v  a2  s .c  om*/
    return new RectF(location[0], location[1], location[0] + view.getMeasuredWidth(),
            location[1] + view.getMeasuredHeight());
}

From source file:com.goka.flickableview.ImageViewTouchBase.java

protected RectF getCenter(Matrix supportMatrix, boolean horizontal, boolean vertical) {
    final Drawable drawable = getDrawable();

    if (drawable == null) {
        return new RectF(0, 0, 0, 0);
    }/*from w  ww  .  j a  v  a  2s  .  c  o  m*/

    mCenterRect.set(0, 0, 0, 0);
    RectF rect = getBitmapRect(supportMatrix);
    float height = rect.height();
    float width = rect.width();
    float deltaX = 0, deltaY = 0;
    if (vertical) {
        if (height < mViewPort.height()) {
            deltaY = (mViewPort.height() - height) / 2 - (rect.top - mViewPort.top);
        } else if (rect.top > mViewPort.top) {
            deltaY = -(rect.top - mViewPort.top);
        } else if (rect.bottom < mViewPort.bottom) {
            deltaY = mViewPort.bottom - rect.bottom;
        }
    }
    if (horizontal) {
        if (width < mViewPort.width()) {
            deltaX = (mViewPort.width() - width) / 2 - (rect.left - mViewPort.left);
        } else if (rect.left > mViewPort.left) {
            deltaX = -(rect.left - mViewPort.left);
        } else if (rect.right < mViewPort.right) {
            deltaX = mViewPort.right - rect.right;
        }
    }
    mCenterRect.set(deltaX, deltaY, 0, 0);
    return mCenterRect;
}

From source file:de.telekom.pde.codelibrary.ui.layout.PDESwipeRefreshLayout.java

/**
 * @brief Draw Circle Path/*from   w  w  w .j  a  va  2 s.  c o m*/
 */
private void drawCirclePath() {
    int width = mBounds.width();
    int height = mBounds.height();
    int cx = width / 2;
    int cy = height / 2;

    float innerRadius = 0.7f * PDEBuildingUnits.BU();
    float outerRadius = 0.9f * PDEBuildingUnits.BU();

    mCirclePath = new Path();
    mCirclePath.moveTo(cx, cy - innerRadius);
    mCirclePath.lineTo(cx, cy - outerRadius);

    mCirclePath.arcTo(new RectF(cx - outerRadius, cy - outerRadius, cx + outerRadius, cy + outerRadius), -90.0f,
            ARC_RADIUS);

    mCirclePath.lineTo((float) (cx + Math.sin(degreesToRadians(ARC_RADIUS)) * innerRadius),
            (float) (cy - Math.cos(degreesToRadians(ARC_RADIUS)) * innerRadius));

    mCirclePath.arcTo(new RectF(cx - innerRadius, cy - innerRadius, cx + innerRadius, cy + innerRadius),
            -90.0f + ARC_RADIUS, -ARC_RADIUS);
}

From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java

@Override
public void draw(Canvas canvas) {
    if (mIcon != null || mPlainIcon != null) {
        final Rect viewBounds = getBounds();

        updatePaddingBounds(viewBounds);
        updateTextSize(viewBounds);/* www .j  a  v  a2s .com*/
        offsetIcon(viewBounds);

        if (mBackgroundPaint != null && mRoundedCornerRy > -1 && mRoundedCornerRx > -1) {
            canvas.drawRoundRect(new RectF(0, 0, viewBounds.width(), viewBounds.height()), mRoundedCornerRx,
                    mRoundedCornerRy, mBackgroundPaint);
        }

        mPath.close();

        if (mDrawContour) {
            canvas.drawPath(mPath, mContourPaint);
        }

        mIconPaint.setAlpha(mAlpha);
        mIconPaint.setColorFilter(mColorFilter == null ? mTintFilter : mColorFilter);

        canvas.drawPath(mPath, mIconPaint);
    }
}

From source file:edu.ptu.navpattern.tooltip.Tooltip.java

public static RectF calculateRectOnScreen(View view) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);//  ww  w. ja  va  2  s.  c o m
    return new RectF(location[0], location[1], location[0] + view.getMeasuredWidth(),
            location[1] + view.getMeasuredHeight());
}

From source file:com.tzutalin.dlibtest.CameraConnectionFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *//*from   w  ww .  j a v a 2  s  . c  o m*/
@DebugLog
private void configureTransform(final int viewWidth, final int viewHeight) {
    final Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    final Matrix matrix = new Matrix();
    final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    final float centerX = viewRect.centerX();
    final float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        final float scale = Math.max((float) viewHeight / previewSize.getHeight(),
                (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    textureView.setTransform(matrix);
}

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 w  w w .j  a v  a 2 s.  com*/
            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:de.telekom.pde.codelibrary.ui.layout.PDESwipeRefreshLayout.java

private void drawTrigger(Canvas canvas, int cx, int cy) {
    float innerRadius;
    float outerRadius;
    Path circlePath;// w w  w.  j ava 2s .com

    if (mTriggerPercentage < 0.05f)
        return;

    innerRadius = 0.7f * PDEBuildingUnits.BU();
    outerRadius = 0.9f * PDEBuildingUnits.BU();

    canvas.drawCircle(cx, cy, PDEBuildingUnits.BU(), mPaint);

    circlePath = new Path();

    circlePath.moveTo(cx, cy - innerRadius);
    circlePath.lineTo(cx, cy - outerRadius);

    circlePath.arcTo(new RectF(cx - outerRadius, cy - outerRadius, cx + outerRadius, cy + outerRadius), -90.0f,
            mTriggerPercentage * 360.0f);

    circlePath.lineTo((float) (cx + Math.sin(degreesToRadians(mTriggerPercentage * 360.0f)) * innerRadius),
            (float) (cy - Math.cos(degreesToRadians(mTriggerPercentage * 360.0f)) * innerRadius));

    circlePath.arcTo(new RectF(cx - innerRadius, cy - innerRadius, cx + innerRadius, cy + innerRadius),
            -90.0f + mTriggerPercentage * 360.0f, -mTriggerPercentage * 360.0f);

    canvas.drawPath(circlePath, mWhitePaint);

}