Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated methods in ShadowDisplay #8840

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void setUp() throws Exception {
public void shouldProvideDisplayMetrics() {
shadow.setDensity(1.5f);
shadow.setDensityDpi(DisplayMetrics.DENSITY_HIGH);
shadow.setScaledDensity(1.6f);
shadow.setWidth(1024);
shadow.setHeight(600);
shadow.setRealWidth(1400);
Expand All @@ -57,7 +56,6 @@ public void shouldProvideDisplayMetrics() {

assertEquals(1.5f, metrics.density, 0.05);
assertEquals(DisplayMetrics.DENSITY_HIGH, metrics.densityDpi);
assertEquals(1.6f, metrics.scaledDensity, 0.05);
utzcoz marked this conversation as resolved.
Show resolved Hide resolved
assertEquals(1024, metrics.widthPixels);
assertEquals(600, metrics.heightPixels);
assertEquals(183.0f, metrics.xdpi, 0.05);
Expand All @@ -69,7 +67,6 @@ public void shouldProvideDisplayMetrics() {

assertEquals(1.5f, metrics.density, 0.05);
assertEquals(DisplayMetrics.DENSITY_HIGH, metrics.densityDpi);
assertEquals(1.6f, metrics.scaledDensity, 0.05);
assertEquals(1400, metrics.widthPixels);
assertEquals(900, metrics.heightPixels);
assertEquals(183.0f, metrics.xdpi, 0.05);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.robolectric.shadows;

import static android.os.Build.VERSION_CODES.JELLY_BEAN;
import static org.robolectric.util.reflector.Reflector.reflector;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.util.DisplayMetrics;
Expand Down Expand Up @@ -46,61 +43,6 @@ public static Display getDefaultDisplay() {

private Float refreshRate;

// the following fields are used only for Jelly Bean...
private String name;
private Integer displayId;
private Integer width;
private Integer height;
private Integer realWidth;
private Integer realHeight;
private Integer densityDpi;
private Float xdpi;
private Float ydpi;
private Float scaledDensity;
private Integer rotation;
private Integer pixelFormat;

/**
* If {@link #setScaledDensity(float)} has been called, {@link DisplayMetrics#scaledDensity} will
* be modified to reflect the value specified. Note that this is not a realistic state.
*
* @deprecated This behavior is deprecated and will be removed in Robolectric 3.7.
*/
@Deprecated
@Implementation
protected void getMetrics(DisplayMetrics outMetrics) {
reflector(_Display_.class, realObject).getMetrics(outMetrics);
if (scaledDensity != null) {
outMetrics.scaledDensity = scaledDensity;
}
}

/**
* If {@link #setScaledDensity(float)} has been called, {@link DisplayMetrics#scaledDensity} will
* be modified to reflect the value specified. Note that this is not a realistic state.
*
* @deprecated This behavior is deprecated and will be removed in Robolectric 3.7.
*/
@Deprecated
@Implementation
protected void getRealMetrics(DisplayMetrics outMetrics) {
reflector(_Display_.class, realObject).getRealMetrics(outMetrics);
if (scaledDensity != null) {
outMetrics.scaledDensity = scaledDensity;
}
}

/**
* If {@link #setDisplayId(int)} has been called, this method will return the specified value.
*
* @deprecated This behavior is deprecated and will be removed in Robolectric 3.7.
*/
@Deprecated
@Implementation
protected int getDisplayId() {
return displayId == null ? reflector(_Display_.class, realObject).getDisplayId() : displayId;
}

/**
* If {@link #setRefreshRate(float)} has been called, this method will return the specified value.
*
Expand All @@ -120,38 +62,6 @@ protected float getRefreshRate() {
return realRefreshRate;
}

/**
* If {@link #setPixelFormat(int)} has been called, this method will return the specified value.
*
* @deprecated This behavior is deprecated and will be removed in Robolectric 3.7.
*/
@Deprecated
@Implementation
protected int getPixelFormat() {
return pixelFormat == null
? reflector(_Display_.class, realObject).getPixelFormat()
: pixelFormat;
}

@Implementation(maxSdk = JELLY_BEAN)
protected void getSizeInternal(Point outSize, boolean doCompat) {
outSize.x = width;
outSize.y = height;
}

@Implementation(maxSdk = JELLY_BEAN)
protected void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) {
int minimum = Math.min(width, height);
int maximum = Math.max(width, height);
outSmallestSize.set(minimum, minimum);
outLargestSize.set(maximum, maximum);
}

@Implementation(maxSdk = JELLY_BEAN)
protected void getRealSize(Point outSize) {
outSize.set(realWidth, realHeight);
}

/**
* Changes the density for this display.
*
Expand Down Expand Up @@ -193,29 +103,6 @@ public void setYdpi(float ydpi) {
ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.physicalYDpi = ydpi);
}

/**
* Changes the scaled density for this display.
*
* @deprecated This method is deprecated and will be removed in Robolectric 3.7.
*/
@Deprecated
public void setScaledDensity(float scaledDensity) {
this.scaledDensity = scaledDensity;
}

/**
* Changes the ID for this display.
*
* <p>Any registered {@link android.hardware.display.DisplayManager.DisplayListener}s will be
* notified of the change.
*
* @deprecated This method is deprecated and will be removed in Robolectric 3.7.
*/
@Deprecated
public void setDisplayId(int displayId) {
this.displayId = displayId;
}

/**
* Changes the name for this display.
*
Expand Down Expand Up @@ -309,16 +196,6 @@ public void setRotation(int rotation) {
ShadowDisplayManager.changeDisplay(realObject.getDisplayId(), di -> di.rotation = rotation);
}

/**
* Changes the pixel format for this display.
*
* @deprecated This method is deprecated and will be removed in Robolectric 3.7.
*/
@Deprecated
public void setPixelFormat(int pixelFormat) {
this.pixelFormat = pixelFormat;
}

/**
* Changes the simulated state for this display, such as whether it is on or off
*
Expand Down Expand Up @@ -393,45 +270,13 @@ public void setDisplayCutout(Object displayCutout) {
realObject.getDisplayId(), displayConfig -> displayConfig.displayCutout = displayCutout);
}

void configureForJBOnly(Configuration configuration, DisplayMetrics displayMetrics) {
int widthPx = (int) (configuration.screenWidthDp * displayMetrics.density);
int heightPx = (int) (configuration.screenHeightDp * displayMetrics.density);

name = "Built-in screen";
displayId = 0;
width = widthPx;
height = heightPx;
realWidth = widthPx;
realHeight = heightPx;
densityDpi = displayMetrics.densityDpi;
xdpi = (float) displayMetrics.densityDpi;
ydpi = (float) displayMetrics.densityDpi;
scaledDensity = displayMetrics.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
rotation =
configuration.orientation == Configuration.ORIENTATION_PORTRAIT
? Surface.ROTATION_0
: Surface.ROTATION_90;
}

/** Reflector interface for {@link Display}'s internals. */
@ForType(Display.class)
interface _Display_ {

@Direct
void getMetrics(DisplayMetrics outMetrics);

@Direct
void getRealMetrics(DisplayMetrics outMetrics);

@Direct
int getDisplayId();

@Direct
float getRefreshRate();

@Direct
int getPixelFormat();

@Accessor("mFlags")
void setFlags(int flags);
}
Expand Down