Device hardware profile for config selector in GLE

- Built-in device list for now
- Config selector in GLE is changed to only have
  - MCC/MNC
  - Locale
  - Device List
  - Device config.
This commit is contained in:
Xavier Ducrohet
2009-08-20 14:00:22 -07:00
parent f051ea0d38
commit 8535518cb2
12 changed files with 410 additions and 787 deletions

View File

@@ -54,6 +54,7 @@ Export-Package: com.android.ide.eclipse.adt;x-friends:="com.android.ide.eclipse.
com.android.ide.eclipse.adt.internal.editors;x-friends:="com.android.ide.eclipse.tests",
com.android.ide.eclipse.adt.internal.editors.descriptors;x-friends:="com.android.ide.eclipse.tests",
com.android.ide.eclipse.adt.internal.editors.layout;x-friends:="com.android.ide.eclipse.tests",
com.android.ide.eclipse.adt.internal.editors.layout.configuration,
com.android.ide.eclipse.adt.internal.editors.layout.descriptors;x-friends:="com.android.ide.eclipse.tests",
com.android.ide.eclipse.adt.internal.editors.layout.parts;x-friends:="com.android.ide.eclipse.tests",
com.android.ide.eclipse.adt.internal.editors.layout.uimodel;x-friends:="com.android.ide.eclipse.tests",

View File

@@ -759,9 +759,6 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// resources need to be updated.
recomputeLayout();
} else {
// update the configuration icons with the new edited config.
mConfigComposite.displayConfigError();
// enable the Create button
mConfigComposite.setEnabledCreate(true);

View File

@@ -20,24 +20,16 @@ import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.ide.eclipse.adt.internal.resources.ResourceType;
import com.android.ide.eclipse.adt.internal.resources.configurations.CountryCodeQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;
import com.android.ide.eclipse.adt.internal.resources.configurations.KeyboardStateQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.LanguageQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.NavigationMethodQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.NetworkCodeQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.RegionQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.ResourceQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenDimensionQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenOrientationQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.TextInputMethodQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.KeyboardStateQualifier.KeyboardState;
import com.android.ide.eclipse.adt.internal.resources.configurations.NavigationMethodQualifier.NavigationMethod;
import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier.Density;
import com.android.ide.eclipse.adt.internal.resources.configurations.VersionQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenOrientationQualifier.ScreenOrientation;
import com.android.ide.eclipse.adt.internal.resources.configurations.TextInputMethodQualifier.TextInputMethod;
import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier.TouchScreenType;
import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources;
import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.DimensionVerifier;
import com.android.ide.eclipse.adt.internal.sdk.DeviceConfiguration;
import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.LanguageRegionVerifier;
import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.MobileCodeVerifier;
import com.android.layoutlib.api.IResourceValue;
@@ -61,9 +53,9 @@ import org.eclipse.swt.widgets.Text;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
public class ConfigurationComposite extends Composite {
@@ -71,34 +63,17 @@ public class ConfigurationComposite extends Composite {
private Text mCountry;
private Text mNetwork;
private Combo mLanguage;
private Combo mRegion;
private Combo mOrientation;
private Combo mDensity;
private Combo mTouch;
private Combo mKeyboard;
private Combo mTextInput;
private Combo mNavigation;
private Text mSize1;
private Text mSize2;
private Combo mLocale;
private Combo mDeviceList;
private Combo mDeviceConfigs;
private Combo mThemeCombo;
private Button mCreateButton;
private Label mCountryIcon;
private Label mNetworkIcon;
private Label mLanguageIcon;
private Label mRegionIcon;
private Label mOrientationIcon;
private Label mDensityIcon;
private Label mTouchIcon;
private Label mKeyboardIcon;
private Label mTextInputIcon;
private Label mNavigationIcon;
private Label mSizeIcon;
private Label mCurrentLayoutLabel;
private Image mWarningImage;
private Image mMatchImage;
private Image mErrorImage;
@@ -107,6 +82,12 @@ public class ConfigurationComposite extends Composite {
/** The {@link FolderConfiguration} representing the state of the UI controls */
private final FolderConfiguration mCurrentConfig = new FolderConfiguration();
private DeviceConfiguration[] mDevices;
private final ArrayList<ResourceQualifier[] > mLocaleList =
new ArrayList<ResourceQualifier[]>();
private final IConfigListener mListener;
public interface IConfigListener {
@@ -123,9 +104,9 @@ public class ConfigurationComposite extends Composite {
public ConfigurationComposite(IConfigListener listener, Composite parent, int style) {
super(parent, style);
mListener = listener;
mDevices = DeviceConfiguration.getDevices();
IconFactory factory = IconFactory.getInstance();
mWarningImage = factory.getIcon("warning"); //$NON-NLS-1$
mMatchImage = factory.getIcon("match"); //$NON-NLS-1$
mErrorImage = factory.getIcon("error"); //$NON-NLS-1$
@@ -172,151 +153,54 @@ public class ConfigurationComposite extends Composite {
}
});
new Label(this, SWT.NONE).setText("Lang");
mLanguageIcon = createControlComposite(this, true /* grab_horizontal */);
mLanguage = new Combo(mLanguageIcon.getParent(), SWT.DROP_DOWN);
mLanguage.setLayoutData(new GridData(
new Label(this, SWT.NONE).setText("Locale");
mLocale = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
mLocale.setLayoutData(new GridData(
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
mLanguage.addVerifyListener(new LanguageRegionVerifier());
mLanguage.addSelectionListener(new SelectionListener() {
mLocale.addVerifyListener(new LanguageRegionVerifier());
mLocale.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
onLanguageChange();
onLocaleChange();
}
public void widgetSelected(SelectionEvent e) {
onLanguageChange();
}
});
mLanguage.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
onLanguageChange();
onLocaleChange();
}
});
new Label(this, SWT.NONE).setText("Region");
mRegionIcon = createControlComposite(this, true /* grab_horizontal */);
mRegion = new Combo(mRegionIcon.getParent(), SWT.DROP_DOWN);
mRegion.setLayoutData(new GridData(
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
mRegion.addVerifyListener(new LanguageRegionVerifier());
mRegion.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
onRegionChange();
}
public void widgetSelected(SelectionEvent e) {
onRegionChange();
}
});
mRegion.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
onRegionChange();
}
});
new Label(this, SWT.NONE).setText("Orient");
mOrientationIcon = createControlComposite(this, true /* grab_horizontal */);
mOrientation = new Combo(mOrientationIcon.getParent(), SWT.DROP_DOWN | SWT.READ_ONLY);
ScreenOrientation[] soValues = ScreenOrientation.values();
mOrientation.add("(Default)");
for (ScreenOrientation value : soValues) {
mOrientation.add(value.getDisplayValue());
new Label(this, SWT.NONE).setText("Devices");
mDeviceList = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
// fill with the devices
for (DeviceConfiguration device : mDevices) {
mDeviceList.add(device.getName());
}
mOrientation.select(0);
mOrientation.setLayoutData(new GridData(
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
mOrientation.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onOrientationChange();
}
});
new Label(this, SWT.NONE).setText("Density");
mDensityIcon = createControlComposite(this, true /* grab_horizontal */);
mDensity = new Combo(mDensityIcon.getParent(), SWT.DROP_DOWN | SWT.READ_ONLY);
Density[] dValues = Density.values();
mDensity.add("(Default)");
for (Density value : dValues) {
mDensity.add(value.getDisplayValue());
}
mDensity.select(0);
mDensity.setLayoutData(new GridData(
mDeviceList.select(0);
mDeviceList.setLayoutData(new GridData(
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
mDensity.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onDensityChange();
}
});
new Label(this, SWT.NONE).setText("Touch");
mTouchIcon = createControlComposite(this, true /* grab_horizontal */);
mTouch = new Combo(mTouchIcon.getParent(), SWT.DROP_DOWN | SWT.READ_ONLY);
TouchScreenType[] tstValues = TouchScreenType.values();
mTouch.add("(Default)");
for (TouchScreenType value : tstValues) {
mTouch.add(value.getDisplayValue());
}
mTouch.select(0);
mTouch.setLayoutData(new GridData(
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
mTouch.addSelectionListener(new SelectionAdapter() {
mDeviceList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onTouchChange();
onDeviceChange();
}
});
new Label(this, SWT.NONE).setText("Keybrd");
mKeyboardIcon = createControlComposite(this, true /* grab_horizontal */);
mKeyboard = new Combo(mKeyboardIcon.getParent(), SWT.DROP_DOWN | SWT.READ_ONLY);
KeyboardState[] ksValues = KeyboardState.values();
mKeyboard.add("(Default)");
for (KeyboardState value : ksValues) {
mKeyboard.add(value.getDisplayValue());
new Label(this, SWT.NONE).setText("Config");
mDeviceConfigs = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
Map<String, FolderConfiguration> configs = mDevices[0].getConfigs();
Set<String> configNames = configs.keySet();
for (String name : configNames) {
mDeviceConfigs.add(name);
}
mKeyboard.select(0);
mKeyboard.setLayoutData(new GridData(
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
mKeyboard.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onKeyboardChange();
}
});
new Label(this, SWT.NONE).setText("Input");
mTextInputIcon = createControlComposite(this, true /* grab_horizontal */);
mTextInput = new Combo(mTextInputIcon.getParent(), SWT.DROP_DOWN | SWT.READ_ONLY);
TextInputMethod[] timValues = TextInputMethod.values();
mTextInput.add("(Default)");
for (TextInputMethod value : timValues) {
mTextInput.add(value.getDisplayValue());
mDeviceConfigs.select(0);
if (configNames.size() == 1) {
mDeviceConfigs.setEnabled(false);
}
mTextInput.select(0);
mTextInput.setLayoutData(new GridData(
mDeviceConfigs.setLayoutData(new GridData(
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
mTextInput.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onTextInputChange();
}
});
new Label(this, SWT.NONE).setText("Nav");
mNavigationIcon = createControlComposite(this, true /* grab_horizontal */);
mNavigation = new Combo(mNavigationIcon.getParent(), SWT.DROP_DOWN | SWT.READ_ONLY);
NavigationMethod[] nValues = NavigationMethod.values();
mNavigation.add("(Default)");
for (NavigationMethod value : nValues) {
mNavigation.add(value.getDisplayValue());
}
mNavigation.select(0);
mNavigation.setLayoutData(new GridData(
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
mNavigation.addSelectionListener(new SelectionAdapter() {
mDeviceConfigs.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onNavigationChange();
onDeviceConfigChange();
}
});
@@ -331,46 +215,6 @@ public class ConfigurationComposite extends Composite {
mCurrentLayoutLabel.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
gd.widthHint = 50;
new Label(labelParent, SWT.NONE).setText("Size");
mSizeIcon = createControlComposite(labelParent, false);
Composite sizeParent = new Composite(mSizeIcon.getParent(), SWT.NONE);
sizeParent.setLayout(gl = new GridLayout(3, false));
gl.marginWidth = gl.marginHeight = 0;
gl.horizontalSpacing = 0;
mSize1 = new Text(sizeParent, SWT.BORDER);
mSize1.setLayoutData(gd = new GridData());
gd.widthHint = 30;
new Label(sizeParent, SWT.NONE).setText("x");
mSize2 = new Text(sizeParent, SWT.BORDER);
mSize2.setLayoutData(gd = new GridData());
gd.widthHint = 30;
DimensionVerifier verifier = new DimensionVerifier();
mSize1.addVerifyListener(verifier);
mSize2.addVerifyListener(verifier);
SelectionListener sl = new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
onSizeChange();
}
public void widgetSelected(SelectionEvent e) {
onSizeChange();
}
};
mSize1.addSelectionListener(sl);
mSize2.addSelectionListener(sl);
ModifyListener sizeModifyListener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
onSizeChange();
}
};
mSize1.addModifyListener(sizeModifyListener);
mSize2.addModifyListener(sizeModifyListener);
// first separator
Label separator = new Label(labelParent, SWT.SEPARATOR | SWT.VERTICAL);
separator.setLayoutData(gd = new GridData(
@@ -405,10 +249,12 @@ public class ConfigurationComposite extends Composite {
}
});
onDeviceConfigChange();
}
public void setConfig(FolderConfiguration config) {
mCurrentConfig.set(config);
// mCurrentConfig.set(config);
throw new UnsupportedOperationException("setConfig");
}
public FolderConfiguration getCurrentConfig() {
@@ -420,35 +266,14 @@ public class ConfigurationComposite extends Composite {
}
public Rectangle getScreenBounds() {
ScreenOrientation orientation = null;
if (mOrientation.getSelectionIndex() == 0) {
orientation = ScreenOrientation.PORTRAIT;
} else {
orientation = ScreenOrientation.getByIndex(
mOrientation.getSelectionIndex() - 1);
}
// get the orientation from the current device config
ScreenOrientationQualifier qual = mCurrentConfig.getScreenOrientationQualifier();
ScreenOrientation orientation = qual.getValue();
int s1, s2;
// get the size from the UI controls. If it fails, revert to default values.
try {
s1 = Integer.parseInt(mSize1.getText().trim());
} catch (NumberFormatException e) {
s1 = 480;
}
try {
s2 = Integer.parseInt(mSize2.getText().trim());
} catch (NumberFormatException e) {
s2 = 320;
}
// make sure s1 is bigger than s2
if (s1 < s2) {
int tmp = s1;
s1 = s2;
s2 = tmp;
}
// get the device screen dimension
ScreenDimensionQualifier qual2 = mCurrentConfig.getScreenDimensionQualifier();
int s1 = qual2.getValue1();
int s2 = qual2.getValue2();
switch (orientation) {
default:
@@ -478,9 +303,11 @@ public class ConfigurationComposite extends Composite {
int selection = mThemeCombo.getSelectionIndex();
mThemeCombo.removeAll();
mPlatformThemeCount = 0;
mLanguage.removeAll();
Set<String> languages = new HashSet<String>();
mLocale.removeAll();
mLocaleList.clear();
SortedSet<String> languages = null;
ArrayList<String> themes = new ArrayList<String>();
// get the themes, and languages from the Framework.
@@ -514,11 +341,6 @@ public class ConfigurationComposite extends Composite {
mPlatformThemeCount = themes.size();
themes.clear();
}
// now get the languages from the framework.
Set<String> frameworkLanguages = frameworkProject.getLanguages();
if (frameworkLanguages != null) {
languages.addAll(frameworkLanguages);
}
}
// now get the themes and languages from the project.
@@ -557,22 +379,34 @@ public class ConfigurationComposite extends Composite {
}
// now get the languages from the project.
Set<String> projectLanguages = project.getLanguages();
if (projectLanguages != null) {
languages.addAll(projectLanguages);
}
languages = project.getLanguages();
}
// add the languages to the Combo
for (String language : languages) {
mLanguage.add(language);
mLocale.add("Default");
mLocaleList.add(new ResourceQualifier[] { null, null });
if (languages != null && languages.size() > 0) {
for (String language : languages) {
// first the language alone
mLocale.add(language);
LanguageQualifier qual = new LanguageQualifier(language);
mLocaleList.add(new ResourceQualifier[] { qual, null });
// now find the matching regions and add them
SortedSet<String> regions = project.getRegions(language);
for (String region : regions) {
mLocale.add(String.format("%1$s_%2$s", language, region)); //$NON-NLS-1$
RegionQualifier qual2 = new RegionQualifier(region);
mLocaleList.add(new ResourceQualifier[] { qual, qual2 });
}
}
} else {
}
mDisableUpdates = false;
// and update the Region UI based on the current language
updateRegionUi();
// handle default selection of themes
if (mThemeCombo.getItemCount() > 0) {
mThemeCombo.setEnabled(true);
@@ -630,142 +464,8 @@ public class ConfigurationComposite extends Composite {
public void setConfiguration(FolderConfiguration config, boolean force) {
mDisableUpdates = true; // we do not want to trigger onXXXChange when setting new values in the widgets.
mCountryIcon.setImage(mMatchImage);
CountryCodeQualifier countryQualifier = config.getCountryCodeQualifier();
if (countryQualifier != null) {
mCountry.setText(String.format("%1$d", countryQualifier.getCode()));
mCurrentConfig.setCountryCodeQualifier(countryQualifier);
} else if (force) {
mCountry.setText(""); //$NON-NLS-1$
mCurrentConfig.setCountryCodeQualifier(null);
} else if (mCountry.getText().length() > 0) {
mCountryIcon.setImage(mWarningImage);
}
// TODO: find a device that can display this particular config or create a custom one if needed.
mNetworkIcon.setImage(mMatchImage);
NetworkCodeQualifier networkQualifier = config.getNetworkCodeQualifier();
if (networkQualifier != null) {
mNetwork.setText(String.format("%1$d", networkQualifier.getCode()));
mCurrentConfig.setNetworkCodeQualifier(networkQualifier);
} else if (force) {
mNetwork.setText(""); //$NON-NLS-1$
mCurrentConfig.setNetworkCodeQualifier(null);
} else if (mNetwork.getText().length() > 0) {
mNetworkIcon.setImage(mWarningImage);
}
mLanguageIcon.setImage(mMatchImage);
LanguageQualifier languageQualifier = config.getLanguageQualifier();
if (languageQualifier != null) {
mLanguage.setText(languageQualifier.getValue());
mCurrentConfig.setLanguageQualifier(languageQualifier);
} else if (force) {
mLanguage.setText(""); //$NON-NLS-1$
mCurrentConfig.setLanguageQualifier(null);
} else if (mLanguage.getText().length() > 0) {
mLanguageIcon.setImage(mWarningImage);
}
mRegionIcon.setImage(mMatchImage);
RegionQualifier regionQualifier = config.getRegionQualifier();
if (regionQualifier != null) {
mRegion.setText(regionQualifier.getValue());
mCurrentConfig.setRegionQualifier(regionQualifier);
} else if (force) {
mRegion.setText(""); //$NON-NLS-1$
mCurrentConfig.setRegionQualifier(null);
} else if (mRegion.getText().length() > 0) {
mRegionIcon.setImage(mWarningImage);
}
mOrientationIcon.setImage(mMatchImage);
ScreenOrientationQualifier orientationQualifier = config.getScreenOrientationQualifier();
if (orientationQualifier != null) {
mOrientation.select(
ScreenOrientation.getIndex(orientationQualifier.getValue()) + 1);
mCurrentConfig.setScreenOrientationQualifier(orientationQualifier);
} else if (force) {
mOrientation.select(0);
mCurrentConfig.setScreenOrientationQualifier(null);
} else if (mOrientation.getSelectionIndex() != 0) {
mOrientationIcon.setImage(mWarningImage);
}
mDensityIcon.setImage(mMatchImage);
PixelDensityQualifier densityQualifier = config.getPixelDensityQualifier();
if (densityQualifier != null) {
mDensity.select(
Density.getIndex(densityQualifier.getValue()) + 1);
mCurrentConfig.setPixelDensityQualifier(densityQualifier);
} else if (force) {
mDensity.select(0);
mCurrentConfig.setPixelDensityQualifier(null);
} else if (mDensity.getSelectionIndex() != 0) {
mDensityIcon.setImage(mWarningImage);
}
mTouchIcon.setImage(mMatchImage);
TouchScreenQualifier touchQualifier = config.getTouchTypeQualifier();
if (touchQualifier != null) {
mTouch.select(TouchScreenType.getIndex(touchQualifier.getValue()) + 1);
mCurrentConfig.setTouchTypeQualifier(touchQualifier);
} else if (force) {
mTouch.select(0);
mCurrentConfig.setTouchTypeQualifier(null);
} else if (mTouch.getSelectionIndex() != 0) {
mTouchIcon.setImage(mWarningImage);
}
mKeyboardIcon.setImage(mMatchImage);
KeyboardStateQualifier keyboardQualifier = config.getKeyboardStateQualifier();
if (keyboardQualifier != null) {
mKeyboard.select(KeyboardState.getIndex(keyboardQualifier.getValue()) + 1);
mCurrentConfig.setKeyboardStateQualifier(keyboardQualifier);
} else if (force) {
mKeyboard.select(0);
mCurrentConfig.setKeyboardStateQualifier(null);
} else if (mKeyboard.getSelectionIndex() != 0) {
mKeyboardIcon.setImage(mWarningImage);
}
mTextInputIcon.setImage(mMatchImage);
TextInputMethodQualifier inputQualifier = config.getTextInputMethodQualifier();
if (inputQualifier != null) {
mTextInput.select(TextInputMethod.getIndex(inputQualifier.getValue()) + 1);
mCurrentConfig.setTextInputMethodQualifier(inputQualifier);
} else if (force) {
mTextInput.select(0);
mCurrentConfig.setTextInputMethodQualifier(null);
} else if (mTextInput.getSelectionIndex() != 0) {
mTextInputIcon.setImage(mWarningImage);
}
mNavigationIcon.setImage(mMatchImage);
NavigationMethodQualifier navigationQualifiter = config.getNavigationMethodQualifier();
if (navigationQualifiter != null) {
mNavigation.select(
NavigationMethod.getIndex(navigationQualifiter.getValue()) + 1);
mCurrentConfig.setNavigationMethodQualifier(navigationQualifiter);
} else if (force) {
mNavigation.select(0);
mCurrentConfig.setNavigationMethodQualifier(null);
} else if (mNavigation.getSelectionIndex() != 0) {
mNavigationIcon.setImage(mWarningImage);
}
mSizeIcon.setImage(mMatchImage);
ScreenDimensionQualifier sizeQualifier = config.getScreenDimensionQualifier();
if (sizeQualifier != null) {
mSize1.setText(String.format("%1$d", sizeQualifier.getValue1()));
mSize2.setText(String.format("%1$d", sizeQualifier.getValue2()));
mCurrentConfig.setScreenDimensionQualifier(sizeQualifier);
} else if (force) {
mSize1.setText(""); //$NON-NLS-1$
mSize2.setText(""); //$NON-NLS-1$
mCurrentConfig.setScreenDimensionQualifier(null);
} else if (mSize1.getText().length() > 0 && mSize2.getText().length() > 0) {
mSizeIcon.setImage(mWarningImage);
}
// update the string showing the folder name
String current = config.toDisplayString();
@@ -774,85 +474,6 @@ public class ConfigurationComposite extends Composite {
mDisableUpdates = false;
}
/**
* Displays an error icon in front of all the non-null qualifiers.
*/
public void displayConfigError() {
mCountryIcon.setImage(mMatchImage);
CountryCodeQualifier countryQualifier = mCurrentConfig.getCountryCodeQualifier();
if (countryQualifier != null) {
mCountryIcon.setImage(mErrorImage);
}
mNetworkIcon.setImage(mMatchImage);
NetworkCodeQualifier networkQualifier = mCurrentConfig.getNetworkCodeQualifier();
if (networkQualifier != null) {
mNetworkIcon.setImage(mErrorImage);
}
mLanguageIcon.setImage(mMatchImage);
LanguageQualifier languageQualifier = mCurrentConfig.getLanguageQualifier();
if (languageQualifier != null) {
mLanguageIcon.setImage(mErrorImage);
}
mRegionIcon.setImage(mMatchImage);
RegionQualifier regionQualifier = mCurrentConfig.getRegionQualifier();
if (regionQualifier != null) {
mRegionIcon.setImage(mErrorImage);
}
mOrientationIcon.setImage(mMatchImage);
ScreenOrientationQualifier orientationQualifier =
mCurrentConfig.getScreenOrientationQualifier();
if (orientationQualifier != null) {
mOrientationIcon.setImage(mErrorImage);
}
mDensityIcon.setImage(mMatchImage);
PixelDensityQualifier densityQualifier = mCurrentConfig.getPixelDensityQualifier();
if (densityQualifier != null) {
mDensityIcon.setImage(mErrorImage);
}
mTouchIcon.setImage(mMatchImage);
TouchScreenQualifier touchQualifier = mCurrentConfig.getTouchTypeQualifier();
if (touchQualifier != null) {
mTouchIcon.setImage(mErrorImage);
}
mKeyboardIcon.setImage(mMatchImage);
KeyboardStateQualifier keyboardQualifier = mCurrentConfig.getKeyboardStateQualifier();
if (keyboardQualifier != null) {
mKeyboardIcon.setImage(mErrorImage);
}
mTextInputIcon.setImage(mMatchImage);
TextInputMethodQualifier inputQualifier = mCurrentConfig.getTextInputMethodQualifier();
if (inputQualifier != null) {
mTextInputIcon.setImage(mErrorImage);
}
mNavigationIcon.setImage(mMatchImage);
NavigationMethodQualifier navigationQualifiter =
mCurrentConfig.getNavigationMethodQualifier();
if (navigationQualifiter != null) {
mNavigationIcon.setImage(mErrorImage);
}
mSizeIcon.setImage(mMatchImage);
ScreenDimensionQualifier sizeQualifier = mCurrentConfig.getScreenDimensionQualifier();
if (sizeQualifier != null) {
mSizeIcon.setImage(mErrorImage);
}
// update the string showing the folder name
String current = mCurrentConfig.toDisplayString();
mCurrentLayoutLabel.setText(current != null ? current : "(Default)");
}
private void onCountryCodeChange() {
// because mCountry triggers onCountryCodeChange at each modification, calling setText()
// will trigger notifications, and we don't want that.
@@ -932,195 +553,68 @@ public class ConfigurationComposite extends Composite {
/**
* Call back for language combo selection
*/
private void onLanguageChange() {
private void onLocaleChange() {
// because mLanguage triggers onLanguageChange at each modification, the filling
// of the combo with data will trigger notifications, and we don't want that.
if (mDisableUpdates == true) {
return;
}
// update the current config
String value = mLanguage.getText();
int localeIndex = mLocale.getSelectionIndex();
ResourceQualifier[] localeQualifiers = mLocaleList.get(localeIndex);
updateRegionUi();
// empty string, means no qualifier.
if (value.length() == 0) {
mCurrentConfig.setLanguageQualifier(null);
} else {
LanguageQualifier qualifier = null;
String segment = LanguageQualifier.getFolderSegment(value);
if (segment != null) {
qualifier = LanguageQualifier.getQualifier(segment);
}
if (qualifier != null) {
mCurrentConfig.setLanguageQualifier(qualifier);
} else {
// Failure! Looks like the value is wrong (for instance a one letter string).
mCurrentConfig.setLanguageQualifier(null);
mLanguageIcon.setImage(mErrorImage);
}
}
mCurrentConfig.setLanguageQualifier((LanguageQualifier)localeQualifiers[0]); // language
mCurrentConfig.setRegionQualifier((RegionQualifier)localeQualifiers[1]); // region
if (mListener != null) {
mListener.onConfigurationChange();
}
}
private void onRegionChange() {
// because mRegion triggers onRegionChange at each modification, the filling
// of the combo with data will trigger notifications, and we don't want that.
if (mDisableUpdates == true) {
return;
private void onDeviceChange() {
int deviceIndex = mDeviceList.getSelectionIndex();
DeviceConfiguration device = mDevices[deviceIndex];
mDeviceConfigs.removeAll();
Set<String> configNames = device.getConfigs().keySet();
for (String name : configNames) {
mDeviceConfigs.add(name);
}
// update the current config
String value = mRegion.getText();
// empty string, means no qualifier.
if (value.length() == 0) {
mCurrentConfig.setRegionQualifier(null);
} else {
RegionQualifier qualifier = null;
String segment = RegionQualifier.getFolderSegment(value);
if (segment != null) {
qualifier = RegionQualifier.getQualifier(segment);
}
if (qualifier != null) {
mCurrentConfig.setRegionQualifier(qualifier);
} else {
// Failure! Looks like the value is wrong (for instance a one letter string).
mCurrentConfig.setRegionQualifier(null);
mRegionIcon.setImage(mErrorImage);
}
mDeviceConfigs.select(0);
if (configNames.size() == 1) {
mDeviceConfigs.setEnabled(false);
}
if (mListener != null) {
mListener.onConfigurationChange();
}
onDeviceConfigChange();
}
private void onOrientationChange() {
// update the current config
int index = mOrientation.getSelectionIndex();
if (index != 0) {
mCurrentConfig.setScreenOrientationQualifier(new ScreenOrientationQualifier(
ScreenOrientation.getByIndex(index-1)));
} else {
mCurrentConfig.setScreenOrientationQualifier(null);
}
private void onDeviceConfigChange() {
int deviceIndex = mDeviceList.getSelectionIndex();
DeviceConfiguration device = mDevices[deviceIndex];
if (mListener != null) {
mListener.onConfigurationChange();
}
}
int configIndex = mDeviceConfigs.getSelectionIndex();
String name = mDeviceConfigs.getItem(configIndex);
FolderConfiguration config = device.getConfigs().get(name);
private void onDensityChange() {
int index = mDensity.getSelectionIndex();
if (index != 0) {
mCurrentConfig.setPixelDensityQualifier((new PixelDensityQualifier(
Density.getByIndex(index-1))));
} else {
mCurrentConfig.setPixelDensityQualifier(null);
}
// get the current qualifiers from the current config
CountryCodeQualifier mcc = mCurrentConfig.getCountryCodeQualifier();
NetworkCodeQualifier mnc = mCurrentConfig.getNetworkCodeQualifier();
LanguageQualifier lang = mCurrentConfig.getLanguageQualifier();
RegionQualifier region = mCurrentConfig.getRegionQualifier();
VersionQualifier version = mCurrentConfig.getVersionQualifier();
if (mListener != null) {
mListener.onConfigurationChange();
}
}
// replace the config with the one from the device
mCurrentConfig.set(config);
private void onTouchChange() {
// update the current config
int index = mTouch.getSelectionIndex();
if (index != 0) {
mCurrentConfig.setTouchTypeQualifier(new TouchScreenQualifier(
TouchScreenType.getByIndex(index-1)));
} else {
mCurrentConfig.setTouchTypeQualifier(null);
}
if (mListener != null) {
mListener.onConfigurationChange();
}
}
private void onKeyboardChange() {
// update the current config
int index = mKeyboard.getSelectionIndex();
if (index != 0) {
mCurrentConfig.setKeyboardStateQualifier(new KeyboardStateQualifier(
KeyboardState.getByIndex(index-1)));
} else {
mCurrentConfig.setKeyboardStateQualifier(null);
}
if (mListener != null) {
mListener.onConfigurationChange();
}
}
private void onTextInputChange() {
// update the current config
int index = mTextInput.getSelectionIndex();
if (index != 0) {
mCurrentConfig.setTextInputMethodQualifier(new TextInputMethodQualifier(
TextInputMethod.getByIndex(index-1)));
} else {
mCurrentConfig.setTextInputMethodQualifier(null);
}
if (mListener != null) {
mListener.onConfigurationChange();
}
}
private void onNavigationChange() {
// update the current config
int index = mNavigation.getSelectionIndex();
if (index != 0) {
mCurrentConfig.setNavigationMethodQualifier(new NavigationMethodQualifier(
NavigationMethod.getByIndex(index-1)));
} else {
mCurrentConfig.setNavigationMethodQualifier(null);
}
if (mListener != null) {
mListener.onConfigurationChange();
}
}
private void onSizeChange() {
// because mSize1 and mSize2 trigger onSizeChange at each modification, calling setText()
// will trigger notifications, and we don't want that.
if (mDisableUpdates == true) {
return;
}
// update the current config
String size1 = mSize1.getText();
String size2 = mSize2.getText();
// if only one of the strings is empty, do nothing
if ((size1.length() == 0) ^ (size2.length() == 0)) {
mSizeIcon.setImage(mErrorImage);
return;
} else if (size1.length() == 0 && size2.length() == 0) {
// both sizes are empty: remove the qualifier.
mCurrentConfig.setScreenDimensionQualifier(null);
} else {
ScreenDimensionQualifier qualifier = ScreenDimensionQualifier.getQualifier(size1,
size2);
if (qualifier != null) {
mCurrentConfig.setScreenDimensionQualifier(qualifier);
} else {
// Failure! Looks like the value is wrong.
// we do nothing in this case.
return;
}
}
// and put back the rest of the qualifiers
mCurrentConfig.addQualifier(mcc);
mCurrentConfig.addQualifier(mnc);
mCurrentConfig.addQualifier(lang);
mCurrentConfig.addQualifier(region);
mCurrentConfig.addQualifier(version);
if (mListener != null) {
mListener.onConfigurationChange();
@@ -1167,49 +661,6 @@ public class ConfigurationComposite extends Composite {
return icon;
}
/**
* Update the Region UI widget based on the current language selection
* @param projectResources the project resources or {@code null}.
* @param frameworkResources the framework resource or {@code null}
*/
private void updateRegionUi() {
if (mListener == null) {
return;
}
ProjectResources projectResources = mListener.getProjectResources();
ProjectResources frameworkResources = mListener.getFrameworkResources();
String currentLanguage = mLanguage.getText();
Set<String> set = null;
if (projectResources != null) {
set = projectResources.getRegions(currentLanguage);
}
if (frameworkResources != null) {
if (set != null) {
Set<String> set2 = frameworkResources.getRegions(currentLanguage);
set.addAll(set2);
} else {
set = frameworkResources.getRegions(currentLanguage);
}
}
if (set != null) {
mDisableUpdates = true;
mRegion.removeAll();
for (String region : set) {
mRegion.add(region);
}
mDisableUpdates = false;
}
}
/**
* Returns whether the given <var>style</var> is a theme.
* This is done by making sure the parent is a theme.

View File

@@ -314,8 +314,11 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
for (ResourceQualifier qualifier : mQualifiers) {
if (qualifier != null) {
result.append(QUALIFIER_SEP);
result.append(qualifier.getFolderSegment(target));
String segment = qualifier.getFolderSegment(target);
if (segment != null && segment.length() > 0) {
result.append(QUALIFIER_SEP);
result.append(segment);
}
}
}

View File

@@ -63,6 +63,14 @@ public final class LanguageQualifier extends ResourceQualifier {
return null;
}
public LanguageQualifier() {
}
public LanguageQualifier(String value) {
mValue = value;
}
public String getValue() {
if (mValue != null) {
return mValue;

View File

@@ -134,8 +134,7 @@ public final class NavigationMethodQualifier extends ResourceQualifier {
public boolean checkAndSet(String value, FolderConfiguration config) {
NavigationMethod method = NavigationMethod.getEnum(value);
if (method != null) {
NavigationMethodQualifier qualifier = new NavigationMethodQualifier();
qualifier.mValue = method;
NavigationMethodQualifier qualifier = new NavigationMethodQualifier(method);
config.setNavigationMethodQualifier(qualifier);
return true;
}

View File

@@ -67,6 +67,14 @@ public final class RegionQualifier extends ResourceQualifier {
return ""; //$NON-NLS-1$
}
public RegionQualifier() {
}
public RegionQualifier(String value) {
mValue = value;
}
public String getValue() {
if (mValue != null) {
return mValue;

View File

@@ -48,6 +48,15 @@ public final class ScreenDimensionQualifier extends ResourceQualifier {
* Default value is <code>DEFAULT_SIZE</code> */
private int mValue2 = DEFAULT_SIZE;
public ScreenDimensionQualifier() {
// pass
}
public ScreenDimensionQualifier(int value1, int value2) {
mValue1 = value1;
mValue2 = value2;
}
public int getValue1() {
return mValue1;
}

View File

@@ -32,10 +32,11 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
/**
* Represents the resources of a project. This is a file view of the resources, with handling
@@ -44,30 +45,30 @@ import java.util.Set;
public class ProjectResources implements IResourceRepository {
private final HashMap<ResourceFolderType, List<ResourceFolder>> mFolderMap =
new HashMap<ResourceFolderType, List<ResourceFolder>>();
private final HashMap<ResourceType, List<ProjectResourceItem>> mResourceMap =
new HashMap<ResourceType, List<ProjectResourceItem>>();
/** Map of (name, id) for resources of type {@link ResourceType#ID} coming from R.java */
private Map<String, Map<String, Integer>> mResourceValueMap;
/** Map of (id, [name, resType]) for all resources coming from R.java */
private Map<Integer, String[]> mResIdValueToNameMap;
/** Map of (int[], name) for styleable resources coming from R.java */
private Map<IntArrayWrapper, String> mStyleableValueToNameMap;
/** Cached list of {@link IdResourceItem}. This is mix of IdResourceItem created by
* {@link MultiResourceFile} for ids coming from XML files under res/values and
* {@link IdResourceItem} created manually, from the list coming from R.java */
private final ArrayList<IdResourceItem> mIdResourceList = new ArrayList<IdResourceItem>();
private final boolean mIsFrameworkRepository;
private final IntArrayWrapper mWrapper = new IntArrayWrapper(null);
public ProjectResources(boolean isFrameworkRepository) {
mIsFrameworkRepository = isFrameworkRepository;
}
public boolean isSystemRepository() {
return mIsFrameworkRepository;
}
@@ -83,7 +84,7 @@ public class ProjectResources implements IResourceRepository {
IAbstractFolder folder) {
// get the list for the resource type
List<ResourceFolder> list = mFolderMap.get(type);
if (list == null) {
list = new ArrayList<ResourceFolder>();
@@ -91,7 +92,7 @@ public class ProjectResources implements IResourceRepository {
list.add(cf);
mFolderMap.put(type, list);
return cf;
}
@@ -109,7 +110,7 @@ public class ProjectResources implements IResourceRepository {
// So we add one.
ResourceFolder cf = new ResourceFolder(type, config, folder, mIsFrameworkRepository);
list.add(cf);
return cf;
}
@@ -121,7 +122,7 @@ public class ProjectResources implements IResourceRepository {
protected void removeFolder(ResourceFolderType type, IFolder folder) {
// get the list of folders for the resource type.
List<ResourceFolder> list = mFolderMap.get(type);
if (list != null) {
int count = list.size();
for (int i = 0 ; i < count ; i++) {
@@ -129,7 +130,7 @@ public class ProjectResources implements IResourceRepository {
if (resFolder.getFolder().getIFolder().equals(folder)) {
// we found the matching ResourceFolder. we need to remove it.
list.remove(i);
// we now need to invalidate this resource type.
// The easiest way is to touch one of the other folders of the same type.
if (list.size() > 0) {
@@ -146,23 +147,23 @@ public class ProjectResources implements IResourceRepository {
// If we don't find a single folder to touch, then it's fine, as the top
// level items (the list of generated resource types) is not cached
// (for now)
// get the lists of ResourceTypes generated by this ResourceFolderType
ResourceType[] resTypes = FolderTypeRelationship.getRelatedResourceTypes(
type);
// for each of those, make sure to find one folder to touch so that the
// list of ResourceItem associated with the type is rebuilt.
for (ResourceType resType : resTypes) {
// get the list of folder that can generate this type
ResourceFolderType[] folderTypes =
FolderTypeRelationship.getRelatedFolders(resType);
// we only need to touch one folder in any of those (since it's one
// folder per type, not per folder type).
for (ResourceFolderType folderType : folderTypes) {
List<ResourceFolder> resFolders = mFolderMap.get(folderType);
if (resFolders != null && resFolders.size() > 0) {
resFolders.get(0).touch();
break;
@@ -170,7 +171,7 @@ public class ProjectResources implements IResourceRepository {
}
}
}
// we're done updating/touching, we can stop
break;
}
@@ -178,7 +179,7 @@ public class ProjectResources implements IResourceRepository {
}
}
/**
* Returns a list of {@link ResourceFolder} for a specific {@link ResourceFolderType}.
* @param type The {@link ResourceFolderType}
@@ -186,13 +187,13 @@ public class ProjectResources implements IResourceRepository {
public List<ResourceFolder> getFolders(ResourceFolderType type) {
return mFolderMap.get(type);
}
/* (non-Javadoc)
* @see com.android.ide.eclipse.editors.resources.IResourceRepository#getAvailableResourceTypes()
*/
public ResourceType[] getAvailableResourceTypes() {
ArrayList<ResourceType> list = new ArrayList<ResourceType>();
// For each key, we check if there's a single ResourceType match.
// If not, we look for the actual content to give us the resource type.
@@ -213,7 +214,7 @@ public class ProjectResources implements IResourceRepository {
if (folders != null) {
for (ResourceFolder folder : folders) {
Collection<ResourceType> folderContent = folder.getResourceTypes();
// then we add them, but only if they aren't already in the list.
for (ResourceType folderResType : folderContent) {
if (list.indexOf(folderResType) == -1) {
@@ -224,7 +225,7 @@ public class ProjectResources implements IResourceRepository {
}
}
}
// in case ResourceType.ID haven't been added yet because there's no id defined
// in XML, we check on the list of compiled id resources.
if (list.indexOf(ResourceType.ID) == -1 && mResourceValueMap != null) {
@@ -237,7 +238,7 @@ public class ProjectResources implements IResourceRepository {
// at this point the list is full of ResourceType defined in the files.
// We need to sort it.
Collections.sort(list);
return list.toArray(new ResourceType[list.size()]);
}
@@ -246,15 +247,15 @@ public class ProjectResources implements IResourceRepository {
*/
public ProjectResourceItem[] getResources(ResourceType type) {
checkAndUpdate(type);
if (type == ResourceType.ID) {
synchronized (mIdResourceList) {
return mIdResourceList.toArray(new ProjectResourceItem[mIdResourceList.size()]);
}
}
List<ProjectResourceItem> items = mResourceMap.get(type);
return items.toArray(new ProjectResourceItem[items.size()]);
}
@@ -287,10 +288,10 @@ public class ProjectResources implements IResourceRepository {
}
}
}
return null;
}
/**
* Returns the {@link ResourceFile} matching the given name, {@link ResourceFolderType} and
* configuration.
@@ -305,29 +306,29 @@ public class ProjectResources implements IResourceRepository {
// look for folders containing a file with the given name.
ArrayList<ResourceFolder> matchingFolders = new ArrayList<ResourceFolder>();
// remove the folders that do not have a file with the given name, or if their config
// is incompatible.
for (int i = 0 ; i < folders.size(); i++) {
ResourceFolder folder = folders.get(i);
if (folder.hasFile(name) == true) {
matchingFolders.add(folder);
}
}
// from those, get the folder with a config matching the given reference configuration.
Resource match = findMatchingConfiguredResource(matchingFolders, config);
// do we have a matching folder?
if (match instanceof ResourceFolder) {
// get the ResourceFile from the filename
return ((ResourceFolder)match).getFile(name);
}
return null;
}
/**
* Returns the resources values matching a given {@link FolderConfiguration}.
* @param referenceConfig the configuration that each value must match.
@@ -337,7 +338,7 @@ public class ProjectResources implements IResourceRepository {
Map<String, Map<String, IResourceValue>> map =
new HashMap<String, Map<String, IResourceValue>>();
// special case for Id since there's a mix of compiled id (declared inline) and id declared
// in the XML files.
if (mIdResourceList.size() > 0) {
@@ -348,10 +349,10 @@ public class ProjectResources implements IResourceRepository {
idMap.put(id.getName(), new ResourceValue(idType, id.getName(),
mIsFrameworkRepository));
}
map.put(ResourceType.ID.getName(), idMap);
}
Set<ResourceType> keys = mResourceMap.keySet();
for (ResourceType key : keys) {
// we don't process ID resources since we already did it above.
@@ -359,10 +360,10 @@ public class ProjectResources implements IResourceRepository {
map.put(key.getName(), getConfiguredResource(key, referenceConfig));
}
}
return map;
}
/**
* Loads all the resources. Essentially this forces to load the values from the
* {@link ResourceFile} objects to make sure they are up to date and loaded
@@ -371,13 +372,13 @@ public class ProjectResources implements IResourceRepository {
public void loadAll() {
// gets all the resource types available.
ResourceType[] types = getAvailableResourceTypes();
// loop on them and load them
for (ResourceType type: types) {
checkAndUpdate(type);
}
}
/**
* Resolves a compiled resource id into the resource name and type
* @param id
@@ -387,7 +388,7 @@ public class ProjectResources implements IResourceRepository {
if (mResIdValueToNameMap != null) {
return mResIdValueToNameMap.get(id);
}
return null;
}
@@ -399,7 +400,7 @@ public class ProjectResources implements IResourceRepository {
mWrapper.set(id);
return mStyleableValueToNameMap.get(mWrapper);
}
return null;
}
@@ -416,12 +417,12 @@ public class ProjectResources implements IResourceRepository {
return null;
}
/**
* Returns the list of languages used in the resources.
* Returns the sorted list of languages used in the resources.
*/
public Set<String> getLanguages() {
Set<String> set = new HashSet<String>();
public SortedSet<String> getLanguages() {
SortedSet<String> set = new TreeSet<String>();
Collection<List<ResourceFolder>> folderList = mFolderMap.values();
for (List<ResourceFolder> folderSubList : folderList) {
@@ -433,22 +434,22 @@ public class ProjectResources implements IResourceRepository {
}
}
}
return set;
}
/**
* Returns the list of regions used in the resources with the given language.
* Returns the sorted list of regions used in the resources with the given language.
* @param currentLanguage the current language the region must be associated with.
*/
public Set<String> getRegions(String currentLanguage) {
Set<String> set = new HashSet<String>();
public SortedSet<String> getRegions(String currentLanguage) {
SortedSet<String> set = new TreeSet<String>();
Collection<List<ResourceFolder>> folderList = mFolderMap.values();
for (List<ResourceFolder> folderSubList : folderList) {
for (ResourceFolder folder : folderSubList) {
FolderConfiguration config = folder.getConfiguration();
// get the language
LanguageQualifier lang = config.getLanguageQualifier();
if (lang != null && lang.getStringValue().equals(currentLanguage)) {
@@ -459,7 +460,7 @@ public class ProjectResources implements IResourceRepository {
}
}
}
return set;
}
@@ -474,23 +475,23 @@ public class ProjectResources implements IResourceRepository {
FolderConfiguration referenceConfig) {
// get the resource item for the given type
List<ProjectResourceItem> items = mResourceMap.get(type);
// create the map
HashMap<String, IResourceValue> map = new HashMap<String, IResourceValue>();
for (ProjectResourceItem item : items) {
// get the source files generating this resource
List<ResourceFile> list = item.getSourceFileList();
// look for the best match for the given configuration
Resource match = findMatchingConfiguredResource(list, referenceConfig);
if (match instanceof ResourceFile) {
ResourceFile matchResFile = (ResourceFile)match;
// get the value of this configured resource.
IResourceValue value = matchResFile.getValue(type, item.getName());
if (value != null) {
map.put(item.getName(), value);
}
@@ -501,7 +502,7 @@ public class ProjectResources implements IResourceRepository {
}
/**
* Returns the best matching {@link Resource}.
* Returns the best matching {@link Resource}.
* @param resources the list of {@link Resource} to choose from.
* @param referenceConfig the {@link FolderConfiguration} to match.
*/
@@ -512,7 +513,7 @@ public class ProjectResources implements IResourceRepository {
ArrayList<Resource> matchingResources = new ArrayList<Resource>();
for (int i = 0 ; i < resources.size(); i++) {
Resource res = resources.get(i);
int count = res.getConfiguration().match(referenceConfig);
if (count > currentMax) {
matchingResources.clear();
@@ -522,7 +523,7 @@ public class ProjectResources implements IResourceRepository {
matchingResources.add(res);
}
}
// if we have more than one match, we look for the match with the qualifiers with the
// highest priority.
Resource resMatch = null;
@@ -537,7 +538,7 @@ public class ProjectResources implements IResourceRepository {
int highest = -1;
for (int i = 0 ; i < matchingResources.size() ; i++) {
Resource folder = matchingResources.get(i);
// get highest priority qualifiers.
int m = folder.getConfiguration().getHighestPriorityQualifier(startIndex);
@@ -552,12 +553,12 @@ public class ProjectResources implements IResourceRepository {
}
}
}
// at this point, we have a list with 1+ resources that all have the same highest
// priority qualifiers. Go through the list again looking for the next highest
// priority qualifier.
startIndex = highest + 1;
// this should not happen, but it's better to check.
if (matchingResources.size() == tmpResources.size() && highest == -1) {
// this means all the resources match with the same qualifiers
@@ -571,7 +572,7 @@ public class ProjectResources implements IResourceRepository {
}
tmpResources.clear();
}
// we should have only one match here.
resMatch = matchingResources.get(0);
}
@@ -581,7 +582,7 @@ public class ProjectResources implements IResourceRepository {
/**
* Checks if the list of {@link ResourceItem}s for the specified {@link ResourceType} needs
* to be updated.
* to be updated.
* @param type the Resource Type.
*/
private void checkAndUpdate(ResourceType type) {
@@ -590,7 +591,7 @@ public class ProjectResources implements IResourceRepository {
for (ResourceFolderType folderType : folderTypes) {
List<ResourceFolder> folders = mFolderMap.get(folderType);
if (folders != null) {
for (ResourceFolder folder : folders) {
if (folder.isTouched()) {
@@ -618,7 +619,7 @@ public class ProjectResources implements IResourceRepository {
// get the cache list, and lets make a backup
List<ProjectResourceItem> items = mResourceMap.get(type);
List<ProjectResourceItem> backup = new ArrayList<ProjectResourceItem>();
if (items == null) {
items = new ArrayList<ProjectResourceItem>();
mResourceMap.put(type, items);
@@ -629,7 +630,7 @@ public class ProjectResources implements IResourceRepository {
// we reset the list itself.
items.clear();
}
// get the list of folder that can output this type
ResourceFolderType[] folderTypes = FolderTypeRelationship.getRelatedFolders(type);
@@ -656,7 +657,7 @@ public class ProjectResources implements IResourceRepository {
for (int i = 0 ; i < count;) {
// get the "new" item
ProjectResourceItem item = items.get(i);
// look for a similar item in the old list.
ProjectResourceItem foundOldItem = null;
for (ProjectResourceItem oldItem : backup) {
@@ -665,15 +666,15 @@ public class ProjectResources implements IResourceRepository {
break;
}
}
if (foundOldItem != null) {
// erase the data of the old item with the data from the new one.
foundOldItem.replaceWith(item);
// remove the old and new item from their respective lists
items.remove(i);
backup.remove(foundOldItem);
// add the old item to the new list
items.add(foundOldItem);
} else {
@@ -682,7 +683,7 @@ public class ProjectResources implements IResourceRepository {
}
}
}
// if this is the ResourceType.ID, we create the actual list, from this list and
// the compiled resource list.
if (type == ResourceType.ID) {
@@ -694,20 +695,20 @@ public class ProjectResources implements IResourceRepository {
}
/**
* Looks up an existing {@link ProjectResourceItem} by {@link ResourceType} and name.
* Looks up an existing {@link ProjectResourceItem} by {@link ResourceType} and name.
* @param type the Resource Type.
* @param name the Resource name.
* @return the existing ResourceItem or null if no match was found.
*/
protected ProjectResourceItem findResourceItem(ResourceType type, String name) {
List<ProjectResourceItem> list = mResourceMap.get(type);
for (ProjectResourceItem item : list) {
if (name.equals(item.getName())) {
return item;
}
}
return null;
}
@@ -745,13 +746,13 @@ public class ProjectResources implements IResourceRepository {
// empty the current list
mIdResourceList.clear();
// get the list of compile id resources.
Map<String, Integer> idMap = null;
if (mResourceValueMap != null) {
idMap = mResourceValueMap.get(ResourceType.ID.getName());
}
if (idMap == null) {
if (xmlIdResources != null) {
for (ProjectResourceItem resourceItem : xmlIdResources) {
@@ -764,21 +765,21 @@ public class ProjectResources implements IResourceRepository {
} else {
// loop on the full list of id, and look for a match in the old list,
// in the list coming from XML (in case a new XML item was created.)
Set<String> idSet = idMap.keySet();
idLoop: for (String idResource : idSet) {
// first look in the XML list in case an id went from inline to XML declared.
if (xmlIdResources != null) {
for (ProjectResourceItem resourceItem : xmlIdResources) {
if (resourceItem instanceof IdResourceItem &&
if (resourceItem instanceof IdResourceItem &&
resourceItem.getName().equals(idResource)) {
mIdResourceList.add((IdResourceItem)resourceItem);
continue idLoop;
}
}
}
// if we haven't found it, look in the old items.
int count = oldItems.size();
for (int i = 0 ; i < count ; i++) {
@@ -789,14 +790,14 @@ public class ProjectResources implements IResourceRepository {
continue idLoop;
}
}
// if we haven't found it, it looks like it's a new id that was
// declared inline.
mIdResourceList.add(new IdResourceItem(idResource,
true /* isDeclaredInline */));
}
}
// now we sort the list
Collections.sort(mIdResourceList);
}

View File

@@ -36,7 +36,7 @@ import java.util.Map;
* This class contains the data of an Android Target as loaded from the SDK.
*/
public class AndroidTargetData {
public final static int DESCRIPTOR_MANIFEST = 1;
public final static int DESCRIPTOR_LAYOUT = 2;
public final static int DESCRIPTOR_MENU = 3;
@@ -45,15 +45,15 @@ public class AndroidTargetData {
public final static int DESCRIPTOR_SEARCHABLE = 6;
public final static int DESCRIPTOR_PREFERENCES = 7;
public final static int DESCRIPTOR_APPWIDGET_PROVIDER = 8;
public final static class LayoutBridge {
/** Link to the layout bridge */
public ILayoutBridge bridge;
public LoadStatus status = LoadStatus.LOADING;
public ClassLoader classLoader;
public int apiLevel;
}
@@ -67,12 +67,12 @@ public class AndroidTargetData {
* The attribute namespace prefix must be:
* - "android" for AndroidConstants.NS_RESOURCES
* - "xmlns" for the XMLNS URI.
*
*
* This is used for attributes that do not have a unique name, but still need to be populated
* with values in the UI. Uniquely named attributes have their values in {@link #mEnumValueMap}.
*/
private Hashtable<String, String[]> mAttributeValues = new Hashtable<String, String[]>();
private IResourceRepository mSystemResourceRepository;
private AndroidManifestDescriptors mManifestDescriptors;
@@ -86,19 +86,20 @@ public class AndroidTargetData {
private LayoutBridge mLayoutBridge;
private boolean mLayoutBridgeInit = false;
private DeviceConfiguration[] mDevices;
AndroidTargetData(IAndroidTarget androidTarget) {
mTarget = androidTarget;
}
void setDexWrapper(DexWrapper wrapper) {
mDexWrapper = wrapper;
}
/**
* Creates an AndroidTargetData object.
* @param platformLibraries
* @param optionalLibraries
* @param platformLibraries
* @param optionalLibraries
*/
void setExtraData(IResourceRepository systemResourceRepository,
AndroidManifestDescriptors manifestDescriptors,
@@ -113,15 +114,17 @@ public class AndroidTargetData {
String[] intentCategoryValues,
String[] platformLibraries,
IOptionalLibrary[] optionalLibraries,
DeviceConfiguration[] devices,
ProjectResources resources,
LayoutBridge layoutBridge) {
mSystemResourceRepository = systemResourceRepository;
mManifestDescriptors = manifestDescriptors;
mLayoutDescriptors = layoutDescriptors;
mMenuDescriptors = menuDescriptors;
mXmlDescriptors = xmlDescriptors;
mEnumValueMap = enumValueMap;
mDevices = devices;
mFrameworkResources = resources;
mLayoutBridge = layoutBridge;
@@ -134,11 +137,11 @@ public class AndroidTargetData {
public DexWrapper getDexWrapper() {
return mDexWrapper;
}
public IResourceRepository getSystemResources() {
return mSystemResourceRepository;
}
/**
* Returns an {@link IDescriptorProvider} from a given Id.
* The Id can be one of {@link #DESCRIPTOR_MANIFEST}, {@link #DESCRIPTOR_LAYOUT},
@@ -168,21 +171,21 @@ public class AndroidTargetData {
throw new IllegalArgumentException();
}
}
/**
* Returns the manifest descriptors.
*/
public AndroidManifestDescriptors getManifestDescriptors() {
return mManifestDescriptors;
}
/**
* Returns the layout Descriptors.
*/
public LayoutDescriptors getLayoutDescriptors() {
return mLayoutDescriptors;
}
/**
* Returns the menu descriptors.
*/
@@ -202,7 +205,7 @@ public class AndroidTargetData {
* <p/>This should only be called for attributes for which possible values depend on the
* parent element node.
* <p/>For attributes that have the same values no matter the parent node, use
* {@link #getEnumValueMap()}.
* {@link #getEnumValueMap()}.
* @param elementName the name of the element containing the attribute.
* @param attributeName the name of the attribute
* @return an array of String with the possible values, or <code>null</code> if no values were
@@ -220,7 +223,7 @@ public class AndroidTargetData {
* <p/>The typical example of this is for the 'name' attribute under
* activity/intent-filter/action
* <p/>For attributes that have the same values no matter the parent node, use
* {@link #getEnumValueMap()}.
* {@link #getEnumValueMap()}.
* @param elementName the name of the element containing the attribute.
* @param attributeName the name of the attribute
* @param greatGrandParentElementName the great-grand-parent node.
@@ -231,13 +234,13 @@ public class AndroidTargetData {
String greatGrandParentElementName) {
if (greatGrandParentElementName != null) {
String key = String.format("(%1$s,%2$s,%3$s)", //$NON-NLS-1$
greatGrandParentElementName, elementName, attributeName);
greatGrandParentElementName, elementName, attributeName);
String[] values = mAttributeValues.get(key);
if (values != null) {
return values;
}
}
return getAttributeValues(elementName, attributeName);
}
@@ -250,14 +253,14 @@ public class AndroidTargetData {
public Map<String, Map<String, Integer>> getEnumValueMap() {
return mEnumValueMap;
}
/**
* Returns the {@link ProjectResources} containing the Framework Resources.
*/
public ProjectResources getFrameworkResources() {
return mFrameworkResources;
}
/**
* Returns a {@link LayoutBridge} object possibly containing a {@link ILayoutBridge} object.
* <p/>If {@link LayoutBridge#bridge} is <code>null</code>, {@link LayoutBridge#status} will
@@ -272,7 +275,11 @@ public class AndroidTargetData {
}
return mLayoutBridge;
}
public DeviceConfiguration[] getDevices() {
return mDevices;
}
/**
* Sets the permission values
* @param permissionValues the list of permissions
@@ -285,7 +292,7 @@ public class AndroidTargetData {
setValues("(service,android:permission)", permissionValues); //$NON-NLS-1$
setValues("(provider,android:permission)", permissionValues); //$NON-NLS-1$
}
private void setIntentFilterActionsAndCategories(String[] activityIntentActions,
String[] broadcastIntentActions, String[] serviceIntentActions,
String[] intentCategoryValues) {
@@ -294,18 +301,18 @@ public class AndroidTargetData {
setValues("(service,action,android:name)", serviceIntentActions); //$NON-NLS-1$
setValues("(category,android:name)", intentCategoryValues); //$NON-NLS-1$
}
private void setOptionalLibraries(String[] platformLibraries,
IOptionalLibrary[] optionalLibraries) {
ArrayList<String> libs = new ArrayList<String>();
if (platformLibraries != null) {
for (String name : platformLibraries) {
libs.add(name);
}
}
if (optionalLibraries != null) {
for (int i = 0; i < optionalLibraries.length; i++) {
libs.add(optionalLibraries[i].getName());

View File

@@ -254,6 +254,9 @@ public final class AndroidTargetParser {
LayoutBridge layoutBridge = loadLayoutBridge();
progress.worked(1);
// get the devices
DeviceConfiguration[] devices = getDevices();
// and finally create the PlatformData with all that we loaded.
targetData.setExtraData(frameworkRepository,
manifestDescriptors,
@@ -268,6 +271,7 @@ public final class AndroidTargetParser {
categories.toArray(new String[categories.size()]),
mAndroidTarget.getPlatformLibraries(),
mAndroidTarget.getOptionalLibraries(),
devices,
resources,
layoutBridge);
@@ -701,4 +705,10 @@ public final class AndroidTargetParser {
return layoutBridge;
}
private DeviceConfiguration[] getDevices() {
// TODO: load this from the target.
return null;
}
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Eclipse Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.eclipse.org/org/documents/epl-v10.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.ide.eclipse.adt.internal.sdk;
import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;
import com.android.ide.eclipse.adt.internal.resources.configurations.KeyboardStateQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.NavigationMethodQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenDimensionQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenOrientationQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenRatioQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenSizeQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.TextInputMethodQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.KeyboardStateQualifier.KeyboardState;
import com.android.ide.eclipse.adt.internal.resources.configurations.NavigationMethodQualifier.NavigationMethod;
import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier.Density;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenOrientationQualifier.ScreenOrientation;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenRatioQualifier.ScreenRatio;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenSizeQualifier.ScreenSize;
import com.android.ide.eclipse.adt.internal.resources.configurations.TextInputMethodQualifier.TextInputMethod;
import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier.TouchScreenType;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class DeviceConfiguration {
private final String mName;
private Map<String, FolderConfiguration> mMap =
new HashMap<String, FolderConfiguration>();
DeviceConfiguration(String name) {
mName = name;
}
void addConfig(String name, FolderConfiguration config) {
mMap.put(name, config);
}
void seal() {
mMap = Collections.unmodifiableMap(mMap);
}
public String getName() {
return mName;
}
public Map<String, FolderConfiguration> getConfigs() {
return mMap;
}
/**
* temp method returning some hard-coded devices.
* TODO: load devices from the SDK and add-ons and remove this method.
*/
public static DeviceConfiguration[] getDevices() {
DeviceConfiguration adp1 = new DeviceConfiguration("ADP1");
// default config
FolderConfiguration defConfig = new FolderConfiguration();
defConfig.addQualifier(new ScreenSizeQualifier(ScreenSize.NORMAL));
defConfig.addQualifier(new ScreenRatioQualifier(ScreenRatio.NOTLONG));
defConfig.addQualifier(new PixelDensityQualifier(Density.MEDIUM));
defConfig.addQualifier(new TouchScreenQualifier(TouchScreenType.FINGER));
defConfig.addQualifier(new TextInputMethodQualifier(TextInputMethod.QWERTY));
defConfig.addQualifier(new NavigationMethodQualifier(NavigationMethod.TRACKBALL));
defConfig.addQualifier(new ScreenDimensionQualifier(480, 320));
// specific configs
FolderConfiguration closedLand = new FolderConfiguration();
closedLand.set(defConfig);
closedLand.addQualifier(new ScreenOrientationQualifier(ScreenOrientation.LANDSCAPE));
closedLand.addQualifier(new KeyboardStateQualifier(KeyboardState.HIDDEN));
adp1.addConfig("Closed, landscape", closedLand);
FolderConfiguration closedPort = new FolderConfiguration();
closedPort.set(defConfig);
closedPort.addQualifier(new ScreenOrientationQualifier(ScreenOrientation.PORTRAIT));
closedPort.addQualifier(new KeyboardStateQualifier(KeyboardState.HIDDEN));
adp1.addConfig("Closed, portrait", closedPort);
FolderConfiguration opened = new FolderConfiguration();
opened.set(defConfig);
opened.addQualifier(new ScreenOrientationQualifier(ScreenOrientation.LANDSCAPE));
opened.addQualifier(new KeyboardStateQualifier(KeyboardState.EXPOSED));
adp1.addConfig("Opened", opened);
DeviceConfiguration ion = new DeviceConfiguration("Ion");
// default config
defConfig = new FolderConfiguration();
defConfig.addQualifier(new ScreenSizeQualifier(ScreenSize.NORMAL));
defConfig.addQualifier(new ScreenRatioQualifier(ScreenRatio.NOTLONG));
defConfig.addQualifier(new PixelDensityQualifier(Density.MEDIUM));
defConfig.addQualifier(new TouchScreenQualifier(TouchScreenType.FINGER));
defConfig.addQualifier(new KeyboardStateQualifier(KeyboardState.EXPOSED));
defConfig.addQualifier(new TextInputMethodQualifier(TextInputMethod.NOKEY));
defConfig.addQualifier(new NavigationMethodQualifier(NavigationMethod.TRACKBALL));
defConfig.addQualifier(new ScreenDimensionQualifier(480, 320));
// specific configs
FolderConfiguration landscape = new FolderConfiguration();
landscape.set(defConfig);
landscape.addQualifier(new ScreenOrientationQualifier(ScreenOrientation.LANDSCAPE));
ion.addConfig("Landscape", landscape);
FolderConfiguration portrait = new FolderConfiguration();
portrait.set(defConfig);
portrait.addQualifier(new ScreenOrientationQualifier(ScreenOrientation.PORTRAIT));
ion.addConfig("Portrait", portrait);
return new DeviceConfiguration[] { adp1, ion };
}
}