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.facebook.litho.MountState.java

private static boolean sameSize(LayoutOutput layoutOutput, MountItem item) {
    final Rect layoutOutputBounds = layoutOutput.getBounds();
    final Object mountedContent = item.getContent();

    return layoutOutputBounds.width() == getWidthForMountedContent(mountedContent)
            && layoutOutputBounds.height() == getHeightForMountedContent(mountedContent);
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);//  ww  w.j  ava  2s.  c  o m
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.announceForAccessibility(accessibilityText);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:com.cachirulop.moneybox.fragment.MoneyboxFragment.java

/**
 * Drop money from the top of the layout to the bottom simulating that a
 * coin or bill is inserted in the moneybox.
 * /* w w  w  .j  av  a2 s.co m*/
 * @param leftMargin
 *            Left side of the coin/bill
 * @param width
 *            Width of the image to slide down
 * @param m
 *            Movement with the value of the money to drop
 */
protected void dropMoney(int leftMargin, int width, Movement m) {
    ImageView money;
    AnimationSet moneyDrop;
    RelativeLayout layout;
    RelativeLayout.LayoutParams lpParams;
    Rect r;
    Activity parent;
    CurrencyValueDef curr;

    parent = getActivity();

    curr = CurrencyManager.getCurrencyDef(Math.abs(m.getAmount()));
    r = curr.getDrawable().getBounds();

    money = new ImageView(parent);
    money.setVisibility(View.INVISIBLE);
    money.setImageDrawable(curr.getDrawable().getConstantState().newDrawable());
    money.setTag(curr);
    money.setId((int) m.getIdMovement());

    layout = findLayout();

    lpParams = new RelativeLayout.LayoutParams(r.width(), r.height());
    lpParams.leftMargin = leftMargin;
    lpParams.rightMargin = layout.getWidth() - (leftMargin + width);
    lpParams.topMargin = 0;
    lpParams.bottomMargin = r.height();

    layout.addView(money, lpParams);

    moneyDrop = createDropAnimation(money, layout, curr);
    money.setVisibility(View.VISIBLE);

    SoundsManager.playMoneySound(curr.getType());
    VibratorManager.vibrateMoneyDrop(curr.getType());

    money.startAnimation(moneyDrop);
}

From source file:com.example.angel.parkpanda.MainActivity.java

public Bitmap drawTextToBitmap(int gResId, String gText) {
    Resources resources = getResources();
    float scale = resources.getDisplayMetrics().density;
    Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId);
    android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();

    if (bitmapConfig == null) {
        bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
    }//from www . j  a v a  2s  .  c om
    bitmap = bitmap.copy(bitmapConfig, true);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.rgb(0, 0, 0));
    paint.setTextSize((int) (15 * scale));
    paint.setShadowLayer(1f, 0f, 1f, Color.BLACK);

    Rect bounds = new Rect();
    paint.getTextBounds(gText, 0, gText.length(), bounds);
    int x = (bitmap.getWidth() - bounds.width()) / 2;
    int y = (bitmap.getHeight() + bounds.height()) / 2 - 10;
    canvas.drawText(gText, x, y, paint);

    return bitmap;
}

From source file:com.onyx.deskclock.deskclock.alarms.AlarmActivity.java

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);//from w w  w.  j  a  v  a  2  s.  c o  m
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            if (Build.VERSION.SDK_INT >= 16) {
                mAlertView.announceForAccessibility(accessibilityText);
            }

            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:com.android.messaging.ui.UIIntentsImpl.java

@Override
public void launchFullScreenPhotoViewer(final Activity activity, final Uri initialPhoto,
        final Rect initialPhotoBounds, final Uri photosUri) {
    final PhotoViewIntentBuilder builder = com.android.ex.photo.Intents.newPhotoViewIntentBuilder(activity,
            BuglePhotoViewActivity.class);
    builder.setPhotosUri(photosUri.toString());
    builder.setInitialPhotoUri(initialPhoto.toString());
    builder.setProjection(ConversationImagePartsView.PhotoViewQuery.PROJECTION);

    // Set the location of the imageView so that the photoviewer can animate from that location
    // to full screen.
    builder.setScaleAnimation(initialPhotoBounds.left, initialPhotoBounds.top, initialPhotoBounds.width(),
            initialPhotoBounds.height());

    builder.setDisplayThumbsFullScreen(false);
    builder.setMaxInitialScale(8);/*from ww w. j a  v  a  2 s . co m*/
    activity.startActivity(builder.build());
    activity.overridePendingTransition(0, 0);
}

From source file:lollipop.iconics.IconicsDrawable.java

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

        updatePaddingBounds(viewBounds);
        updateTextSize(viewBounds);//from   w w  w  .  j  ava2 s  .  c o  m
        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);

        canvas.drawPath(mPath, mIconPaint);
    }
}

From source file:de.stkl.gbgvertretungsplan.fragments.MainFragment.java

private int calculateTableCellWidth(String content, View textContainer) {
    if (!(textContainer instanceof TextView))
        return 0;
    Rect bounds = new Rect();
    Paint textPaint = ((TextView) textContainer).getPaint();
    textPaint.getTextBounds(content, 0, content.length(), bounds);
    //Log.d("calculateTableCellWidth", content+": "+bounds.width());
    //RelativeLayout.MarginLayoutParams params = ((RelativeLayout.MarginLayoutParams)((TextView) textContainer).getLayoutParams());
    int width = /*params.leftMargin + params.rightMargin + */((TextView) textContainer).getTotalPaddingLeft()
            + ((TextView) textContainer).getTotalPaddingRight() + bounds.width();
    return width;
}

From source file:org.alfresco.mobile.android.application.extension.samsung.pen.SNoteEditorActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    AnalyticsHelper.reportScreen(this, AnalyticsManager.SCREEN_SAMSUNG_SNOTE_EDITOR);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.snote_editor);
    context = this;

    // TOOLBAR/*from www. j a  v a 2  s.com*/
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }

    // Retrieve information
    String action = getIntent().getAction();
    if (Intent.ACTION_VIEW.equals(action)) {
        if (getIntent().getData() != null) {
            String filePath = BaseActionUtils.getPath(this, getIntent().getData());
            file = new File(filePath);
        } else {
            AlfrescoNotificationManager.getInstance(this).showLongToast(getString(R.string.editor_error_open));
            finish();
            return;
        }
    }

    // Init Spen
    boolean isSpenFeatureEnabled = false;
    Spen spenPackage = new Spen();
    try {
        spenPackage.initialize(this);
        isSpenFeatureEnabled = spenPackage.isFeatureEnabled(Spen.DEVICE_PEN);
    } catch (SsdkUnsupportedException e) {
        if (SNoteUtils.processUnsupportedException(this, e)) {
            return;
        }
    } catch (Exception e1) {
        Log.e(TAG, Log.getStackTraceString(e1));
        finish();
    }

    FrameLayout spenViewContainer = (FrameLayout) findViewById(R.id.spenViewContainer);
    RelativeLayout spenViewLayout = (RelativeLayout) findViewById(R.id.spenViewLayout);

    // PEN SETTINGS
    spenSettingView = new SpenSettingPenLayout(context, "", spenViewLayout);
    if (spenSettingView == null) {
        finish();
    }
    spenViewContainer.addView(spenSettingView);

    // ERASER SETTINGS
    eraserSettingView = new SpenSettingEraserLayout(context, "", spenViewLayout);
    if (eraserSettingView == null) {
        finish();
    }
    spenViewContainer.addView(eraserSettingView);

    // TEXT SETTINGS
    textSettingView = new SpenSettingTextLayout(context, "", new HashMap<String, String>(), spenViewLayout);
    if (textSettingView == null) {
        finish();
    }
    spenViewContainer.addView(textSettingView);

    // SELECTION SETTINGS
    selectionSettingView = new SpenSettingSelectionLayout(context, "", spenViewLayout);
    if (textSettingView == null) {
        finish();
    }
    spenViewContainer.addView(selectionSettingView);

    // SURFACE VIEW
    spenSurfaceView = new SpenSurfaceView(context);
    if (spenSurfaceView == null) {
        finish();
    }
    spenViewLayout.addView(spenSurfaceView);
    spenSettingView.setCanvasView(spenSurfaceView);
    eraserSettingView.setCanvasView(spenSurfaceView);
    textSettingView.setCanvasView(spenSurfaceView);
    selectionSettingView.setCanvasView(spenSurfaceView);

    // NOTE DOCUMENT
    Display display = getWindowManager().getDefaultDisplay();
    Rect mScreenRect = new Rect();
    display.getRectSize(mScreenRect);
    try {
        if (file != null && file.length() > 0) {
            spenNoteDoc = new SpenNoteDoc(context, file.getAbsolutePath(), mScreenRect.width(),
                    SpenNoteDoc.MODE_WRITABLE);
            if (spenNoteDoc.getPageCount() == 0) {
                spenPageDoc = spenNoteDoc.appendPage();
            } else {
                spenPageDoc = spenNoteDoc.getPage(spenNoteDoc.getLastEditedPageIndex());
            }
        } else {
            spenNoteDoc = new SpenNoteDoc(context, SpenNoteDoc.ORIENTATION_LANDSCAPE,
                    (mScreenRect.width() > mScreenRect.height()) ? mScreenRect.width() : mScreenRect.height(),
                    (mScreenRect.width() < mScreenRect.height()) ? mScreenRect.width() : mScreenRect.height());
            spenPageDoc = spenNoteDoc.appendPage();
            spenPageDoc.setBackgroundColor(getResources().getColor(android.R.color.white));
            spenPageDoc.clearHistory();
        }
    } catch (Exception e) {
        finish();
    }

    // Display Document
    spenSurfaceView.setPageDoc(spenPageDoc, true);
    spenSurfaceView.setBlankColor(getResources().getColor(R.color.grey_light));

    if (!isSpenFeatureEnabled) {
        mToolType = SpenSurfaceView.TOOL_FINGER;
        spenSurfaceView.setToolTypeAction(mToolType, SpenSurfaceView.ACTION_STROKE);

        // Touch listener for swipe if on Finger mode
        gdt = new GestureDetector(context, new GestureListener());
        spenSurfaceView.setOnTouchListener(touchListener);
    }

    // Init Pages
    mTxtView = (TextView) findViewById(R.id.spen_page);
    mTxtView.setText(String.format(getString(R.string.editor_paging),
            String.valueOf((spenNoteDoc.getPageIndexById(spenPageDoc.getId()) + 1)),
            spenNoteDoc.getPageCount()));

    // INIT Setting & Listeners
    initSettingInfo();
    spenSurfaceView.setTouchListener(penTouchListener);
    spenSurfaceView.setControlListener(controlListener);
    spenSurfaceView.setFlickListener(mFlickListener);

}

From source file:de.madvertise.android.sdk.MadvertiseView.java

/**
 * Convenience method for a shiny background for text ads
 *
 * @param rect/*  w w  w . j ava  2s. c  o  m*/
 * @param backgroundColor
 * @param mTextColor
 * @return
 */
private BitmapDrawable generateBackgroundDrawable(final Rect rect, final int backgroundColor,
        final int shineColor) {
    try {
        Bitmap bitmap = Bitmap.createBitmap(rect.width(), rect.height(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawTextBannerBackground(canvas, rect, backgroundColor, shineColor);
        return new BitmapDrawable(bitmap);
    } catch (Throwable t) {
        return null;
    }
}