diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-08-11 19:25:59 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-08-11 19:25:59 -0700 |
commit | df3eb2780dc5a4ba8d74da8202436c89b5147686 (patch) | |
tree | 1322c32e50310e149c27c7e13c0fdeb308c38707 | |
parent | 4b94cdff020a67cb4683f1f1200b1f2752e6a9ac (diff) | |
parent | c73f936b21eaff6e14f2b0076f3ea34dc799590a (diff) | |
download | sdk-df3eb2780dc5a4ba8d74da8202436c89b5147686.zip sdk-df3eb2780dc5a4ba8d74da8202436c89b5147686.tar.gz sdk-df3eb2780dc5a4ba8d74da8202436c89b5147686.tar.bz2 |
Merge change 20877 into donut
* changes:
Add internal support for screen size/ratio, and version qualifiers.
5 files changed, 565 insertions, 14 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/FolderConfiguration.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/FolderConfiguration.java index ff8c26a..23a6440 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/FolderConfiguration.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/FolderConfiguration.java @@ -32,18 +32,21 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration private final ResourceQualifier[] mQualifiers = new ResourceQualifier[INDEX_COUNT]; - private final static int INDEX_COUNTRY_CODE = 0; - private final static int INDEX_NETWORK_CODE = 1; - private final static int INDEX_LANGUAGE = 2; - private final static int INDEX_REGION = 3; - private final static int INDEX_SCREEN_ORIENTATION = 4; - private final static int INDEX_PIXEL_DENSITY = 5; - private final static int INDEX_TOUCH_TYPE = 6; - private final static int INDEX_KEYBOARD_STATE = 7; - private final static int INDEX_TEXT_INPUT_METHOD = 8; - private final static int INDEX_NAVIGATION_METHOD = 9; - private final static int INDEX_SCREEN_DIMENSION = 10; - private final static int INDEX_COUNT = 11; + private final static int INDEX_COUNTRY_CODE = 0; + private final static int INDEX_NETWORK_CODE = 1; + private final static int INDEX_LANGUAGE = 2; + private final static int INDEX_REGION = 3; + private final static int INDEX_SCREEN_SIZE = 4; + private final static int INDEX_SCREEN_RATIO = 5; + private final static int INDEX_SCREEN_ORIENTATION = 6; + private final static int INDEX_PIXEL_DENSITY = 7; + private final static int INDEX_TOUCH_TYPE = 8; + private final static int INDEX_KEYBOARD_STATE = 9; + private final static int INDEX_TEXT_INPUT_METHOD = 10; + private final static int INDEX_NAVIGATION_METHOD = 11; + private final static int INDEX_SCREEN_DIMENSION = 12; + private final static int INDEX_VERSION = 13; + private final static int INDEX_COUNT = 14; /** * Sets the config from the qualifiers of a given <var>config</var>. @@ -108,6 +111,10 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration mQualifiers[INDEX_LANGUAGE] = qualifier; } else if (qualifier instanceof RegionQualifier) { mQualifiers[INDEX_REGION] = qualifier; + } else if (qualifier instanceof ScreenSizeQualifier) { + mQualifiers[INDEX_SCREEN_SIZE] = qualifier; + } else if (qualifier instanceof ScreenRatioQualifier) { + mQualifiers[INDEX_SCREEN_RATIO] = qualifier; } else if (qualifier instanceof ScreenOrientationQualifier) { mQualifiers[INDEX_SCREEN_ORIENTATION] = qualifier; } else if (qualifier instanceof PixelDensityQualifier) { @@ -122,6 +129,8 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration mQualifiers[INDEX_NAVIGATION_METHOD] = qualifier; } else if (qualifier instanceof ScreenDimensionQualifier) { mQualifiers[INDEX_SCREEN_DIMENSION] = qualifier; + } else if (qualifier instanceof VersionQualifier) { + mQualifiers[INDEX_VERSION] = qualifier; } } @@ -170,6 +179,22 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration return (RegionQualifier)mQualifiers[INDEX_REGION]; } + public void setScreenSizeQualifier(ScreenSizeQualifier qualifier) { + mQualifiers[INDEX_SCREEN_SIZE] = qualifier; + } + + public ScreenSizeQualifier getScreenSizeQualifier() { + return (ScreenSizeQualifier)mQualifiers[INDEX_SCREEN_SIZE]; + } + + public void setScreenRatioQualifier(ScreenRatioQualifier qualifier) { + mQualifiers[INDEX_SCREEN_RATIO] = qualifier; + } + + public ScreenRatioQualifier getScreenRatioQualifier() { + return (ScreenRatioQualifier)mQualifiers[INDEX_SCREEN_RATIO]; + } + public void setScreenOrientationQualifier(ScreenOrientationQualifier qualifier) { mQualifiers[INDEX_SCREEN_ORIENTATION] = qualifier; } @@ -226,6 +251,14 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration return (ScreenDimensionQualifier)mQualifiers[INDEX_SCREEN_DIMENSION]; } + public void setVersionQualifier(VersionQualifier qualifier) { + mQualifiers[INDEX_VERSION] = qualifier; + } + + public VersionQualifier getVersionQualifier() { + return (VersionQualifier)mQualifiers[INDEX_VERSION]; + } + /** * Returns whether an object is equals to the receiver. */ @@ -467,6 +500,8 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration mQualifiers[INDEX_NETWORK_CODE] = new NetworkCodeQualifier(); mQualifiers[INDEX_LANGUAGE] = new LanguageQualifier(); mQualifiers[INDEX_REGION] = new RegionQualifier(); + mQualifiers[INDEX_SCREEN_SIZE] = new ScreenSizeQualifier(); + mQualifiers[INDEX_SCREEN_RATIO] = new ScreenRatioQualifier(); mQualifiers[INDEX_SCREEN_ORIENTATION] = new ScreenOrientationQualifier(); mQualifiers[INDEX_PIXEL_DENSITY] = new PixelDensityQualifier(); mQualifiers[INDEX_TOUCH_TYPE] = new TouchScreenQualifier(); @@ -474,6 +509,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration mQualifiers[INDEX_TEXT_INPUT_METHOD] = new TextInputMethodQualifier(); mQualifiers[INDEX_NAVIGATION_METHOD] = new NavigationMethodQualifier(); mQualifiers[INDEX_SCREEN_DIMENSION] = new ScreenDimensionQualifier(); + mQualifiers[INDEX_VERSION] = new VersionQualifier(); } /** diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/ScreenRatioQualifier.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/ScreenRatioQualifier.java new file mode 100644 index 0000000..dda49fc --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/ScreenRatioQualifier.java @@ -0,0 +1,180 @@ +/* + * 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.resources.configurations; + +import com.android.ide.eclipse.adt.internal.editors.IconFactory; +import com.android.sdklib.AndroidVersion; +import com.android.sdklib.IAndroidTarget; + +import org.eclipse.swt.graphics.Image; + +public class ScreenRatioQualifier extends ResourceQualifier { + + public static final String NAME = "Screen Ratio"; + + private ScreenRatio mValue = null; + + /** + * Screen Orientation enum. + */ + public static enum ScreenRatio { + NOTLONG("notlong", "Not Long"), //$NON-NLS-1$ + LONG("long", "Long"); //$NON-NLS-1$ + + private String mValue; + private String mDisplayValue; + + private ScreenRatio(String value, String displayValue) { + mValue = value; + mDisplayValue = displayValue; + } + + /** + * Returns the enum for matching the provided qualifier value. + * @param value The qualifier value. + * @return the enum for the qualifier value or null if no matching was found. + */ + static ScreenRatio getEnum(String value) { + for (ScreenRatio orient : values()) { + if (orient.mValue.equals(value)) { + return orient; + } + } + + return null; + } + + public String getValue() { + return mValue; + } + + public String getDisplayValue() { + return mDisplayValue; + } + + public static int getIndex(ScreenRatio orientation) { + int i = 0; + for (ScreenRatio orient : values()) { + if (orient == orientation) { + return i; + } + + i++; + } + + return -1; + } + + public static ScreenRatio getByIndex(int index) { + int i = 0; + for (ScreenRatio orient : values()) { + if (i == index) { + return orient; + } + i++; + } + + return null; + } + } + + public ScreenRatioQualifier() { + } + + public ScreenRatioQualifier(ScreenRatio value) { + mValue = value; + } + + public ScreenRatio getValue() { + return mValue; + } + + @Override + public String getName() { + return NAME; + } + + @Override + public String getShortName() { + return "Ratio"; + } + + @Override + public Image getIcon() { + return IconFactory.getInstance().getIcon("ratio"); //$NON-NLS-1$ + } + + @Override + public boolean isValid() { + return mValue != null; + } + + @Override + public boolean checkAndSet(String value, FolderConfiguration config) { + ScreenRatio size = ScreenRatio.getEnum(value); + if (size != null) { + ScreenRatioQualifier qualifier = new ScreenRatioQualifier(size); + config.setScreenRatioQualifier(qualifier); + return true; + } + + return false; + } + + @Override + public boolean equals(Object qualifier) { + if (qualifier instanceof ScreenRatioQualifier) { + return mValue == ((ScreenRatioQualifier)qualifier).mValue; + } + + return false; + } + + @Override + public int hashCode() { + if (mValue != null) { + return mValue.hashCode(); + } + + return 0; + } + + /** + * Returns the string used to represent this qualifier in the folder name. + */ + @Override + public String getFolderSegment(IAndroidTarget target) { + if (mValue != null) { + AndroidVersion version = target.getVersion(); + if (version.getApiLevel() >= 4 || + (version.getApiLevel() == 3 && "Donut".equals(version.getCodename()))) { + return mValue.getValue(); + } + } + + return ""; //$NON-NLS-1$ + } + + @Override + public String getStringValue() { + if (mValue != null) { + return mValue.getDisplayValue(); + } + + return ""; //$NON-NLS-1$ + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/ScreenSizeQualifier.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/ScreenSizeQualifier.java new file mode 100644 index 0000000..6132193 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/ScreenSizeQualifier.java @@ -0,0 +1,184 @@ +/* + * 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.resources.configurations; + +import com.android.ide.eclipse.adt.internal.editors.IconFactory; +import com.android.sdklib.AndroidVersion; +import com.android.sdklib.IAndroidTarget; + +import org.eclipse.swt.graphics.Image; + +/** + * Resource Qualifier for Screen Size. Size can be "small", "normal", and "large" + */ +public class ScreenSizeQualifier extends ResourceQualifier { + + public static final String NAME = "Screen Size"; + + private ScreenSize mValue = null; + + /** + * Screen Orientation enum. + */ + public static enum ScreenSize { + SMALL("small", "Small"), //$NON-NLS-1$ + NORMAL("normal", "Normal"), //$NON-NLS-1$ + LARGE("large", "Large"); //$NON-NLS-1$ + + private String mValue; + private String mDisplayValue; + + private ScreenSize(String value, String displayValue) { + mValue = value; + mDisplayValue = displayValue; + } + + /** + * Returns the enum for matching the provided qualifier value. + * @param value The qualifier value. + * @return the enum for the qualifier value or null if no matching was found. + */ + static ScreenSize getEnum(String value) { + for (ScreenSize orient : values()) { + if (orient.mValue.equals(value)) { + return orient; + } + } + + return null; + } + + public String getValue() { + return mValue; + } + + public String getDisplayValue() { + return mDisplayValue; + } + + public static int getIndex(ScreenSize orientation) { + int i = 0; + for (ScreenSize orient : values()) { + if (orient == orientation) { + return i; + } + + i++; + } + + return -1; + } + + public static ScreenSize getByIndex(int index) { + int i = 0; + for (ScreenSize orient : values()) { + if (i == index) { + return orient; + } + i++; + } + + return null; + } + } + + public ScreenSizeQualifier() { + } + + public ScreenSizeQualifier(ScreenSize value) { + mValue = value; + } + + public ScreenSize getValue() { + return mValue; + } + + @Override + public String getName() { + return NAME; + } + + @Override + public String getShortName() { + return "Size"; + } + + @Override + public Image getIcon() { + return IconFactory.getInstance().getIcon("size"); //$NON-NLS-1$ + } + + @Override + public boolean isValid() { + return mValue != null; + } + + @Override + public boolean checkAndSet(String value, FolderConfiguration config) { + ScreenSize size = ScreenSize.getEnum(value); + if (size != null) { + ScreenSizeQualifier qualifier = new ScreenSizeQualifier(size); + config.setScreenSizeQualifier(qualifier); + return true; + } + + return false; + } + + @Override + public boolean equals(Object qualifier) { + if (qualifier instanceof ScreenSizeQualifier) { + return mValue == ((ScreenSizeQualifier)qualifier).mValue; + } + + return false; + } + + @Override + public int hashCode() { + if (mValue != null) { + return mValue.hashCode(); + } + + return 0; + } + + /** + * Returns the string used to represent this qualifier in the folder name. + */ + @Override + public String getFolderSegment(IAndroidTarget target) { + if (mValue != null) { + AndroidVersion version = target.getVersion(); + if (version.getApiLevel() >= 4 || + (version.getApiLevel() == 3 && "Donut".equals(version.getCodename()))) { + return mValue.getValue(); + } + } + + return ""; //$NON-NLS-1$ + } + + @Override + public String getStringValue() { + if (mValue != null) { + return mValue.getDisplayValue(); + } + + return ""; //$NON-NLS-1$ + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/VersionQualifier.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/VersionQualifier.java new file mode 100644 index 0000000..c82e7e9 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/VersionQualifier.java @@ -0,0 +1,151 @@ +/* + * 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.resources.configurations; + +import com.android.ide.eclipse.adt.internal.editors.IconFactory; +import com.android.sdklib.AndroidVersion; +import com.android.sdklib.IAndroidTarget; + +import org.eclipse.swt.graphics.Image; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Resource Qualifier for Platform Version. + */ +public final class VersionQualifier extends ResourceQualifier { + /** Default pixel density value. This means the property is not set. */ + private final static int DEFAULT_VERSION = -1; + + private final static Pattern sCountryCodePattern = Pattern.compile("^v(\\d+)$");//$NON-NLS-1$ + + private int mVersion = DEFAULT_VERSION; + + public static final String NAME = "Platform Version"; + + /** + * Creates and returns a qualifier from the given folder segment. If the segment is incorrect, + * <code>null</code> is returned. + * @param segment the folder segment from which to create a qualifier. + * @return a new {@link VersionQualifier} object or <code>null</code> + */ + public static VersionQualifier getQualifier(String segment) { + Matcher m = sCountryCodePattern.matcher(segment); + if (m.matches()) { + String v = m.group(1); + + int code = -1; + try { + code = Integer.parseInt(v); + } catch (NumberFormatException e) { + // looks like the string we extracted wasn't a valid number. + return null; + } + + VersionQualifier qualifier = new VersionQualifier(); + qualifier.mVersion = code; + return qualifier; + } + + return null; + } + + /** + * Returns the folder name segment for the given value. This is equivalent to calling + * {@link #toString()} on a {@link VersionQualifier} object. + * @param version the value of the qualifier, as returned by {@link #getVersion()}. + */ + public static String getFolderSegment(int version) { + if (version != DEFAULT_VERSION) { + return String.format("v%1$d", version); //$NON-NLS-1$ + } + + return ""; //$NON-NLS-1$ + } + + public int getVersion() { + return mVersion; + } + + @Override + public String getName() { + return NAME; + } + + @Override + public String getShortName() { + return "Version"; + } + + @Override + public Image getIcon() { + return IconFactory.getInstance().getIcon("version"); //$NON-NLS-1$ + } + + @Override + public boolean isValid() { + return mVersion != DEFAULT_VERSION; + } + + @Override + public boolean checkAndSet(String value, FolderConfiguration config) { + VersionQualifier qualifier = getQualifier(value); + if (qualifier != null) { + config.setVersionQualifier(qualifier); + return true; + } + + return false; + } + + @Override + public boolean equals(Object qualifier) { + if (qualifier instanceof VersionQualifier) { + return mVersion == ((VersionQualifier)qualifier).mVersion; + } + + return false; + } + + @Override + public int hashCode() { + return mVersion; + } + + /** + * Returns the string used to represent this qualifier in the folder name. + */ + @Override + public String getFolderSegment(IAndroidTarget target) { + AndroidVersion version = target.getVersion(); + if (version.getApiLevel() >= 3) { + return getFolderSegment(mVersion); + } + + return ""; //$NON-NLS-1$ + } + + @Override + public String getStringValue() { + if (mVersion != DEFAULT_VERSION) { + return String.format("v%1$d", mVersion); + } + + return ""; //$NON-NLS-1$ + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/manager/ConfigMatchTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/manager/ConfigMatchTest.java index c93f2a2..7601648 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/manager/ConfigMatchTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/manager/ConfigMatchTest.java @@ -34,7 +34,7 @@ import com.android.ide.eclipse.adt.internal.resources.manager.files.IFileWrapper import com.android.ide.eclipse.adt.internal.resources.manager.files.IFolderWrapper; import com.android.ide.eclipse.mock.FileMock; import com.android.ide.eclipse.mock.FolderMock; -import com.android.sdklib.SdkConstants; +import com.android.sdklib.IAndroidTarget; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -221,7 +221,7 @@ public class ConfigMatchTest extends TestCase { FileMock[] memberList) throws Exception { // figure out the folder name based on the configuration - String folderName = config.getFolderName(ResourceFolderType.LAYOUT); + String folderName = config.getFolderName(ResourceFolderType.LAYOUT, (IAndroidTarget)null); // create the folder mock FolderMock folder = new FolderMock(folderName, memberList); |