aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-10-24 15:21:02 -0700
committerTor Norbye <tnorbye@google.com>2012-10-24 15:21:02 -0700
commitc3fa0391879acd10e613e3aa8d725f14f67fc149 (patch)
tree41e4af93e6205437c67b8365a4a9e82d52edb70b /sdkmanager
parentad15e1511fc30b097b25649208f93ff09cf3ff7c (diff)
downloadsdk-c3fa0391879acd10e613e3aa8d725f14f67fc149.zip
sdk-c3fa0391879acd10e613e3aa8d725f14f67fc149.tar.gz
sdk-c3fa0391879acd10e613e3aa8d725f14f67fc149.tar.bz2
Clean up new avd dialog, unify with layout manager device menu
Change-Id: Iaa6cf80bfb0b6c3d3d150f6c6f853ec420315db2
Diffstat (limited to 'sdkmanager')
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/DeviceManagerPage.java9
-rw-r--r--sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java372
2 files changed, 257 insertions, 124 deletions
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/DeviceManagerPage.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/DeviceManagerPage.java
index 2f1193b..ad0ee6f 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/DeviceManagerPage.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/DeviceManagerPage.java
@@ -525,14 +525,17 @@ public class DeviceManagerPage extends Composite
sb.append(name);
int pos1 = sb.length();
- String manu = device.getManufacturer();
+ String manufacturer = device.getManufacturer();
+ String manu = manufacturer;
if (isUser) {
item.setImage(mUserImage);
} else if (GENERIC.equals(manu)) {
item.setImage(mGenericImage);
} else {
item.setImage(mOtherImage);
- sb.append(" by ").append(device.getManufacturer());
+ if (!manufacturer.contains(NEXUS)) {
+ sb.append(" by ").append(manufacturer);
+ }
}
Hardware hw = device.getDefaultHardware();
@@ -723,7 +726,7 @@ public class DeviceManagerPage extends Composite
mImageFactory,
mUpdaterData.getSdkLog(),
null);
- dlg.setlectInitialDevice(ci.mDevice);
+ dlg.selectInitialDevice(ci.mDevice);
if (dlg.open() == Window.OK) {
onRefresh();
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java
index b97881e..79adba0 100644
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java
@@ -17,6 +17,7 @@
package com.android.sdkuilib.internal.widgets;
import com.android.SdkConstants;
+import com.android.annotations.Nullable;
import com.android.prefs.AndroidLocation.AndroidLocationException;
import com.android.resources.Density;
import com.android.resources.ScreenSize;
@@ -29,6 +30,7 @@ import com.android.sdklib.devices.Device;
import com.android.sdklib.devices.DeviceManager;
import com.android.sdklib.devices.Hardware;
import com.android.sdklib.devices.Screen;
+import com.android.sdklib.devices.Software;
import com.android.sdklib.devices.Storage;
import com.android.sdklib.internal.avd.AvdInfo;
import com.android.sdklib.internal.avd.AvdManager;
@@ -61,9 +63,13 @@ import org.eclipse.swt.widgets.Text;
import java.io.File;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class AvdCreationDialog extends GridDialog {
@@ -73,8 +79,6 @@ public class AvdCreationDialog extends GridDialog {
private AvdInfo mAvdInfo;
private boolean mHaveSystemImage;
- // A map from manufacturers to their list of devices.
- private Map<String, List<Device>> mDeviceMap;
private final TreeMap<String, IAndroidTarget> mCurrentTargets =
new TreeMap<String, IAndroidTarget>();
@@ -82,8 +86,7 @@ public class AvdCreationDialog extends GridDialog {
private Text mAvdName;
- private Combo mDeviceManufacturer;
- private Combo mDeviceName;
+ private Combo mDevice;
private Combo mTarget;
private Combo mAbi;
@@ -148,23 +151,6 @@ public class AvdCreationDialog extends GridDialog {
mImageFactory = imageFactory;
mSdkLog = log;
mAvdInfo = editAvdInfo;
-
- mDeviceMap = new TreeMap<String, List<Device>>();
-
- SdkManager sdkMan = avdManager.getSdkManager();
- if (sdkMan != null && sdkMan.getLocation() != null) {
- List<Device> devices = (new DeviceManager(log)).getDevices(sdkMan.getLocation());
- for (Device d : devices) {
- List<Device> list;
- if (mDeviceMap.containsKey(d.getManufacturer())) {
- list = mDeviceMap.get(d.getManufacturer());
- } else {
- list = new ArrayList<Device>();
- mDeviceMap.put(d.getManufacturer(), list);
- }
- list.add(d);
- }
- }
}
/** Returns the AVD Created, if successful. */
@@ -208,27 +194,12 @@ public class AvdCreationDialog extends GridDialog {
// --- device selection
label = new Label(parent, SWT.NONE);
- label.setText("Device\nManufacturer:");
- tooltip = "The manufacturer of the device this AVD will be based on";
- mDeviceManufacturer = new Combo(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
- for (String manufacturer : mDeviceMap.keySet()) {
- mDeviceManufacturer.add(manufacturer);
- }
- mDeviceManufacturer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- mDeviceManufacturer.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- reloadDeviceNameCombo();
- validatePage();
- }
- });
-
- label = new Label(parent, SWT.NONE);
- label.setText("Device Name:");
- tooltip = "The name of the device this AVD will be based on";
- mDeviceName = new Combo(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
- mDeviceName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- mDeviceName.addSelectionListener(new DeviceSelectionListener());
+ label.setText("Device:");
+ tooltip = "The device this AVD will be based on";
+ mDevice = new Combo(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
+ mDevice.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ initializeDevices();
+ mDevice.addSelectionListener(new DeviceSelectionListener());
// --- api target
label = new Label(parent, SWT.NONE);
@@ -411,7 +382,7 @@ public class AvdCreationDialog extends GridDialog {
mSnapshot.setToolTipText("Emulator's state will be persisted between emulator executions");
mSnapshot.addSelectionListener(validateListener);
mGpuEmulation = new Button(optionsGroup, SWT.CHECK);
- mGpuEmulation.setText("GPU Emulation");
+ mGpuEmulation.setText("Use Host GPU");
mGpuEmulation.setToolTipText("Enable hardware OpenGLES emulation");
mGpuEmulation.addSelectionListener(validateListener);
@@ -445,12 +416,98 @@ public class AvdCreationDialog extends GridDialog {
mStatusLabel.setText(""); //$NON-NLS-1$
}
+ @Nullable
+ private Device getSelectedDevice() {
+ Device[] devices = (Device[]) mDevice.getData();
+ if (devices != null) {
+ int index = mDevice.getSelectionIndex();
+ if (index != -1 && index < devices.length) {
+ return devices[index];
+ }
+ }
+
+ return null;
+ }
+
+ private void selectDevice(String manufacturer, String name) {
+ Device[] devices = (Device[]) mDevice.getData();
+ if (devices != null) {
+ for (int i = 0, n = devices.length; i < n; i++) {
+ Device device = devices[i];
+ if (device.getManufacturer().equals(manufacturer)
+ && device.getName().equals(name)) {
+ mDevice.select(i);
+ break;
+ }
+ }
+ }
+ }
+
+ private void selectDevice(Device device) {
+ Device[] devices = (Device[]) mDevice.getData();
+ if (devices != null) {
+ for (int i = 0, n = devices.length; i < n; i++) {
+ if (devices[i].equals(device)) {
+ mDevice.select(i);
+ break;
+ }
+ }
+ }
+ }
+
+ private void initializeDevices() {
+ assert mDevice != null;
+
+ SdkManager sdkManager = mAvdManager.getSdkManager();
+ String location = sdkManager.getLocation();
+ if (sdkManager != null && location != null) {
+ DeviceManager deviceManager = new DeviceManager(mSdkLog);
+ List<Device> deviceList = new ArrayList<Device>(deviceManager.getDevices(location));
+
+ // Sort
+ List<Device> nexus = new ArrayList<Device>(deviceList.size());
+ List<Device> other = new ArrayList<Device>(deviceList.size());
+ for (Device device : deviceList) {
+ if (isNexus(device)) {
+ if (!isGeneric(device)) { // Filter out repeated definitions
+ nexus.add(device);
+ }
+ } else {
+ other.add(device);
+ }
+ }
+ Collections.reverse(other);
+ Collections.sort(nexus, new Comparator<Device>() {
+ @Override
+ public int compare(Device device1, Device device2) {
+ // Descending order of age
+ return nexusRank(device2) - nexusRank(device1);
+ }
+ });
+ List<Device> all = nexus;
+ all.addAll(other);
+
+ Device[] devices = all.toArray(new Device[all.size()]);
+ String[] labels = new String[devices.length];
+ for (int i = 0, n = devices.length; i < n; i++) {
+ Device device = devices[i];
+ if (isNexus(device)) {
+ labels[i] = getNexusLabel(device);
+ } else {
+ labels[i] = getGenericLabel(device);
+ }
+ }
+ mDevice.setData(devices);
+ mDevice.setItems(labels);
+ }
+ }
+
/**
* Can be called after the constructor to set the default device for this AVD.
* Useful especially for new AVDs.
* @param device
*/
- public void setlectInitialDevice(Device device) {
+ public void selectInitialDevice(Device device) {
mInitWithDevice = device;
}
@@ -517,14 +574,7 @@ public class AvdCreationDialog extends GridDialog {
@Override
public void widgetSelected(SelectionEvent arg0) {
- Device currentDevice = null;
- for (Device d : mDeviceMap.get(mDeviceManufacturer.getText())) {
- if (d.getName().equals(mDeviceName.getText())) {
- currentDevice = d;
- break;
- }
- }
-
+ Device currentDevice = getSelectedDevice();
if (currentDevice != null) {
fillDeviceProperties(currentDevice);
}
@@ -532,7 +582,6 @@ public class AvdCreationDialog extends GridDialog {
toggleCameras();
validatePage();
}
-
}
private void fillDeviceProperties(Device device) {
@@ -577,37 +626,54 @@ public class AvdCreationDialog extends GridDialog {
}
}
mVmHeap.setText(Integer.toString(vmHeapSize));
- }
- private void toggleCameras() {
- mFrontCamera.setEnabled(false);
- mBackCamera.setEnabled(false);
- if (mDeviceName.getSelectionIndex() >= 0) {
- List<Device> devices = mDeviceMap.get(mDeviceManufacturer.getText());
- for (Device d : devices) {
- if (mDeviceName.getText().equals(d.getName())) {
- for (Camera c : d.getDefaultHardware().getCameras()) {
- if (CameraLocation.FRONT.equals(c.getLocation())) {
- mFrontCamera.setEnabled(true);
- }
- if (CameraLocation.BACK.equals(c.getLocation())) {
- mBackCamera.setEnabled(true);
+ List<Software> allSoftware = device.getAllSoftware();
+ if (allSoftware != null && !allSoftware.isEmpty()) {
+ Software first = allSoftware.get(0);
+ int min = first.getMinSdkLevel();;
+ int max = first.getMaxSdkLevel();;
+ for (int i = 1; i < allSoftware.size(); i++) {
+ min = Math.min(min, first.getMinSdkLevel());
+ max = Math.max(max, first.getMaxSdkLevel());
+ }
+ if (mCurrentTargets != null) {
+ int bestApiLevel = Integer.MAX_VALUE;
+ IAndroidTarget bestTarget = null;
+ for (IAndroidTarget target : mCurrentTargets.values()) {
+ if (!target.isPlatform()) {
+ continue;
+ }
+ int apiLevel = target.getVersion().getApiLevel();
+ if (apiLevel >= min && apiLevel <= max) {
+ if (bestTarget == null || apiLevel < bestApiLevel) {
+ bestTarget = target;
+ bestApiLevel = apiLevel;
}
}
}
- }
+ if (bestTarget != null) {
+ selectTarget(bestTarget);
+ reloadAbiTypeCombo();
+ }
+ }
}
}
- private void reloadDeviceNameCombo() {
- mDeviceName.removeAll();
- if (mDeviceMap.containsKey(mDeviceManufacturer.getText())) {
- for (final Device d : mDeviceMap.get(mDeviceManufacturer.getText())) {
- mDeviceName.add(d.getName());
+ private void toggleCameras() {
+ mFrontCamera.setEnabled(false);
+ mBackCamera.setEnabled(false);
+ Device d = getSelectedDevice();
+ if (d != null) {
+ for (Camera c : d.getDefaultHardware().getCameras()) {
+ if (CameraLocation.FRONT.equals(c.getLocation())) {
+ mFrontCamera.setEnabled(true);
+ }
+ if (CameraLocation.BACK.equals(c.getLocation())) {
+ mBackCamera.setEnabled(true);
+ }
}
}
-
}
private void reloadTargetCombo() {
@@ -623,6 +689,7 @@ public class AvdCreationDialog extends GridDialog {
boolean found = false;
index = -1;
+ List<IAndroidTarget> targetData = new ArrayList<IAndroidTarget>();
SdkManager sdkManager = mAvdManager.getSdkManager();
if (sdkManager != null) {
for (IAndroidTarget target : sdkManager.getTargets()) {
@@ -639,6 +706,7 @@ public class AvdCreationDialog extends GridDialog {
}
mCurrentTargets.put(name, target);
mTarget.add(name);
+ targetData.add(target);
if (!found) {
index++;
found = name.equals(selected);
@@ -647,12 +715,35 @@ public class AvdCreationDialog extends GridDialog {
}
mTarget.setEnabled(mCurrentTargets.size() > 0);
+ mTarget.setData(targetData.toArray(new IAndroidTarget[targetData.size()]));
if (found) {
mTarget.select(index);
}
}
+ private void selectTarget(IAndroidTarget target) {
+ IAndroidTarget[] targets = (IAndroidTarget[]) mTarget.getData();
+ if (targets != null) {
+ for (int i = 0; i < targets.length; i++) {
+ if (target == targets[i]) {
+ mTarget.select(i);
+ break;
+ }
+ }
+ }
+ }
+
+ private IAndroidTarget getSelectedTarget() {
+ IAndroidTarget[] targets = (IAndroidTarget[]) mTarget.getData();
+ int index = mTarget.getSelectionIndex();
+ if (targets != null && index != -1 && index < targets.length) {
+ return targets[index];
+ }
+
+ return null;
+ }
+
/**
* Reload all the abi types in the selection list
*/
@@ -752,7 +843,7 @@ public class AvdCreationDialog extends GridDialog {
return;
}
- if (mDeviceManufacturer.getSelectionIndex() < 0 || mDeviceName.getSelectionIndex() < 0) {
+ if (mDevice.getSelectionIndex() < 0) {
setPageValid(false, error, warning);
return;
}
@@ -907,19 +998,7 @@ public class AvdCreationDialog extends GridDialog {
}
// Get the device
- List<Device> devices = mDeviceMap.get(mDeviceManufacturer.getText());
- if (devices == null) {
- return false;
- }
-
- Device device = null;
- for (Device d : devices) {
- if (mDeviceName.getText().equals(d.getName())) {
- device = d;
- break;
- }
- }
-
+ Device device = getSelectedDevice();
if (device == null) {
return false;
}
@@ -1012,22 +1091,7 @@ public class AvdCreationDialog extends GridDialog {
private void fillExistingAvdInfo(AvdInfo avd) {
mAvdName.setText(avd.getName());
- String manufacturer = avd.getDeviceManufacturer();
- for (int i = 0; i < mDeviceManufacturer.getItemCount(); i++) {
- if (mDeviceManufacturer.getItem(i).equals(manufacturer)) {
- mDeviceManufacturer.select(i);
- break;
- }
- }
- reloadDeviceNameCombo();
-
- String deviceName = avd.getDeviceName();
- for (int i = 0; i < mDeviceName.getItemCount(); i++) {
- if (mDeviceName.getItem(i).equals(deviceName)) {
- mDeviceName.select(i);
- break;
- }
- }
+ selectDevice(avd.getDeviceManufacturer(), avd.getDeviceName());
toggleCameras();
IAndroidTarget target = avd.getTarget();
@@ -1172,24 +1236,8 @@ public class AvdCreationDialog extends GridDialog {
name = name.replaceAll("[^0-9a-zA-Z_-]+", " ").trim().replaceAll("[ _]+", "_");
mAvdName.setText(name);
- // Select the manufacturer of the device
- String manufacturer = device.getManufacturer();
- for (int i = 0; i < mDeviceManufacturer.getItemCount(); i++) {
- if (mDeviceManufacturer.getItem(i).equals(manufacturer)) {
- mDeviceManufacturer.select(i);
- break;
- }
- }
- reloadDeviceNameCombo();
-
// Select the device
- String deviceName = device.getName();
- for (int i = 0; i < mDeviceName.getItemCount(); i++) {
- if (mDeviceName.getItem(i).equals(deviceName)) {
- mDeviceName.select(i);
- break;
- }
- }
+ selectDevice(device);
toggleCameras();
// If there's only one target, select it by default.
@@ -1229,4 +1277,86 @@ public class AvdCreationDialog extends GridDialog {
return new ISystemImage[0];
}
+
+ // Code copied from DeviceMenuListener in ADT; unify post release
+
+ private static final String NEXUS = "Nexus"; //$NON-NLS-1$
+ private static final String GENERIC = "Generic"; //$NON-NLS-1$
+ private static Pattern PATTERN = Pattern.compile(
+ "(\\d+\\.?\\d*)in (.+?)( \\(.*Nexus.*\\))?"); //$NON-NLS-1$
+
+ private static int nexusRank(Device device) {
+ String name = device.getName();
+ if (name.endsWith(" One")) { //$NON-NLS-1$
+ return 1;
+ }
+ if (name.endsWith(" S")) { //$NON-NLS-1$
+ return 2;
+ }
+ if (name.startsWith("Galaxy")) { //$NON-NLS-1$
+ return 3;
+ }
+ if (name.endsWith(" 7")) { //$NON-NLS-1$
+ return 4;
+ }
+
+ return 5;
+ }
+
+ private static boolean isGeneric(Device device) {
+ return device.getManufacturer().equals(GENERIC);
+ }
+
+ private static boolean isNexus(Device device) {
+ return device.getName().contains(NEXUS);
+ }
+
+ private static String getGenericLabel(Device d) {
+ // * Replace "'in'" with '"' (e.g. 2.7" QVGA instead of 2.7in QVGA)
+ // * Use the same precision for all devices (all but one specify decimals)
+ // * Add some leading space such that the dot ends up roughly in the
+ // same space
+ // * Add in screen resolution and density
+ String name = d.getName();
+ if (name.equals("3.7 FWVGA slider")) { //$NON-NLS-1$
+ // Fix metadata: this one entry doesn't have "in" like the rest of them
+ name = "3.7in FWVGA slider"; //$NON-NLS-1$
+ }
+
+ Matcher matcher = PATTERN.matcher(name);
+ if (matcher.matches()) {
+ String size = matcher.group(1);
+ String n = matcher.group(2);
+ int dot = size.indexOf('.');
+ if (dot == -1) {
+ size = size + ".0";
+ dot = size.length() - 2;
+ }
+ for (int i = 0; i < 2 - dot; i++) {
+ size = ' ' + size;
+ }
+ name = size + "\" " + n;
+ }
+
+ return String.format(java.util.Locale.US, "%1$s (%2$s)", name,
+ getResolutionString(d));
+ }
+
+ private static String getNexusLabel(Device d) {
+ String name = d.getName();
+ Screen screen = d.getDefaultHardware().getScreen();
+ float length = (float) screen.getDiagonalLength();
+ return String.format(java.util.Locale.US, "%1$s (%3$s\", %2$s)",
+ name, getResolutionString(d), Float.toString(length));
+ }
+
+ @Nullable
+ private static String getResolutionString(Device device) {
+ Screen screen = device.getDefaultHardware().getScreen();
+ return String.format(java.util.Locale.US,
+ "%1$d \u00D7 %2$d: %3$s", // U+00D7: Unicode multiplication sign
+ screen.getXDimension(),
+ screen.getYDimension(),
+ screen.getPixelDensity().getResourceValue());
+ }
}