use of com.android.ide.common.rendering.api.ResourceValue in project android_frameworks_base by AOSPA.
the class AppCompatActionBar method getInflater.
@Override
protected LayoutInflater getInflater(BridgeContext context) {
// Other than the resource resolution part, the code has been taken from the support
// library. see code from line 269 onwards in
// https://android.googlesource.com/platform/frameworks/support/+/android-5.1.0_r1/v7/appcompat/src/android/support/v7/app/ActionBarActivityDelegateBase.java
Context themedContext = context;
RenderResources resources = context.getRenderResources();
ResourceValue actionBarTheme = resources.findItemInTheme("actionBarTheme", false);
if (actionBarTheme != null) {
// resolve it, if needed.
actionBarTheme = resources.resolveResValue(actionBarTheme);
}
if (actionBarTheme instanceof StyleResourceValue) {
int styleId = context.getDynamicIdByStyle(((StyleResourceValue) actionBarTheme));
if (styleId != 0) {
themedContext = new ContextThemeWrapper(context, styleId);
}
}
return LayoutInflater.from(themedContext);
}
use of com.android.ide.common.rendering.api.ResourceValue in project android_frameworks_base by AOSPA.
the class BridgeActionBar method setTitle.
private void setTitle() {
RenderResources res = mBridgeContext.getRenderResources();
String title = mParams.getAppLabel();
ResourceValue titleValue = res.findResValue(title, false);
if (titleValue != null && titleValue.getValue() != null) {
setTitle(titleValue.getValue());
} else {
setTitle(title);
}
}
use of com.android.ide.common.rendering.api.ResourceValue in project android by JetBrains.
the class GradleInstantRunAndroidTest method testResourceChangeIsDetected.
public void testResourceChangeIsDetected() throws Exception {
myFixture.copyFileToProject(BASEDIR + "AndroidManifest.xml", SdkConstants.FN_ANDROID_MANIFEST_XML);
myFixture.copyFileToProject(BASEDIR + "res/values/strings.xml", "res/values/strings.xml");
myFixture.copyFileToProject(BASEDIR + "res/drawable-hdpi/ic_launcher.png", "res/drawable-hdpi/ic_launcher.png");
HashCode hash = GradleInstantRunContext.getManifestResourcesHash(myFacet);
// change a resource not referenced from manifest
AppResourceRepository repository = AppResourceRepository.create(myFacet);
ResourceValue resValue = repository.getConfiguredValue(ResourceType.STRING, "title_section1", new FolderConfiguration());
resValue.setValue("foo");
assertEquals("Hash should not change if a resource not referenced from the manifest is changed", hash, GradleInstantRunContext.getManifestResourcesHash(myFacet));
// change the app_name referenced from manifest
resValue = repository.getConfiguredValue(ResourceType.STRING, "app_name", new FolderConfiguration());
resValue.setValue("testapp");
assertNotEquals("Hash should change if a resource referenced from the manifest is changed", hash, GradleInstantRunContext.getManifestResourcesHash(myFacet));
// change the contents of the launcher icon referenced from manifest
hash = GradleInstantRunContext.getManifestResourcesHash(myFacet);
myFixture.copyFileToProject(BASEDIR + "res/drawable-mdpi/ic_launcher.png", "res/drawable-hdpi/ic_launcher.png");
assertNotEquals("Hash should change if a resource referenced from the manifest is changed", hash, GradleInstantRunContext.getManifestResourcesHash(myFacet));
}
use of com.android.ide.common.rendering.api.ResourceValue in project android by JetBrains.
the class NlOldPalettePanel method setColors.
private void setColors() {
Color background;
Color foreground;
Configuration configuration = null;
if (myDesignSurface != null) {
configuration = myDesignSurface.getConfiguration();
}
ResourceResolver resolver = null;
if (configuration != null) {
resolver = configuration.getResourceResolver();
}
if (resolver == null || myMode != Mode.PREVIEW) {
foreground = UIUtil.getTreeForeground();
background = UIUtil.getTreeBackground();
} else {
ResourceValue windowBackground = resolver.findItemInTheme("colorBackground", true);
background = ResourceHelper.resolveColor(resolver, windowBackground, myProject);
if (background == null) {
background = UIUtil.getTreeBackground();
}
ResourceValue textForeground = resolver.findItemInTheme("colorForeground", true);
foreground = ResourceHelper.resolveColor(resolver, textForeground, myProject);
if (foreground == null) {
foreground = UIUtil.getTreeForeground();
}
// Ensure the colors can be differentiated:
if (Math.abs(ImageUtils.getBrightness(background.getRGB()) - ImageUtils.getBrightness(foreground.getRGB())) < 64) {
if (ImageUtils.getBrightness(background.getRGB()) < 128) {
foreground = JBColor.WHITE;
} else {
foreground = JBColor.BLACK;
}
}
}
myPaletteTree.setBackground(background);
myPaletteTree.setForeground(foreground);
}
use of com.android.ide.common.rendering.api.ResourceValue in project android by JetBrains.
the class ThemeEditorTable method getPopupMenuAtCell.
private JPopupMenu getPopupMenuAtCell(final int row, final int column) {
if (row < 0 || column < 0) {
return null;
}
TableModel rawModel = getModel();
if (!(rawModel instanceof AttributesTableModel)) {
return null;
}
final AttributesTableModel model = (AttributesTableModel) rawModel;
AttributesTableModel.RowContents contents = model.getRowContents(this.convertRowIndexToModel(row));
if (contents instanceof AttributesTableModel.AttributeContents) {
final AttributesTableModel.AttributeContents attribute = (AttributesTableModel.AttributeContents) contents;
final EditedStyleItem item = attribute.getValue();
if (item == null) {
return null;
}
final JBPopupMenu popupMenu = new JBPopupMenu();
if (attribute.getCellClass(1) == ConfiguredThemeEditorStyle.class) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goTo(item);
}
});
} else {
final ResourceResolver resolver = myContext.getResourceResolver();
assert resolver != null;
final Project project = myContext.getProject();
final ResourceValue resourceValue = resolver.resolveResValue(item.getSelectedValue());
final File file = new File(resourceValue.getValue());
final VirtualFileManager manager = VirtualFileManager.getInstance();
final VirtualFile virtualFile = file.exists() ? manager.findFileByUrl("file://" + file.getAbsolutePath()) : null;
if (virtualFile != null) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
FileEditorManager.getInstance(project).openEditor(descriptor, true);
}
});
}
}
myJavadocAction.setCurrentItem(item);
popupMenu.add(myJavadocAction);
final ConfiguredThemeEditorStyle selectedStyle = model.getSelectedStyle();
if (!selectedStyle.isReadOnly() && selectedStyle.hasItem(item)) {
popupMenu.add(new AbstractAction("Reset value") {
@Override
public void actionPerformed(ActionEvent e) {
selectedStyle.removeAttribute(item.getQualifiedName());
model.fireTableCellUpdated(attribute.getRowIndex(), 0);
}
});
}
return popupMenu;
} else if (contents instanceof AttributesTableModel.ParentAttribute) {
final ConfiguredThemeEditorStyle parentStyle = model.getSelectedStyle().getParent();
if (parentStyle == null) {
return null;
}
final JBPopupMenu menu = new JBPopupMenu();
menu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goToParent();
}
});
return menu;
}
return null;
}
Aggregations