Example usage for android.graphics Rect width

List of usage examples for android.graphics Rect width

Introduction

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

Prototype

public final int width() 

Source Link

Usage

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  w  w w. j  ava2 s  .c  om*/
        animSet.addAnimation(alpha);
        animSet.setFillEnabled(true);
        animSet.setFillAfter(true);

        v.clearAnimation();
        v.startAnimation(animSet);
    }
}

From source file:com.hezaijin.advance.widgets.view.progress.DiscreteSeekBar.java

private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) {
    final Rect bounds = mTempRect;
    mThumb.copyBounds(bounds);/*from  w  w w.j av a 2 s.  com*/
    //Grow the current thumb rect for a bigger touch area
    bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY()));
    if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) {
        //If the user clicked outside the thumb, we compute the current position
        //and force an immediate drag to it.
        mIsDragging = true;
        mDraggOffset = (bounds.width() / 2) - mAddedTouchBounds;
        updateDragging(ev);
        //As the thumb may have moved, get the bounds again
        mThumb.copyBounds(bounds);
        bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    }
    if (mIsDragging) {
        setPressed(true);
        attemptClaimDrag();
        setHotspot(ev.getX(), ev.getY());
        mDraggOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds);
    }
    return mIsDragging;
}

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  a v a2 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:com.dirkgassen.wator.ui.view.RollingGraphView.java

/**
 * Paints the data points of one series vertically.
 *
 * @param c          canvas to paint to/* www.  j  a  v a  2  s .  c o 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 paintSeriesVertical(Canvas c, Rect nameBounds, int seriesNo, int width,
        @SuppressWarnings("UnusedParameters") int height, float maxValue) {
    float paddingLeft = getPaddingLeft();
    float paddingTop = getPaddingTop();
    float paddingRight = getPaddingRight();
    float paddingBottom = getPaddingBottom();

    float y = nameBounds.height() + paddingTop;
    float x;
    if (currentValue == -1) {
        x = (width - paddingLeft - paddingRight) / (seriesNames.length + 1) * (seriesNo + 1) + paddingLeft;
    } 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);
        }
        x = dataValues[currentValue][seriesNo] * (width - paddingLeft - paddingRight) / maxValue + paddingLeft;
    }
    c.drawText(seriesNames[seriesNo], x - nameBounds.width() / 2, y, seriesPaints[seriesNo]);

    float scale = seriesPaints[seriesNo].getStrokeWidth();
    y += 6f * scale;
    c.drawLine(x, y, x, y - 3f * scale, 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 = dataValues[no][seriesNo] * (width - paddingLeft - paddingRight) / maxValue
                    + paddingLeft;
            float newY = y + 1;
            c.drawLine(x, y, newX, newY, seriesPaints[seriesNo]);
            x = newX;
            y = newY;
            no = no == 0 ? dataValues.length - 1 : no - 1;
        } while (no != oldestValue && y < height - paddingBottom);
    }
}

From source file:com.roger.lineselectionwebview.LSWebView.java

/**
 * ?/* w  w  w.  j a  v a2 s .co  m*/
 */
private void drawImage() {
    int size = rectList.size();
    Rect endRect = rectList.get(size - 1);
    Rect realEndRect = endRect;

    // ?left???,,?
    if (size > 2) {
        Rect endPreRect = rectList.get(size - 2);
        if (endRect.left == endPreRect.left) {
            if (endRect.width() > endPreRect.width()) {
                realEndRect = endPreRect;
            } else {
                realEndRect = endRect;
            }
        }
    }

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.del);
    ImageView imageView = new ImageView(mContext);
    imageView.setImageBitmap(bitmap);
    imageView.setScaleType(ScaleType.CENTER);
    imageView.setTag(selectContext);
    MyAbsoluteLayout.LayoutParams lp = new MyAbsoluteLayout.LayoutParams(
            MyAbsoluteLayout.LayoutParams.WRAP_CONTENT, MyAbsoluteLayout.LayoutParams.WRAP_CONTENT,
            realEndRect.right, realEndRect.bottom);
    imageView.setLayoutParams(lp);

    imageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String tag = (String) v.getTag();
            lineView.remove(tag);
            myLayout.removeView(v);
            if (onTextSelectListener != null) {
                onTextSelectListener.cancle(tag.split(SELECT_SPLIT)[0]);
            }
        }

    });
    myLayout.addView(imageView, lp);
}

From source file:com.acious.android.paginationseekbar.PaginationSeekBar.java

private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) {
    final Rect bounds = mTempRect;
    mThumb.copyBounds(bounds);//from  ww  w . j ava  2 s .c  o  m
    //Grow the current thumb rect for a bigger touch area
    bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY()));

    if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) {
        //If the user clicked outside the thumb, we compute the current position
        //and force an immediate drag to it.                    setProgress(mMax-1);

        mIsDragging = true;
        mDragOffset = (bounds.width() / 2) - mAddedTouchBounds;
        updateDragging(ev);
        //As the thumb may have moved, get the bounds again
        mThumb.copyBounds(bounds);
        bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    }
    if (mIsDragging) {
        setPressed(true);
        attemptClaimDrag();
        setHotspot(ev.getX(), ev.getY());
        mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds);
    }

    return mIsDragging;
}

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.  ja  va2  s. c om*/
            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.waz.zclient.pages.main.participants.dialog.ParticipantsDialogFragment.java

private void setDialogPosition(Rect rect, int posX, int posY, int dialogWidth, int dialogHeight) {
    if (getControllerFactory().getConversationScreenController()
            .getPopoverLaunchMode() == DialogLaunchMode.COMMON_USER) {
        dialogTranslationX = posX + (rect.width() - dialogWidth) / 2;
        marker.setVisibility(View.VISIBLE);
    } else if (getControllerFactory().getConversationScreenController()
            .getPopoverLaunchMode() == DialogLaunchMode.CONVERSATION_TOOLBAR) {
        int screenWidth = ViewUtils.getRealDisplayWidth(getActivity());
        dialogTranslationX = screenWidth / 2 - dialogWidth / 2;
        marker.setVisibility(View.INVISIBLE);
    } else {//  w w  w  .  j a  v  a  2  s  .com
        dialogTranslationX = getResources()
                .getDimensionPixelSize(R.dimen.framework__participants_dialog__pos_x);
        marker.setVisibility(View.VISIBLE);
    }

    int markerHeight = marker.getMeasuredHeight() / 2; // because we draw on our own
    int markerWidth = marker.getMeasuredWidth();

    markerTranslationX = posX + (rect.width() - markerWidth) / 2;

    int displayHeight;
    int displayWidth;

    boolean forceRight = getControllerFactory().getConversationScreenController()
            .getPopoverLaunchMode() == DialogLaunchMode.SEARCH
            || getControllerFactory().getConversationScreenController()
                    .getPopoverLaunchMode() == DialogLaunchMode.CONVERSATION_MENU;

    if (ViewUtils.isInPortrait(getActivity())) {
        displayHeight = ViewUtils.getOrientationIndependentDisplayHeight(getActivity());
        displayWidth = ViewUtils.getOrientationIndependentDisplayWidth(getActivity());
    } else {
        displayHeight = ViewUtils.getOrientationIndependentDisplayWidth(getActivity());
        displayWidth = ViewUtils.getOrientationIndependentDisplayHeight(getActivity());
    }

    final int screenBottom = displayHeight - participantDialogPadding
            - ViewUtils.getStatusBarHeight(getActivity());
    final int screenRight = displayWidth - participantDialogPadding;
    final int screenLeft = participantDialogPadding;

    if ((posY - dialogHeight - markerHeight) >= participantDialogPadding && !forceRight) {
        // put above
        markerTranslationY = posY - markerHeight;
        dialogTranslationY = markerTranslationY - dialogHeight;
        marker.setRotation(0f);
        if (dialogTranslationX + dialogWidth > screenRight) {
            // too far right
            dialogTranslationX = screenRight - dialogWidth;
        } else if (dialogTranslationX < participantDialogPadding) {
            // too far left
            dialogTranslationX = participantDialogPadding;
        }
        selfGravity = Gravity.TOP;
    } else if (posY + rect.height() + dialogHeight + markerHeight < screenBottom && !forceRight) {
        // put below
        markerTranslationY = posY + rect.height() - markerHeight;
        dialogTranslationY = markerTranslationY + 2 * markerHeight; // 2 * because we draw on our own
        marker.setRotation(180f);
        if (dialogTranslationX + dialogWidth > screenRight) {
            // too far right
            dialogTranslationX = screenRight - dialogWidth;
        } else if (dialogTranslationX < participantDialogPadding) {
            // too far left
            dialogTranslationX = participantDialogPadding;
        }
        selfGravity = Gravity.BOTTOM;
    } else if (posX + rect.width() + markerWidth + dialogWidth <= displayWidth - participantDialogPadding
            || forceRight) {
        int tmp = markerHeight;
        //noinspection SuspiciousNameCombination
        markerHeight = markerWidth;
        markerWidth = tmp;

        // centered
        markerTranslationX = posX + rect.width() - markerWidth;
        dialogTranslationX = markerTranslationX + 2 * markerWidth; // 2 * because we draw on our own

        markerTranslationY = (posY + rect.centerY()) - (markerHeight / 2);
        dialogTranslationY = (posY + rect.centerY()) - (dialogHeight / 2);
        marker.setRotation(90f);

        if (dialogTranslationY < participantDialogPadding) {
            // too high
            dialogTranslationY = participantDialogPadding;
        } else if (posY + dialogHeight > screenBottom) {
            // too low
            dialogTranslationY = displayHeight - participantDialogPadding - dialogHeight
                    - ViewUtils.getStatusBarHeight(getActivity());
        }

        // too far right
        if (dialogTranslationX + dialogWidth > screenRight) {
            dialogTranslationX = screenRight - dialogWidth;
            markerTranslationX = dialogTranslationX - 2 * markerWidth; // 2 * because we draw on our own
        }
        selfGravity = Gravity.RIGHT;
    } else {
        int tmp = markerHeight;
        //noinspection SuspiciousNameCombination
        markerHeight = markerWidth;
        markerWidth = tmp;

        // centered
        markerTranslationX = posX - markerWidth;
        dialogTranslationX = markerTranslationX - dialogWidth;

        markerTranslationY = (posY + rect.centerY()) - (markerHeight / 2);
        dialogTranslationY = (posY + rect.centerY()) - (dialogHeight / 2);
        marker.setRotation(270f);

        if (dialogTranslationY < participantDialogPadding) {
            // too high
            dialogTranslationY = participantDialogPadding;
        } else if (posY + dialogHeight > screenBottom) {
            // too low
            dialogTranslationY = displayHeight - participantDialogPadding - dialogHeight
                    - ViewUtils.getStatusBarHeight(getActivity());
        }

        // too far left
        if (dialogTranslationX < screenLeft) {
            dialogTranslationX = screenLeft;
            markerTranslationX = dialogTranslationX + dialogWidth;
        }

        selfGravity = Gravity.LEFT;
    }

    dialogFrameLayout.setTranslationX(dialogTranslationX);
    dialogFrameLayout.setTranslationY(dialogTranslationY);

    marker.setTranslationX(markerTranslationX);
    marker.setTranslationY(markerTranslationY);
}

From source file:com.duy.pascal.ui.view.console.ConsoleView.java

public boolean updateSize() {
    boolean invalid = false;
    Rect visibleRect = new Rect();
    getWindowVisibleDisplayFrame(visibleRect);
    int newHeight;
    int newWidth;
    int newTop;/*from w w  w . j  a va 2  s . co  m*/
    int newLeft;

    if (mConsoleScreen.isFullScreen()) {
        newTop = Math.min(getTop(), visibleRect.top);
        newHeight = visibleRect.bottom - newTop;
    } else {
        newTop = getTop();
        newHeight = visibleRect.height();
    }
    newWidth = visibleRect.width();
    newLeft = visibleRect.left;

    if ((newWidth != mConsoleScreen.getVisibleWidth()) || (newHeight != mConsoleScreen.getVisibleHeight())) {
        mConsoleScreen.setVisibleWidth(newWidth);
        mConsoleScreen.setVisibleHeight(newHeight);
        try {
            updateSize(mConsoleScreen.getVisibleWidth(), mConsoleScreen.getVisibleHeight());
        } catch (ArrayIndexOutOfBoundsException ignored) {
        }
        invalid = true;
    }
    if ((newLeft != mConsoleScreen.getLeftVisible()) || (newTop != mConsoleScreen.getTopVisible())) {
        mConsoleScreen.setLeftVisible(newLeft);
        mConsoleScreen.setTopVisible(newTop);
        invalid = true;
    }

    if (invalid)
        postInvalidate();
    return invalid;
}

From source file:com.example.mr_holmes.slidingbartest.DiscreteSeekBar.java

private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) {
    final Rect bounds = mTempRect;
    mThumb.copyBounds(bounds);/*from   www. j  av a2  s  .  co m*/
    //Grow the current thumb rect for a bigger touch area
    bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY()));
    if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) {
        //If the user clicked outside the thumb, we compute the current position
        //and force an immediate drag to it.
        mIsDragging = true;
        mDragOffset = (bounds.width() / 2) - mAddedTouchBounds;
        updateDragging(ev);
        //As the thumb may have moved, get the bounds again
        mThumb.copyBounds(bounds);
        bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    }
    if (mIsDragging) {
        setPressed(true);
        attemptClaimDrag();
        setHotspot(ev.getX(), ev.getY());
        mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds);
    }
    return mIsDragging;
}