use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class Coordinates method pxToDp.
@AndroidDpCoordinate
public static int pxToDp(@NotNull ScreenView view, @AndroidCoordinate int androidPx) {
final Configuration configuration = view.getConfiguration();
final int dpiValue = configuration.getDensity().getDpiValue();
return Math.round(androidPx * (DEFAULT_DENSITY / dpiValue));
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class CanvasResizeInteraction method end.
@Override
public void end(@SwingCoordinate int x, @SwingCoordinate int y, @InputEventMask int modifiers, boolean canceled) {
super.end(x, y, modifiers, canceled);
ScreenView screenView = myDesignSurface.getCurrentScreenView();
if (screenView == null) {
return;
}
// Set the surface in resize mode so it doesn't try to re-center the screen views all the time
screenView.getSurface().setResizeMode(false);
// When disabling the resize mode, add a render handler to call zoomToFit
screenView.getModel().addListener(new ModelListener() {
@Override
public void modelChanged(@NotNull NlModel model) {
}
@Override
public void modelRendered(@NotNull NlModel model) {
model.removeListener(this);
}
@Override
public void modelChangedOnLayout(@NotNull NlModel model, boolean animate) {
// Do nothing
}
});
int androidX = Coordinates.getAndroidX(screenView, x);
int androidY = Coordinates.getAndroidY(screenView, y);
if (canceled || androidX < 0 || androidY < 0) {
Configuration configuration = screenView.getConfiguration();
configuration.setEffectiveDevice(myOriginalDevice, myOriginalDeviceState);
} else {
int snapThreshold = Coordinates.getAndroidDimension(screenView, MAX_MATCH_DISTANCE);
Device deviceToSnap = snapToDevice(androidX, androidY, snapThreshold);
if (deviceToSnap != null) {
State deviceState = deviceToSnap.getState(androidX < androidY ? "Portrait" : "Landscape");
myDesignSurface.getConfiguration().setEffectiveDevice(deviceToSnap, deviceState);
} else {
screenView.getModel().overrideConfigurationScreenSize(androidX, androidY);
}
}
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class ScreenView method switchDevice.
public void switchDevice() {
List<Device> devices = myModel.getFacet().getConfigurationManager().getDevices();
List<Device> applicable = Lists.newArrayList();
for (Device device : devices) {
if (HardwareConfigHelper.isNexus(device)) {
applicable.add(device);
}
}
Configuration configuration = getConfiguration();
Device currentDevice = configuration.getDevice();
for (int i = 0, n = applicable.size(); i < n; i++) {
if (applicable.get(i) == currentDevice) {
Device newDevice = applicable.get((i + 1) % applicable.size());
configuration.setDevice(newDevice, true);
break;
}
}
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class LayoutTestUtilities method createScreen.
public static ScreenView createScreen(DesignSurface surface, NlModel model, SelectionModel selectionModel, double scale, @SwingCoordinate int x, @SwingCoordinate int y, Density density) {
Configuration configuration = mock(Configuration.class);
when(configuration.getDensity()).thenReturn(density);
when(configuration.getFile()).thenReturn(model.getFile().getVirtualFile());
when(configuration.getFullConfig()).thenReturn(new FolderConfiguration());
ScreenView screenView = mock(ScreenView.class);
when(screenView.getConfiguration()).thenReturn(configuration);
when(screenView.getModel()).thenReturn(model);
when(screenView.getScale()).thenReturn(scale);
when(screenView.getSelectionModel()).thenReturn(selectionModel);
when(screenView.getSize()).thenReturn(new Dimension());
when(screenView.getSurface()).thenReturn(surface);
when(screenView.getX()).thenReturn(x);
when(screenView.getY()).thenReturn(y);
when(surface.getScreenView(anyInt(), anyInt())).thenReturn(screenView);
return screenView;
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class RefreshRenderAction method clearCache.
public static void clearCache(EditorDesignSurface surface) {
ModuleClassLoader.clearCache();
Configuration configuration = surface.getConfiguration();
if (configuration != null) {
// Clear layoutlib bitmap cache (in case files have been modified externally)
IAndroidTarget target = configuration.getTarget();
Module module = configuration.getModule();
if (module != null) {
ResourceClassRegistry.get(module.getProject()).clearCache();
if (target != null) {
AndroidTargetData targetData = AndroidTargetData.getTargetData(target, module);
if (targetData != null) {
targetData.clearLayoutBitmapCache(module);
}
}
}
AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
if (facet != null) {
facet.refreshResources();
}
configuration.updated(ConfigurationListener.MASK_RENDERING);
}
surface.requestRender();
}
Aggregations