android.graphics.Rect Java Examples

The following examples show how to use android.graphics.Rect. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LayoutManager.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link LayoutManager} instance.
 * @param host A {@link LayoutManagerHost} instance.
 */
public LayoutManager(LayoutManagerHost host) {
    mHost = host;
    mPxToDp = 1.f / mHost.getContext().getResources().getDisplayMetrics().density;
    mSceneChangeObservers = new ObserverList<SceneChangeObserver>();

    int hostWidth = host.getWidth();
    int hostHeight = host.getHeight();
    mLastViewportPx.set(0, 0, hostWidth, hostHeight);
    mLastVisibleViewportPx.set(0, 0, hostWidth, hostHeight);
    mLastFullscreenViewportPx.set(0, 0, hostWidth, hostHeight);

    mLastContentWidthDp = hostWidth * mPxToDp;
    mLastContentHeightDp = hostHeight * mPxToDp;
    mLastViewportDp.set(0, 0, mLastContentWidthDp, mLastContentHeightDp);
    mLastVisibleViewportDp.set(0, 0, mLastContentWidthDp, mLastContentHeightDp);
    mLastFullscreenViewportDp.set(0, 0, mLastContentWidthDp, mLastContentHeightDp);

    mCachedVisibleViewport = new Rect();

    mLastHeightMinusBrowserControlsDp = mLastContentHeightDp;
}
 
Example #2
Source File: ExampleDateEndPaddingItemDecoration.java    From SnappyRecyclerView with MIT License 6 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if(parent.getChildAdapterPosition(view) == 0) {
        if(orientation == SnappingRecyclerView.VERTICAL) {
            outRect.top = (parent.getHeight() / 2) - (view.getHeight() / 2);
        } else {
            outRect.left = (parent.getWidth() / 2) - (view.getWidth() / 2);
        }
    } else if (parent.getChildAdapterPosition(view) == parent.getAdapter().getItemCount() - 1) {
        if(orientation == SnappingRecyclerView.VERTICAL) {
            outRect.bottom = (parent.getHeight() / 2) - (view.getHeight() / 2);
        } else {
            outRect.right = (parent.getWidth() / 2) - (view.getWidth() / 2);
        }
    }
}
 
Example #3
Source File: HighlightView.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
void handleMotion(int edge, float dx, float dy) {
    Rect r = computeLayout();
    if (edge == MOVE) {
        // Convert to image space before sending to moveBy()
        moveBy(dx * (cropRect.width() / r.width()),
               dy * (cropRect.height() / r.height()));
    } else {
        if (((GROW_LEFT_EDGE | GROW_RIGHT_EDGE) & edge) == 0) {
            dx = 0;
        }

        if (((GROW_TOP_EDGE | GROW_BOTTOM_EDGE) & edge) == 0) {
            dy = 0;
        }

        // Convert to image space before sending to growBy()
        float xDelta = dx * (cropRect.width() / r.width());
        float yDelta = dy * (cropRect.height() / r.height());
        growBy((((edge & GROW_LEFT_EDGE) != 0) ? -1 : 1) * xDelta,
                (((edge & GROW_TOP_EDGE) != 0) ? -1 : 1) * yDelta);
    }
}
 
Example #4
Source File: ReorderingHintDrawable.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void drawStage2(Canvas canvas, float progress) {
    final Rect bounds = getBounds();

    progress = interpolator.getInterpolation(progress);

    tempRect.left = (int) (AndroidUtilities.dp(2) * scaleX);
    tempRect.bottom = bounds.bottom - ((int) (AndroidUtilities.dp(6) * scaleY));
    tempRect.right = bounds.right - tempRect.left;
    tempRect.top = tempRect.bottom - ((int) (AndroidUtilities.dp(4) * scaleY));
    tempRect.offset(0, AndroidUtilities.dp(AndroidUtilities.lerp(0, -8, progress)));
    secondaryRectDrawable.setBounds(tempRect);
    secondaryRectDrawable.draw(canvas);

    tempRect.left = (int) (AndroidUtilities.dpf2(AndroidUtilities.lerp(1, 2, progress)) * scaleX);
    tempRect.top = (int) (AndroidUtilities.dpf2(AndroidUtilities.lerp(5, 6, progress)) * scaleY);
    tempRect.right = bounds.right - tempRect.left;
    tempRect.bottom = tempRect.top + (int) (AndroidUtilities.dpf2(AndroidUtilities.lerp(6, 4, progress)) * scaleY);
    tempRect.offset(0, AndroidUtilities.dp(AndroidUtilities.lerp(0, 8, progress)));
    primaryRectDrawable.setBounds(tempRect);
    primaryRectDrawable.setAlpha(255);
    primaryRectDrawable.draw(canvas);
}
 
Example #5
Source File: CameraManager.java    From QrModule with Apache License 2.0 6 votes vote down vote up
/**
 * A factory method to build the appropriate LuminanceSource object based on the format
 * of the preview buffers, as described by Camera.Parameters.
 *
 * @param data   A preview frame.
 * @param width  The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
    Rect rect = getFramingRectInPreview();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.getPreviewFormatString();
    switch (previewFormat) {
        // This is the standard Android format which all devices are REQUIRED to support.
        // In theory, it's the only one we should ever care about.
        case ImageFormat.NV21:
            // This format has never been seen in the wild, but is compatible as we only care
            // about the Y channel, so allow it.
        case ImageFormat.NV16:
            return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
                    rect.width(), rect.height());
        default:
            // The Samsung Moment incorrectly uses this variant instead of the 'sp' version.
            // Fortunately, it too has all the Y data up front, so we can read it.
            if ("yuv420p".equals(previewFormatString)) {
                return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
                        rect.width(), rect.height());
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
 
Example #6
Source File: ContrastSwatch.java    From brailleback with Apache License 2.0 6 votes vote down vote up
private ContrastSwatch(Parcel source) {
    mBackgroundColors = new LinkedList<Integer>();
    mForegroundColors = new LinkedList<Integer>();
    mLuminanceMap = new HashMap<Integer, Double>();
    mLuminanceHistogram = new HashMap<Double, Integer>();

    mName = source.readString();
    source.readMap(mLuminanceMap, null);
    source.readMap(mLuminanceHistogram, null);
    source.readList(mBackgroundColors, null);
    source.readList(mForegroundColors, null);
    mBackgroundLuminance = source.readDouble();
    mForegroundLuminance = source.readDouble();
    mScreenBounds = (Rect) source.readValue(Rect.class.getClassLoader());
    mContrastRatio = source.readDouble();
}
 
Example #7
Source File: SharedElementCallback.java    From letv with Apache License 2.0 6 votes vote down vote up
private static Bitmap createDrawableBitmap(Drawable drawable) {
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    if (width <= 0 || height <= 0) {
        return null;
    }
    float scale = Math.min(1.0f, ((float) MAX_IMAGE_SIZE) / ((float) (width * height)));
    if ((drawable instanceof BitmapDrawable) && scale == 1.0f) {
        return ((BitmapDrawable) drawable).getBitmap();
    }
    int bitmapWidth = (int) (((float) width) * scale);
    int bitmapHeight = (int) (((float) height) * scale);
    Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Rect existingBounds = drawable.getBounds();
    int left = existingBounds.left;
    int top = existingBounds.top;
    int right = existingBounds.right;
    int bottom = existingBounds.bottom;
    drawable.setBounds(0, 0, bitmapWidth, bitmapHeight);
    drawable.draw(canvas);
    drawable.setBounds(left, top, right, bottom);
    return bitmap;
}
 
Example #8
Source File: ThemeChoiceDrawable.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
	Rect bounds = getBounds();
	int radius = Math.min(bounds.width(), bounds.height()) / 2;
	int cx = bounds.centerX();
	int cy = bounds.centerY();
	Paint paint = this.paint;
	paint.setColor(background);
	canvas.drawCircle(cx, cy, radius * 1f, paint);
	if (accent != primary && accent != Color.TRANSPARENT) {
		RectF rectF = this.rectF;
		applyRectRadius(rectF, cx, cy, radius * 0.8f);
		paint.setColor(accent);
		canvas.drawArc(rectF, -20, 130, true, paint);
		paint.setColor(background);
		canvas.drawCircle(cx, cy, radius * 0.7f, paint);
		paint.setColor(primary);
		canvas.drawCircle(cx, cy, radius * 0.65f, paint);
		canvas.drawArc(rectF, 114, 222, true, paint);
	} else {
		paint.setColor(primary);
		canvas.drawCircle(cx, cy, radius * 0.8f, paint);
	}
}
 
Example #9
Source File: ImageUtils.java    From Android_framework with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 截屏,只能截取当前屏幕显示的区域,不包含status bar
 */
public static Bitmap screenShot(Activity activity){
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap b1 = view.getDrawingCache();
    // 获取状态栏高度
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;
    // 获取屏幕长和高
    int width = CommonUtils.getScreenWidth();
    int height = CommonUtils.getScreenHeight();
    // 去掉标题栏
    Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return b;
}
 
Example #10
Source File: SwipeLayout.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * close surface
 * @param smooth smoothly or not.
 * @param notify if notify all the listeners.
 */
public void close(boolean smooth, boolean notify){
    ViewGroup surface = getSurfaceView();
    int dx, dy;
    if(smooth)
        mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(), getPaddingTop());
    else {
        Rect rect = computeSurfaceLayoutArea(false);
        dx = rect.left - surface.getLeft();
        dy = rect.top - surface.getTop();
        surface.layout(rect.left, rect.top, rect.right, rect.bottom);
        if(notify) {
            dispatchRevealEvent(rect.left, rect.top, rect.right, rect.bottom);
            dispatchSwipeEvent(rect.left, rect.top, dx, dy);
        }else{
            safeBottomView();
        }
    }
    invalidate();
}
 
Example #11
Source File: FocusedBasePositionManager.java    From android-tv-launcher with MIT License 6 votes vote down vote up
private void drawStaticFocus(Canvas paramCanvas) {
	float f1 = this.mScaleXValue - 1.0F;
	float f2 = this.mScaleYValue - 1.0F;
	int i = this.mFrameRate;
	int j = this.mCurrentFrame;
	float f3 = 1.0F + f1 * j / i;
	float f4 = 1.0F + f2 * j / i;
	Rect localRect = getDstRectAfterScale(true);
	if (null == localRect) {
		return;
	}
	this.mFocusRect = localRect;
	this.mCurrentRect = localRect;
	if (isLastFrame()) {
		this.mMySelectedDrawableShadow.setBounds(localRect);
		this.mMySelectedDrawableShadow.draw(paramCanvas);
		this.mMySelectedDrawableShadow.setVisible(true, true);
	} else {
		this.mMySelectedDrawable.setBounds(localRect);
		this.mMySelectedDrawable.draw(paramCanvas);
		this.mMySelectedDrawable.setVisible(true, true);
	}
	if ((this.mSelectedView != null) && (paramCanvas != null) && ((this.mState == 0) || (isLastFrame()))) {
		drawChild(paramCanvas);
	}
}
 
Example #12
Source File: ScreenUtils.java    From Android_UE with Apache License 2.0 6 votes vote down vote up
/**
 * 获取当前屏幕截图,不包含状态栏
 *
 * @param activity
 * @return
 */
public static Bitmap snapShotWithoutStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;

    int width = getScreenWidth(activity);
    int height = getScreenHeight(activity);
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height
            - statusBarHeight);
    view.destroyDrawingCache();
    return bp;

}
 
Example #13
Source File: ReorderedLayerView.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Draws a black border over the screenshot of the view passed in.
 */
protected Bitmap getBitmapWithBorder(View v)
{
    Bitmap bitmap = getBitmapFromView(v);
    Canvas canvas = new Canvas(bitmap);

    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    canvas.drawBitmap(bitmap, 0, 0, null);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(LINE_THICKNESS);

    int accentColor = ControlHelper.getColor(getContext(), R.attr.colorAccent);

    paint.setColor(accentColor);
    canvas.drawRect(rect, paint);

    return bitmap;
}
 
Example #14
Source File: Launcher.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
public Bundle getActivityLaunchOptions(View v) {
    if (AndroidVersion.isAtLeastMarshmallow) {
        int left = 0, top = 0;
        int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
        if (v instanceof TextView) {
            // Launch from center of icon, not entire view
            Drawable icon = Workspace.getTextViewIcon((TextView) v);
            if (icon != null) {
                Rect bounds = icon.getBounds();
                left = (width - bounds.width()) / 2;
                top = v.getPaddingTop();
                width = bounds.width();
                height = bounds.height();
            }
        }
        return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height).toBundle();
    } else if (AndroidVersion.isAtLeastLollipopMR1) {
        // On L devices, we use the device default slide-up transition.
        // On L MR1 devices, we use a custom version of the slide-up transition which
        // doesn't have the delay present in the device default.
        return ActivityOptions.makeCustomAnimation(
                this, R.anim.task_open_enter, R.anim.no_anim).toBundle();
    }
    return null;
}
 
Example #15
Source File: CameraManager.java    From vmqApk with MIT License 6 votes vote down vote up
/**
     * Like {@link #getFramingRect} but coordinates are in terms of the preview frame,
     * not UI / screen.
     */
    public Rect getFramingRectInPreview() {
        if (framingRectInPreview == null) {
            Rect rect = new Rect(getFramingRect());
            Point cameraResolution = configManager.getCameraResolution();
            Point screenResolution = configManager.getScreenResolution();
            //modify here
//      rect.left = rect.left * cameraResolution.x / screenResolution.x;
//      rect.right = rect.right * cameraResolution.x / screenResolution.x;
//      rect.top = rect.top * cameraResolution.y / screenResolution.y;
//      rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;
            rect.left = rect.left * cameraResolution.y / screenResolution.x;
            rect.right = rect.right * cameraResolution.y / screenResolution.x;
            rect.top = rect.top * cameraResolution.x / screenResolution.y;
            rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;
            framingRectInPreview = rect;
        }
        return framingRectInPreview;
    }
 
Example #16
Source File: GestureTrailsDrawingPreview.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
private boolean drawGestureTrails(final Canvas offscreenCanvas, final Paint paint,
        final Rect dirtyRect) {
    // Clear previous dirty rectangle.
    if (!dirtyRect.isEmpty()) {
        paint.setColor(Color.TRANSPARENT);
        paint.setStyle(Paint.Style.FILL);
        offscreenCanvas.drawRect(dirtyRect, paint);
    }
    dirtyRect.setEmpty();
    boolean needsUpdatingGestureTrail = false;
    // Draw gesture trails to offscreen buffer.
    synchronized (mGestureTrails) {
        // Trails count == fingers count that have ever been active.
        final int trailsCount = mGestureTrails.size();
        for (int index = 0; index < trailsCount; index++) {
            final GestureTrailDrawingPoints trail = mGestureTrails.valueAt(index);
            needsUpdatingGestureTrail |= trail.drawGestureTrail(offscreenCanvas, paint,
                    mGestureTrailBoundsRect, mDrawingParams);
            // {@link #mGestureTrailBoundsRect} has bounding box of the trail.
            dirtyRect.union(mGestureTrailBoundsRect);
        }
    }
    return needsUpdatingGestureTrail;
}
 
Example #17
Source File: ZeroInsetsFrameLayout.java    From HgLauncher with GNU General Public License v3.0 6 votes vote down vote up
@Override protected final boolean fitSystemWindows(@NonNull Rect insets) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // Intentionally do not modify the bottom inset. For some reason,
        // if the bottom inset is modified, window resizing stops working.
        // TODO: Figure out why.

        mInsets[0] = insets.left;
        mInsets[1] = insets.top;
        mInsets[2] = insets.right;

        insets.left = 0;
        insets.top = 0;
        insets.right = 0;
    }

    return super.fitSystemWindows(insets);
}
 
Example #18
Source File: CameraManager.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
/**
 * Allows third party apps to specify the scanning rectangle dimensions, rather than determine
 * them automatically based on screen resolution.
 *
 * @param width The width in pixels to scan.
 * @param height The height in pixels to scan.
 */
public synchronized void setManualFramingRect(int width, int height) {
  if (initialized) {
    Point screenResolution = configManager.getScreenResolution();
    if (width > screenResolution.x) {
      width = screenResolution.x;
    }
    if (height > screenResolution.y) {
      height = screenResolution.y;
    }
    int leftOffset = (screenResolution.x - width) / 2;
    int topOffset = (screenResolution.y - height) / 2;
    framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
    Log.d(TAG, "Calculated manual framing rect: " + framingRect);
    framingRectInPreview = null;
  } else {
    requestedFramingRectWidth = width;
    requestedFramingRectHeight = height;
  }
}
 
Example #19
Source File: ToolbarPhone.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate the bounds for UrlViewport and set them to out rect.
 */
private void updateUrlViewportBounds(Rect out, VisualState visualState,
        boolean ignoreTranslationY) {
    // Calculate the visible boundaries of the left and right most child views
    // of the location bar.
    int leftViewPosition = (int) MathUtils.interpolate(
            getViewBoundsLeftOfLocationBar(visualState), 0f, mUrlExpansionPercent)
            - mUrlBackgroundPadding.left;
    int rightViewPosition = (int) MathUtils.interpolate(
            getViewBoundsRightOfLocationBar(visualState), getWidth(), mUrlExpansionPercent)
            + mUrlBackgroundPadding.right;

    // The bounds are set by the following:
    // - The left most visible location bar child view.
    // - The top of the viewport is aligned with the top of the location bar.
    // - The right most visible location bar child view.
    // - The bottom of the viewport is aligned with the bottom of the location bar.
    // Additional padding can be applied for use during animations.
    float yOffset = ignoreTranslationY ? mPhoneLocationBar.getTop() : mPhoneLocationBar.getY();

    out.set(leftViewPosition,
            (int) (yOffset - (mUrlBackgroundPadding.top * mUrlExpansionPercent)),
            rightViewPosition,
            (int) (yOffset + MathUtils.interpolate(mPhoneLocationBar.getMeasuredHeight(),
                    getHeight() + mUrlBackgroundPadding.bottom, mUrlExpansionPercent)));
}
 
Example #20
Source File: RippleDrawable.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private int drawMaskingLayer(Canvas canvas, Rect bounds, PorterDuffXfermode mode) {
    // Ensure that DST_IN blends using the entire layer.
    canvas.drawColor(Color.TRANSPARENT);

    mMask.draw(canvas);

    return -1;
}
 
Example #21
Source File: InsettableFrameLayout.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
public void setInsets(Rect insets) {
    final int n = getChildCount();
    for (int i = 0; i < n; i++) {
        final View child = getChildAt(i);
        setFrameLayoutChildInsets(child, insets, mInsets);
    }
    mInsets.set(insets);
}
 
Example #22
Source File: TDDStatsActivity.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        View myView = getCurrentFocus();
        if (myView instanceof EditText) {
            Rect rect = new Rect();
            myView.getGlobalVisibleRect(rect);
            if (!rect.contains((int) event.getRawX(), (int) event.getRawY())) {
                myView.clearFocus();
            }
        }
    }
    return super.dispatchTouchEvent(event);
}
 
Example #23
Source File: FrescoVitoImage2Spec.java    From fresco with MIT License 5 votes vote down vote up
@OnBoundsDefined
static void onBoundsDefined(
    ComponentContext c, ComponentLayout layout, Output<Rect> viewportDimensions) {
  final int width = layout.getWidth();
  final int height = layout.getHeight();
  int paddingX = 0, paddingY = 0;
  if (layout.isPaddingSet()) {
    paddingX = layout.getPaddingLeft() + layout.getPaddingRight();
    paddingY = layout.getPaddingTop() + layout.getPaddingBottom();
  }

  viewportDimensions.set(new Rect(0, 0, width - paddingX, height - paddingY));
}
 
Example #24
Source File: ChangeColorIconWithText.java    From HHComicViewer with Apache License 2.0 5 votes vote down vote up
/**
 * 获取自定义属性的值
 *
 * @param context
 * @param attrs
 * @param defStyleAttr
 */
public ChangeColorIconWithText(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ChangeColorIconWithText);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
            case R.styleable.ChangeColorIconWithText_icon:
                BitmapDrawable drawable = (BitmapDrawable) a.getDrawable(attr);
                if (drawable != null) {
                    mIconBitmap = drawable.getBitmap();
                }
                break;
            case R.styleable.ChangeColorIconWithText_color:
                mColor = a.getColor(attr, 0xFF45C01A);
                break;
            case R.styleable.ChangeColorIconWithText_text:
                mText = a.getString(attr);
                break;
            case R.styleable.ChangeColorIconWithText_text_size:
                mTextSize = (int) a.getDimension(attr,
                        TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12,
                                getResources().getDisplayMetrics()));
                break;
        }
    }
    a.recycle();

    //初始化成员变量
    mTextBound = new Rect();
    mTextPaint = new Paint();
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setColor(0xff555555);
    mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBound);
    mTextPaint.setAntiAlias(true); //抗锯齿
}
 
Example #25
Source File: AccessibilityUtilsTest.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Test
public void testResizeRect_correctSize() {
  Rect testRect = new Rect(0, 0, 48, 48);
  Rect expected = new Rect(0, 0, 48, 48);
  AccessibilityUtils.resizeRect(48, testRect);
  assertTrue(testRect.equals(expected));
}
 
Example #26
Source File: TransitionsExtension.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMount(TransitionsExtensionInput input, Rect localVisibleRect) {
  resetAcquiredReferences();
  mInput = input;

  if (input.getComponentTreeId() != mLastMountedComponentTreeId) {
    mLastTransitionsExtensionInput = null;
  }

  updateTransitions(input, ((LithoView) mLithoView).getComponentTree());
  extractDisappearingItems(input);
}
 
Example #27
Source File: FormattableEditText.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
    super.onFocusChanged(focused, direction, previouslyFocusedRect);
    if (focused)
        mFormatBar.setEditText(this);
    else
        mFormatBar.setEditText(null);
}
 
Example #28
Source File: WallpaperManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Specify extra padding that the wallpaper should have outside of the display.
 * That is, the given padding supplies additional pixels the wallpaper should extend
 * outside of the display itself.
 *
 * <p>This method requires the caller to hold the permission
 * {@link android.Manifest.permission#SET_WALLPAPER_HINTS}.
 *
 * @param padding The number of pixels the wallpaper should extend beyond the display,
 * on its left, top, right, and bottom sides.
 */
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER_HINTS)
public void setDisplayPadding(Rect padding) {
    try {
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            throw new RuntimeException(new DeadSystemException());
        } else {
            sGlobals.mService.setDisplayPadding(padding, mContext.getOpPackageName());
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #29
Source File: CoverPageAnim.java    From NovelReader with MIT License 5 votes vote down vote up
public CoverPageAnim(int w, int h, View view, OnPageChangeListener listener) {
    super(w, h, view, listener);
    mSrcRect = new Rect(0, 0, mViewWidth, mViewHeight);
    mDestRect = new Rect(0, 0, mViewWidth, mViewHeight);
    int[] mBackShadowColors = new int[] { 0x66000000,0x00000000};
    mBackShadowDrawableLR = new GradientDrawable(
            GradientDrawable.Orientation.LEFT_RIGHT, mBackShadowColors);
    mBackShadowDrawableLR.setGradientType(GradientDrawable.LINEAR_GRADIENT);
}
 
Example #30
Source File: CustomViewPager.java    From material-intro-screen with MIT License 5 votes vote down vote up
/**
 * We only want the current page that is being shown to be focusable.
 */
@Override
protected boolean onRequestFocusInDescendants(int direction,
                                              Rect previouslyFocusedRect) {
    int index;
    int increment;
    int end;
    int count = getChildCount();
    if ((direction & FOCUS_FORWARD) != 0) {
        index = 0;
        increment = 1;
        end = count;
    } else {
        index = count - 1;
        increment = -1;
        end = -1;
    }
    for (int i = index; i != end; i += increment) {
        View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == mCurItem) {
                if (child.requestFocus(direction, previouslyFocusedRect)) {
                    return true;
                }
            }
        }
    }
    return false;
}