List of usage examples for android.graphics Rect inset
public void inset(int dx, int dy)
From source file:tyrantgit.explosionfield.ExplosionField.java
public void explode(final View view) { Rect r = new Rect(); view.getGlobalVisibleRect(r);/*from www.j a v a 2 s. c om*/ int[] location = new int[2]; getLocationOnScreen(location); r.offset(-location[0], -location[1]); r.inset(-mExpandInset[0], -mExpandInset[1]); int startDelay = 100; ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f).setDuration(150); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { Random random = new Random(); @Override public void onAnimationUpdate(ValueAnimator animation) { ViewCompat.setTranslationX(view, (random.nextFloat() - 0.5f) * view.getWidth() * 0.05f); ViewCompat.setTranslationY(view, (random.nextFloat() - 0.5f) * view.getHeight() * 0.05f); } }); animator.start(); //ViewCompat.animate(view) ViewCompat.animate(view).setDuration(150).setStartDelay(startDelay).scaleX(0f).scaleY(0f).alpha(0f).start(); explode(Utils.createBitmapFromView(view), r, startDelay, ExplosionAnimator.DEFAULT_DURATION); }
From source file:cs.man.ac.uk.tavernamobile.WorkflowDetail.java
public Object onTaskComplete(Object... result) { if (result[0] instanceof String) { String exception = (String) result[0]; if (exception != null) { MessageHelper.showMessageDialog(currentActivity, null, exception, null); }/*from w w w . j av a 2 s .co m*/ } else { // Scale it to 125 x 125 Drawable avatarDrawable = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(avatarBitmap, 125, 125, true)); Rect outRect = new Rect(); userName.getDrawingRect(outRect); // resize the Rect outRect.inset(-10, 10); avatarDrawable.setBounds(outRect); userName.setCompoundDrawables(null, avatarDrawable, null, null); userName.setText(uploader.getName()); } return null; }
From source file:com.sutromedia.android.core.PhotoActivity.java
private void setupTouchOnPlayButton() { View playButton = findViewById(R.image.play_slideshow); Rect expandedSize = new Rect(); playButton.getHitRect(expandedSize); expandedSize.inset(30, 30); TouchDelegate delegate = new TouchDelegate(expandedSize, playButton); View parent = (View) playButton.getParent(); parent.setTouchDelegate(delegate);/* ww w . j a v a 2 s.c o m*/ }
From source file:org.jraf.android.hellomundo.app.welcome.WelcomeActivity.java
private void setShowCasePosition(View view, Rect r) { Log.d("r=" + r); Rect rect = new Rect(r); if (rect.top > 0) { int margin = getResources().getDimensionPixelSize(R.dimen.welcome_showCase_margin); rect.inset(-margin, -margin); }//w w w . j a v a 2s . c om View imgShowCase = view.findViewById(R.id.imgShowCase); LayoutParams layoutParams = imgShowCase.getLayoutParams(); layoutParams.width = rect.width(); layoutParams.height = rect.height(); ((RelativeLayout.LayoutParams) layoutParams).topMargin = rect.top; ((RelativeLayout.LayoutParams) layoutParams).leftMargin = rect.left; imgShowCase.setLayoutParams(layoutParams); View imgShowCaseHide = view.findViewById(R.id.imgShowCase_hide); layoutParams = imgShowCaseHide.getLayoutParams(); layoutParams.width = rect.width(); layoutParams.height = rect.height(); ((RelativeLayout.LayoutParams) layoutParams).topMargin = rect.top; ((RelativeLayout.LayoutParams) layoutParams).leftMargin = rect.left; imgShowCaseHide.setLayoutParams(layoutParams); View imgAbove = view.findViewById(R.id.imgAbove); layoutParams = imgAbove.getLayoutParams(); layoutParams.height = rect.top; imgAbove.setLayoutParams(layoutParams); View imgLeft = view.findViewById(R.id.imgLeft); layoutParams = imgLeft.getLayoutParams(); layoutParams.width = rect.left; imgLeft.setLayoutParams(layoutParams); }
From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java
/** * Handles the touch events to dismiss all apps when clicking outside the bounds of the * recycler view.// w w w .ja v a 2 s. c o m */ private boolean handleTouchEvent(MotionEvent ev) { DeviceProfile grid = mLauncher.getDeviceProfile(); int x = (int) ev.getX(); int y = (int) ev.getY(); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: if (!mContentBounds.isEmpty()) { // Outset the fixed bounds and check if the touch is outside all apps Rect tmpRect = new Rect(mContentBounds); tmpRect.inset(-grid.allAppsIconSizePx / 2, 0); if (ev.getX() < tmpRect.left || ev.getX() > tmpRect.right) { mBoundsCheckLastTouchDownPos.set(x, y); return true; } } else { // Check if the touch is outside all apps if (ev.getX() < getPaddingLeft() || ev.getX() > (getWidth() - getPaddingRight())) { mBoundsCheckLastTouchDownPos.set(x, y); return true; } } break; case MotionEvent.ACTION_UP: if (mBoundsCheckLastTouchDownPos.x > -1) { ViewConfiguration viewConfig = ViewConfiguration.get(getContext()); float dx = ev.getX() - mBoundsCheckLastTouchDownPos.x; float dy = ev.getY() - mBoundsCheckLastTouchDownPos.y; float distance = (float) Math.hypot(dx, dy); if (distance < viewConfig.getScaledTouchSlop()) { // The background was clicked, so just go home Launcher launcher = Launcher.getLauncher(getContext()); launcher.showWorkspace(true); return true; } } // Fall through case MotionEvent.ACTION_CANCEL: mBoundsCheckLastTouchDownPos.set(-1, -1); break; } return false; }
From source file:com.android.camera.HighlightView.java
private void moveBy(float dx, float dy) { Rect invalRect = new Rect(mDrawRect); mCropRect.offset(dx, dy);/*from w ww . j a v a 2s . co m*/ // Put the cropping rectangle inside image rectangle. mCropRect.offset(Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top)); mCropRect.offset(Math.min(0, mImageRect.right - mCropRect.right), Math.min(0, mImageRect.bottom - mCropRect.bottom)); mDrawRect = computeLayout(); invalRect.union(mDrawRect); invalRect.inset(-10, -10); mContext.invalidate(invalRect); }
From source file:com.example.gatsu.theevent.HighlightView.java
void moveBy(float dx, float dy) { Rect invalRect = new Rect(mDrawRect); mCropRect.offset(dx, dy);/*from w ww . ja va 2 s.c om*/ // Put the cropping rectangle inside image rectangle. mCropRect.offset(Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top)); mCropRect.offset(Math.min(0, mImageRect.right - mCropRect.right), Math.min(0, mImageRect.bottom - mCropRect.bottom)); mDrawRect = computeLayout(); invalRect.union(mDrawRect); invalRect.inset(-10, -10); mContext.invalidate(invalRect); }
From source file:org.caojun.library.cropimage.HighlightView.java
void moveBy(float dx, float dy) { Rect invalRect = new Rect(mDrawRect); mCropRect.offset(dx, dy);/*from w ww .j av a 2 s . c o m*/ // Put the cropping rectangle inside image rectangle. mCropRect.offset(Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top)); mCropRect.offset(Math.min(0, mImageRect.right - mCropRect.right), Math.min(0, mImageRect.bottom - mCropRect.bottom)); mDrawRect = computeLayout(); invalRect.union(mDrawRect); invalRect.inset(-10, -10); mView.invalidate(invalRect); }
From source file:com.acious.android.paginationseekbar.PaginationSeekBar.java
private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) { final Rect bounds = mTempRect; mThumb.copyBounds(bounds);/* ww w .j a v a 2s. 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.hezaijin.advance.widgets.view.progress.DiscreteSeekBar.java
private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) { final Rect bounds = mTempRect; mThumb.copyBounds(bounds);//w ww. j a va 2 s. c om //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; }