本文整理汇总了Java中com.android.sdklib.devices.Device类的典型用法代码示例。如果您正苦于以下问题:Java Device类的具体用法?Java Device怎么用?Java Device使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Device类属于com.android.sdklib.devices包,在下文中一共展示了Device类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGenericLabel
import com.android.sdklib.devices.Device; //导入依赖的package包/类
/**
* Returns a user-displayable description of the given generic device
* @param device the device to check
* @return the label
* @see #isGeneric(Device)
*/
@NonNull
public static String getGenericLabel(@NonNull Device device) {
// * Use the same precision for all devices (all but one specify decimals)
// * Add some leading space such that the dot ends up roughly in the
// same space
// * Add in screen resolution and density
String name = device.getDisplayName();
Matcher matcher = GENERIC_PATTERN.matcher(name);
if (matcher.matches()) {
String size = matcher.group(1);
String n = matcher.group(2);
int dot = size.indexOf('.');
if (dot == -1) {
size += ".0";
dot = size.length() - 2;
}
for (int i = 0; i < 2 - dot; i++) {
size = ' ' + size;
}
name = size + "\" " + n;
}
return String.format(Locale.US, "%1$s (%2$s)", name,
getResolutionString(device));
}
示例2: getScreenPosition
import com.android.sdklib.devices.Device; //导入依赖的package包/类
@Nullable
public Point getScreenPosition(@NotNull Device device, @NotNull ScreenOrientation orientation, int screenHeight) {
DeviceData data = getDeviceData(device);
if (data == null) {
return null;
}
FrameData frame = data.getFrameData(orientation, Integer.MAX_VALUE);
int screenX = frame.getScreenX();
int screenY = frame.getScreenY();
double scale = screenHeight / (double) frame.getScreenHeight();
screenX *= scale;
screenY *= scale;
// TODO: Also consider the frame scale?
return new Point(screenX, screenY);
}
示例3: testNexus7
import com.android.sdklib.devices.Device; //导入依赖的package包/类
public void testNexus7() {
DeviceManager deviceManager = getDeviceManager();
Device n7 = deviceManager.getDevice("Nexus 7", "Google");
Device n7b = deviceManager.getDevice("Nexus 7 2013", "Google");
assertNotNull(n7);
assertNotNull(n7b);
assertEquals("Nexus 7 (2012)", n7.getDisplayName());
assertEquals("Nexus 7", n7b.getDisplayName());
assertTrue(isNexus(n7));
assertTrue(isNexus(n7b));
assertTrue(nexusRank(n7b) > nexusRank(n7));
assertEquals("Nexus 7 (2012) (7.0\", 800 × 1280: tvdpi)", getNexusLabel(n7));
assertEquals("Nexus 7 (7.0\", 1200 × 1920: xhdpi)", getNexusLabel(n7b));
assertFalse(isGeneric(n7));
assertFalse(isGeneric(n7));
}
示例4: getRequiredWidth
import com.android.sdklib.devices.Device; //导入依赖的package包/类
/** Returns the required width to show the scaled image, including drop shadows if applicable */
public int getRequiredWidth() {
int width = (int)(myScale * myImage.getWidth());
if (myThumbnailHasFrame || myImageBounds == null && myScaledImage == null && myDeviceFrameEnabled &&
AndroidEditorSettings.getInstance().getGlobalState().isShowDeviceFrames()) {
DeviceArtPainter framePainter = DeviceArtPainter.getInstance();
Device device = myConfiguration.getDevice();
if (device != null) {
State deviceState = myConfiguration.getDeviceState();
if (deviceState != null) {
double frameFactor = framePainter.getFrameWidthOverhead(device, deviceState.getOrientation());
width *= frameFactor;
return width;
}
}
}
if (hasDropShadow()) {
width += myUseLargeShadows ? SHADOW_SIZE : SMALL_SHADOW_SIZE;
}
return width;
}
示例5: getRequiredHeight
import com.android.sdklib.devices.Device; //导入依赖的package包/类
/** Returns the required height to show the scaled image, including drop shadows if applicable */
public int getRequiredHeight() {
int height = (int)(myScale * myImage.getHeight());
if (myThumbnailHasFrame || myImageBounds == null && myScaledImage == null && myDeviceFrameEnabled &&
AndroidEditorSettings.getInstance().getGlobalState().isShowDeviceFrames()) {
DeviceArtPainter framePainter = DeviceArtPainter.getInstance();
Device device = myConfiguration.getDevice();
if (device != null) {
State deviceState = myConfiguration.getDeviceState();
if (deviceState != null) {
double frameFactor = framePainter.getFrameHeightOverhead(device, deviceState.getOrientation());
height *= frameFactor;
return height;
}
}
}
if (hasDropShadow()) {
height += myUseLargeShadows ? SHADOW_SIZE : SMALL_SHADOW_SIZE;
}
return height;
}
示例6: paintClipped
import com.android.sdklib.devices.Device; //导入依赖的package包/类
/** Paints a rendered device image into the given graphics context */
public static void paintClipped(@NotNull Graphics2D g,
@NotNull BufferedImage image,
@Nullable Device device,
int x,
int y,
boolean withRetina) {
Shape prevClip = null;
Shape clip = getClip(device, x, y, image.getWidth(), image.getHeight());
if (clip != null) {
prevClip = g.getClip();
g.setClip(clip);
}
if (withRetina) {
//noinspection ConstantConditions
UIUtil.drawImage(g, image, x, y, null);
} else {
g.drawImage(image, x, y, null);
}
if (clip != null) {
g.setClip(prevClip);
}
}
示例7: setScreenClip
import com.android.sdklib.devices.Device; //导入依赖的package包/类
/**
* Sets a screen clip for the overlay if applicable. Returns the new clip if it was set.
*/
@Nullable
protected Shape setScreenClip(@NotNull OverlayContainer container, @NotNull Component component, @NotNull Graphics2D gc,
int deltaX, int deltaY) {
Configuration configuration = container.getConfiguration();
Shape clip = null;
if (configuration != null) {
Device device = configuration.getDevice();
if (device != null && device.isScreenRound()) {
Screen screen = device.getDefaultHardware().getScreen();
int width = screen.getXDimension();
int height = screen.getYDimension();
Rectangle m = container.fromModel(component, new Rectangle(0, 0, width, height));
clip = RenderedImage.getClip(device, m.x + deltaX, m.y + deltaY, m.width, m.height);
}
if (clip != null) {
gc.setClip(clip);
}
}
return clip;
}
示例8: setEffectiveDevice
import com.android.sdklib.devices.Device; //导入依赖的package包/类
public void setEffectiveDevice(@Nullable Device device, @Nullable State state) {
int updateFlags = 0;
if (myDevice != device) {
updateFlags = CFG_DEVICE;
myDevice = device;
}
if (myState != state) {
myState = state;
myStateName = state != null ? state.getName() : null;
updateFlags |= CFG_DEVICE_STATE;
}
if (updateFlags != 0) {
updated(updateFlags);
}
}
示例9: ChooseDeviceDefinitionStep
import com.android.sdklib.devices.Device; //导入依赖的package包/类
public ChooseDeviceDefinitionStep(@Nullable Disposable parentDisposable) {
super(parentDisposable);
setBodyComponent(myPanel);
myDeviceDefinitionList.addSelectionListener(new DeviceDefinitionList.DeviceDefinitionSelectionListener() {
@Override
public void onDeviceSelectionChanged(@Nullable Device selectedDevice) {
myDeviceDefinitionPreview.setDevice(selectedDevice);
myState.put(DEVICE_DEFINITION_KEY, selectedDevice);
updateEditButton(selectedDevice);
}
});
myDeviceDefinitionList.addCategoryListener(myDeviceDefinitionPreview);
myEditButtonContainer.setBackground(JBColor.background());
myEditDeviceButton.setBackground(JBColor.background());
myDeviceDefinitionList.setBorder(BorderFactory.createLineBorder(JBColor.lightGray));
updateEditButton(null);
}
示例10: createDeviceForAvd
import com.android.sdklib.devices.Device; //导入依赖的package包/类
@Nullable
public Device createDeviceForAvd(@NotNull AvdInfo avd) {
AndroidFacet facet = AndroidFacet.getInstance(myModule);
assert facet != null;
for (Device device : getDevices()) {
if (device.getManufacturer().equals(avd.getDeviceManufacturer())
&& (device.getId().equals(avd.getDeviceName()) || device.getDisplayName().equals(avd.getDeviceName()))) {
String avdName = avd.getName();
Device.Builder builder = new Device.Builder(device);
builder.setName(avdName);
return builder.build();
}
}
return null;
}
示例11: getDefaultDevice
import com.android.sdklib.devices.Device; //导入依赖的package包/类
@Nullable
public Device getDefaultDevice() {
if (myDefaultDevice == null) {
// Note that this may not be the device actually used in new layouts; the ConfigMatcher
// has a PhoneComparator which sorts devices for a best match
List<Device> devices = getDevices();
if (!devices.isEmpty()) {
Device device = devices.get(0);
for (Device d : devices) {
String name = d.getId();
if (name.equals("Nexus 4")) {
device = d;
break;
} else if (name.equals("Galaxy Nexus")) {
device = d;
}
}
myDefaultDevice = device;
}
}
return myDefaultDevice;
}
示例12: getRecentDevices
import com.android.sdklib.devices.Device; //导入依赖的package包/类
/** Returns the most recently used devices, in MRU order */
public List<Device> getRecentDevices() {
List<String> deviceIds = getStateManager().getProjectState().getDeviceIds();
if (deviceIds.isEmpty()) {
return Collections.emptyList();
}
List<Device> devices = Lists.newArrayListWithExpectedSize(deviceIds.size());
ListIterator<String> iterator = deviceIds.listIterator();
while (iterator.hasNext()) {
String id = iterator.next();
Device device = getDeviceById(id);
if (device != null) {
devices.add(device);
} else {
iterator.remove();
}
}
return devices;
}
示例13: setDeviceState
import com.android.sdklib.devices.Device; //导入依赖的package包/类
@Override
public void setDeviceState(State state) {
if (isOverridingDeviceState()) {
super.setDeviceState(state);
}
else {
if (isOverridingDevice()) {
Device device = super.getDevice();
if (device != null) {
State equivalentState = device.getState(state.getName());
if (equivalentState != null) {
state = equivalentState;
}
}
}
myParent.setDeviceState(state);
}
}
示例14: findDescriptor
import com.android.sdklib.devices.Device; //导入依赖的package包/类
@NotNull
private DeviceArtDescriptor findDescriptor(@NotNull Device device) {
String id = device.getId();
String name = device.getDisplayName();
// Make generic devices use the frames as well:
if (id.equals("3.7in WVGA (Nexus One)")) {
id = "nexus_one";
} else if (id.equals("4in WVGA (Nexus S)")) {
id = "nexus_s";
} else if (id.equals("4.65in 720p (Galaxy Nexus)")) {
id = "galaxy_nexus";
} else {
id = id.replace(' ', '_');
}
DeviceArtDescriptor descriptor = findDescriptor(id, name);
if (descriptor == null) {
// Fallback to generic stretchable images
boolean isTablet = isTablet(device);
descriptor = findDescriptor(isTablet ? "tablet" : "phone", null);
assert descriptor != null; // These should always exist
}
return descriptor;
}
示例15: getComparator
import com.android.sdklib.devices.Device; //导入依赖的package包/类
@Nullable
@Override
public Comparator<Device> getComparator() {
return new Comparator<Device>() {
@Override
public int compare(Device o1, Device o2) {
if (o1 == null) {
return -1;
} else if (o2 == null) {
return 1;
} else {
Dimension d1 = o1.getScreenSize(o1.getDefaultState().getOrientation());
Dimension d2 = o2.getScreenSize(o2.getDefaultState().getOrientation());
if (d1 == null) {
return -1;
} else if (d2 == null) {
return 1;
} else {
return Integer.valueOf(d1.width*d1.height).compareTo(d2.width*d2.height);
}
}
}
};
}