diff options
author | Xavier Ducrohet <xav@android.com> | 2011-01-28 15:18:32 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2011-01-28 16:45:05 -0800 |
commit | 1f72cb7cb032538b79e79d6fc7ff3905e9766ce1 (patch) | |
tree | 65cc57954e239cd9cd3c9e302b4e6ad574667a78 /common | |
parent | 2e97908089f76b4c270f018cbd2e1762511df183 (diff) | |
download | sdk-1f72cb7cb032538b79e79d6fc7ff3905e9766ce1.zip sdk-1f72cb7cb032538b79e79d6fc7ff3905e9766ce1.tar.gz sdk-1f72cb7cb032538b79e79d6fc7ff3905e9766ce1.tar.bz2 |
Move Pair and annoatations into resources.jar now renamed as common.jar
Move all the resource query methods that returned an array of 2 Strings
to return a pair of ResourceType and String.
Change-Id: I6b8447aa27005de786e2defef81ad88a72363523
Diffstat (limited to 'common')
21 files changed, 1530 insertions, 0 deletions
diff --git a/common/.classpath b/common/.classpath new file mode 100644 index 0000000..fb50116 --- /dev/null +++ b/common/.classpath @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/common/.gitignore b/common/.gitignore new file mode 100644 index 0000000..fe99505 --- /dev/null +++ b/common/.gitignore @@ -0,0 +1,2 @@ +bin + diff --git a/common/.project b/common/.project new file mode 100644 index 0000000..3a7717d --- /dev/null +++ b/common/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>common</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/common/Android.mk b/common/Android.mk new file mode 100644 index 0000000..aa2ba8e --- /dev/null +++ b/common/Android.mk @@ -0,0 +1,27 @@ +# +# Copyright (C) 2008 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 +# +# 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. +# +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-java-files-under,src) + +LOCAL_JAVA_LIBRARIES := \ + +LOCAL_MODULE := common + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_HOST_JAVA_LIBRARY) diff --git a/common/README.txt b/common/README.txt new file mode 100644 index 0000000..d4c6232 --- /dev/null +++ b/common/README.txt @@ -0,0 +1,14 @@ +common.jar contains resource configuration enums. It is used by various tools, but also +by layoutlib.jar + +Layoutlib.jar is built from frameworks/base.git and therefore is versioned with the platform. + +IMPORTANT NOTE REGARDING CHANGES IN common.jar: + +- The API must stay compatible. This is because while layoutlib.jar compiles against it, + the client provides the implementation and must be able to load earlier versions of layoutlib.jar. + +- Updated version of common should be copied to the current in-dev branch of + prebuilt/common/common/common-prebuilt.jar + The PREBUILT file in the same folder must be updated as well to reflect how to rebuild this + prebuilt jar file.
\ No newline at end of file diff --git a/common/src/com/android/annotations/Nullable.java b/common/src/com/android/annotations/Nullable.java new file mode 100755 index 0000000..0de1b6f --- /dev/null +++ b/common/src/com/android/annotations/Nullable.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2010 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.annotations; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Denotes a parameter or field can be null. + * <p/> + * When decorating a method call parameter, this denotes the parameter can + * legitimately be null and the method will gracefully deal with it. Typically used + * on optional parameters. + * <p/> + * When decorating a method, this denotes the method might legitimately return null. + * <p/> + * This is a marker annotation and it has no specific attributes. + */ +@Retention(RetentionPolicy.SOURCE) +public @interface Nullable { +} diff --git a/common/src/com/android/annotations/VisibleForTesting.java b/common/src/com/android/annotations/VisibleForTesting.java new file mode 100755 index 0000000..6741d93 --- /dev/null +++ b/common/src/com/android/annotations/VisibleForTesting.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2010 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.annotations; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Denotes that the class, method or field has its visibility relaxed so + * that unit tests can access it. + * <p/> + * The <code>visibility</code> argument can be used to specific what the original + * visibility should have been if it had not been made public or package-private for testing. + * The default is to consider the element private. + */ +@Retention(RetentionPolicy.SOURCE) +public @interface VisibleForTesting { + /** + * Intended visibility if the element had not been made public or package-private for + * testing. + */ + enum Visibility { + /** The element should be considered protected. */ + PROTECTED, + /** The element should be considered package-private. */ + PACKAGE, + /** The element should be considered private. */ + PRIVATE + } + + /** + * Intended visibility if the element had not been made public or package-private for testing. + * If not specified, one should assume the element originally intended to be private. + */ + Visibility visibility() default Visibility.PRIVATE; +} diff --git a/common/src/com/android/resources/Density.java b/common/src/com/android/resources/Density.java new file mode 100644 index 0000000..c1d7e3f --- /dev/null +++ b/common/src/com/android/resources/Density.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + + +/** + * Density enum. + * <p/>This is used in the manifest in the uses-configuration node and in the resource folder names + * as well as other places needing to know the density values. + */ +public enum Density implements ResourceEnum { + XHIGH("xhdpi", "X-High Density", 320), //$NON-NLS-1$ + HIGH("hdpi", "High Density", 240), //$NON-NLS-1$ + MEDIUM("mdpi", "Medium Density", 160), //$NON-NLS-1$ + LOW("ldpi", "Low Density", 120), //$NON-NLS-1$ + NODPI("nodpi", "No Density", 0); //$NON-NLS-1$ + + public final static int DEFAULT_DENSITY = 160; + + private final String mValue; + private final String mDisplayValue; + private final int mDensity; + + private Density(String value, String displayValue, int density) { + mValue = value; + mDisplayValue = displayValue; + mDensity = density; + } + + /** + * Returns the enum matching the provided qualifier value. + * @param value The qualifier value. + * @return the enum for the qualifier value or null if no match was found. + */ + public static Density getEnum(String value) { + for (Density orient : values()) { + if (orient.mValue.equals(value)) { + return orient; + } + } + + return null; + } + + /** + * Returns the enum matching the given density value + * @param value The density value. + * @return the enum for the density value or null if no match was found. + */ + public static Density getEnum(int value) { + for (Density d : values()) { + if (d.mDensity == value) { + return d; + } + } + + return null; + } + + public String getResourceValue() { + return mValue; + } + + public int getDpiValue() { + return mDensity; + } + + public String getLegacyValue() { + if (this != NODPI) { + return String.format("%1$ddpi", getDpiValue()); + } + + return ""; + } + + public String getShortDisplayValue() { + return mDisplayValue; + } + + public String getLongDisplayValue() { + return mDisplayValue; + } + + public static int getIndex(Density value) { + int i = 0; + for (Density input : values()) { + if (value == input) { + return i; + } + + i++; + } + + return -1; + } + + public static Density getByIndex(int index) { + int i = 0; + for (Density value : values()) { + if (i == index) { + return value; + } + i++; + } + return null; + } + + public boolean isFakeValue() { + return false; + } + + public boolean isValidValueForDevice() { + return this != NODPI; // nodpi is not a valid config for devices. + } +} diff --git a/common/src/com/android/resources/DockMode.java b/common/src/com/android/resources/DockMode.java new file mode 100644 index 0000000..bbae6bf --- /dev/null +++ b/common/src/com/android/resources/DockMode.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + +/** + * Dock enum. + * <p/>This is used in the resource folder names. + */ +public enum DockMode implements ResourceEnum { + NONE("", "No Dock"), + CAR("car", "Car Dock"), + DESK("desk", "Desk Dock"); + + private final String mValue; + private final String mDisplayValue; + + private DockMode(String value, String display) { + mValue = value; + mDisplayValue = display; + } + + /** + * 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. + */ + public static DockMode getEnum(String value) { + for (DockMode mode : values()) { + if (mode.mValue.equals(value)) { + return mode; + } + } + + return null; + } + + public String getResourceValue() { + return mValue; + } + + public String getShortDisplayValue() { + return mDisplayValue; + } + + public String getLongDisplayValue() { + return mDisplayValue; + } + + public static int getIndex(DockMode value) { + int i = 0; + for (DockMode mode : values()) { + if (mode == value) { + return i; + } + + i++; + } + + return -1; + } + + public static DockMode getByIndex(int index) { + int i = 0; + for (DockMode value : values()) { + if (i == index) { + return value; + } + i++; + } + return null; + } + + public boolean isFakeValue() { + return this == NONE; // NONE is not a real enum. it's used for internal state only. + } + + public boolean isValidValueForDevice() { + return this != NONE; + } +} diff --git a/common/src/com/android/resources/Keyboard.java b/common/src/com/android/resources/Keyboard.java new file mode 100644 index 0000000..eb99f9b --- /dev/null +++ b/common/src/com/android/resources/Keyboard.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + +/** + * Keyboard enum. + * <p/>This is used in the manifest in the uses-configuration node and in the resource folder names. + */ +public enum Keyboard implements ResourceEnum { + NOKEY("nokeys", null, "No Keys", "No keyboard"), //$NON-NLS-1$ + QWERTY("qwerty", null, "Qwerty", "Qwerty keybard"), //$NON-NLS-1$ + TWELVEKEY("12key", "twelvekey", "12 Key", "12 key keyboard"); //$NON-NLS-1$ //$NON-NLS-2$ + + private final String mValue, mValue2; + private final String mShortDisplayValue; + private final String mLongDisplayValue; + + private Keyboard(String value, String value2, String shortDisplayValue, + String longDisplayValue) { + mValue = value; + mValue2 = value2; + mShortDisplayValue = shortDisplayValue; + mLongDisplayValue = longDisplayValue; + } + + /** + * 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. + */ + public static Keyboard getEnum(String value) { + for (Keyboard kbrd : values()) { + if (kbrd.mValue.equals(value) || + (kbrd.mValue2 != null && kbrd.mValue2.equals(value))) { + return kbrd; + } + } + + return null; + } + + public String getResourceValue() { + return mValue; + } + + public String getShortDisplayValue() { + return mShortDisplayValue; + } + + public String getLongDisplayValue() { + return mLongDisplayValue; + } + + public static int getIndex(Keyboard value) { + int i = 0; + for (Keyboard input : values()) { + if (value == input) { + return i; + } + + i++; + } + + return -1; + } + + public static Keyboard getByIndex(int index) { + int i = 0; + for (Keyboard value : values()) { + if (i == index) { + return value; + } + i++; + } + return null; + } + + public boolean isFakeValue() { + return false; + } + + public boolean isValidValueForDevice() { + return true; + } +} diff --git a/common/src/com/android/resources/KeyboardState.java b/common/src/com/android/resources/KeyboardState.java new file mode 100644 index 0000000..e3333f5 --- /dev/null +++ b/common/src/com/android/resources/KeyboardState.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + +/** + * Keyboard state enum. + * <p/>This is used in the manifest in the uses-configuration node and in the resource folder names. + */ +public enum KeyboardState implements ResourceEnum { + EXPOSED("keysexposed", "Exposed", "Exposed keyboard"), //$NON-NLS-1$ + HIDDEN("keyshidden", "Hidden", "Hidden keyboard"), //$NON-NLS-1$ + SOFT("keyssoft", "Soft", "Soft keyboard"); //$NON-NLS-1$ + + private final String mValue; + private final String mShortDisplayValue; + private final String mLongDisplayValue; + + private KeyboardState(String value, String shortDisplayValue, String longDisplayValue) { + mValue = value; + mShortDisplayValue = shortDisplayValue; + mLongDisplayValue = longDisplayValue; + } + + /** + * 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. + */ + public static KeyboardState getEnum(String value) { + for (KeyboardState state : values()) { + if (state.mValue.equals(value)) { + return state; + } + } + + return null; + } + + public String getResourceValue() { + return mValue; + } + + public String getShortDisplayValue() { + return mShortDisplayValue; + } + + public String getLongDisplayValue() { + return mLongDisplayValue; + } + + public static int getIndex(KeyboardState value) { + int i = 0; + for (KeyboardState input : values()) { + if (value == input) { + return i; + } + + i++; + } + + return -1; + } + + public static KeyboardState getByIndex(int index) { + int i = 0; + for (KeyboardState value : values()) { + if (i == index) { + return value; + } + i++; + } + return null; + } + + public boolean isFakeValue() { + return false; + } + + public boolean isValidValueForDevice() { + return true; + } + +} diff --git a/common/src/com/android/resources/Navigation.java b/common/src/com/android/resources/Navigation.java new file mode 100644 index 0000000..d5d9541 --- /dev/null +++ b/common/src/com/android/resources/Navigation.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + +/** + * Navigation enum. + * <p/>This is used in the manifest in the uses-configuration node and in the resource folder names. + */ +public enum Navigation implements ResourceEnum { + NONAV("nonav", "None", "No navigation"), //$NON-NLS-1$ + DPAD("dpad", "D-pad", "D-pad navigation"), //$NON-NLS-1$ + TRACKBALL("trackball", "Trackball", "Trackball navigation"), //$NON-NLS-1$ + WHEEL("wheel", "Wheel", "Wheel navigation"); //$NON-NLS-1$ + + private final String mValue; + private final String mShortDisplayValue; + private final String mLongDisplayValue; + + private Navigation(String value, String shortDisplayValue, String longDisplayValue) { + mValue = value; + mShortDisplayValue = shortDisplayValue; + mLongDisplayValue = longDisplayValue; + } + + /** + * 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. + */ + public static Navigation getEnum(String value) { + for (Navigation nav : values()) { + if (nav.mValue.equals(value)) { + return nav; + } + } + + return null; + } + + public String getResourceValue() { + return mValue; + } + + public String getShortDisplayValue() { + return mShortDisplayValue; + } + + public String getLongDisplayValue() { + return mLongDisplayValue; + } + + public static int getIndex(Navigation value) { + int i = 0; + for (Navigation nav : values()) { + if (nav == value) { + return i; + } + + i++; + } + + return -1; + } + + public static Navigation getByIndex(int index) { + int i = 0; + for (Navigation value : values()) { + if (i == index) { + return value; + } + i++; + } + return null; + } + + public boolean isFakeValue() { + return false; + } + + public boolean isValidValueForDevice() { + return true; + } + +}
\ No newline at end of file diff --git a/common/src/com/android/resources/NavigationState.java b/common/src/com/android/resources/NavigationState.java new file mode 100644 index 0000000..266d9da --- /dev/null +++ b/common/src/com/android/resources/NavigationState.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + +/** + * Navigation state enum. + * <p/>This is used in the resource folder names. + */ +public enum NavigationState implements ResourceEnum { + EXPOSED("navexposed", "Exposed", "Exposed navigation"), //$NON-NLS-1$ + HIDDEN("navhidden", "Hidden", "Hidden navigation"); //$NON-NLS-1$ + + private final String mValue; + private final String mShortDisplayValue; + private final String mLongDisplayValue; + + private NavigationState(String value, String shortDisplayValue, String longDisplayValue) { + mValue = value; + mShortDisplayValue = shortDisplayValue; + mLongDisplayValue = longDisplayValue; + } + + /** + * 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. + */ + public static NavigationState getEnum(String value) { + for (NavigationState state : values()) { + if (state.mValue.equals(value)) { + return state; + } + } + + return null; + } + + public String getResourceValue() { + return mValue; + } + + public String getShortDisplayValue() { + return mShortDisplayValue; + } + + public String getLongDisplayValue() { + return mLongDisplayValue; + } + + public static int getIndex(NavigationState value) { + int i = 0; + for (NavigationState input : values()) { + if (value == input) { + return i; + } + + i++; + } + + return -1; + } + + public static NavigationState getByIndex(int index) { + int i = 0; + for (NavigationState value : values()) { + if (i == index) { + return value; + } + i++; + } + return null; + } + + public boolean isFakeValue() { + return false; + } + + public boolean isValidValueForDevice() { + return true; + } + +} diff --git a/common/src/com/android/resources/NightMode.java b/common/src/com/android/resources/NightMode.java new file mode 100644 index 0000000..2d64316 --- /dev/null +++ b/common/src/com/android/resources/NightMode.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + +/** + * Night enum. + * <p/>This is used in the resource folder names. + */ +public enum NightMode implements ResourceEnum { + NOTNIGHT("notnight", "Not Night", "Day time"), + NIGHT("night", "Night", "Night time"); + + private final String mValue; + private final String mShortDisplayValue; + private final String mLongDisplayValue; + + private NightMode(String value, String shortDisplayValue, String longDisplayValue) { + mValue = value; + mShortDisplayValue = shortDisplayValue; + mLongDisplayValue = longDisplayValue; + } + + /** + * 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. + */ + public static NightMode getEnum(String value) { + for (NightMode mode : values()) { + if (mode.mValue.equals(value)) { + return mode; + } + } + + return null; + } + + public String getResourceValue() { + return mValue; + } + + public String getShortDisplayValue() { + return mShortDisplayValue; + } + + public String getLongDisplayValue() { + return mLongDisplayValue; + } + + public static int getIndex(NightMode value) { + int i = 0; + for (NightMode mode : values()) { + if (mode == value) { + return i; + } + + i++; + } + + return -1; + } + + public static NightMode getByIndex(int index) { + int i = 0; + for (NightMode value : values()) { + if (i == index) { + return value; + } + i++; + } + return null; + } + + public boolean isFakeValue() { + return false; + } + + public boolean isValidValueForDevice() { + return true; + } + +} diff --git a/common/src/com/android/resources/ResourceEnum.java b/common/src/com/android/resources/ResourceEnum.java new file mode 100644 index 0000000..7f4e16a --- /dev/null +++ b/common/src/com/android/resources/ResourceEnum.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + +/** + * An enum representing a resource qualifier value. + */ +public interface ResourceEnum { + + /** + * Returns the resource string. This is to be used in resource folder names. + */ + String getResourceValue(); + + /** + * Whether the value actually used on device. This returns true only if a device can report + * this value, false if it's just used to qualify resources. + */ + boolean isValidValueForDevice(); + + /** + * Whether the value is neither used for device nor resources. This returns false when + * the value is only used for internal usage in the custom editors. + */ + boolean isFakeValue(); + + /** + * Returns a short string for display value. The string does not need to show the context. + * <p/>For instance "exposed", which can be the value for the keyboard state or the navigation + * state, would be valid since something else in the UI is expected to show if this is about the + * keyboard or the navigation state. + * + * @see #getLongDisplayValue() + */ + String getShortDisplayValue(); + + /** + * Returns a long string for display value. This must not only include the enum value but + * context (qualifier) about what the value represents. + * <p/>For instance "Exposed keyboard", and "Export navigation", as "exposed" would not be + * enough to know what qualifier the value is about. + * + * @see #getShortDisplayValue() + */ + String getLongDisplayValue(); +} diff --git a/common/src/com/android/resources/ResourceType.java b/common/src/com/android/resources/ResourceType.java new file mode 100644 index 0000000..f5f7063 --- /dev/null +++ b/common/src/com/android/resources/ResourceType.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2007 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.resources; + + +/** + * Enum representing a type of compiled resource. + */ +public enum ResourceType { + ANIM("anim", "Animation"), //$NON-NLS-1$ + ANIMATOR("animator", "Animator"), //$NON-NLS-1$ + ARRAY("array", "Array", "string-array", "integer-array"), //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-4$ + ATTR("attr", "Attr"), //$NON-NLS-1$ + BOOL("bool", "Boolean"), //$NON-NLS-1$ + COLOR("color", "Color"), //$NON-NLS-1$ + DECLARE_STYLEABLE("declare-styleable", "Declare Stylable"), //$NON-NLS-1$ + DIMEN("dimen", "Dimension"), //$NON-NLS-1$ + DRAWABLE("drawable", "Drawable"), //$NON-NLS-1$ + FRACTION("fraction", "Fraction"), //$NON-NLS-1$ + ID("id", "ID"), //$NON-NLS-1$ + INTEGER("integer", "Integer"), //$NON-NLS-1$ + INTERPOLATOR("interpolator", "Interpolator"), //$NON-NLS-1$ + LAYOUT("layout", "Layout"), //$NON-NLS-1$ + MENU("menu", "Menu"), //$NON-NLS-1$ + PLURALS("plurals", "Plurals"), //$NON-NLS-1$ + RAW("raw", "Raw"), //$NON-NLS-1$ + STRING("string", "String"), //$NON-NLS-1$ + STYLE("style", "Style"), //$NON-NLS-1$ + STYLEABLE("styleable", "Styleable"), //$NON-NLS-1$ + XML("xml", "XML"), //$NON-NLS-1$ + // this is not actually used. Only there because they get parsed and since we want to + // detect new resource type, we need to have this one exist. + PUBLIC("public", "###"); //$NON-NLS-1$ //$NON-NLS-2$ + + private final String mName; + private final String mDisplayName; + private final String[] mAlternateXmlNames; + + ResourceType(String name, String displayName, String... alternateXmlNames) { + mName = name; + mDisplayName = displayName; + mAlternateXmlNames = alternateXmlNames; + } + + /** + * Returns the resource type name, as used by XML files. + */ + public String getName() { + return mName; + } + + /** + * Returns a translated display name for the resource type. + */ + public String getDisplayName() { + return mDisplayName; + } + + /** + * Returns the enum by its name as it appears in the XML or the R class. + * @param name name of the resource + * @return the matching {@link ResourceType} or <code>null</code> if no match was found. + */ + public static ResourceType getEnum(String name) { + for (ResourceType rType : values()) { + if (rType.mName.equals(name)) { + return rType; + } else if (rType.mAlternateXmlNames != null) { + // if there are alternate Xml Names, we test those too + for (String alternate : rType.mAlternateXmlNames) { + if (alternate.equals(name)) { + return rType; + } + } + } + } + return null; + } + + /** + * Returns an array with all the names defined by this enum. + */ + public static String[] getNames() { + ResourceType[] values = values(); + String[] names = new String[values.length]; + for (int i = values.length - 1; i >= 0; --i) { + names[i] = values[i].getName(); + } + return names; + } + + @Override + public String toString() { + return getName(); + } +} diff --git a/common/src/com/android/resources/ScreenOrientation.java b/common/src/com/android/resources/ScreenOrientation.java new file mode 100644 index 0000000..56f907b --- /dev/null +++ b/common/src/com/android/resources/ScreenOrientation.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + +/** + * Screen Orientation enum. + * <p/>This is used in the manifest in the uses-configuration node and in the resource folder names. + */ +public enum ScreenOrientation implements ResourceEnum { + PORTRAIT("port", "Portrait", "Portrait Orientation"), //$NON-NLS-1$ + LANDSCAPE("land", "Landscape", "Landscape Orientation"), //$NON-NLS-1$ + SQUARE("square", "Square", "Square Orientation"); //$NON-NLS-1$ + + private final String mValue; + private final String mShortDisplayValue; + private final String mLongDisplayValue; + + private ScreenOrientation(String value, String shortDisplayValue, String longDisplayValue) { + mValue = value; + mShortDisplayValue = shortDisplayValue; + mLongDisplayValue = longDisplayValue; + } + + /** + * 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. + */ + public static ScreenOrientation getEnum(String value) { + for (ScreenOrientation orient : values()) { + if (orient.mValue.equals(value)) { + return orient; + } + } + + return null; + } + + public String getResourceValue() { + return mValue; + } + + public String getShortDisplayValue() { + return mShortDisplayValue; + } + + public String getLongDisplayValue() { + return mLongDisplayValue; + } + + public static int getIndex(ScreenOrientation orientation) { + int i = 0; + for (ScreenOrientation orient : values()) { + if (orient == orientation) { + return i; + } + + i++; + } + + return -1; + } + + public static ScreenOrientation getByIndex(int index) { + int i = 0; + for (ScreenOrientation orient : values()) { + if (i == index) { + return orient; + } + i++; + } + + return null; + } + + public boolean isFakeValue() { + return false; + } + + public boolean isValidValueForDevice() { + return true; + } + +} diff --git a/common/src/com/android/resources/ScreenRatio.java b/common/src/com/android/resources/ScreenRatio.java new file mode 100644 index 0000000..2794b6e --- /dev/null +++ b/common/src/com/android/resources/ScreenRatio.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + +/** + * Screen Ratio enum. + * <p/>This is used in the manifest in the uses-configuration node and in the resource folder names. + */ +public enum ScreenRatio implements ResourceEnum { + NOTLONG("notlong", "Not Long", "Short screen aspect ratio"), //$NON-NLS-1$ + LONG("long", "Long", "Long screen aspect ratio"); //$NON-NLS-1$ + + private final String mValue; + private final String mShortDisplayValue; + private final String mLongDisplayValue; + + private ScreenRatio(String value, String displayValue, String longDisplayValue) { + mValue = value; + mShortDisplayValue = displayValue; + mLongDisplayValue = longDisplayValue; + } + + /** + * 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. + */ + public static ScreenRatio getEnum(String value) { + for (ScreenRatio orient : values()) { + if (orient.mValue.equals(value)) { + return orient; + } + } + + return null; + } + + public String getResourceValue() { + return mValue; + } + + public String getShortDisplayValue() { + return mShortDisplayValue; + } + + public String getLongDisplayValue() { + return mLongDisplayValue; + } + + 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 boolean isFakeValue() { + return false; + } + + public boolean isValidValueForDevice() { + return true; + } + +} + diff --git a/common/src/com/android/resources/ScreenSize.java b/common/src/com/android/resources/ScreenSize.java new file mode 100644 index 0000000..b6ffc50 --- /dev/null +++ b/common/src/com/android/resources/ScreenSize.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + +/** + * Screen size enum. + * <p/>This is used in the manifest in the uses-configuration node and in the resource folder names. + */ +public enum ScreenSize implements ResourceEnum { + SMALL("small", "Small", "Small Screen"), //$NON-NLS-1$ + NORMAL("normal", "Normal", "Normal Screen"), //$NON-NLS-1$ + LARGE("large", "Large", "Large Screen"), //$NON-NLS-1$ + XLARGE("xlarge", "X-Large", "Extra Large Screen"); //$NON-NLS-1$ + + private final String mValue; + private final String mShortDisplayValue; + private final String mLongDisplayValue; + + private ScreenSize(String value, String shortDisplayValue, String longDisplayValue) { + mValue = value; + mShortDisplayValue = shortDisplayValue; + mLongDisplayValue = longDisplayValue; + } + + /** + * 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. + */ + public static ScreenSize getEnum(String value) { + for (ScreenSize orient : values()) { + if (orient.mValue.equals(value)) { + return orient; + } + } + + return null; + } + + public String getResourceValue() { + return mValue; + } + + public String getShortDisplayValue() { + return mShortDisplayValue; + } + + public String getLongDisplayValue() { + return mLongDisplayValue; + } + + 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 boolean isFakeValue() { + return false; + } + + public boolean isValidValueForDevice() { + return true; + } + +} diff --git a/common/src/com/android/resources/TouchScreen.java b/common/src/com/android/resources/TouchScreen.java new file mode 100644 index 0000000..7ee1f0f --- /dev/null +++ b/common/src/com/android/resources/TouchScreen.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources; + +/** + * Touch screen enum. + * <p/>This is used in the manifest in the uses-configuration node and in the resource folder names. + */ +public enum TouchScreen implements ResourceEnum { + NOTOUCH("notouch", "No Touch", "No-touch screen"), //$NON-NLS-1$ + STYLUS("stylus", "Stylus", "Stylus-based touchscreen"), //$NON-NLS-1$ + FINGER("finger", "Finger", "Finger-based touchscreen"); //$NON-NLS-1$ + + private final String mValue; + private final String mShortDisplayValue; + private final String mLongDisplayValue; + + private TouchScreen(String value, String displayValue, String longDisplayValue) { + mValue = value; + mShortDisplayValue = displayValue; + mLongDisplayValue = longDisplayValue; + } + + /** + * 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. + */ + public static TouchScreen getEnum(String value) { + for (TouchScreen orient : values()) { + if (orient.mValue.equals(value)) { + return orient; + } + } + + return null; + } + + public String getResourceValue() { + return mValue; + } + + public String getShortDisplayValue() { + return mShortDisplayValue; + } + + public String getLongDisplayValue() { + return mLongDisplayValue; + } + + public static int getIndex(TouchScreen touch) { + int i = 0; + for (TouchScreen t : values()) { + if (t == touch) { + return i; + } + + i++; + } + + return -1; + } + + public static TouchScreen getByIndex(int index) { + int i = 0; + for (TouchScreen value : values()) { + if (i == index) { + return value; + } + i++; + } + + return null; + } + + public boolean isFakeValue() { + return false; + } + + public boolean isValidValueForDevice() { + return true; + } + +} diff --git a/common/src/com/android/util/Pair.java b/common/src/com/android/util/Pair.java new file mode 100644 index 0000000..8817cd7 --- /dev/null +++ b/common/src/com/android/util/Pair.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.util; + +/** + * A Pair class is simply a 2-tuple for use in this package. We might want to + * think about adding something like this to a more central utility place, or + * replace it by a common tuple class if one exists, or even rewrite the layout + * classes using this Pair by a more dedicated data structure (so we don't have + * to pass around generic signatures as is currently done, though at least the + * construction is helped a bit by the {@link #of} factory method. + * + * @param <S> The type of the first value + * @param <T> The type of the second value + */ +public class Pair<S,T> { + private final S mFirst; + private final T mSecond; + + // Use {@link Pair#of} factory instead since it infers generic types + private Pair(S first, T second) { + this.mFirst = first; + this.mSecond = second; + } + + /** + * Return the first item in the pair + * + * @return the first item in the pair + */ + public S getFirst() { + return mFirst; + } + + /** + * Return the second item in the pair + * + * @return the second item in the pair + */ + public T getSecond() { + return mSecond; + } + + /** + * Constructs a new pair of the given two objects, inferring generic types. + * + * @param first the first item to store in the pair + * @param second the second item to store in the pair + * @param <S> the type of the first item + * @param <T> the type of the second item + * @return a new pair wrapping the two items + */ + public static <S,T> Pair<S,T> of(S first, T second) { + return new Pair<S,T>(first,second); + } + + @Override + public String toString() { + return "Pair [first=" + mFirst + ", second=" + mSecond + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((mFirst == null) ? 0 : mFirst.hashCode()); + result = prime * result + ((mSecond == null) ? 0 : mSecond.hashCode()); + return result; + } + + @SuppressWarnings("unchecked") + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Pair other = (Pair) obj; + if (mFirst == null) { + if (other.mFirst != null) + return false; + } else if (!mFirst.equals(other.mFirst)) + return false; + if (mSecond == null) { + if (other.mSecond != null) + return false; + } else if (!mSecond.equals(other.mSecond)) + return false; + return true; + } +} |