use of com.android.tools.idea.npw.FormFactor in project android by JetBrains.
the class FormFactorUtils method getFormFactorsImage.
/**
* Create an image showing icons for each of the available form factors. The icons are drawn from left to right, using the form factors
* large icon. This is an example of this method usage:
* <pre>
* <code>
* myJLabel.setIcon(getFormFactorsImage(myJLabel, true));
* </code>
* </pre>
* @param component Icon will be drawn in the context of the given {@code component}
* @param requireEmulator If true, only include icons for form factors that have an emulator available.
* @return <code>null</code> if it can't create a graphics Object to render the image (for example not enough memory)
*/
@Nullable
public static Icon getFormFactorsImage(JComponent component, boolean requireEmulator) {
int width = 0;
int height = 0;
for (FormFactor formFactor : FormFactor.values()) {
if (formFactor == FormFactor.GLASS) {
continue;
}
if (requireEmulator && !formFactor.hasEmulator()) {
continue;
}
Icon icon = formFactor.getLargeIcon();
height = Math.max(height, icon.getIconHeight());
width += formFactor.getLargeIcon().getIconWidth();
}
//noinspection UndesirableClassUsage
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = image.createGraphics();
int x = 0;
for (FormFactor formFactor : FormFactor.values()) {
if (requireEmulator && !formFactor.hasEmulator()) {
continue;
}
if (formFactor == FormFactor.GLASS) {
continue;
}
Icon icon = formFactor.getLargeIcon();
icon.paintIcon(component, graphics, x, 0);
x += icon.getIconWidth();
}
if (graphics != null) {
graphics.dispose();
return new ImageIcon(image);
} else {
return null;
}
}
use of com.android.tools.idea.npw.FormFactor in project android by JetBrains.
the class AndroidVersionsInfo method loadRemoteTargets.
private void loadRemoteTargets(@NotNull FormFactor myFormFactor, int minSdkLevel, @NotNull List<VersionItem> versionItemList, ItemsLoaded completedCallback) {
AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
final Runnable runCallbacks = () -> {
if (completedCallback != null) {
completedCallback.onDataLoadedFinished(versionItemList);
}
};
RepoManager.RepoLoadedCallback onComplete = packages -> {
addPackages(myFormFactor, versionItemList, packages.getNewPkgs(), minSdkLevel);
addOfflineLevels(myFormFactor, versionItemList);
runCallbacks.run();
};
// We need to pick up addons that don't have a target created due to the base platform not being installed.
RepoManager.RepoLoadedCallback onLocalComplete = packages -> addPackages(myFormFactor, versionItemList, packages.getLocalPackages().values(), minSdkLevel);
Runnable onError = () -> ApplicationManager.getApplication().invokeLater(() -> {
addOfflineLevels(myFormFactor, versionItemList);
runCallbacks.run();
}, ModalityState.any());
StudioProgressRunner runner = new StudioProgressRunner(false, false, "Refreshing Targets", true, null);
sdkHandler.getSdkManager(REPO_LOG).load(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, ImmutableList.of(onLocalComplete), ImmutableList.of(onComplete), ImmutableList.of(onError), runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
use of com.android.tools.idea.npw.FormFactor in project android by JetBrains.
the class AndroidVersionsInfo method addPackages.
private void addPackages(@NotNull FormFactor myFormFactor, @NotNull List<VersionItem> versionItemList, @NotNull Collection<? extends RepoPackage> packages, int minSdkLevel) {
List<RepoPackage> sorted = packages.stream().filter(repoPackage -> repoPackage != null && filterPkgDesc(repoPackage, myFormFactor, minSdkLevel)).collect(Collectors.toList());
Collections.sort(sorted, (repoPackage, other) -> getAndroidVersion(repoPackage).compareTo(getAndroidVersion(other)));
int existingApiLevel = -1;
int prevInsertedApiLevel = -1;
int index = -1;
for (RepoPackage info : sorted) {
int apiLevel = getFeatureLevel(info);
while (apiLevel > existingApiLevel) {
existingApiLevel = ++index < versionItemList.size() ? versionItemList.get(index).myApiLevel : Integer.MAX_VALUE;
}
if (apiLevel != existingApiLevel && apiLevel != prevInsertedApiLevel) {
versionItemList.add(index++, new VersionItem(info));
prevInsertedApiLevel = apiLevel;
}
}
}
use of com.android.tools.idea.npw.FormFactor in project android by JetBrains.
the class DeviceMenuAction method createPopupActionGroup.
@Override
@NotNull
protected DefaultActionGroup createPopupActionGroup() {
DefaultActionGroup group = new DefaultActionGroup(null, true);
Configuration configuration = myRenderContext.getConfiguration();
if (configuration == null) {
return group;
}
Device current = configuration.getDevice();
ConfigurationManager configurationManager = configuration.getConfigurationManager();
List<Device> deviceList = configurationManager.getDevices();
if (LIST_RECENT_DEVICES) {
List<Device> recent = configurationManager.getDevices();
if (recent.size() > 1) {
boolean separatorNeeded = false;
for (Device device : recent) {
String label = getLabel(device, isNexus(device));
Icon icon = getDeviceClassIcon(device);
group.add(new SetDeviceAction(myRenderContext, label, device, icon, device == current));
separatorNeeded = true;
}
if (separatorNeeded) {
group.addSeparator();
}
}
}
AndroidFacet facet = AndroidFacet.getInstance(configurationManager.getModule());
if (facet == null) {
// Unlikely, but has happened - see http://b.android.com/68091
return group;
}
if (!deviceList.isEmpty()) {
Map<String, List<Device>> manufacturers = new TreeMap<>();
for (Device device : deviceList) {
List<Device> devices;
if (manufacturers.containsKey(device.getManufacturer())) {
devices = manufacturers.get(device.getManufacturer());
} else {
devices = new ArrayList<>();
manufacturers.put(device.getManufacturer(), devices);
}
devices.add(device);
}
List<Device> nexus = new ArrayList<>();
Map<FormFactor, List<Device>> deviceMap = Maps.newEnumMap(FormFactor.class);
for (FormFactor factor : FormFactor.values()) {
deviceMap.put(factor, Lists.newArrayList());
}
for (List<Device> devices : manufacturers.values()) {
for (Device device : devices) {
if (isNexus(device) && !device.getManufacturer().equals(MANUFACTURER_GENERIC) && !isWear(device) && !isTv(device)) {
nexus.add(device);
} else {
deviceMap.get(FormFactor.getFormFactor(device)).add(device);
}
}
}
sortDevicesByScreenSize(nexus);
for (List<Device> list : splitDevicesByScreenSize(nexus)) {
addNexusDeviceSection(group, current, list);
group.addSeparator();
}
addDeviceSection(group, current, deviceMap, false, FormFactor.WEAR);
group.addSeparator();
addDeviceSection(group, current, deviceMap, false, FormFactor.TV);
group.addSeparator();
final AvdManager avdManager = facet.getAvdManagerSilently();
if (avdManager != null) {
boolean separatorNeeded = false;
boolean first = true;
for (AvdInfo avd : avdManager.getValidAvds()) {
Device device = configurationManager.createDeviceForAvd(avd);
if (device != null) {
String avdName = "AVD: " + avd.getName();
boolean selected = current != null && (current.getDisplayName().equals(avdName) || current.getId().equals(avdName));
Icon icon = first ? getDeviceClassIcon(device) : null;
group.add(new SetDeviceAction(myRenderContext, avdName, device, icon, selected));
first = false;
separatorNeeded = true;
}
}
if (separatorNeeded) {
group.addSeparator();
}
}
DefaultActionGroup genericGroup = new DefaultActionGroup("_Generic Phones and Tablets", true);
sortDevicesByScreenSize(deviceMap.get(FormFactor.MOBILE));
addDeviceSection(genericGroup, current, deviceMap, true, FormFactor.MOBILE);
group.add(genericGroup);
}
group.add(new RunAndroidAvdManagerAction("Add Device Definition..."));
return group;
}
use of com.android.tools.idea.npw.FormFactor in project android by JetBrains.
the class ChooseModuleTypeStep method init.
@Override
public void init() {
super.init();
ImmutableList.Builder<ModuleTemplate> deviceTemplates = ImmutableList.builder();
ImmutableList.Builder<ModuleTemplate> extrasTemplates = ImmutableList.builder();
Set<FormFactor> formFactorSet = Sets.newHashSet();
// Android device templates are shown first, with less important templates following
for (ModuleTemplateProvider provider : myModuleTypesProviders) {
for (ModuleTemplate moduleTemplate : provider.getModuleTemplates()) {
FormFactor formFactor = moduleTemplate.getFormFactor();
if (formFactor != null) {
if (formFactor == FormFactor.GLASS && !AndroidSdkUtils.isGlassInstalled()) {
// Hidden if not installed
continue;
}
if (formFactor != FormFactor.CAR) {
// Auto is not a standalone module (but rather a modification to a mobile module):
deviceTemplates.add(moduleTemplate);
formFactorSet.add(formFactor);
}
} else {
extrasTemplates.add(moduleTemplate);
}
}
}
for (final FormFactor formFactor : formFactorSet) {
registerValueDeriver(FormFactorUtils.getInclusionKey(formFactor), new ValueDeriver<Boolean>() {
@Nullable
@Override
public Boolean deriveValue(@NotNull ScopedStateStore state, @Nullable ScopedStateStore.Key changedKey, @Nullable Boolean currentValue) {
ModuleTemplate moduleTemplate = myState.get(SELECTED_MODULE_TYPE_KEY);
return moduleTemplate != null && Objects.equal(formFactor, moduleTemplate.getFormFactor());
}
});
}
List<ModuleTemplate> galleryTemplatesList = deviceTemplates.build();
List<ModuleTemplate> extrasTemplatesList = extrasTemplates.build();
Iterable<ModuleTemplate> allTemplates = Iterables.concat(galleryTemplatesList, extrasTemplatesList);
myFormFactorGallery.setModel(JBList.createDefaultListModel(Iterables.toArray(allTemplates, ModuleTemplate.class)));
ModuleTypeBinding binding = new ModuleTypeBinding();
register(SELECTED_MODULE_TYPE_KEY, myPanel, binding);
myFormFactorGallery.addListSelectionListener(new ModuleTypeSelectionListener());
if (!galleryTemplatesList.isEmpty()) {
myState.put(SELECTED_MODULE_TYPE_KEY, galleryTemplatesList.get(0));
}
}
Aggregations