use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class OverrideResourceAction method forkResourceFile.
/**
* Create a variation (copy) of a given resource file (of a given type).
*
* @param xmlFile the XML resource file to fork
* @param myNewFolder the resource folder to create, or null to ask the user
* @param open if true, open the file after creating it
*/
public static void forkResourceFile(@NotNull final XmlFile xmlFile, @Nullable String myNewFolder, boolean open) {
VirtualFile file = xmlFile.getVirtualFile();
if (file == null) {
return;
}
Module module = AndroidPsiUtils.getModuleSafely(xmlFile);
if (module == null) {
return;
}
ResourceFolderType folderType = ResourceHelper.getFolderType(xmlFile);
if (folderType == null || folderType == ResourceFolderType.VALUES) {
return;
}
Configuration configuration = null;
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
configuration = facet.getConfigurationManager().getConfiguration(file);
}
forkResourceFile(module.getProject(), folderType, file, xmlFile, myNewFolder, configuration, open);
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class AndroidThemePreviewToolWindowManager method processFileEditorChange.
/**
* Method called when the current XML editor focus changes to a new one.
*
* @param newEditor the new editor, or null if no editor is selected.
*/
private void processFileEditorChange(@Nullable final TextEditor newEditor) {
if (myToolWindow == null) {
return;
}
if (myActiveEditor == newEditor) {
return;
}
myToolWindowUpdateQueue.cancelAllUpdates();
if (myActiveEditor != null) {
myActiveEditor.getEditor().getCaretModel().removeCaretListener(myCaretListener);
myActiveEditor.getEditor().getDocument().removeDocumentListener(myDocumentListener);
myActiveEditor = null;
}
boolean available = false;
if (newEditor != null && isApplicableEditor(newEditor)) {
myActiveEditor = newEditor;
CaretModel caretModel = myActiveEditor.getEditor().getCaretModel();
caretModel.addCaretListener(myCaretListener);
Document document = myActiveEditor.getEditor().getDocument();
document.addDocumentListener(myDocumentListener);
PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
Configuration configuration = getBestConfiguration(psiFile);
if (configuration != null) {
if (myThemeEditorContext == null) {
myThemeEditorContext = new ThemeEditorContext(configuration);
} else {
myThemeEditorContext.setConfiguration(configuration);
}
// Check if there is a theme at the current offset before enabling the preview
if (getThemeAtEditorOffset(document, caretModel.getOffset()) != null) {
available = true;
updatePreview();
}
}
}
myToolWindow.setAvailable(available, null);
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class Coordinates method dpToPx.
public static int dpToPx(@NotNull ScreenView view, @AndroidDpCoordinate float androidDp) {
final Configuration configuration = view.getConfiguration();
final int dpiValue = configuration.getDensity().getDpiValue();
return Math.round(androidDp * (dpiValue / DEFAULT_DENSITY));
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class Coordinates method dpToPx.
// DPI
public static int dpToPx(@NotNull ScreenView view, @AndroidDpCoordinate int androidDp) {
final Configuration configuration = view.getConfiguration();
final int dpiValue = configuration.getDensity().getDpiValue();
return Math.round(androidDp * (dpiValue / DEFAULT_DENSITY));
}
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));
}
Aggregations