Search in sources :

Example 6 with IdDisplay

use of com.android.sdklib.repository.IdDisplay in project android by JetBrains.

the class AvdComboBox method doUpdateAvds.

private void doUpdateAvds() {
    final Module module = getModule();
    if (module == null || module.isDisposed()) {
        return;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    final IdDisplay[] newAvds;
    if (facet != null) {
        final Set<String> filteringSet = new HashSet<String>();
        if (myShowNotLaunchedOnly) {
            final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(facet.getModule().getProject());
            if (debugBridge != null) {
                for (IDevice device : debugBridge.getDevices()) {
                    final String avdName = device.getAvdName();
                    if (avdName != null && avdName.length() > 0) {
                        filteringSet.add(avdName);
                    }
                }
            }
        }
        final List<IdDisplay> newAvdList = new ArrayList<IdDisplay>();
        if (myAddEmptyElement) {
            newAvdList.add(IdDisplay.create("", ""));
        }
        for (AvdInfo avd : facet.getAllAvds()) {
            String displayName = avd.getProperties().get(AvdManager.AVD_INI_DISPLAY_NAME);
            final String avdName = displayName == null || displayName.isEmpty() ? avd.getName() : displayName;
            if (!filteringSet.contains(avdName)) {
                newAvdList.add(IdDisplay.create(avd.getName(), avdName));
            }
        }
        newAvds = ArrayUtil.toObjectArray(newAvdList, IdDisplay.class);
    } else {
        newAvds = new IdDisplay[0];
    }
    if (!Arrays.equals(myOldAvds, newAvds)) {
        myOldAvds = newAvds;
        final Object selected = getComboBox().getSelectedItem();
        getComboBox().setModel(new DefaultComboBoxModel(newAvds));
        getComboBox().setSelectedItem(selected);
    }
}
Also used : ArrayList(java.util.ArrayList) IDevice(com.android.ddmlib.IDevice) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) IdDisplay(com.android.sdklib.repository.IdDisplay) Module(com.intellij.openapi.module.Module) HashSet(com.intellij.util.containers.HashSet) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 7 with IdDisplay

use of com.android.sdklib.repository.IdDisplay in project android by JetBrains.

the class EmulatorTargetConfigurable method createUIComponents.

private void createUIComponents() {
    myAvdCombo = new AvdComboBox(myProject, true, false) {

        @Override
        public Module getModule() {
            return myContext.getModule();
        }
    };
    myAvdCombo.startUpdatingAvds(ModalityState.current());
    JComboBox avdComboBox = myAvdCombo.getComboBox();
    avdComboBox.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof IdDisplay) {
                setText(((IdDisplay) value).getDisplay());
            } else {
                setText(String.format("<html><font color='red'>Unknown AVD %1$s</font></html>", value == null ? "" : value.toString()));
            }
        }
    });
    avdComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            resetAvdCompatibilityWarningLabel();
        }
    });
    myAvdComboWithButton = new ComboboxWithBrowseButton(avdComboBox);
    Disposer.register(myParentDisposable, myAvdCombo);
}
Also used : ActionEvent(java.awt.event.ActionEvent) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) AvdComboBox(com.android.tools.idea.run.AvdComboBox) IdDisplay(com.android.sdklib.repository.IdDisplay) ActionListener(java.awt.event.ActionListener) ComboboxWithBrowseButton(com.intellij.ui.ComboboxWithBrowseButton) Module(com.intellij.openapi.module.Module)

Example 8 with IdDisplay

use of com.android.sdklib.repository.IdDisplay in project android by JetBrains.

the class ConfigureDeviceModel method buildDevice.

/**
   * Once we finish editing the device, we set it to its final configuration
   */
@NotNull
private Device buildDevice() {
    String deviceName = myDeviceData.name().get();
    myBuilder.setName(deviceName);
    myBuilder.setId(deviceName);
    myBuilder.addSoftware(myDeviceData.software().getValue());
    myBuilder.setManufacturer(myDeviceData.manufacturer().get());
    IdDisplay tag = myDeviceData.deviceType().getValueOrNull();
    myBuilder.setTagId((SystemImage.DEFAULT_TAG.equals(tag) || tag == null) ? null : tag.getId());
    List<State> states = generateStates(new AvdHardwareData(myDeviceData).buildHardware());
    myBuilder.addAllState(states);
    return myBuilder.build();
}
Also used : IdDisplay(com.android.sdklib.repository.IdDisplay) State(com.android.sdklib.devices.State) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with IdDisplay

use of com.android.sdklib.repository.IdDisplay in project android by JetBrains.

the class ConfigureDeviceOptionsStep method attachBindingsAndValidators.

private void attachBindingsAndValidators() {
    final AvdDeviceData deviceModel = getModel().getDeviceData();
    myBindings.bindTwoWay(new TextProperty(myDeviceName), deviceModel.name());
    myBindings.bind(deviceModel.diagonalScreenSize(), myDiagScreenSizeAdapter);
    myBindings.bind(deviceModel.screenResolutionWidth(), myScreenResWidthAdapter);
    myBindings.bind(deviceModel.screenResolutionHeight(), myScreenResHeightAdapter);
    myBindings.bindTwoWay(myRamField.storage(), deviceModel.ramStorage());
    myBindings.bindTwoWay(new SelectedProperty(myHasHardwareButtons), deviceModel.hasHardwareButtons());
    myBindings.bindTwoWay(new SelectedProperty(myHasHardwareKeyboard), deviceModel.hasHardwareKeyboard());
    myBindings.bindTwoWay(new SelectedItemProperty<>(myNavigationControlsCombo), deviceModel.navigation());
    myBindings.bindTwoWay(new SelectedProperty(myIsScreenRound), deviceModel.isScreenRound());
    myBindings.bindTwoWay(new SelectedProperty(mySupportsLandscape), deviceModel.supportsLandscape());
    myBindings.bindTwoWay(new SelectedProperty(mySupportsPortrait), deviceModel.supportsPortrait());
    myBindings.bindTwoWay(new SelectedProperty(myHasBackFacingCamera), deviceModel.hasBackCamera());
    myBindings.bindTwoWay(new SelectedProperty(myHasFrontFacingCamera), deviceModel.hasFrontCamera());
    myBindings.bindTwoWay(new SelectedProperty(myHasAccelerometer), deviceModel.hasAccelerometer());
    myBindings.bindTwoWay(new SelectedProperty(myHasGyroscope), deviceModel.hasGyroscope());
    myBindings.bindTwoWay(new SelectedProperty(myHasGps), deviceModel.hasGps());
    myBindings.bindTwoWay(new SelectedProperty(myHasProximitySensor), deviceModel.hasProximitySensor());
    myBindings.bindTwoWay(new SelectedItemProperty<>(myCustomSkinPath.getComboBox()), deviceModel.customSkinFile());
    SelectedItemProperty<IdDisplay> selectedDeviceType = new SelectedItemProperty<>(myDeviceTypeComboBox);
    myBindings.bindTwoWay(selectedDeviceType, deviceModel.deviceType());
    myListeners.receive(selectedDeviceType, idDisplayOptional -> {
        if (idDisplayOptional.isPresent()) {
            IdDisplay selectedType = idDisplayOptional.get();
            getModel().getDeviceData().isWear().set(selectedType.equals(SystemImage.WEAR_TAG));
            getModel().getDeviceData().isTv().set(selectedType.equals(SystemImage.TV_TAG));
            myIsScreenRound.setEnabled(selectedType.equals(SystemImage.WEAR_TAG));
            myIsScreenRound.setSelected(getModel().getDeviceData().isScreenRound().get());
        }
    });
    myValidatorPanel.registerValidator(deviceModel.name().isEmpty().not(), "Please write a name for the new device.");
    myValidatorPanel.registerValidator(myDiagScreenSizeAdapter.inSync().and(deviceModel.diagonalScreenSize().isEqualTo(myDiagScreenSizeAdapter)), "Please enter a non-zero positive floating point value for the screen size.");
    myValidatorPanel.registerValidator(myScreenResWidthAdapter.inSync().and(deviceModel.screenResolutionWidth().isEqualTo(myScreenResWidthAdapter)), "Please enter a valid value for the screen width.");
    myValidatorPanel.registerValidator(myScreenResHeightAdapter.inSync().and(deviceModel.screenResolutionHeight().isEqualTo(myScreenResHeightAdapter)), "Please enter a valid value for the screen height.");
    myValidatorPanel.registerValidator(deviceModel.ramStorage(), value -> (value.getSize() > 0) ? Result.OK : new Result(Validator.Severity.ERROR, "Please specify a non-zero amount of RAM."));
    myValidatorPanel.registerValidator(deviceModel.screenDpi().isGreaterThan(0), "The given resolution and screen size specified have a DPI that is too low.");
    myValidatorPanel.registerValidator(deviceModel.supportsLandscape().or(deviceModel.supportsPortrait()), "A device must support at least one orientation (Portrait or Landscape).");
    myValidatorPanel.registerValidator(deviceModel.customSkinFile(), value -> {
        File skinPath = value.orElse(null);
        if (skinPath != null && !FileUtil.filesEqual(skinPath, AvdWizardUtils.NO_SKIN) && !skinPath.getPath().equals(skinPath.getName())) {
            File layoutFile = new File(skinPath, SdkConstants.FN_SKIN_LAYOUT);
            if (!layoutFile.isFile()) {
                return new Result(Validator.Severity.ERROR, "The skin directory does not point to a valid skin.");
            }
        }
        return Result.OK;
    });
    myValidatorPanel.registerValidator(getModel().getDeviceData().compatibleSkinSize(), Validator.Severity.WARNING, "The selected skin is not large enough to view the entire screen.");
}
Also used : SelectedItemProperty(com.android.tools.idea.ui.properties.swing.SelectedItemProperty) IdDisplay(com.android.sdklib.repository.IdDisplay) File(java.io.File) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty) Result(com.android.tools.idea.ui.validation.Validator.Result)

Example 10 with IdDisplay

use of com.android.sdklib.repository.IdDisplay in project android by JetBrains.

the class ConfigureDeviceOptionsStep method onWizardStarting.

@Override
protected void onWizardStarting(@NotNull ModelWizard.Facade wizard) {
    myDeviceTypeComboBox.setModel(new CollectionComboBoxModel<>(AvdWizardUtils.ALL_DEVICE_TAGS));
    myDeviceTypeComboBox.setRenderer(new ListCellRendererWrapper<IdDisplay>() {

        @Override
        public void customize(JList list, IdDisplay value, int index, boolean selected, boolean hasFocus) {
            if (value == null || SystemImage.DEFAULT_TAG.equals(value)) {
                setText(DEFAULT_DEVICE_TYPE_LABEL);
            } else {
                setText(value.getDisplay());
            }
        }
    });
    myScrollPane.getVerticalScrollBar().setUnitIncrement(10);
    myHelpAndErrorLabel.setBackground(JBColor.background());
    myHelpAndErrorLabel.setForeground(JBColor.foreground());
    myHelpAndErrorLabel.setBorder(BorderFactory.createEmptyBorder(15, 15, 10, 10));
    myDiagScreenSizeAdapter = new StringToDoubleAdapterProperty(new TextProperty(myDiagonalScreenSize), 1, 2);
    myScreenResWidthAdapter = new StringToIntAdapterProperty(new TextProperty(myScreenResolutionWidth));
    myScreenResHeightAdapter = new StringToIntAdapterProperty(new TextProperty(myScreenResolutionHeight));
    attachBindingsAndValidators();
}
Also used : IdDisplay(com.android.sdklib.repository.IdDisplay) StringToIntAdapterProperty(com.android.tools.idea.ui.properties.adapters.StringToIntAdapterProperty) StringToDoubleAdapterProperty(com.android.tools.idea.ui.properties.adapters.StringToDoubleAdapterProperty) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty)

Aggregations

IdDisplay (com.android.sdklib.repository.IdDisplay)13 Module (com.intellij.openapi.module.Module)3 Nullable (org.jetbrains.annotations.Nullable)3 TypeDetails (com.android.repository.impl.meta.TypeDetails)2 AndroidVersion (com.android.sdklib.AndroidVersion)2 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)2 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)2 TextProperty (com.android.tools.idea.ui.properties.swing.TextProperty)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)1 IDevice (com.android.ddmlib.IDevice)1 State (com.android.sdklib.devices.State)1 AvdManager (com.android.sdklib.internal.avd.AvdManager)1 AvdComboBox (com.android.tools.idea.run.AvdComboBox)1 LaunchCompatibility (com.android.tools.idea.run.LaunchCompatibility)1 StringToDoubleAdapterProperty (com.android.tools.idea.ui.properties.adapters.StringToDoubleAdapterProperty)1 StringToIntAdapterProperty (com.android.tools.idea.ui.properties.adapters.StringToIntAdapterProperty)1 SelectedItemProperty (com.android.tools.idea.ui.properties.swing.SelectedItemProperty)1 SelectedProperty (com.android.tools.idea.ui.properties.swing.SelectedProperty)1 Result (com.android.tools.idea.ui.validation.Validator.Result)1